#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ packet_disp_err(int);
int packet_pack_reg_req(char *, char *, char *);
int packet_unpack_reg_resp(char *);
int /*<<< orphan*/ printf(char *);
int recv_packet(int, char *);
int /*<<< orphan*/ register_input(char *, char *);
int send_fix_len(int, char *, int);
int do_register(int sockfd) {
  int ret = 0;
  char name[32];
  char password[32];
  char packet[1024];
  register_input(name, password);
  ret = packet_pack_reg_req(packet, name, password);
  ret = send_fix_len(sockfd, packet, ret);
  if (-1 == ret) {
    goto exit;
  }
  ret = recv_packet(sockfd, packet);
  if (ret <= 0) {
    goto exit;
  }
  ret = packet_unpack_reg_resp(packet);
  if (0 == ret) {
    printf("Register OK!\n");
  } else {
    packet_disp_err(ret);
  }
  ret = 1;
exit:
  return ret;
}


x86 assembly (clang, -O0):
<do_register>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    -0x30(%rbp),%rdi
lea    -0x50(%rbp),%rsi
call   1040 <register_input@plt>
lea    -0x450(%rbp),%rdi
lea    -0x30(%rbp),%rsi
lea    -0x50(%rbp),%rdx
call   1080 <packet_pack_reg_req@plt>
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x450(%rbp),%rsi
mov    -0x8(%rbp),%edx
call   1030 <send_fix_len@plt>
mov    %eax,-0x8(%rbp)
mov    $0xffffffff,%eax
cmp    -0x8(%rbp),%eax
jne    11d1 <do_register+0x61>
jmp    122c <do_register+0xbc>
mov    -0x4(%rbp),%edi
lea    -0x450(%rbp),%rsi
call   1090 <recv_packet@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jg     11f2 <do_register+0x82>
jmp    122c <do_register+0xbc>
lea    -0x450(%rbp),%rdi
call   1070 <packet_unpack_reg_resp@plt>
mov    %eax,-0x8(%rbp)
xor    %eax,%eax
cmp    -0x8(%rbp),%eax
jne    121d <do_register+0xad>
lea    0xded(%rip),%rdi
call   1050 <printf@plt>
jmp    1225 <do_register+0xb5>
mov    -0x8(%rbp),%edi
call   1060 <packet_disp_err@plt>
movl   $0x1,-0x8(%rbp)
mov    -0x8(%rbp),%eax
add    $0x450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_register>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x448,%rsp
mov    %edi,%ebx
lea    0x20(%rsp),%r14
mov    %rsp,%r15
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <register_input@plt>
lea    0x40(%rsp),%r12
mov    %r12,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1080 <packet_pack_reg_req@plt>
mov    %ebx,%edi
mov    %r12,%rsi
mov    %eax,%edx
call   1030 <send_fix_len@plt>
cmp    $0xffffffff,%eax
je     11de <do_register+0x6e>
lea    0x40(%rsp),%rsi
mov    %ebx,%edi
call   1090 <recv_packet@plt>
test   %eax,%eax
jle    11f6 <do_register+0x86>
lea    0x40(%rsp),%rdi
call   1070 <packet_unpack_reg_resp@plt>
test   %eax,%eax
je     11e5 <do_register+0x75>
mov    %eax,%edi
call   1060 <packet_disp_err@plt>
jmp    11f1 <do_register+0x81>
mov    $0xffffffff,%eax
jmp    11f6 <do_register+0x86>
lea    0xe14(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%eax
add    $0x448,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [14 x i8] c"Register OK!\0A\00"
define i32 @do_register(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [32 x i8]
%5 = alloca [32 x i8]
%6 = alloca [1024 x i8]
store i32 %0, i32* %2
store i32 0, i32* %3
%7 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%9 = call i32 @register_input(i8* %7, i8* %8)
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%11 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%12 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%13 = call i32 @packet_pack_reg_req(i8* %10, i8* %11, i8* %12)
store i32 %13, i32* %3
%14 = load i32, i32* %2
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%16 = load i32, i32* %3
%17 = call i32 @send_fix_len(i32 %14, i8* %15, i32 %16)
store i32 %17, i32* %3
%18 = load i32, i32* %3
%19 = icmp eq i32 -1, %18
br i1 %19, label %20, label %21
20: ; preds = %1
br label %39
21: ; preds = %1
%22 = load i32, i32* %2
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%24 = call i32 @recv_packet(i32 %22, i8* %23)
store i32 %24, i32* %3
%25 = load i32, i32* %3
%26 = icmp sle i32 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %21
br label %39
28: ; preds = %21
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%30 = call i32 @packet_unpack_reg_resp(i8* %29)
store i32 %30, i32* %3
%31 = load i32, i32* %3
%32 = icmp eq i32 0, %31
br i1 %32, label %33, label %35
33: ; preds = %28
%34 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %38
35: ; preds = %28
%36 = load i32, i32* %3
%37 = call i32 @packet_disp_err(i32 %36)
br label %38
38: ; preds = %35, %33
store i32 1, i32* %3
br label %39
39: ; preds = %38, %27, %20
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
@str = [13 x i8] c"Register OK!\00"
define i32 @do_register(i32 %0) {
%2 = alloca [32 x i8]
%3 = alloca [32 x i8]
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%8 = call i32 @register_input(i8* %5, i8* %6)
%9 = call i32 @packet_pack_reg_req(i8* %7, i8* %5, i8* %6)
%10 = call i32 @send_fix_len(i32 %0, i8* %7, i32 %9)
%11 = icmp eq i32 %10, -1
br i1 %11, label %22, label %12
12: ; preds = %1
%13 = call i32 @recv_packet(i32 %0, i8* %7)
%14 = icmp slt i32 %13, 1
br i1 %14, label %22, label %15
15: ; preds = %12
%16 = call i32 @packet_unpack_reg_resp(i8* %7)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
br label %22
20: ; preds = %15
%21 = call i32 @packet_disp_err(i32 %16)
br label %22
22: ; preds = %18, %20, %12, %1
%23 = phi i32 [ -1, %1 ], [ %13, %12 ], [ 1, %20 ], [ 1, %18 ]
ret i32 %23
}