#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*/);
scalar_t__ strncmp(char *, char *, int);
void child(int client) {
  char buffer[1024];
  int bytes;
  do {
    bytes = recv(client, buffer, sizeof(buffer), 0);
    if (bytes > 0)
      send(client, buffer, bytes, 0);
  } while (bytes > 0 && strncmp(buffer, "bye\r", 4) != 0);
  close(client);
  exit(0);
}


x86 assembly (clang, -O0):
<child>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x414(%rbp)
cmpl   $0x0,-0x414(%rbp)
jle    119e <child+0x4e>
mov    -0x4(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    -0x414(%rbp),%edx
xor    %ecx,%ecx
call   1050 <send@plt>
jmp    11a3 <child+0x53>
xor    %eax,%eax
cmpl   $0x0,-0x414(%rbp)
mov    %al,-0x415(%rbp)
jle    11dd <child+0x8d>
lea    -0x410(%rbp),%rdi
lea    0xe3a(%rip),%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x415(%rbp)
mov    -0x415(%rbp),%al
test   $0x1,%al
jne    115e <child+0xe>
mov    -0x4(%rbp),%edi
call   1060 <close@plt>
xor    %edi,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<child>:
push   %r15
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %edi,%ebx
mov    %rsp,%r14
lea    0xe98(%rip),%r15
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jle    11a8 <child+0x58>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
jne    1170 <child+0x20>
mov    %ebx,%edi
call   1060 <close@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"bye\0D\00"
define void @child(i32 %0) {
%2 = alloca i32
%3 = alloca [1024 x i8]
%4 = alloca i32
store i32 %0, i32* %2
br label %5
5: ; preds = %24, %1
%6 = load i32, i32* %2
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%8 = call i32 @recv(i32 %6, i8* %7, i32 1024, i32 0)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %5
%12 = load i32, i32* %2
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%14 = load i32, i32* %4
%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* %4
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %17
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%22 = call i64 @strncmp(i8* %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%23 = icmp ne i64 %22, 0
br label %24
24: ; preds = %20, %17
%25 = phi i1 [ false, %17 ], [ %23, %20 ]
br i1 %25, label %5, label %26
26: ; preds = %24
%27 = load i32, i32* %2
%28 = call i32 @close(i32 %27)
%29 = call i32 @exit(i32 0)
unreachable
}

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