#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*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int getpid();
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ sprintf(char *, char *);
int /*<<< orphan*/ stdout;
scalar_t__ strlen(char *);
int /*<<< orphan*/ write(int, char *, scalar_t__);
void father(int fd1[2], int fd2[2]) {
  char line[132];
  int i = 0;
  close(fd1[0]);
  close(fd2[1]);
  while (i < 10) {
    fprintf(stdout, "I'm the father (PID=%d)\n", getpid());
    sprintf(line, "X");
    write(fd1[1], line, strlen(line) + 1);
    i++;
    read(fd2[0], line, 132);
  }
  sprintf(line, "end");
  write(fd1[1], line, strlen(line) + 1);
  close(fd1[1]);
  close(fd2[0]);
  return;
}


x86 assembly (clang, -O0):
<father>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0xa4(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   1060 <close@plt>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edi
call   1060 <close@plt>
cmpl   $0xa,-0xa4(%rbp)
jge    1259 <father+0xe9>
mov    0x2e28(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xb8(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    -0xb8(%rbp),%edi
mov    %eax,%edx
lea    0xe2a(%rip),%rsi
call   1080 <fprintf@plt>
lea    -0xa0(%rbp),%rdi
lea    0xe30(%rip),%rsi
call   1090 <sprintf@plt>
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%eax
mov    %eax,-0xb4(%rbp)
lea    -0xa0(%rbp),%rax
mov    %rax,-0xb0(%rbp)
lea    -0xa0(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0xb4(%rbp),%edi
mov    -0xb0(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1030 <write@plt>
mov    -0xa4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xa4(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
lea    -0xa0(%rbp),%rsi
mov    $0x84,%edx
call   1070 <read@plt>
jmp    11a4 <father+0x34>
lea    -0xa0(%rbp),%rdi
lea    0xdb4(%rip),%rsi
call   1090 <sprintf@plt>
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%eax
mov    %eax,-0xc4(%rbp)
lea    -0xa0(%rbp),%rax
mov    %rax,-0xc0(%rbp)
lea    -0xa0(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0xc4(%rbp),%edi
mov    -0xc0(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1030 <write@plt>
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%edi
call   1060 <close@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1060 <close@plt>
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<father>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    %rsi,%r14
mov    %rdi,%r12
mov    (%rdi),%edi
call   1060 <close@plt>
mov    0x4(%r14),%edi
call   1060 <close@plt>
mov    $0xa,%ebx
lea    0xe6d(%rip),%r15
mov    %rsp,%r13
cs nopw 0x0(%rax,%rax,1)
mov    0x2e39(%rip),%rax
mov    (%rax),%ebp
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %ebp,%edi
mov    %r15,%rsi
mov    %eax,%edx
call   1080 <fprintf@plt>
movw   $0x58,(%rsp)
mov    0x4(%r12),%ebp
mov    %r13,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %ebp,%edi
mov    %r13,%rsi
call   1030 <write@plt>
mov    (%r14),%edi
mov    %r13,%rsi
mov    $0x84,%edx
call   1070 <read@plt>
add    $0xffffffff,%ebx
jne    11a0 <father+0x40>
movl   $0x646e65,(%rsp)
mov    0x4(%r12),%ebx
mov    %rsp,%rbp
mov    %rbp,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %ebx,%edi
mov    %rbp,%rsi
call   1030 <write@plt>
mov    0x4(%r12),%edi
call   1060 <close@plt>
mov    (%r14),%edi
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <close@plt>

LLVM IR (-O0):
@stdout = global i32 0
@.str = [25 x i8] c"I'm the father (PID=%d)\0A\00"
@.str.1 = [2 x i8] c"X\00"
@.str.2 = [4 x i8] c"end\00"
define void @father(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca [132 x i8]
%6 = alloca i32
store i32* %0, i32** %3
store i32* %1, i32** %4
store i32 0, i32* %6
%7 = load i32*, i32** %3
%8 = getelementptr inbounds i32, i32* %7, i64 0
%9 = load i32, i32* %8
%10 = call i32 @close(i32 %9)
%11 = load i32*, i32** %4
%12 = getelementptr inbounds i32, i32* %11, i64 1
%13 = load i32, i32* %12
%14 = call i32 @close(i32 %13)
br label %15
15: ; preds = %18, %2
%16 = load i32, i32* %6
%17 = icmp slt i32 %16, 10
br i1 %17, label %18, label %39
18: ; preds = %15
%19 = load i32, i32* @stdout
%20 = call i32 (...) @getpid()
%21 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %20)
%22 = getelementptr inbounds [132 x i8], [132 x i8]* %5, i64 0, i64 0
%23 = call i32 @sprintf(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%24 = load i32*, i32** %3
%25 = getelementptr inbounds i32, i32* %24, i64 1
%26 = load i32, i32* %25
%27 = getelementptr inbounds [132 x i8], [132 x i8]* %5, i64 0, i64 0
%28 = getelementptr inbounds [132 x i8], [132 x i8]* %5, i64 0, i64 0
%29 = call i64 @strlen(i8* %28)
%30 = add nsw i64 %29, 1
%31 = call i32 @write(i32 %26, i8* %27, i64 %30)
%32 = load i32, i32* %6
%33 = add nsw i32 %32, 1
store i32 %33, i32* %6
%34 = load i32*, i32** %4
%35 = getelementptr inbounds i32, i32* %34, i64 0
%36 = load i32, i32* %35
%37 = getelementptr inbounds [132 x i8], [132 x i8]* %5, i64 0, i64 0
%38 = call i32 @read(i32 %36, i8* %37, i32 132)
br label %15
39: ; preds = %15
%40 = getelementptr inbounds [132 x i8], [132 x i8]* %5, i64 0, i64 0
%41 = call i32 @sprintf(i8* %40, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%42 = load i32*, i32** %3
%43 = getelementptr inbounds i32, i32* %42, i64 1
%44 = load i32, i32* %43
%45 = getelementptr inbounds [132 x i8], [132 x i8]* %5, i64 0, i64 0
%46 = getelementptr inbounds [132 x i8], [132 x i8]* %5, i64 0, i64 0
%47 = call i64 @strlen(i8* %46)
%48 = add nsw i64 %47, 1
%49 = call i32 @write(i32 %44, i8* %45, i64 %48)
%50 = load i32*, i32** %3
%51 = getelementptr inbounds i32, i32* %50, i64 1
%52 = load i32, i32* %51
%53 = call i32 @close(i32 %52)
%54 = load i32*, i32** %4
%55 = getelementptr inbounds i32, i32* %54, i64 0
%56 = load i32, i32* %55
%57 = call i32 @close(i32 %56)
ret void
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [25 x i8] c"I'm the father (PID=%d)\0A\00"
define void @father(i32* nocapture %0, i32* nocapture %1) {
%3 = alloca [132 x i8]
%4 = getelementptr inbounds [132 x i8], [132 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* %0
%6 = tail call i32 @close(i32 %5)
%7 = getelementptr inbounds i32, i32* %1, i64 1
%8 = load i32, i32* %7
%9 = tail call i32 @close(i32 %8)
%10 = bitcast [132 x i8]* %3 to i16*
%11 = getelementptr inbounds i32, i32* %0, i64 1
br label %12
12: ; preds = %2, %12
%13 = phi i32 [ 0, %2 ], [ %21, %12 ]
%14 = load i32, i32* @stdout
%15 = tail call i32 (...) @getpid()
%16 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %15)
store i16 88, i16* %10
%17 = load i32, i32* %11
%18 = call i64 @strlen(i8* %4)
%19 = add nsw i64 %18, 1
%20 = call i32 @write(i32 %17, i8* %4, i64 %19)
%21 = add nuw nsw i32 %13, 1
%22 = load i32, i32* %1
%23 = call i32 @read(i32 %22, i8* %4, i32 132)
%24 = icmp eq i32 %21, 10
br i1 %24, label %25, label %12
25: ; preds = %12
%26 = bitcast [132 x i8]* %3 to i32*
store i32 6581861, i32* %26
%27 = load i32, i32* %11
%28 = call i64 @strlen(i8* %4)
%29 = add nsw i64 %28, 1
%30 = call i32 @write(i32 %27, i8* %4, i64 %29)
%31 = load i32, i32* %11
%32 = tail call i32 @close(i32 %31)
%33 = load i32, i32* %1
%34 = tail call i32 @close(i32 %33)
ret void
}