#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*/ figlioConsumatore(int *);
int /*<<< orphan*/ figlioProduttore(scalar_t__, int *);
scalar_t__ fork();
int /*<<< orphan*/ pipe(int *);
int /*<<< orphan*/ wait(int *);
int main() {
  pid_t pid;
  int fd[2];
  pipe(fd);
  pid = fork();
  if (pid == 0) {
    figlioConsumatore(fd);
  } else {
    if (fork()) {
      wait((int *)0);
    } else {
      figlioProduttore(pid, fd);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x18(%rbp),%rdi
call   1030 <pipe@plt>
mov    $0x0,%al
call   1070 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    118c <main+0x3c>
lea    -0x18(%rbp),%rdi
call   1050 <figlioConsumatore@plt>
jmp    11bd <main+0x6d>
mov    $0x0,%al
call   1070 <fork@plt>
cmp    $0x0,%rax
je     11ab <main+0x5b>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <wait@plt>
jmp    11b8 <main+0x68>
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <figlioProduttore@plt>
jmp    11bd <main+0x6d>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0x8(%rsp),%rdi
call   1030 <pipe@plt>
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
je     1183 <main+0x33>
mov    %rax,%rbx
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
je     118f <main+0x3f>
xor    %edi,%edi
call   1060 <wait@plt>
jmp    119c <main+0x4c>
lea    0x8(%rsp),%rdi
call   1050 <figlioConsumatore@plt>
jmp    119c <main+0x4c>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <figlioProduttore@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca [2 x i32]
store i32 0, i32* %1
%4 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%5 = call i32 @pipe(i32* %4)
%6 = call i64 (...) @fork()
store i64 %6, i64* %2
%7 = load i64, i64* %2
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%11 = call i32 @figlioConsumatore(i32* %10)
br label %22
12: ; preds = %0
%13 = call i64 (...) @fork()
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = call i32 @wait(i32* null)
br label %21
17: ; preds = %12
%18 = load i64, i64* %2
%19 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%20 = call i32 @figlioProduttore(i64 %18, i32* %19)
br label %21
21: ; preds = %17, %15
br label %22
22: ; preds = %21, %9
ret i32 0
}

LLVM IR (-O2):
define i32 @main() {
%1 = alloca [2 x i32]
%2 = bitcast [2 x i32]* %1 to i8*
%3 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%4 = call i32 @pipe(i32* %3)
%5 = call i64 (...) @fork()
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @figlioConsumatore(i32* %3)
br label %16
9: ; preds = %0
%10 = call i64 (...) @fork()
%11 = icmp eq i64 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %9
%13 = call i32 @wait(i32* null)
br label %16
14: ; preds = %9
%15 = call i32 @figlioProduttore(i64 %5, i32* %3)
br label %16
16: ; preds = %12, %14, %7
ret i32 0
}