#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*/ fatalError(char *);
int read(int, int *, int);
int strlen(char *);
int write(int, ...);
int sayHello(int socketFD, char *username) {
  int serverResponse = 0;
  int argLength = strlen(username) + 1;
  int n = 0;
  if (write(socketFD, &serverResponse, 4) == -1)
    fatalError("Client protocol error 0");
  n = read(socketFD, &serverResponse, 4);
  if (n != 4 || serverResponse != 0) {
    fatalError("Client protocol error 2");
  }
  if (write(socketFD, &argLength, 4) == -1)
    fatalError("Client protocol error 3");
  n = read(socketFD, &serverResponse, 4);
  if (n != 4 || serverResponse != 0)
    fatalError("Client protocol error 4");
  if (argLength != 1) {
    if ((n = write(socketFD, username, argLength)) == -1)
      fatalError("Client protocol error 5");
    n = read(socketFD, &serverResponse, 4);
    if (n != 4 || serverResponse != 0)
      fatalError("Client protocol error 6");
  }
  return 0;
}


x86 assembly (clang, -O0):
<sayHello>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x14(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    1194 <sayHello+0x54>
lea    0xe71(%rip),%rdi
call   1060 <fatalError@plt>
mov    -0x4(%rbp),%edi
lea    -0x14(%rbp),%rsi
mov    $0x4,%edx
call   1050 <read@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x4,-0x1c(%rbp)
jne    11bc <sayHello+0x7c>
cmpl   $0x0,-0x14(%rbp)
je     11c8 <sayHello+0x88>
lea    0xe55(%rip),%rdi
call   1060 <fatalError@plt>
mov    -0x4(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    11f0 <sayHello+0xb0>
lea    0xe45(%rip),%rdi
call   1060 <fatalError@plt>
mov    -0x4(%rbp),%edi
lea    -0x14(%rbp),%rsi
mov    $0x4,%edx
call   1050 <read@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x4,-0x1c(%rbp)
jne    1218 <sayHello+0xd8>
cmpl   $0x0,-0x14(%rbp)
je     1224 <sayHello+0xe4>
lea    0xe29(%rip),%rdi
call   1060 <fatalError@plt>
cmpl   $0x1,-0x18(%rbp)
je     1290 <sayHello+0x150>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%edx
mov    $0x0,%al
call   1030 <write@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
jne    1257 <sayHello+0x117>
lea    0xe0e(%rip),%rdi
call   1060 <fatalError@plt>
mov    -0x4(%rbp),%edi
lea    -0x14(%rbp),%rsi
mov    $0x4,%edx
call   1050 <read@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x4,-0x1c(%rbp)
jne    127f <sayHello+0x13f>
cmpl   $0x0,-0x14(%rbp)
je     128b <sayHello+0x14b>
lea    0xdf2(%rip),%rdi
call   1060 <fatalError@plt>
jmp    1290 <sayHello+0x150>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sayHello>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebx
movl   $0x0,(%rsp)
mov    %rsi,%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
mov    %eax,0x4(%rsp)
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x4,%edx
xor    %eax,%eax
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    1181 <sayHello+0x41>
lea    0xe84(%rip),%rdi
call   1060 <fatalError@plt>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1050 <read@plt>
cmp    $0x4,%eax
jne    119b <sayHello+0x5b>
cmpl   $0x0,(%rsp)
je     11a7 <sayHello+0x67>
lea    0xe76(%rip),%rdi
call   1060 <fatalError@plt>
lea    0x4(%rsp),%rsi
mov    %ebx,%edi
mov    $0x4,%edx
xor    %eax,%eax
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    11cb <sayHello+0x8b>
lea    0xe6a(%rip),%rdi
call   1060 <fatalError@plt>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1050 <read@plt>
cmp    $0x4,%eax
jne    11e5 <sayHello+0xa5>
cmpl   $0x0,(%rsp)
je     11f1 <sayHello+0xb1>
lea    0xe5c(%rip),%rdi
call   1060 <fatalError@plt>
mov    0x4(%rsp),%edx
cmp    $0x1,%edx
je     123d <sayHello+0xfd>
mov    %ebx,%edi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    1217 <sayHello+0xd7>
lea    0xe4e(%rip),%rdi
call   1060 <fatalError@plt>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1050 <read@plt>
cmp    $0x4,%eax
jne    1231 <sayHello+0xf1>
cmpl   $0x0,(%rsp)
je     123d <sayHello+0xfd>
lea    0xe40(%rip),%rdi
call   1060 <fatalError@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [24 x i8] c"Client protocol error 0\00"
@.str.1 = [24 x i8] c"Client protocol error 2\00"
@.str.2 = [24 x i8] c"Client protocol error 3\00"
@.str.3 = [24 x i8] c"Client protocol error 4\00"
@.str.4 = [24 x i8] c"Client protocol error 5\00"
@.str.5 = [24 x i8] c"Client protocol error 6\00"
define i32 @sayHello(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
store i32 0, i32* %5
%8 = load i8*, i8** %4
%9 = call i32 @strlen(i8* %8)
%10 = add nsw i32 %9, 1
store i32 %10, i32* %6
store i32 0, i32* %7
%11 = load i32, i32* %3
%12 = call i32 (i32, ...) @write(i32 %11, i32* %5, i32 4)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 @fatalError(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %14, %2
%17 = load i32, i32* %3
%18 = call i32 @read(i32 %17, i32* %5, i32 4)
store i32 %18, i32* %7
%19 = load i32, i32* %7
%20 = icmp ne i32 %19, 4
br i1 %20, label %24, label %21
21: ; preds = %16
%22 = load i32, i32* %5
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %21, %16
%25 = call i32 @fatalError(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %26
26: ; preds = %24, %21
%27 = load i32, i32* %3
%28 = call i32 (i32, ...) @write(i32 %27, i32* %6, i32 4)
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %32
30: ; preds = %26
%31 = call i32 @fatalError(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
br label %32
32: ; preds = %30, %26
%33 = load i32, i32* %3
%34 = call i32 @read(i32 %33, i32* %5, i32 4)
store i32 %34, i32* %7
%35 = load i32, i32* %7
%36 = icmp ne i32 %35, 4
br i1 %36, label %40, label %37
37: ; preds = %32
%38 = load i32, i32* %5
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %37, %32
%41 = call i32 @fatalError(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %42
42: ; preds = %40, %37
%43 = load i32, i32* %6
%44 = icmp ne i32 %43, 1
br i1 %44, label %45, label %64
45: ; preds = %42
%46 = load i32, i32* %3
%47 = load i8*, i8** %4
%48 = load i32, i32* %6
%49 = call i32 (i32, ...) @write(i32 %46, i8* %47, i32 %48)
store i32 %49, i32* %7
%50 = icmp eq i32 %49, -1
br i1 %50, label %51, label %53
51: ; preds = %45
%52 = call i32 @fatalError(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
br label %53
53: ; preds = %51, %45
%54 = load i32, i32* %3
%55 = call i32 @read(i32 %54, i32* %5, i32 4)
store i32 %55, i32* %7
%56 = load i32, i32* %7
%57 = icmp ne i32 %56, 4
br i1 %57, label %61, label %58
58: ; preds = %53
%59 = load i32, i32* %5
%60 = icmp ne i32 %59, 0
br i1 %60, label %61, label %63
61: ; preds = %58, %53
%62 = call i32 @fatalError(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
br label %63
63: ; preds = %61, %58
br label %64
64: ; preds = %63, %42
ret i32 0
}

LLVM IR (-O2):
@.str = [24 x i8] c"Client protocol error 0\00"
@.str.1 = [24 x i8] c"Client protocol error 2\00"
@.str.2 = [24 x i8] c"Client protocol error 3\00"
@.str.3 = [24 x i8] c"Client protocol error 4\00"
@.str.4 = [24 x i8] c"Client protocol error 5\00"
@.str.5 = [24 x i8] c"Client protocol error 6\00"
define i32 @sayHello(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%6 = bitcast i32* %4 to i8*
%7 = tail call i32 @strlen(i8* %1)
%8 = add nsw i32 %7, 1
store i32 %8, i32* %4
%9 = call i32 (i32, ...) @write(i32 %0, i32* %3, i32 4)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @fatalError(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %2
%14 = call i32 @read(i32 %0, i32* %3, i32 4)
%15 = icmp ne i32 %14, 4
%16 = load i32, i32* %3
%17 = icmp ne i32 %16, 0
%18 = select i1 %15, i1 true, i1 %17
br i1 %18, label %19, label %21
19: ; preds = %13
%20 = call i32 @fatalError(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %13, %19
%22 = call i32 (i32, ...) @write(i32 %0, i32* %4, i32 4)
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = call i32 @fatalError(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
br label %26
26: ; preds = %24, %21
%27 = call i32 @read(i32 %0, i32* %3, i32 4)
%28 = icmp ne i32 %27, 4
%29 = load i32, i32* %3
%30 = icmp ne i32 %29, 0
%31 = select i1 %28, i1 true, i1 %30
br i1 %31, label %32, label %34
32: ; preds = %26
%33 = call i32 @fatalError(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %34
34: ; preds = %26, %32
%35 = load i32, i32* %4
%36 = icmp eq i32 %35, 1
br i1 %36, label %50, label %37
37: ; preds = %34
%38 = call i32 (i32, ...) @write(i32 %0, i8* %1, i32 %35)
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %42
40: ; preds = %37
%41 = call i32 @fatalError(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
br label %42
42: ; preds = %40, %37
%43 = call i32 @read(i32 %0, i32* %3, i32 4)
%44 = icmp ne i32 %43, 4
%45 = load i32, i32* %3
%46 = icmp ne i32 %45, 0
%47 = select i1 %44, i1 true, i1 %46
br i1 %47, label %48, label %50
48: ; preds = %42
%49 = call i32 @fatalError(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
br label %50
50: ; preds = %48, %42, %34
ret i32 0
}