#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 fork();
int getpid();
int getppid();
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ sleep(int);
int main() {
  int p = 0;
  p = fork();
  if (p == 0) {
    printf("Mio padre è: %d\n", getppid());
    sleep(2);
    for (int i = 0; i < 100; i++) {
      printf("%d,", i);
    }
    printf("\nMio padre è: %d\n", getppid());
  } else {
    printf("Io sono il processo %d\n", getpid());
    sleep(1);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    11e1 <main+0x91>
mov    $0x0,%al
call   1050 <getppid@plt>
mov    %eax,%esi
lea    0xe7b(%rip),%rdi
call   1040 <printf@plt>
mov    $0x2,%edi
call   1060 <sleep@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0x64,-0xc(%rbp)
jge    11c7 <main+0x77>
mov    -0xc(%rbp),%esi
lea    0xe4c(%rip),%rdi
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11a0 <main+0x50>
mov    $0x0,%al
call   1050 <getppid@plt>
mov    %eax,%esi
lea    0xe2d(%rip),%rdi
call   1040 <printf@plt>
jmp    1200 <main+0xb0>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe26(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
xor    %ebx,%ebx
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
je     1182 <main+0x32>
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xea8(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
jmp    11d7 <main+0x87>
xor    %eax,%eax
call   1050 <getppid@plt>
lea    0xe75(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    $0x2,%edi
call   1060 <sleep@plt>
lea    0xe58(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %ebx,%esi
call   1040 <printf@plt>
add    $0x1,%ebx
cmp    $0x64,%ebx
jne    11b0 <main+0x60>
xor    %eax,%eax
call   1050 <getppid@plt>
lea    0xe34(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [18 x i8] c"Mio padre \C3\A8: %d\0A\00"
@.str.1 = [4 x i8] c"%d,\00"
@.str.2 = [19 x i8] c"\0AMio padre \C3\A8: %d\0A\00"
@.str.3 = [24 x i8] c"Io sono il processo %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
%4 = call i32 (...) @fork()
store i32 %4, i32* %2
%5 = load i32, i32* %2
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %23
7: ; preds = %0
%8 = call i32 (...) @getppid()
%9 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = call i32 @sleep(i32 2)
store i32 0, i32* %3
br label %11
11: ; preds = %17, %7
%12 = load i32, i32* %3
%13 = icmp slt i32 %12, 100
br i1 %13, label %14, label %20
14: ; preds = %11
%15 = load i32, i32* %3
%16 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %15)
br label %17
17: ; preds = %14
%18 = load i32, i32* %3
%19 = add nsw i32 %18, 1
store i32 %19, i32* %3
br label %11
20: ; preds = %11
%21 = call i32 (...) @getppid()
%22 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %21)
br label %27
23: ; preds = %0
%24 = call i32 (...) @getpid()
%25 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %24)
%26 = call i32 @sleep(i32 1)
br label %27
27: ; preds = %23, %20
%28 = load i32, i32* %1
ret i32 %28
}

LLVM IR (-O2):
@.str = [18 x i8] c"Mio padre \C3\A8: %d\0A\00"
@.str.1 = [4 x i8] c"%d,\00"
@.str.2 = [19 x i8] c"\0AMio padre \C3\A8: %d\0A\00"
@.str.3 = [24 x i8] c"Io sono il processo %d\0A\00"
define i32 @main() {
%1 = tail call i32 (...) @fork()
%2 = icmp eq i32 %1, 0
br i1 %2, label %3, label %15
3: ; preds = %0
%4 = tail call i32 (...) @getppid()
%5 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = tail call i32 @sleep(i32 2)
br label %10
7: ; preds = %10
%8 = tail call i32 (...) @getppid()
%9 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %8)
br label %19
10: ; preds = %3, %10
%11 = phi i32 [ 0, %3 ], [ %13, %10 ]
%12 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = add nuw nsw i32 %11, 1
%14 = icmp eq i32 %13, 100
br i1 %14, label %7, label %10
15: ; preds = %0
%16 = tail call i32 (...) @getpid()
%17 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %16)
%18 = tail call i32 @sleep(i32 1)
br label %19
19: ; preds = %15, %7
ret i32 0
}