#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 scalar_t__ pid_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ _exit(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ read(int, char **, int);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int /*<<< orphan*/ write(int, char *, int);
void forkConnection(int dataSocket, int *pipe) {
  pid_t childPID;
  childPID = fork();
  if (childPID == 0) {
    printf("child\n");
    while (1) {
      char writeBuff[3];
      printf("binging read\n");
      read(dataSocket, &writeBuff, 4);
      printf("ending read\n");
      write(pipe[1], writeBuff, 4);
      printf("write finished\n");
      if ((writeBuff[0] == '#') && (writeBuff[1] == 'F') &&
          (writeBuff[2] == 'I') && (writeBuff[3] == 'N')) {
        break;
      }
    }
    _exit(EXIT_SUCCESS);
  }
  wait(NULL);
}


x86 assembly (clang, -O0):
<forkConnection>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1080 <fork@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1227 <forkConnection+0xc7>
lea    0xe74(%rip),%rdi
call   1050 <printf@plt>
lea    0xe6f(%rip),%rdi
call   1050 <printf@plt>
mov    -0x4(%rbp),%edi
lea    -0x1b(%rbp),%rsi
mov    $0x4,%edx
call   1060 <read@plt>
lea    0xe60(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edi
lea    -0x1b(%rbp),%rsi
mov    $0x4,%edx
call   1040 <write@plt>
lea    0xe4c(%rip),%rdi
call   1050 <printf@plt>
movsbl -0x1b(%rbp),%eax
cmp    $0x23,%eax
jne    1214 <forkConnection+0xb4>
movsbl -0x1a(%rbp),%eax
cmp    $0x46,%eax
jne    1214 <forkConnection+0xb4>
movsbl -0x19(%rbp),%eax
cmp    $0x49,%eax
jne    1214 <forkConnection+0xb4>
movsbl -0x18(%rbp),%eax
cmp    $0x4e,%eax
jne    1214 <forkConnection+0xb4>
jmp    1219 <forkConnection+0xb9>
jmp    1191 <forkConnection+0x31>
mov    0x2dc0(%rip),%rax
mov    (%rax),%edi
call   1030 <_exit@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <wait@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<forkConnection>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
je     1191 <forkConnection+0x31>
xor    %edi,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <wait@plt>
lea    0xe68(%rip),%rdi
call   1040 <puts@plt>
lea    0xe62(%rip),%r14
lea    0x5(%rsp),%r15
lea    0xe63(%rip),%r12
lea    0xe68(%rip),%r13
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1040 <puts@plt>
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x4,%edx
call   1060 <read@plt>
mov    %r12,%rdi
call   1040 <puts@plt>
mov    0x4(%rbx),%edi
mov    %r15,%rsi
mov    $0x4,%edx
call   1050 <write@plt>
mov    %r13,%rdi
call   1040 <puts@plt>
cmpb   $0x23,0x5(%rsp)
jne    11c0 <forkConnection+0x60>
cmpb   $0x46,0x6(%rsp)
jne    11c0 <forkConnection+0x60>
cmpb   $0x49,0x7(%rsp)
jne    11c0 <forkConnection+0x60>
cmpb   $0x4e,0x8(%rsp)
jne    11c0 <forkConnection+0x60>
mov    0x2dc6(%rip),%rax
mov    (%rax),%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"child\0A\00"
@.str.1 = [14 x i8] c"binging read\0A\00"
@.str.2 = [13 x i8] c"ending read\0A\00"
@.str.3 = [16 x i8] c"write finished\0A\00"
@EXIT_SUCCESS = global i32 0
define void @forkConnection(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i64
%6 = alloca [3 x i8]
store i32 %0, i32* %3
store i32* %1, i32** %4
%7 = call i64 (...) @fork()
store i64 %7, i64* %5
%8 = load i64, i64* %5
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %48
10: ; preds = %2
%11 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %44
%13 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%14 = load i32, i32* %3
%15 = bitcast [3 x i8]* %6 to i8**
%16 = call i32 @read(i32 %14, i8** %15, i32 4)
%17 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%18 = load i32*, i32** %4
%19 = getelementptr inbounds i32, i32* %18, i64 1
%20 = load i32, i32* %19
%21 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 0
%22 = call i32 @write(i32 %20, i8* %21, i32 4)
%23 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%24 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 0
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 35
br i1 %27, label %28, label %44
28: ; preds = %12
%29 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 1
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 70
br i1 %32, label %33, label %44
33: ; preds = %28
%34 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 2
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %36, 73
br i1 %37, label %38, label %44
38: ; preds = %33
%39 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 3
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp eq i32 %41, 78
br i1 %42, label %43, label %44
43: ; preds = %38
br label %45
44: ; preds = %38, %33, %28, %12
br label %12
45: ; preds = %43
%46 = load i32, i32* @EXIT_SUCCESS
%47 = call i32 @_exit(i32 %46)
unreachable
48: ; preds = %2
%49 = call i32 @wait(i32* null)
ret void
}

LLVM IR (-O2):
@EXIT_SUCCESS = global i32 0
@str = [6 x i8] c"child\00"
@str.4 = [13 x i8] c"binging read\00"
@str.5 = [12 x i8] c"ending read\00"
@str.6 = [15 x i8] c"write finished\00"
define void @forkConnection(i32 %0, i32* nocapture %1) {
%3 = alloca [3 x i8]
%4 = tail call i64 (...) @fork()
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %36
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
%8 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 3
%9 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%10 = bitcast [3 x i8]* %3 to i8**
%11 = getelementptr inbounds i32, i32* %1, i64 1
%12 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 1
%13 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 2
br label %14
14: ; preds = %32, %6
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.4, i64 0, i64 0))
%16 = call i32 @read(i32 %0, i8** %10, i32 4)
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.5, i64 0, i64 0))
%18 = load i32, i32* %11
%19 = call i32 @write(i32 %18, i8* %9, i32 4)
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.6, i64 0, i64 0))
%21 = load i8, i8* %9
%22 = icmp eq i8 %21, 35
%23 = load i8, i8* %12
%24 = icmp eq i8 %23, 70
%25 = select i1 %22, i1 %24, i1 false
%26 = load i8, i8* %13
%27 = icmp eq i8 %26, 73
%28 = select i1 %25, i1 %27, i1 false
br i1 %28, label %29, label %32
29: ; preds = %14
%30 = load i8, i8* %8
%31 = icmp eq i8 %30, 78
br i1 %31, label %33, label %32
32: ; preds = %14, %29
br label %14
33: ; preds = %29
%34 = load i32, i32* @EXIT_SUCCESS
%35 = tail call i32 @_exit(i32 %34)
unreachable
36: ; preds = %2
%37 = tail call i32 @wait(i32* null)
ret void
}