#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*/ dup(int);
int /*<<< orphan*/ execlp(char *, char *, int /*<<< orphan*/ *);
int fork();
int /*<<< orphan*/ pipe(int *);
int /*<<< orphan*/ waitpid(int, void *, int /*<<< orphan*/);
int main(int arc, char **argv) {
  int resFils;
  int pid1, pid2;
  int tube[2];
  pipe(tube);
  pid1 = fork();
  if (pid1 == 0) {
    close(tube[0]);
    close(1);
    dup(tube[1]);
    execlp("/home/pascalfares/mesgit/nsy103/RingOfProcess/traitement/inc",
           "inc", NULL);
  }
  pid2 = fork();
  if (pid2 == 0) {
    close(tube[1]);
    close(0);
    dup(tube[0]);
    execlp("/home/pascalfares/mesgit/nsy103/RingOfProcess/traitement/inc",
           "inc", NULL);
  }
  waitpid(pid1, (void *)&resFils, 0);
  waitpid(pid2, (void *)&resFils, 0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x24(%rbp),%rdi
call   1050 <pipe@plt>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    11c4 <main+0x64>
mov    -0x24(%rbp),%edi
call   1040 <close@plt>
mov    $0x1,%edi
call   1040 <close@plt>
mov    -0x20(%rbp),%edi
call   1030 <dup@plt>
lea    0xe4c(%rip),%rdi
lea    0xe7e(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1070 <execlp@plt>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    1206 <main+0xa6>
mov    -0x20(%rbp),%edi
call   1040 <close@plt>
xor    %edi,%edi
call   1040 <close@plt>
mov    -0x24(%rbp),%edi
call   1030 <dup@plt>
lea    0xe0a(%rip),%rdi
lea    0xe3c(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1070 <execlp@plt>
mov    -0x18(%rbp),%edi
lea    -0x14(%rbp),%rsi
xor    %edx,%edx
call   1060 <waitpid@plt>
mov    -0x1c(%rbp),%edi
lea    -0x14(%rbp),%rsi
xor    %edx,%edx
call   1060 <waitpid@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0x4(%rsp),%rdi
call   1050 <pipe@plt>
xor    %eax,%eax
call   1080 <fork@plt>
mov    %eax,%r14d
test   %eax,%eax
jne    11b1 <main+0x51>
mov    0x4(%rsp),%edi
call   1040 <close@plt>
mov    $0x1,%edi
call   1040 <close@plt>
mov    0x8(%rsp),%edi
call   1030 <dup@plt>
lea    0xe5d(%rip),%rdi
lea    0xe8f(%rip),%rsi
xor    %edx,%edx
call   1070 <execlp@plt>
xor    %eax,%eax
call   1080 <fork@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    11ec <main+0x8c>
mov    0x8(%rsp),%edi
call   1040 <close@plt>
xor    %edi,%edi
call   1040 <close@plt>
mov    0x4(%rsp),%edi
call   1030 <dup@plt>
lea    0xe22(%rip),%rdi
lea    0xe54(%rip),%rsi
xor    %edx,%edx
call   1070 <execlp@plt>
lea    0xc(%rsp),%rbx
mov    %r14d,%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1060 <waitpid@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1060 <waitpid@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [61 x i8] c"/home/pascalfares/mesgit/nsy103/RingOfProcess/traitement/inc\00"
@.str.1 = [4 x i8] c"inc\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [2 x i32]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 0
%11 = call i32 @pipe(i32* %10)
%12 = call i32 (...) @fork()
store i32 %12, i32* %7
%13 = load i32, i32* %7
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %24
15: ; preds = %2
%16 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 0
%17 = load i32, i32* %16
%18 = call i32 @close(i32 %17)
%19 = call i32 @close(i32 1)
%20 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 1
%21 = load i32, i32* %20
%22 = call i32 @dup(i32 %21)
%23 = call i32 @execlp(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32* null)
br label %24
24: ; preds = %15, %2
%25 = call i32 (...) @fork()
store i32 %25, i32* %8
%26 = load i32, i32* %8
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %37
28: ; preds = %24
%29 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 1
%30 = load i32, i32* %29
%31 = call i32 @close(i32 %30)
%32 = call i32 @close(i32 0)
%33 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 0
%34 = load i32, i32* %33
%35 = call i32 @dup(i32 %34)
%36 = call i32 @execlp(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32* null)
br label %37
37: ; preds = %28, %24
%38 = load i32, i32* %7
%39 = bitcast i32* %6 to i8*
%40 = call i32 @waitpid(i32 %38, i8* %39, i32 0)
%41 = load i32, i32* %8
%42 = bitcast i32* %6 to i8*
%43 = call i32 @waitpid(i32 %41, i8* %42, i32 0)
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
@.str = [61 x i8] c"/home/pascalfares/mesgit/nsy103/RingOfProcess/traitement/inc\00"
@.str.1 = [4 x i8] c"inc\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca [2 x i32]
%5 = bitcast i32* %3 to i8*
%6 = bitcast [2 x i32]* %4 to i8*
%7 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%8 = call i32 @pipe(i32* %7)
%9 = call i32 (...) @fork()
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %19
11: ; preds = %2
%12 = load i32, i32* %7
%13 = call i32 @close(i32 %12)
%14 = call i32 @close(i32 1)
%15 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%16 = load i32, i32* %15
%17 = call i32 @dup(i32 %16)
%18 = call i32 @execlp(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32* null)
br label %19
19: ; preds = %11, %2
%20 = call i32 (...) @fork()
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %30
22: ; preds = %19
%23 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%24 = load i32, i32* %23
%25 = call i32 @close(i32 %24)
%26 = call i32 @close(i32 0)
%27 = load i32, i32* %7
%28 = call i32 @dup(i32 %27)
%29 = call i32 @execlp(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32* null)
br label %30
30: ; preds = %22, %19
%31 = call i32 @waitpid(i32 %9, i8* %5, i32 0)
%32 = call i32 @waitpid(i32 %20, i8* %5, i32 0)
ret i32 0
}