#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 /*<<< orphan*/ fscanf(int /*<<< orphan*/, char *, int *);
scalar_t__ malloc(int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ wait(int *);
int main(int argc, char *argv[]) {
  int n, *vett, i;
  pid_t pid;
  int ret;
  if (argc != 2) {
    fprintf(stderr, "Errore numero argomenti.\n");
    return -1;
  }
  n = atoi(argv[1]);
  vett = (int *)malloc(n * sizeof(int));
  for (i = 0; i < n; i++) {
    fprintf(stdout, "Inserire un intero:\n");
    fscanf(stdin, "%d", &vett[i]);
  }
  for (i = 0; i < n - 1; i++) {
    pid = fork();
    if (pid > 0) {
      wait(&ret);
      break;
    }
  }
  if (pid != 0)
    fprintf(stdout, "%d%s", vett[i], "\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)
cmpl   $0x2,-0x8(%rbp)
je     11a3 <main+0x43>
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
lea    0xe70(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12ac <main+0x14c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x14(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1222 <main+0xc2>
mov    0x2df0(%rip),%rax
mov    (%rax),%edi
lea    0xe31(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
movslq -0x24(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdx
lea    0xe20(%rip),%rsi
call   1030 <fscanf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11cd <main+0x6d>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1271 <main+0x111>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jle    125e <main+0xfe>
lea    -0x34(%rbp),%rdi
call   1070 <wait@plt>
jmp    1271 <main+0x111>
jmp    1263 <main+0x103>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1229 <main+0xc9>
cmpq   $0x0,-0x30(%rbp)
je     12a5 <main+0x145>
mov    0x2d4d(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xd9b(%rip),%rsi
lea    0xd7a(%rip),%rcx
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   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x2,%edi
jne    1241 <main+0xe1>
mov    0x8(%rsi),%rdi
call   1060 <atoi@plt>
mov    %eax,%ebp
lea    0x0(,%rbp,4),%edi
call   1050 <malloc@plt>
xor    %r14d,%r14d
mov    $0x0,%ebx
test   %ebp,%ebp
jle    1270 <main+0x110>
mov    %rbp,0x8(%rsp)
mov    %ebp,%r14d
mov    0x2e23(%rip),%r15
lea    0xe66(%rip),%r13
mov    0x2e2d(%rip),%r12
lea    0xe6d(%rip),%rbx
mov    %rax,(%rsp)
mov    %rax,%rbp
nopl   0x0(%rax)
mov    (%r15),%edi
mov    %r13,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%r12),%edi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   1030 <fscanf@plt>
add    $0x4,%rbp
add    $0xffffffffffffffff,%r14
jne    11d0 <main+0x70>
xor    %ebx,%ebx
mov    0x8(%rsp),%rcx
cmp    $0x2,%ecx
mov    $0x0,%r14d
mov    (%rsp),%rax
jl     1270 <main+0x110>
mov    %ecx,%ebx
add    $0xffffffff,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
jg     1260 <main+0x100>
add    $0x1,%ebp
cmp    %ebp,%ebx
jne    1220 <main+0xc0>
test   %rax,%rax
mov    (%rsp),%rax
jne    1270 <main+0x110>
xor    %r14d,%r14d
jmp    1293 <main+0x133>
mov    0x2d90(%rip),%rax
mov    (%rax),%edi
lea    0xdaf(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0xffffffff,%r14d
jmp    1293 <main+0x133>
lea    0x14(%rsp),%rdi
call   1070 <wait@plt>
mov    %ebp,%ebx
mov    (%rsp),%rax
mov    0x2d59(%rip),%rcx
mov    (%rcx),%edi
mov    %ebx,%ecx
mov    (%rax,%rcx,4),%edx
lea    0xdad(%rip),%rsi
lea    0xd8c(%rip),%rcx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %r14d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
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 = [21 x i8] c"Inserire un intero:\0A\00"
@stdin = global i32 0
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [5 x i8] c"%d%s\00"
@.str.4 = [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 i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 2
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %71
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @atoi(i8* %19)
store i32 %20, i32* %6
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = mul i64 %22, 4
%24 = trunc i64 %23 to i32
%25 = call i64 @malloc(i32 %24)
%26 = inttoptr i64 %25 to i32*
store i32* %26, i32** %7
store i32 0, i32* %8
br label %27
27: ; preds = %40, %16
%28 = load i32, i32* %8
%29 = load i32, i32* %6
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %43
31: ; preds = %27
%32 = load i32, i32* @stdout
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%34 = load i32, i32* @stdin
%35 = load i32*, i32** %7
%36 = load i32, i32* %8
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i32, i32* %35, i64 %37
%39 = call i32 @fscanf(i32 %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %38)
br label %40
40: ; preds = %31
%41 = load i32, i32* %8
%42 = add nsw i32 %41, 1
store i32 %42, i32* %8
br label %27
43: ; preds = %27
store i32 0, i32* %8
br label %44
44: ; preds = %56, %43
%45 = load i32, i32* %8
%46 = load i32, i32* %6
%47 = sub nsw i32 %46, 1
%48 = icmp slt i32 %45, %47
br i1 %48, label %49, label %59
49: ; preds = %44
%50 = call i64 (...) @fork()
store i64 %50, i64* %9
%51 = load i64, i64* %9
%52 = icmp sgt i64 %51, 0
br i1 %52, label %53, label %55
53: ; preds = %49
%54 = call i32 @wait(i32* %10)
br label %59
55: ; preds = %49
br label %56
56: ; preds = %55
%57 = load i32, i32* %8
%58 = add nsw i32 %57, 1
store i32 %58, i32* %8
br label %44
59: ; preds = %53, %44
%60 = load i64, i64* %9
%61 = icmp ne i64 %60, 0
br i1 %61, label %62, label %70
62: ; preds = %59
%63 = load i32, i32* @stdout
%64 = load i32*, i32** %7
%65 = load i32, i32* %8
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i32, i32* %64, i64 %66
%68 = load i32, i32* %67
%69 = call i32 (i32, i8*, ...) @fprintf(i32 %63, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %68, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %70
70: ; preds = %62, %59
store i32 0, i32* %3
br label %71
71: ; preds = %70, %13
%72 = load i32, i32* %3
ret i32 %72
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [26 x i8] c"Errore numero argomenti.\0A\00"
@stdout = global i32 0
@.str.1 = [21 x i8] c"Inserire un intero:\0A\00"
@stdin = global i32 0
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [5 x i8] c"%d%s\00"
@.str.4 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %49
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @atoi(i8* %11)
%13 = shl i32 %12, 2
%14 = tail call i64 @malloc(i32 %13)
%15 = inttoptr i64 %14 to i32*
%16 = icmp sgt i32 %12, 0
br i1 %16, label %17, label %42
17: ; preds = %9
%18 = zext i32 %12 to i64
br label %22
19: ; preds = %22
%20 = add i32 %12, -1
%21 = icmp sgt i32 %12, 1
br i1 %21, label %31, label %42
22: ; preds = %17, %22
%23 = phi i64 [ 0, %17 ], [ %29, %22 ]
%24 = load i32, i32* @stdout
%25 = tail call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%26 = load i32, i32* @stdin
%27 = getelementptr inbounds i32, i32* %15, i64 %23
%28 = tail call i32 @fscanf(i32 %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %27)
%29 = add nuw nsw i64 %23, 1
%30 = icmp eq i64 %29, %18
br i1 %30, label %19, label %22
31: ; preds = %19, %37
%32 = phi i32 [ %38, %37 ], [ 0, %19 ]
%33 = tail call i64 (...) @fork()
%34 = icmp sgt i64 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %31
%36 = call i32 @wait(i32* %3)
br label %42
37: ; preds = %31
%38 = add nuw nsw i32 %32, 1
%39 = icmp eq i32 %38, %20
br i1 %39, label %40, label %31
40: ; preds = %37
%41 = icmp eq i64 %33, 0
br i1 %41, label %49, label %42
42: ; preds = %9, %19, %35, %40
%43 = phi i32 [ %32, %35 ], [ %20, %40 ], [ 0, %19 ], [ 0, %9 ]
%44 = load i32, i32* @stdout
%45 = zext i32 %43 to i64
%46 = getelementptr inbounds i32, i32* %15, i64 %45
%47 = load i32, i32* %46
%48 = call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %47, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %49
49: ; preds = %40, %42, %6
%50 = phi i32 [ -1, %6 ], [ 0, %42 ], [ 0, %40 ]
ret i32 %50
}