#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 atoi(char *);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int getpid();
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  int n, t, i;
  pid_t pid1, pid2;
  int continua = 1;
  if (argc != 3) {
    fprintf(stderr, "Errore numero argomenti.\n");
    return -1;
  }
  n = atoi(argv[1]);
  t = atoi(argv[2]);
  for (i = 0; i < n && continua; i++) {
    pid1 = fork();
    if (pid1 > 0) {
      pid2 = fork();
      if (pid2 > 0) {
        continua = 0;
      }
    }
  }
  if (i == n && continua) {
    sleep(t);
    fprintf(stdout, "%s %d %s", "Terminazione foglia processo: ", getpid(),
            "\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x34(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     119a <main+0x4a>
mov    0x2e62(%rip),%rax
mov    (%rax),%edi
lea    0xe79(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1290 <main+0x140>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%ecx
xor    %eax,%eax
cmp    -0x14(%rbp),%ecx
mov    %al,-0x35(%rbp)
jge    11dc <main+0x8c>
cmpl   $0x0,-0x34(%rbp)
setne  %al
mov    %al,-0x35(%rbp)
mov    -0x35(%rbp),%al
test   $0x1,%al
jne    11ec <main+0x9c>
jmp    1237 <main+0xe7>
mov    $0x0,%al
call   1070 <fork@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jle    1224 <main+0xd4>
mov    $0x0,%al
call   1070 <fork@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jle    121f <main+0xcf>
movl   $0x0,-0x34(%rbp)
jmp    1224 <main+0xd4>
jmp    1229 <main+0xd9>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11c1 <main+0x71>
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    1289 <main+0x139>
cmpl   $0x0,-0x34(%rbp)
je     1289 <main+0x139>
mov    -0x18(%rbp),%edi
call   1060 <sleep@plt>
mov    0x2d7c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x3c(%rbp),%edi
mov    %eax,%ecx
lea    0xda6(%rip),%rsi
lea    0xda8(%rip),%rdx
lea    0xd96(%rip),%r8
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    $0x3,%edi
jne    11b7 <main+0x67>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   1050 <atoi@plt>
mov    %eax,%ebp
mov    0x10(%rbx),%rdi
call   1050 <atoi@plt>
mov    %eax,%r14d
xor    %r15d,%r15d
test   %ebp,%ebp
jle    11d6 <main+0x86>
xor    %ebx,%ebx
nop
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
jle    11a0 <main+0x50>
xor    %eax,%eax
call   1070 <fork@plt>
xor    %ecx,%ecx
test   %rax,%rax
setle  %cl
jmp    11a5 <main+0x55>
nopl   (%rax)
mov    $0x1,%ecx
add    $0x1,%ebx
test   %ecx,%ecx
setne  %al
cmp    %ebp,%ebx
jge    11da <main+0x8a>
test   %ecx,%ecx
jne    1180 <main+0x30>
jmp    11da <main+0x8a>
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
lea    0xe39(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0xffffffff,%r15d
jmp    121d <main+0xcd>
mov    $0x1,%al
xor    %ebx,%ebx
cmp    %ebp,%ebx
jne    121d <main+0xcd>
test   %al,%al
je     121d <main+0xcd>
mov    %r14d,%edi
call   1060 <sleep@plt>
mov    0x2de7(%rip),%rax
mov    (%rax),%ebp
xor    %r15d,%r15d
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe16(%rip),%rsi
lea    0xe18(%rip),%rdx
lea    0xe06(%rip),%r8
mov    %ebp,%edi
mov    %eax,%ecx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [26 x i8] c"Errore numero argomenti.\0A\00"
@stdout = global i32 0
@.str.1 = [9 x i8] c"%s %d %s\00"
@.str.2 = [31 x i8] c"Terminazione foglia processo: \00"
@.str.3 = [2 x i8] c"\0A\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 i64
%10 = alloca i64
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %11
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 3
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %63
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32 @atoi(i8* %20)
store i32 %21, i32* %6
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 2
%24 = load i8*, i8** %23
%25 = call i32 @atoi(i8* %24)
store i32 %25, i32* %7
store i32 0, i32* %8
br label %26
26: ; preds = %46, %17
%27 = load i32, i32* %8
%28 = load i32, i32* %6
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %33
30: ; preds = %26
%31 = load i32, i32* %11
%32 = icmp ne i32 %31, 0
br label %33
33: ; preds = %30, %26
%34 = phi i1 [ false, %26 ], [ %32, %30 ]
br i1 %34, label %35, label %49
35: ; preds = %33
%36 = call i64 (...) @fork()
store i64 %36, i64* %9
%37 = load i64, i64* %9
%38 = icmp sgt i64 %37, 0
br i1 %38, label %39, label %45
39: ; preds = %35
%40 = call i64 (...) @fork()
store i64 %40, i64* %10
%41 = load i64, i64* %10
%42 = icmp sgt i64 %41, 0
br i1 %42, label %43, label %44
43: ; preds = %39
store i32 0, i32* %11
br label %44
44: ; preds = %43, %39
br label %45
45: ; preds = %44, %35
br label %46
46: ; preds = %45
%47 = load i32, i32* %8
%48 = add nsw i32 %47, 1
store i32 %48, i32* %8
br label %26
49: ; preds = %33
%50 = load i32, i32* %8
%51 = load i32, i32* %6
%52 = icmp eq i32 %50, %51
br i1 %52, label %53, label %62
53: ; preds = %49
%54 = load i32, i32* %11
%55 = icmp ne i32 %54, 0
br i1 %55, label %56, label %62
56: ; preds = %53
%57 = load i32, i32* %7
%58 = call i32 @sleep(i32 %57)
%59 = load i32, i32* @stdout
%60 = call i32 (...) @getpid()
%61 = call i32 (i32, i8*, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %60, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %62
62: ; preds = %56, %53, %49
store i32 0, i32* %3
br label %63
63: ; preds = %62, %14
%64 = load i32, i32* %3
ret i32 %64
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [26 x i8] c"Errore numero argomenti.\0A\00"
@stdout = global i32 0
@.str.1 = [9 x i8] c"%s %d %s\00"
@.str.2 = [31 x i8] c"Terminazione foglia processo: \00"
@.str.3 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %39
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @atoi(i8* %9)
%11 = getelementptr inbounds i8*, i8** %1, i64 2
%12 = load i8*, i8** %11
%13 = tail call i32 @atoi(i8* %12)
%14 = icmp sgt i32 %10, 0
br i1 %14, label %15, label %29
15: ; preds = %7, %23
%16 = phi i32 [ %25, %23 ], [ 0, %7 ]
%17 = tail call i64 (...) @fork()
%18 = icmp sgt i64 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %15
%20 = tail call i64 (...) @fork()
%21 = icmp slt i64 %20, 1
%22 = zext i1 %21 to i32
br label %23
23: ; preds = %19, %15
%24 = phi i32 [ 1, %15 ], [ %22, %19 ]
%25 = add nuw nsw i32 %16, 1
%26 = icmp slt i32 %25, %10
%27 = icmp ne i32 %24, 0
%28 = and i1 %26, %27
br i1 %28, label %15, label %29
29: ; preds = %23, %7
%30 = phi i32 [ 0, %7 ], [ %25, %23 ]
%31 = phi i1 [ true, %7 ], [ %27, %23 ]
%32 = icmp eq i32 %30, %10
%33 = and i1 %32, %31
br i1 %33, label %34, label %39
34: ; preds = %29
%35 = tail call i32 @sleep(i32 %13)
%36 = load i32, i32* @stdout
%37 = tail call i32 (...) @getpid()
%38 = tail call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %37, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %39
39: ; preds = %29, %34, %4
%40 = phi i32 [ -1, %4 ], [ 0, %34 ], [ 0, %29 ]
ret i32 %40
}