#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*/ line;

/* Variables and functions */
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ send(int, char *, int, int /*<<< orphan*/);
scalar_t__ strncmp(char *, char *, int);
void Child(void *arg) {
  char line[100];
  int bytes_read;
  int client = *(int *)arg;
  do {
    bytes_read = recv(client, line, sizeof(line), 0);
    if (bytes_read < 0)
      perror("Read socket");
    send(client, line, bytes_read, 0);
  } while (strncmp(line, "bye\r", 4) != 0 || bytes_read < 0);
  close(client);
  exit(0);
}


x86 assembly (clang, -O0):
<Child>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x78(%rbp)
mov    -0x78(%rbp),%edi
lea    -0x70(%rbp),%rsi
mov    $0x64,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x74(%rbp)
cmpl   $0x0,-0x74(%rbp)
jge    11a4 <Child+0x44>
lea    0xe61(%rip),%rdi
call   1070 <perror@plt>
mov    -0x78(%rbp),%edi
lea    -0x70(%rbp),%rsi
mov    -0x74(%rbp),%edx
xor    %ecx,%ecx
call   1050 <send@plt>
lea    -0x70(%rbp),%rdi
lea    0xe4c(%rip),%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x79(%rbp)
jne    11e6 <Child+0x86>
cmpl   $0x0,-0x74(%rbp)
setl   %al
mov    %al,-0x79(%rbp)
mov    -0x79(%rbp),%al
test   $0x1,%al
jne    1178 <Child+0x18>
mov    -0x78(%rbp),%edi
call   1060 <close@plt>
xor    %edi,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<Child>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x70,%rsp
mov    (%rdi),%ebx
mov    %rsp,%r14
lea    0xe88(%rip),%r15
lea    0xe8d(%rip),%r12
nop
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x64,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,%ebp
test   %eax,%eax
js     11c0 <Child+0x60>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %ebp,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    %r14,%rdi
mov    %r12,%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
jne    1180 <Child+0x20>
test   %ebp,%ebp
js     1180 <Child+0x20>
jmp    11ca <Child+0x6a>
mov    %r15,%rdi
call   1070 <perror@plt>
jmp    1197 <Child+0x37>
mov    %ebx,%edi
call   1060 <close@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"Read socket\00"
@.str.1 = [5 x i8] c"bye\0D\00"
define void @Child(i8* %0) {
%2 = alloca i8*
%3 = alloca [100 x i8]
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = bitcast i8* %6 to i32*
%8 = load i32, i32* %7
store i32 %8, i32* %5
br label %9
9: ; preds = %29, %1
%10 = load i32, i32* %5
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%12 = call i32 @recv(i32 %10, i8* %11, i32 100, i32 0)
store i32 %12, i32* %4
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %9
%16 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %15, %9
%18 = load i32, i32* %5
%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)
br label %22
22: ; preds = %17
%23 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%24 = call i64 @strncmp(i8* %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%25 = icmp ne i64 %24, 0
br i1 %25, label %29, label %26
26: ; preds = %22
%27 = load i32, i32* %4
%28 = icmp slt i32 %27, 0
br label %29
29: ; preds = %26, %22
%30 = phi i1 [ true, %22 ], [ %28, %26 ]
br i1 %30, label %9, label %31
31: ; preds = %29
%32 = load i32, i32* %5
%33 = call i32 @close(i32 %32)
%34 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [12 x i8] c"Read socket\00"
@.str.1 = [5 x i8] c"bye\0D\00"
define void @Child(i8* nocapture %0) {
%2 = alloca [100 x i8]
%3 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%4 = bitcast i8* %0 to i32*
%5 = load i32, i32* %4
br label %6
6: ; preds = %11, %1
%7 = call i32 @recv(i32 %5, i8* %3, i32 100, i32 0)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %6
%12 = call i32 @send(i32 %5, i8* %3, i32 %7, i32 0)
%13 = call i64 @strncmp(i8* %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%14 = icmp ne i64 %13, 0
%15 = select i1 %14, i1 true, i1 %8
br i1 %15, label %6, label %16
16: ; preds = %11
%17 = call i32 @close(i32 %5)
%18 = call i32 @exit(i32 0)
unreachable
}