#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 EXIT_FAILURE;
int atoi(char *);
int fprintf(int /*<<< orphan*/, char *, char *);
int nfork(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stdout;
int main(int argc, char **argv) {
  int user_nb_fork = 0;
  int nfork_return = 0;
  int fprintf_return = 0;
  if (argc != 2) {
    fprintf_return =
        fprintf(stdout, "Usage: %s <nb de processus fils> \n", argv[0]);
    if (fprintf_return < 0) {
      perror("Error fprintf");
      return fprintf_return;
    }
    return -1;
  }
  user_nb_fork = atoi(argv[1]);
  if (user_nb_fork == 0) {
    return -1;
  }
  nfork_return = nfork(user_nb_fork);
  if (nfork_return <= 0)
    return EXIT_FAILURE;
  return nfork_return;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11c1 <main+0x81>
mov    0x2e5c(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe74(%rip),%rsi
call   1040 <fprintf@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11b5 <main+0x75>
lea    0xe7e(%rip),%rdi
call   1050 <perror@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1213 <main+0xd3>
movl   $0xffffffff,-0x4(%rbp)
jmp    1213 <main+0xd3>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    11e7 <main+0xa7>
movl   $0xffffffff,-0x4(%rbp)
jmp    1213 <main+0xd3>
mov    -0x14(%rbp),%edi
call   1030 <nfork@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jg     120d <main+0xcd>
mov    0x2ddd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1213 <main+0xd3>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
cmp    $0x2,%edi
jne    1169 <main+0x29>
mov    0x8(%rsi),%rdi
call   1060 <atoi@plt>
test   %eax,%eax
je     118e <main+0x4e>
mov    %eax,%edi
call   1030 <nfork@plt>
test   %eax,%eax
jg     118c <main+0x4c>
mov    0x2e7b(%rip),%rax
mov    (%rax),%eax
jmp    118c <main+0x4c>
mov    0x2e68(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xe84(%rip),%rsi
call   1040 <fprintf@plt>
mov    %eax,%ebx
mov    $0xffffffff,%eax
test   %ebx,%ebx
js     1195 <main+0x55>
pop    %rbx
ret
mov    $0xffffffff,%eax
pop    %rbx
ret
lea    0xe87(%rip),%rdi
call   1050 <perror@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@stdout = global i32 0
@.str = [35 x i8] c"Usage: %s <nb de processus fils> \0A\00"
@.str.1 = [14 x i8] c"Error fprintf\00"
@EXIT_FAILURE = 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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %23
11: ; preds = %2
%12 = load i32, i32* @stdout
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %15)
store i32 %16, i32* %8
%17 = load i32, i32* %8
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %11
%20 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%21 = load i32, i32* %8
store i32 %21, i32* %3
br label %40
22: ; preds = %11
store i32 -1, i32* %3
br label %40
23: ; preds = %2
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32 @atoi(i8* %26)
store i32 %27, i32* %6
%28 = load i32, i32* %6
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %23
store i32 -1, i32* %3
br label %40
31: ; preds = %23
%32 = load i32, i32* %6
%33 = call i32 @nfork(i32 %32)
store i32 %33, i32* %7
%34 = load i32, i32* %7
%35 = icmp sle i32 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %31
%37 = load i32, i32* @EXIT_FAILURE
store i32 %37, i32* %3
br label %40
38: ; preds = %31
%39 = load i32, i32* %7
store i32 %39, i32* %3
br label %40
40: ; preds = %38, %36, %30, %22, %19
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [35 x i8] c"Usage: %s <nb de processus fils> \0A\00"
@.str.1 = [14 x i8] c"Error fprintf\00"
@EXIT_FAILURE = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %11, label %4
4: ; preds = %2
%5 = load i32, i32* @stdout
%6 = load i8*, i8** %1
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %21
9: ; preds = %4
%10 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %21
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = tail call i32 @atoi(i8* %13)
%15 = icmp eq i32 %14, 0
br i1 %15, label %21, label %16
16: ; preds = %11
%17 = tail call i32 @nfork(i32 %14)
%18 = icmp slt i32 %17, 1
%19 = load i32, i32* @EXIT_FAILURE
%20 = select i1 %18, i32 %19, i32 %17
br label %21
21: ; preds = %16, %11, %4, %9
%22 = phi i32 [ %7, %9 ], [ -1, %4 ], [ -1, %11 ], [ %20, %16 ]
ret i32 %22
}