#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*/ dprintf(int, char *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int getpid();
int /*<<< orphan*/ pipe(int *);
int /*<<< orphan*/ printf(char *, int);
int read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main() {
  int p[2];
  char buffer[10];
  int nbc;
  pipe(p);
  if (fork() == 0) {
    close(p[1]);
    printf("[INFO] Le pid du fils est %d\n", getpid());
    nbc = read(p[0], buffer, 10);
    write(1, buffer, nbc);
    exit(0);
  } else {
    close(p[0]);
    printf("[INFO] Le pid du père est %d\n", getpid());
    dprintf(p[1], "%d\n", getpid());
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x8(%rbp),%rdi
call   1080 <pipe@plt>
mov    $0x0,%al
call   10b0 <fork@plt>
cmp    $0x0,%rax
jne    11fb <main+0x6b>
mov    -0x4(%rbp),%edi
call   1060 <close@plt>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%esi
lea    0xe36(%rip),%rdi
call   1050 <printf@plt>
mov    -0x8(%rbp),%edi
lea    -0x12(%rbp),%rsi
mov    $0xa,%edx
call   1090 <read@plt>
mov    %eax,-0x18(%rbp)
lea    -0x12(%rbp),%rsi
mov    -0x18(%rbp),%edx
mov    $0x1,%edi
call   1030 <write@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%esi
lea    0xe0b(%rip),%rdi
call   1050 <printf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    -0x1c(%rbp),%edi
mov    %eax,%edx
lea    0xe08(%rip),%rsi
call   1070 <dprintf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
lea    0xc(%rsp),%rdi
call   1080 <pipe@plt>
xor    %eax,%eax
call   10b0 <fork@plt>
test   %rax,%rax
je     11ec <main+0x5c>
mov    0xc(%rsp),%edi
call   1060 <close@plt>
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe5c(%rip),%rdi
mov    %eax,%esi
call   1050 <printf@plt>
mov    0x10(%rsp),%ebx
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe5e(%rip),%rsi
mov    %ebx,%edi
mov    %eax,%edx
call   1070 <dprintf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret
mov    0x10(%rsp),%edi
call   1060 <close@plt>
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xdfd(%rip),%rdi
mov    %eax,%esi
call   1050 <printf@plt>
mov    0xc(%rsp),%edi
lea    0x16(%rsp),%rbx
mov    %rbx,%rsi
mov    $0xa,%edx
call   1090 <read@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [30 x i8] c"[INFO] Le pid du fils est %d\0A\00"
@.str.1 = [31 x i8] c"[INFO] Le pid du p\C3\A8re est %d\0A\00"
@.str.2 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca [2 x i32]
%2 = alloca [10 x i8]
%3 = alloca i32
%4 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%5 = call i32 @pipe(i32* %4)
%6 = call i64 (...) @fork()
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %22
8: ; preds = %0
%9 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%10 = load i32, i32* %9
%11 = call i32 @close(i32 %10)
%12 = call i32 (...) @getpid()
%13 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%15 = load i32, i32* %14
%16 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%17 = call i32 @read(i32 %15, i8* %16, i32 10)
store i32 %17, i32* %3
%18 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%19 = load i32, i32* %3
%20 = call i32 @write(i32 1, i8* %18, i32 %19)
%21 = call i32 @exit(i32 0)
unreachable
22: ; preds = %0
%23 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%24 = load i32, i32* %23
%25 = call i32 @close(i32 %24)
%26 = call i32 (...) @getpid()
%27 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %26)
%28 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%29 = load i32, i32* %28
%30 = call i32 (...) @getpid()
%31 = call i32 @dprintf(i32 %29, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %30)
br label %32
32: ; preds = %22
ret i32 0
}

LLVM IR (-O2):
@.str = [30 x i8] c"[INFO] Le pid du fils est %d\0A\00"
@.str.1 = [31 x i8] c"[INFO] Le pid du p\C3\A8re est %d\0A\00"
@.str.2 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca [2 x i32]
%2 = alloca [10 x i8]
%3 = bitcast [2 x i32]* %1 to i8*
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%6 = call i32 @pipe(i32* %5)
%7 = call i64 (...) @fork()
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %19
9: ; preds = %0
%10 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%11 = load i32, i32* %10
%12 = call i32 @close(i32 %11)
%13 = call i32 (...) @getpid()
%14 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = load i32, i32* %5
%16 = call i32 @read(i32 %15, i8* %4, i32 10)
%17 = call i32 @write(i32 1, i8* %4, i32 %16)
%18 = call i32 @exit(i32 0)
unreachable
19: ; preds = %0
%20 = load i32, i32* %5
%21 = call i32 @close(i32 %20)
%22 = call i32 (...) @getpid()
%23 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %22)
%24 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%25 = load i32, i32* %24
%26 = call i32 (...) @getpid()
%27 = call i32 @dprintf(i32 %25, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %26)
ret i32 0
}