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


x86 assembly (clang, -O0):
<HandleClient>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
movl   $0xffffffff,-0x34(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x20,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
jge    117d <HandleClient+0x3d>
lea    0xe88(%rip),%rdi
call   1060 <Die@plt>
jmp    1182 <HandleClient+0x42>
cmpl   $0x0,-0x34(%rbp)
jle    11d4 <HandleClient+0x94>
mov    -0x4(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x20,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
jge    11b7 <HandleClient+0x77>
lea    0xe7a(%rip),%rdi
call   1060 <Die@plt>
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
mov    -0x34(%rbp),%edx
lea    0xe91(%rip),%rsi
call   1050 <fprintf@plt>
jmp    1182 <HandleClient+0x42>
mov    -0x4(%rbp),%edi
call   1040 <close@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<HandleClient>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %edi,%ebx
mov    %rsp,%rsi
mov    $0x20,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
js     11ab <HandleClient+0x6b>
je     11d7 <HandleClient+0x97>
mov    %rsp,%r14
mov    0x2e73(%rip),%r12
lea    0xee7(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x20,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,%ebp
test   %eax,%eax
js     11b9 <HandleClient+0x79>
mov    (%r12),%edi
mov    %r15,%rsi
mov    %ebp,%edx
call   1050 <fprintf@plt>
test   %ebp,%ebp
jne    1180 <HandleClient+0x40>
jmp    11d7 <HandleClient+0x97>
lea    0xe4e(%rip),%rdi
call   1060 <Die@plt>
jmp    11d7 <HandleClient+0x97>
lea    0xe6c(%rip),%rdi
call   1060 <Die@plt>
mov    (%r12),%edi
lea    0xe8b(%rip),%rsi
mov    %ebp,%edx
call   1050 <fprintf@plt>
mov    %ebx,%edi
call   1040 <close@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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