#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 int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ EOF;
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int main(int argc, char *argv[]) {
  FILE *sorgente;
  char string[128];
  char **vett;
  int i, j;
  if (argc != 2) {
    fprintf(stderr, "Errore numero argomenti.\n");
    return (-1);
  }
  if ((sorgente = fopen(argv[1], "r")) == NULL) {
    fprintf(stderr, "Errore apertura file.\n");
    return (-2);
  }
  vett = (char **)malloc(10 * sizeof(char *));
  i = 0;
  while (fscanf(sorgente, "%s", string) != EOF) {
    vett[i] = (char *)malloc(10 * sizeof(char));
    if (strcmp(string, "end") != 0) {
      strcpy(vett[i++], string);
    } else {
      vett[i] = NULL;
      if (fork() > 0) {
        sleep(3);
      } else {
        execvp(vett[0], vett);
      }
      for (j = i; j >= 0; j--)
        free(vett[j]);
      i = 0;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11e4 <main+0x44>
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
lea    0xe2d(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    137b <main+0x1db>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe27(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1227 <main+0x87>
mov    0x2dcb(%rip),%rax
mov    (%rax),%edi
lea    0xe06(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    137b <main+0x1db>
mov    $0x50,%edi
call   1080 <malloc@plt>
mov    %rax,-0xa8(%rbp)
movl   $0x0,-0xac(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0xa0(%rbp),%rdx
lea    0xddf(%rip),%rsi
call   1050 <fscanf@plt>
mov    0x2d88(%rip),%rcx
cmp    (%rcx),%rax
je     1374 <main+0x1d4>
mov    $0xa,%edi
call   1080 <malloc@plt>
mov    %rax,%rdx
mov    -0xa8(%rbp),%rax
movslq -0xac(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
lea    -0xa0(%rbp),%rdi
lea    0xda0(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     12d5 <main+0x135>
mov    -0xa8(%rbp),%rax
mov    -0xac(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0xac(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
lea    -0xa0(%rbp),%rsi
call   1040 <strcpy@plt>
jmp    136f <main+0x1cf>
mov    -0xa8(%rbp),%rax
movslq -0xac(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    $0x0,%al
call   10c0 <fork@plt>
cmp    $0x0,%rax
jle    130b <main+0x16b>
mov    $0x3,%edi
call   10b0 <sleep@plt>
jmp    1321 <main+0x181>
mov    -0xa8(%rbp),%rax
mov    (%rax),%rdi
mov    -0xa8(%rbp),%rsi
call   10a0 <execvp@plt>
mov    -0xac(%rbp),%eax
mov    %eax,-0xb0(%rbp)
cmpl   $0x0,-0xb0(%rbp)
jl     1365 <main+0x1c5>
mov    -0xa8(%rbp),%rax
movslq -0xb0(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <free@plt>
mov    -0xb0(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xb0(%rbp)
jmp    132d <main+0x18d>
movl   $0x0,-0xac(%rbp)
jmp    1242 <main+0xa2>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
cmp    $0x2,%edi
jne    12b4 <main+0x114>
mov    0x8(%rsi),%rdi
lea    0xe55(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     12c2 <main+0x122>
mov    %rax,%r14
mov    $0x50,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
lea    0xe49(%rip),%rsi
mov    %rsp,%rdx
mov    %r14,%rdi
call   1050 <fscanf@plt>
mov    0x2dec(%rip),%rcx
xor    %ebp,%ebp
cmp    (%rcx),%rax
je     12dc <main+0x13c>
mov    %rsp,%r12
xor    %ebp,%ebp
jmp    1245 <main+0xa5>
xchg   %ax,%ax
lea    0x1(%r13),%r15d
mov    (%rbx,%r13,8),%rdi
mov    %r12,%rsi
call   1040 <strcpy@plt>
mov    %r14,%rdi
lea    0xe09(%rip),%rsi
mov    %r12,%rdx
call   1050 <fscanf@plt>
mov    %r15d,%ebp
mov    0x2dac(%rip),%rcx
cmp    (%rcx),%rax
je     12f0 <main+0x150>
mov    $0xa,%edi
call   1080 <malloc@plt>
movslq %ebp,%r13
mov    %rax,(%rbx,%r13,8)
mov    %r12,%rdi
lea    0xdd6(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    1210 <main+0x70>
movq   $0x0,(%rbx,%r13,8)
xor    %eax,%eax
call   10c0 <fork@plt>
test   %rax,%rax
jle    128a <main+0xea>
mov    $0x3,%edi
call   10b0 <sleep@plt>
jmp    1295 <main+0xf5>
mov    (%rbx),%rdi
mov    %rbx,%rsi
call   10a0 <execvp@plt>
xor    %r15d,%r15d
test   %ebp,%ebp
js     1220 <main+0x80>
mov    %ebp,%ebp
xchg   %ax,%ax
mov    (%rbx,%rbp,8),%rdi
call   1030 <free@plt>
add    $0xffffffffffffffff,%rbp
jb     12a0 <main+0x100>
jmp    1220 <main+0x80>
mov    $0xffffffff,%ebp
lea    0xd40(%rip),%rsi
jmp    12ce <main+0x12e>
mov    $0xfffffffe,%ebp
lea    0xd4e(%rip),%rsi
mov    0x2d03(%rip),%rax
mov    (%rax),%edi
call   1070 <fprintf@plt>
mov    %ebp,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ebp,%ebp
jmp    12dc <main+0x13c>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [26 x i8] c"Errore numero argomenti.\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [23 x i8] c"Errore apertura file.\0A\00"
@.str.3 = [3 x i8] c"%s\00"
@EOF = global i64 0
@.str.4 = [4 x i8] c"end\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [128 x i8]
%8 = alloca i8**
%9 = alloca i32
%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 @fprintf(i32 %14, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %86
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %20, i32** %6
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %25
22: ; preds = %16
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
store i32 -2, i32* %3
br label %86
25: ; preds = %16
%26 = call i64 @malloc(i32 80)
%27 = inttoptr i64 %26 to i8**
store i8** %27, i8*** %8
store i32 0, i32* %9
br label %28
28: ; preds = %84, %25
%29 = load i32*, i32** %6
%30 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%31 = call i64 @fscanf(i32* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %30)
%32 = load i64, i64* @EOF
%33 = icmp ne i64 %31, %32
br i1 %33, label %34, label %85
34: ; preds = %28
%35 = call i64 @malloc(i32 10)
%36 = inttoptr i64 %35 to i8*
%37 = load i8**, i8*** %8
%38 = load i32, i32* %9
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8*, i8** %37, i64 %39
store i8* %36, i8** %40
%41 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%42 = call i64 @strcmp(i8* %41, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %53
44: ; preds = %34
%45 = load i8**, i8*** %8
%46 = load i32, i32* %9
%47 = add nsw i32 %46, 1
store i32 %47, i32* %9
%48 = sext i32 %46 to i64
%49 = getelementptr inbounds i8*, i8** %45, i64 %48
%50 = load i8*, i8** %49
%51 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%52 = call i32 @strcpy(i8* %50, i8* %51)
br label %84
53: ; preds = %34
%54 = load i8**, i8*** %8
%55 = load i32, i32* %9
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8*, i8** %54, i64 %56
store i8* null, i8** %57
%58 = call i64 (...) @fork()
%59 = icmp sgt i64 %58, 0
br i1 %59, label %60, label %62
60: ; preds = %53
%61 = call i32 @sleep(i32 3)
br label %68
62: ; preds = %53
%63 = load i8**, i8*** %8
%64 = getelementptr inbounds i8*, i8** %63, i64 0
%65 = load i8*, i8** %64
%66 = load i8**, i8*** %8
%67 = call i32 @execvp(i8* %65, i8** %66)
br label %68
68: ; preds = %62, %60
%69 = load i32, i32* %9
store i32 %69, i32* %10
br label %70
70: ; preds = %80, %68
%71 = load i32, i32* %10
%72 = icmp sge i32 %71, 0
br i1 %72, label %73, label %83
73: ; preds = %70
%74 = load i8**, i8*** %8
%75 = load i32, i32* %10
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds i8*, i8** %74, i64 %76
%78 = load i8*, i8** %77
%79 = call i32 @free(i8* %78)
br label %80
80: ; preds = %73
%81 = load i32, i32* %10
%82 = add nsw i32 %81, -1
store i32 %82, i32* %10
br label %70
83: ; preds = %70
store i32 0, i32* %9
br label %84
84: ; preds = %83, %44
br label %28
85: ; preds = %28
store i32 0, i32* %3
br label %86
86: ; preds = %85, %22, %13
%87 = load i32, i32* %3
ret i32 %87
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [26 x i8] c"Errore numero argomenti.\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [23 x i8] c"Errore apertura file.\0A\00"
@.str.3 = [3 x i8] c"%s\00"
@EOF = global i64 0
@.str.4 = [4 x i8] c"end\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [128 x i8]
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 2
br i1 %5, label %6, label %53
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %53, label %11
11: ; preds = %6
%12 = tail call i64 @malloc(i32 80)
%13 = inttoptr i64 %12 to i8**
%14 = call i64 @fscanf(i32* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%15 = load i64, i64* @EOF
%16 = icmp eq i64 %14, %15
br i1 %16, label %58, label %17
17: ; preds = %11, %48
%18 = phi i32 [ %49, %48 ], [ 0, %11 ]
%19 = call i64 @malloc(i32 10)
%20 = inttoptr i64 %19 to i8*
%21 = sext i32 %18 to i64
%22 = getelementptr inbounds i8*, i8** %13, i64 %21
store i8* %20, i8** %22
%23 = call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %29, label %25
25: ; preds = %17
%26 = add nsw i32 %18, 1
%27 = load i8*, i8** %22
%28 = call i32 @strcpy(i8* %27, i8* %4)
br label %48
29: ; preds = %17
store i8* null, i8** %22
%30 = call i64 (...) @fork()
%31 = icmp sgt i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %29
%33 = call i32 @sleep(i32 3)
br label %37
34: ; preds = %29
%35 = load i8*, i8** %13
%36 = call i32 @execvp(i8* %35, i8** %13)
br label %37
37: ; preds = %34, %32
%38 = icmp sgt i32 %18, -1
br i1 %38, label %39, label %48
39: ; preds = %37
%40 = zext i32 %18 to i64
br label %41
41: ; preds = %39, %41
%42 = phi i64 [ %40, %39 ], [ %46, %41 ]
%43 = getelementptr inbounds i8*, i8** %13, i64 %42
%44 = load i8*, i8** %43
%45 = call i32 @free(i8* %44)
%46 = add nsw i64 %42, -1
%47 = icmp eq i64 %42, 0
br i1 %47, label %48, label %41
48: ; preds = %41, %37, %25
%49 = phi i32 [ %26, %25 ], [ 0, %37 ], [ 0, %41 ]
%50 = call i64 @fscanf(i32* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%51 = load i64, i64* @EOF
%52 = icmp eq i64 %50, %51
br i1 %52, label %58, label %17
53: ; preds = %6, %2
%54 = phi i8* [ getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), %2 ], [ getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), %6 ]
%55 = phi i32 [ -1, %2 ], [ -2, %6 ]
%56 = load i32, i32* @stderr
%57 = tail call i32 @fprintf(i32 %56, i8* %54)
br label %58
58: ; preds = %48, %53, %11
%59 = phi i32 [ 0, %11 ], [ %55, %53 ], [ 0, %48 ]
ret i32 %59
}