#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*/ printf(char *, ...);
size_t read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
void child(int fdin, int fdout) {
  size_t n;
  char buf[256];
  printf("[child] I'm the child!\n");
  printf("[child] Socket FD: %d, %d\n", fdin, fdout);
  write(fdout, "Hello from child!", 18);
  n = read(fdin, buf, 256);
  printf("[child] Got message: %s\n", buf);
  write(fdin, "Hello from child!", 19);
  n = read(fdout, buf, 256);
  printf("[child] Got message: %s\n", buf);
}


x86 assembly (clang, -O0):
<child>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
lea    0xeb8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
lea    0xebc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
lea    0xec6(%rip),%rsi
mov    $0x12,%edx
call   1030 <write@plt>
mov    -0x4(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    $0x100,%edx
call   1050 <read@plt>
mov    %rax,-0x10(%rbp)
lea    -0x110(%rbp),%rsi
lea    0xea8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%edi
lea    0xe85(%rip),%rsi
mov    $0x13,%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    $0x100,%edx
call   1050 <read@plt>
mov    %rax,-0x10(%rbp)
lea    -0x110(%rbp),%rsi
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<child>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x100,%rsp
mov    %esi,%ebx
mov    %edi,%ebp
lea    0xeec(%rip),%rdi
call   1030 <puts@plt>
lea    0xe9a(%rip),%rdi
mov    %ebp,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xea3(%rip),%r14
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x12,%edx
call   1040 <write@plt>
mov    %rsp,%r15
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x100,%edx
call   1060 <read@plt>
lea    0xe8d(%rip),%r12
mov    %r12,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x13,%edx
call   1040 <write@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x100,%edx
call   1060 <read@plt>
mov    %r12,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x100,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"[child] I'm the child!\0A\00"
@.str.1 = [27 x i8] c"[child] Socket FD: %d, %d\0A\00"
@.str.2 = [18 x i8] c"Hello from child!\00"
@.str.3 = [25 x i8] c"[child] Got message: %s\0A\00"
define void @child(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
%6 = alloca [256 x i8]
store i32 %0, i32* %3
store i32 %1, i32* %4
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* %3
%9 = load i32, i32* %4
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %8, i32 %9)
%11 = load i32, i32* %4
%12 = call i32 @write(i32 %11, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 18)
%13 = load i32, i32* %3
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%15 = call i64 @read(i32 %13, i8* %14, i32 256)
store i64 %15, i64* %5
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %16)
%18 = load i32, i32* %3
%19 = call i32 @write(i32 %18, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 19)
%20 = load i32, i32* %4
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%22 = call i64 @read(i32 %20, i8* %21, i32 256)
store i64 %22, i64* %5
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %23)
ret void
}

LLVM IR (-O2):
@.str.1 = [27 x i8] c"[child] Socket FD: %d, %d\0A\00"
@.str.2 = [18 x i8] c"Hello from child!\00"
@.str.3 = [25 x i8] c"[child] Got message: %s\0A\00"
@str = [23 x i8] c"[child] I'm the child!\00"
define void @child(i32 %0, i32 %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %0, i32 %1)
%7 = tail call i32 @write(i32 %1, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 18)
%8 = call i64 @read(i32 %0, i8* %4, i32 256)
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%10 = call i32 @write(i32 %0, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 19)
%11 = call i64 @read(i32 %1, i8* %4, i32 256)
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %4)
ret void
}