#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*/ Die(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ printf(char *, char *);
int recv(int, char *, int, int /*<<< orphan*/);
int send(int, char *, int, int /*<<< orphan*/);
void HandleClient(int sock) {
  char buffer[100];
  printf("%p\n", buffer);
  int received = -1;
  if ((received = recv(sock, buffer, 128, 0)) < 0) {
    Die("Failed to receive initial bytes from client");
  }
  while (received > 0) {
    if (send(sock, buffer, received, 0) != received) {
      Die("Failed to send bytes to client");
    }
    if ((received = recv(sock, buffer, 100, 0)) < 0) {
      Die("Failed to receive additional bytes from client");
    }
  }
  close(sock);
}


x86 assembly (clang, -O0):
<HandleClient>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x70(%rbp),%rsi
lea    0xe97(%rip),%rdi
call   1050 <printf@plt>
movl   $0xffffffff,-0x74(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x70(%rbp),%rsi
mov    $0x80,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x74(%rbp)
cmp    $0x0,%eax
jge    11a0 <HandleClient+0x50>
lea    0xe69(%rip),%rdi
call   1070 <Die@plt>
jmp    11a5 <HandleClient+0x55>
cmpl   $0x0,-0x74(%rbp)
jle    1205 <HandleClient+0xb5>
mov    -0x4(%rbp),%edi
lea    -0x70(%rbp),%rsi
mov    -0x74(%rbp),%edx
xor    %ecx,%ecx
call   1040 <send@plt>
cmp    -0x74(%rbp),%eax
je     11d5 <HandleClient+0x85>
lea    0xe60(%rip),%rdi
call   1070 <Die@plt>
mov    -0x4(%rbp),%edi
lea    -0x70(%rbp),%rsi
mov    $0x64,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x74(%rbp)
cmp    $0x0,%eax
jge    1200 <HandleClient+0xb0>
lea    0xe54(%rip),%rdi
call   1070 <Die@plt>
jmp    11a5 <HandleClient+0x55>
mov    -0x4(%rbp),%edi
call   1060 <close@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<HandleClient>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x70,%rsp
mov    %edi,%ebx
lea    0xe9b(%rip),%rdi
mov    %rsp,%rbp
mov    %rbp,%rsi
call   1050 <printf@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x80,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
js     11d5 <HandleClient+0x85>
je     11e4 <HandleClient+0x94>
mov    %eax,%ebp
mov    %rsp,%r15
lea    0xebc(%rip),%r14
lea    0xe96(%rip),%r12
nopw   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r15,%rsi
mov    %ebp,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
cmp    %ebp,%eax
je     11ba <HandleClient+0x6a>
mov    %r12,%rdi
call   1070 <Die@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x64,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
js     11dc <HandleClient+0x8c>
mov    %eax,%ebp
jne    11a0 <HandleClient+0x50>
jmp    11e4 <HandleClient+0x94>
lea    0xe28(%rip),%r14
mov    %r14,%rdi
call   1070 <Die@plt>
mov    %ebx,%edi
call   1060 <close@plt>
add    $0x70,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%p\0A\00"
@.str.1 = [44 x i8] c"Failed to receive initial bytes from client\00"
@.str.2 = [31 x i8] c"Failed to send bytes to client\00"
@.str.3 = [47 x i8] c"Failed to receive additional bytes from client\00"
define void @HandleClient(i32 %0) {
%2 = alloca i32
%3 = alloca [100 x i8]
%4 = alloca i32
store i32 %0, i32* %2
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%6 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %5)
store i32 -1, i32* %4
%7 = load i32, i32* %2
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%9 = call i32 @recv(i32 %7, i8* %8, i32 128, i32 0)
store i32 %9, i32* %4
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = call i32 @Die(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %11, %1
br label %14
14: ; preds = %33, %13
%15 = load i32, i32* %4
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %34
17: ; preds = %14
%18 = load i32, i32* %2
%19 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%20 = load i32, i32* %4
%21 = call i32 @send(i32 %18, i8* %19, i32 %20, i32 0)
%22 = load i32, i32* %4
%23 = icmp ne i32 %21, %22
br i1 %23, label %24, label %26
24: ; preds = %17
%25 = call i32 @Die(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
br label %26
26: ; preds = %24, %17
%27 = load i32, i32* %2
%28 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%29 = call i32 @recv(i32 %27, i8* %28, i32 100, i32 0)
store i32 %29, i32* %4
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %26
%32 = call i32 @Die(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0))
br label %33
33: ; preds = %31, %26
br label %14
34: ; preds = %14
%35 = load i32, i32* %2
%36 = call i32 @close(i32 %35)
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"%p\0A\00"
@.str.1 = [44 x i8] c"Failed to receive initial bytes from client\00"
@.str.2 = [31 x i8] c"Failed to send bytes to client\00"
@.str.3 = [47 x i8] c"Failed to receive additional bytes from client\00"
define void @HandleClient(i32 %0) {
%2 = alloca [100 x i8]
%3 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%4 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %3)
%5 = call i32 @recv(i32 %0, i8* %3, i32 128, i32 0)
%6 = icmp slt i32 %5, 0
br i1 %6, label %20, label %7
7: ; preds = %1
%8 = icmp eq i32 %5, 0
br i1 %8, label %23, label %9
9: ; preds = %7, %18
%10 = phi i32 [ %16, %18 ], [ %5, %7 ]
%11 = call i32 @send(i32 %0, i8* %3, i32 %10, i32 0)
%12 = icmp eq i32 %11, %10
br i1 %12, label %15, label %13
13: ; preds = %9
%14 = call i32 @Die(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
br label %15
15: ; preds = %13, %9
%16 = call i32 @recv(i32 %0, i8* %3, i32 100, i32 0)
%17 = icmp slt i32 %16, 0
br i1 %17, label %20, label %18
18: ; preds = %15
%19 = icmp eq i32 %16, 0
br i1 %19, label %23, label %9
20: ; preds = %15, %1
%21 = phi i8* [ getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), %1 ], [ getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0), %15 ]
%22 = call i32 @Die(i8* %21)
br label %23
23: ; preds = %18, %20, %7
%24 = call i32 @close(i32 %0)
ret void
}