#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 */
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ send(int, char *, int, int /*<<< orphan*/);
void child(int clientfd) {
  int bytes;
  char buffer[4096];
  do {
    bytes = recv(clientfd, buffer, sizeof(buffer), 0);
    if (bytes > 0)
      send(clientfd, buffer, bytes, 0);
  } while (bytes > 0);
  close(clientfd);
  exit(0);
}


x86 assembly (clang, -O0):
<child>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1010,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x1010(%rbp),%rsi
mov    $0x1000,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    1185 <child+0x45>
mov    -0x4(%rbp),%edi
lea    -0x1010(%rbp),%rsi
mov    -0x8(%rbp),%edx
xor    %ecx,%ecx
call   1040 <send@plt>
jmp    118a <child+0x4a>
cmpl   $0x0,-0x8(%rbp)
jg     114e <child+0xe>
mov    -0x4(%rbp),%edi
call   1050 <close@plt>
xor    %edi,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<child>:
push   %r14
push   %rbx
sub    $0x1008,%rsp
mov    %edi,%ebx
mov    %rsp,%rsi
mov    $0x1000,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jle    1193 <child+0x53>
mov    %rsp,%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1000,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jg     1170 <child+0x30>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
define void @child(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [4096 x i8]
store i32 %0, i32* %2
br label %5
5: ; preds = %17, %1
%6 = load i32, i32* %2
%7 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%8 = call i32 @recv(i32 %6, i8* %7, i32 4096, i32 0)
store i32 %8, i32* %3
%9 = load i32, i32* %3
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %5
%12 = load i32, i32* %2
%13 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%14 = load i32, i32* %3
%15 = call i32 @send(i32 %12, i8* %13, i32 %14, i32 0)
br label %16
16: ; preds = %11, %5
br label %17
17: ; preds = %16
%18 = load i32, i32* %3
%19 = icmp sgt i32 %18, 0
br i1 %19, label %5, label %20
20: ; preds = %17
%21 = load i32, i32* %2
%22 = call i32 @close(i32 %21)
%23 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
define void @child(i32 %0) {
%2 = alloca [4096 x i8]
%3 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%4 = call i32 @recv(i32 %0, i8* %3, i32 4096, i32 0)
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %11
6: ; preds = %1, %6
%7 = phi i32 [ %9, %6 ], [ %4, %1 ]
%8 = call i32 @send(i32 %0, i8* %3, i32 %7, i32 0)
%9 = call i32 @recv(i32 %0, i8* %3, i32 4096, i32 0)
%10 = icmp sgt i32 %9, 0
br i1 %10, label %6, label %11
11: ; preds = %6, %1
%12 = call i32 @close(i32 %0)
%13 = call i32 @exit(i32 0)
unreachable
}