#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*/ EXIT_SUCCESS;
int /*<<< orphan*/ analize_status(int);
int /*<<< orphan*/ child_process();
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ printf(char *, int, ...);
int waitpid(int, int *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int ret;
  int pid, pid_w;
  int count;
  int status;
  count = 0;
  while (count < 3) {
    pid = fork();
    if (pid == 0)
      child_process();
    else {
      pid_w = waitpid(pid, &status, 0);
      printf("Child terminato (count = %d)!\n", count);
      if (pid_w != pid)
        printf("Pid ritornato (%d) diverso da pid originale (%d)\n", pid,
               pid_w);
      analize_status(status);
      ++count;
    }
  }
  exit(EXIT_SUCCESS);
  return 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)
movl   $0x0,-0x20(%rbp)
cmpl   $0x3,-0x20(%rbp)
jge    11ff <main+0x9f>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    11a7 <main+0x47>
mov    $0x0,%al
call   1040 <child_process@plt>
jmp    11fa <main+0x9a>
mov    -0x18(%rbp),%edi
lea    -0x24(%rbp),%rsi
xor    %edx,%edx
call   1060 <waitpid@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%esi
lea    0xe3e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
je     11e9 <main+0x89>
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x24(%rbp),%edi
call   1050 <analize_status@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    117d <main+0x1d>
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0x4(%rsp),%r14
lea    0xe89(%rip),%r12
lea    0xea1(%rip),%r15
xor    %r13d,%r13d
jmp    11a3 <main+0x43>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x4(%rsp),%edi
call   1050 <analize_status@plt>
add    $0x1,%r13d
cmp    $0x3,%r13d
jge    11ed <main+0x8d>
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     11e0 <main+0x80>
mov    %eax,%ebx
mov    %eax,%edi
mov    %r14,%rsi
xor    %edx,%edx
call   1060 <waitpid@plt>
mov    %eax,%ebp
mov    %r12,%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1030 <printf@plt>
cmp    %ebx,%ebp
je     1190 <main+0x30>
mov    %r15,%rdi
mov    %ebx,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1190 <main+0x30>
nop
xor    %eax,%eax
call   1040 <child_process@plt>
cmp    $0x3,%r13d
jl     11a3 <main+0x43>
mov    0x2dec(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [31 x i8] c"Child terminato (count = %d)!\0A\00"
@.str.1 = [50 x i8] c"Pid ritornato (%d) diverso da pid originale (%d)\0A\00"
@EXIT_SUCCESS = global i32 0
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 i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %9
br label %11
11: ; preds = %37, %2
%12 = load i32, i32* %9
%13 = icmp slt i32 %12, 3
br i1 %13, label %14, label %38
14: ; preds = %11
%15 = call i32 (...) @fork()
store i32 %15, i32* %7
%16 = load i32, i32* %7
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = call i32 (...) @child_process()
br label %37
20: ; preds = %14
%21 = load i32, i32* %7
%22 = call i32 @waitpid(i32 %21, i32* %10, i32 0)
store i32 %22, i32* %8
%23 = load i32, i32* %9
%24 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %23)
%25 = load i32, i32* %8
%26 = load i32, i32* %7
%27 = icmp ne i32 %25, %26
br i1 %27, label %28, label %32
28: ; preds = %20
%29 = load i32, i32* %7
%30 = load i32, i32* %8
%31 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0), i32 %29, i32 %30)
br label %32
32: ; preds = %28, %20
%33 = load i32, i32* %10
%34 = call i32 @analize_status(i32 %33)
%35 = load i32, i32* %9
%36 = add nsw i32 %35, 1
store i32 %36, i32* %9
br label %37
37: ; preds = %32, %18
br label %11
38: ; preds = %11
%39 = load i32, i32* @EXIT_SUCCESS
%40 = call i32 @exit(i32 %39)
unreachable
}

LLVM IR (-O2):
@.str = [31 x i8] c"Child terminato (count = %d)!\0A\00"
@.str.1 = [50 x i8] c"Pid ritornato (%d) diverso da pid originale (%d)\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
br label %5
5: ; preds = %2, %21
%6 = phi i32 [ 0, %2 ], [ %22, %21 ]
%7 = call i32 (...) @fork()
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %5
%10 = call i32 (...) @child_process()
br label %21
11: ; preds = %5
%12 = call i32 @waitpid(i32 %7, i32* %3, i32 0)
%13 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %6)
%14 = icmp eq i32 %12, %7
br i1 %14, label %17, label %15
15: ; preds = %11
%16 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0), i32 %7, i32 %12)
br label %17
17: ; preds = %15, %11
%18 = load i32, i32* %3
%19 = call i32 @analize_status(i32 %18)
%20 = add nsw i32 %6, 1
br label %21
21: ; preds = %17, %9
%22 = phi i32 [ %6, %9 ], [ %20, %17 ]
%23 = icmp slt i32 %22, 3
br i1 %23, label %5, label %24
24: ; preds = %21
%25 = load i32, i32* @EXIT_SUCCESS
%26 = call i32 @exit(i32 %25)
unreachable
}