Question: Help me fix this bug: ( Either Lastname or First name is not printing out correctly. ) I provided the C code and the Assembly

Help me fix this bug: (Either Lastname or First name is not printing out correctly.) I provided the C code and the Assembly code I written and what it outputs versus what it should output. The function(read_record) is commented out in C code and used (globl read_record) in assembly.
```
typedef struct {
char *last_name;
char *first_name;
long id_number;
} RECORD;
RECORD *read_record();
/* This function reads in the data for a single record frod
standard input by calling scanf. If scanf succeeds in
reading the data, a new RECOfo is allocated, populated
with the data, and a pointer to the record is returned
*/
/*
REcoRD *read_record()
{
char lastname[190], firstname[180];
RECORD *p;
long id;
int res = scanf("%s %s %ld", lastname, firstname, &id);
if (res == EOF)// EOF is -1
return NULL;
p = malloc(sizeof(RECORD));
p->last_name = malloc(strlen(lastname)+1);
strcpy(p->last_name, lastname);
p->first_name = malloc(strlen(lastname)+1);
strcpy(p->first_name, firstname);
p->id_number = id;
return p;
}
*/
``````
-globl read_record
read_record:
pushq \%rbp
movq \\rsp,%rbp
subq $216,%rsp
pushq \rbx
*Record *p
movq $32, Xrex
call malloc
movq \/rax, Z_bx #saving the pointer of Record into rbx
#scanf inputs
leaq format_str(%%rip), X/rcx
leaq -18e(Xrsp), Yrdx #lastname
leaq -2ee(Xrsp), Xrs #firstnare
leaq -2es(Xrrsp),%rr9 #id
call scanf
crp $-1, Xgax
je fail_scanf
#last_nane
leaq -18e(Xrsp), Zrcx #address of lastnane in rex
call strlen #rax = strlen(lastnane)
addq $ $1,%`rax ##ull terninator
movq \/rax, Zrcx #allocating memory
call malloc
movq \rax, e(Y_(%bx)
leaq -1es(Xrsp), Xrdx #lastnane
movq \rax, Zrcx #nove to destination
call strcpy
#first_name
leaq -2ee(Xrsp), Yrcx #address of first in rcx
call strlen #rax = strlen(firstname)
addqq $1,%rax #null terninator
movq %rax, Zrcx #allocating memory
call malloc
mov \rax,8(Y_rbx) #record->firstnane =...
leaq -28e(%rsp), Z_dx #first
movq \rax, Zrcx #move to destination
call strcpy
*id
movq -2es(%rsp), Zrax
movq %rax,16(%rbx)
#return record pointer
movq \rbx, #rax
addq $216,%rsp
popq \rbx
popq %
retq
fail_scanf:
movq $e,\ rrax
addq $215, $rsp
```
```
popq %rbp
retq
fornst_str:
.asciz "%5%s \ld"
``` Sorted
```
14333263: Vongnorkeo, Anouparb
19917171: Koncke, Gonzalo
20370670: Civili, Patrizio
41723721: Enkhbold, Vorshilov
56982797: Amrit, Deiye
72035786: Abdelaziz, Maged
78313673: Konfourou, Issa
96104140: Stevanovic, Nemanja
98563496: Niang, Cheikh
99243760: Markova, Seid
154646637: Ladeb, Tarek
169570318: Turay, Alhaji
172733459: Andriamiarisoa, Vero
183543766: Horvath, Zsuzsanna
185789567: Liburd, Ian
205509358: Kontoleontos, Ifigeneia
208989934: Valtysson, Jorundur
``````
.globl read_record
read_record:
pushq \%rbp
movq \\rsp,%rbp
subq $216,%rsp
pushq \/rbx
*Record *p
movq $32, X_rcx
call malloc
movq Yrax, Yrbx #saving the pointer of Record into rbx
*scanf inputs
```
```
leaq -18e(Xrsp), Zrdx #lastname
leaq -2ee(%rsp), Zrs *firstnare
leaq -2es(%rrp), Krs *id
call scanf
crp $-1, Y.gax
jc fail_scanf
#last_nane
leaq -10e(Krsp), Zrcx #address of lastnane in rex
call strlen #rax = strlen(lastnane)
addq $ $1,%rax {null terninator
movq X_rax, Zrcx #allocating menory
call malloc
movq \\rax, e(Z_brx)
leaq -18e(%rrsp), Zrdx #lastnane
```
```
call strcpy
*first_name
leaq -2ee(Krsp), Krcx #address of first in rcx
call strlen #rax = strlen(firstname)
addq $$1,%rax ##null terninator
movq \rax, Yrcx #allocating memory
call malloc
mov \\rax,8(%_rbx) #record->firstnane =...
leaq -28e(Krsp), $%rdx #first
movq %rax, #rcex #nove to destination
call strcpy
*id
movq -2es(%rsp), Z_rax
movq %/rax,15(%%bx)
#return record painter
movq \rbx,%rax
addq $216,%rsp
popq \rbx
popq %%rbp
retq
fail_scanf:
movq $e,\rax
addq $215, Mrsp
popq %%
popq %rbp
retq
fornst_str:
.asciz "Xs %s xld"
``` Sorted
Help me fix this bug: ( Either Lastname or First

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!