#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 */
struct registration {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int registerUser(char *, int, struct registration *, size_t *);
int sendall(int, char *, int *);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
int handleRegisterMsg(int socketfd, const char *msg, size_t msglen,
                      struct registration *registrations, size_t *numReg) {
  int ret;
  int userNameLen = msglen - 9 - 1;
  char user[40];
  if (userNameLen < 40) {
    memset(user, 0, 40);
    strncpy(user, msg + 9, userNameLen);
    strcat(user, "\0");
    ret = registerUser(user, socketfd, registrations, numReg);
  } else {
    ret = 401;
  }
  if (ret == 200) {
    char retStr[] = "200 OK\r\n\0";
    int len = strlen(retStr);
    if (sendall(socketfd, retStr, &len) == -1) {
      perror("200 OK send (Register)");
    }
  } else {
    char retStr[] = "401\r\n\0";
    int len = strlen(retStr);
    if (sendall(socketfd, retStr, &len) == -1) {
      perror("401 send (Register)");
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<handleRegisterMsg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x18(%rbp),%rax
sub    $0x9,%rax
sub    $0x1,%rax
mov    %eax,-0x30(%rbp)
cmpl   $0x28,-0x30(%rbp)
jge    11f7 <handleRegisterMsg+0x87>
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1060 <memset@plt>
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    $0x9,%rsi
mov    -0x30(%rbp),%edx
call   1030 <strncpy@plt>
lea    -0x60(%rbp),%rdi
lea    0xe2a(%rip),%rsi
call   1090 <strcat@plt>
lea    -0x60(%rbp),%rdi
mov    -0x4(%rbp),%esi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1040 <registerUser@plt>
mov    %eax,-0x2c(%rbp)
jmp    11fe <handleRegisterMsg+0x8e>
movl   $0x191,-0x2c(%rbp)
cmpl   $0xc8,-0x2c(%rbp)
jne    1257 <handleRegisterMsg+0xe7>
mov    0xdf0(%rip),%rax
mov    %rax,-0x6a(%rbp)
mov    0xded(%rip),%ax
mov    %ax,-0x62(%rbp)
lea    -0x6a(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x70(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x6a(%rbp),%rsi
lea    -0x70(%rbp),%rdx
call   1070 <sendall@plt>
cmp    $0xffffffff,%eax
jne    1252 <handleRegisterMsg+0xe2>
lea    0xdc6(%rip),%rdi
call   1080 <perror@plt>
jmp    12aa <handleRegisterMsg+0x13a>
mov    0xdaf(%rip),%eax
mov    %eax,-0x77(%rbp)
mov    0xda9(%rip),%ax
mov    %ax,-0x73(%rbp)
mov    0xda1(%rip),%al
mov    %al,-0x71(%rbp)
lea    -0x77(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x7c(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x77(%rbp),%rsi
lea    -0x7c(%rbp),%rdx
call   1070 <sendall@plt>
cmp    $0xffffffff,%eax
jne    12a5 <handleRegisterMsg+0x135>
lea    0xd8a(%rip),%rdi
call   1080 <perror@plt>
jmp    12aa <handleRegisterMsg+0x13a>
mov    $0x1,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handleRegisterMsg>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rdx,%rbx
mov    %edi,%r12d
add    $0xfffffff6,%ebx
cmp    $0x27,%ebx
jg     122a <handleRegisterMsg+0xba>
mov    %r8,%r14
mov    %rcx,%r15
mov    %rsi,%rbp
lea    0x20(%rsp),%r13
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1060 <memset@plt>
add    $0x9,%rbp
mov    %r13,%rdi
mov    %rbp,%rsi
mov    %ebx,%edx
call   1030 <strncpy@plt>
lea    0xe3b(%rip),%rsi
mov    %r13,%rdi
call   1090 <strcat@plt>
mov    %r13,%rdi
mov    %r12d,%esi
mov    %r15,%rdx
mov    %r14,%rcx
call   1040 <registerUser@plt>
cmp    $0xc8,%eax
jne    122a <handleRegisterMsg+0xba>
movabs $0xa0d4b4f20303032,%rax
4b 0d 0a
mov    %rax,0x10(%rsp)
movw   $0x0,0x18(%rsp)
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdx
mov    %r12d,%edi
mov    %rbx,%rsi
call   1070 <sendall@plt>
cmp    $0xffffffff,%eax
jne    1260 <handleRegisterMsg+0xf0>
lea    0xdeb(%rip),%rdi
jmp    127b <handleRegisterMsg+0x10b>
movl   $0xa0d,0x13(%rsp)
movl   $0xd313034,0x10(%rsp)
0d
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdx
mov    %r12d,%edi
mov    %rbx,%rsi
call   1070 <sendall@plt>
cmp    $0xffffffff,%eax
je     1274 <handleRegisterMsg+0x104>
mov    $0x1,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdaf(%rip),%rdi
call   1080 <perror@plt>
jmp    1260 <handleRegisterMsg+0xf0>

LLVM IR (-O0):
%struct.registration = type { i32 }
@.str = [2 x i8] zeroinitializer
@__const.handleRegisterMsg.retStr = [10 x i8] c"200 OK\0D\0A\00\00"
@.str.1 = [23 x i8] c"200 OK send (Register)\00"
@__const.handleRegisterMsg.retStr.2 = [7 x i8] c"401\0D\0A\00\00"
@.str.3 = [20 x i8] c"401 send (Register)\00"
define i32 @handleRegisterMsg(i32 %0, i8* %1, i64 %2, %struct.registration* %3, i64* %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca %struct.registration*
%10 = alloca i64*
%11 = alloca i32
%12 = alloca i32
%13 = alloca [40 x i8]
%14 = alloca [10 x i8]
%15 = alloca i32
%16 = alloca [7 x i8]
%17 = alloca i32
store i32 %0, i32* %6
store i8* %1, i8** %7
store i64 %2, i64* %8
store %struct.registration* %3, %struct.registration** %9
store i64* %4, i64** %10
%18 = load i64, i64* %8
%19 = sub i64 %18, 9
%20 = sub i64 %19, 1
%21 = trunc i64 %20 to i32
store i32 %21, i32* %12
%22 = load i32, i32* %12
%23 = icmp slt i32 %22, 40
br i1 %23, label %24, label %39
24: ; preds = %5
%25 = getelementptr inbounds [40 x i8], [40 x i8]* %13, i64 0, i64 0
%26 = call i32 @memset(i8* %25, i32 0, i32 40)
%27 = getelementptr inbounds [40 x i8], [40 x i8]* %13, i64 0, i64 0
%28 = load i8*, i8** %7
%29 = getelementptr inbounds i8, i8* %28, i64 9
%30 = load i32, i32* %12
%31 = call i32 @strncpy(i8* %27, i8* %29, i32 %30)
%32 = getelementptr inbounds [40 x i8], [40 x i8]* %13, i64 0, i64 0
%33 = call i32 @strcat(i8* %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%34 = getelementptr inbounds [40 x i8], [40 x i8]* %13, i64 0, i64 0
%35 = load i32, i32* %6
%36 = load %struct.registration*, %struct.registration** %9
%37 = load i64*, i64** %10
%38 = call i32 @registerUser(i8* %34, i32 %35, %struct.registration* %36, i64* %37)
store i32 %38, i32* %11
br label %40
39: ; preds = %5
store i32 401, i32* %11
br label %40
40: ; preds = %39, %24
%41 = load i32, i32* %11
%42 = icmp eq i32 %41, 200
br i1 %42, label %43, label %54
43: ; preds = %40
%44 = bitcast [10 x i8]* %14 to i8*
%45 = getelementptr inbounds [10 x i8], [10 x i8]* %14, i64 0, i64 0
%46 = call i32 @strlen(i8* %45)
store i32 %46, i32* %15
%47 = load i32, i32* %6
%48 = getelementptr inbounds [10 x i8], [10 x i8]* %14, i64 0, i64 0
%49 = call i32 @sendall(i32 %47, i8* %48, i32* %15)
%50 = icmp eq i32 %49, -1
br i1 %50, label %51, label %53
51: ; preds = %43
%52 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %53
53: ; preds = %51, %43
br label %65
54: ; preds = %40
%55 = bitcast [7 x i8]* %16 to i8*
%56 = getelementptr inbounds [7 x i8], [7 x i8]* %16, i64 0, i64 0
%57 = call i32 @strlen(i8* %56)
store i32 %57, i32* %17
%58 = load i32, i32* %6
%59 = getelementptr inbounds [7 x i8], [7 x i8]* %16, i64 0, i64 0
%60 = call i32 @sendall(i32 %58, i8* %59, i32* %17)
%61 = icmp eq i32 %60, -1
br i1 %61, label %62, label %64
62: ; preds = %54
%63 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %64
64: ; preds = %62, %54
br label %65
65: ; preds = %64, %53
ret i32 1
}

LLVM IR (-O2):
%struct.registration = type { i32 }
@.str = [2 x i8] zeroinitializer
@__const.handleRegisterMsg.retStr = [10 x i8] c"200 OK\0D\0A\00\00"
@.str.1 = [23 x i8] c"200 OK send (Register)\00"
@__const.handleRegisterMsg.retStr.2 = [7 x i8] c"401\0D\0A\00\00"
@.str.3 = [20 x i8] c"401 send (Register)\00"
define i32 @handleRegisterMsg(i32 %0, i8* %1, i64 %2, %struct.registration* %3, i64* %4) {
%6 = alloca [40 x i8]
%7 = alloca [10 x i8]
%8 = alloca i32
%9 = alloca [7 x i8]
%10 = alloca i32
%11 = trunc i64 %2 to i32
%12 = add i32 %11, -10
%13 = getelementptr inbounds [40 x i8], [40 x i8]* %6, i64 0, i64 0
%14 = icmp slt i32 %12, 40
br i1 %14, label %15, label %31
15: ; preds = %5
%16 = call i32 @memset(i8* %13, i32 0, i32 40)
%17 = getelementptr inbounds i8, i8* %1, i64 9
%18 = call i32 @strncpy(i8* %13, i8* %17, i32 %12)
%19 = call i32 @strcat(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%20 = call i32 @registerUser(i8* %13, i32 %0, %struct.registration* %3, i64* %4)
%21 = icmp eq i32 %20, 200
br i1 %21, label %22, label %31
22: ; preds = %15
%23 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%24 = bitcast i32* %8 to i8*
%25 = call i32 @strlen(i8* %23)
store i32 %25, i32* %8
%26 = call i32 @sendall(i32 %0, i8* %23, i32* %8)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %30
28: ; preds = %22
%29 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %30
30: ; preds = %28, %22
br label %40
31: ; preds = %5, %15
%32 = getelementptr inbounds [7 x i8], [7 x i8]* %9, i64 0, i64 0
%33 = bitcast i32* %10 to i8*
%34 = call i32 @strlen(i8* %32)
store i32 %34, i32* %10
%35 = call i32 @sendall(i32 %0, i8* %32, i32* %10)
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %39
37: ; preds = %31
%38 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %39
39: ; preds = %37, %31
br label %40
40: ; preds = %39, %30
ret i32 1
}