#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ system(char *);
int main(int argc, char *argv[]) {
  FILE *sorgente;
  char string[1024], command[1024];
  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);
  }
  command[0] = '\0';
  while (fscanf(sorgente, "%s", string) != EOF) {
    if (strcmp(string, "end") != 0) {
      strcat(command, string);
      strcat(command, " ");
    } else {
      system(command);
      command[0] = '\0';
    }
  }
  fclose(sorgente);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11b4 <main+0x44>
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
lea    0xe5d(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1295 <main+0x125>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe57(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11f7 <main+0x87>
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
lea    0xe36(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1295 <main+0x125>
movb   $0x0,-0x820(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x420(%rbp),%rdx
lea    0xe23(%rip),%rsi
call   1050 <fscanf@plt>
mov    0x2dcc(%rip),%rcx
cmp    (%rcx),%rax
je     1285 <main+0x115>
lea    -0x420(%rbp),%rdi
lea    0xe03(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     126d <main+0xfd>
lea    -0x820(%rbp),%rdi
lea    -0x420(%rbp),%rsi
call   1090 <strcat@plt>
lea    -0x820(%rbp),%rdi
lea    0xdd7(%rip),%rsi
call   1090 <strcat@plt>
jmp    1280 <main+0x110>
lea    -0x820(%rbp),%rdi
call   1040 <system@plt>
movb   $0x0,-0x820(%rbp)
jmp    11fe <main+0x8e>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x808,%rsp
cmp    $0x2,%edi
jne    11d2 <main+0x62>
mov    0x8(%rsi),%rdi
lea    0xe89(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11ee <main+0x7e>
mov    %rax,%r15
movb   $0x0,(%rsp)
lea    0xe8a(%rip),%rsi
lea    0x400(%rsp),%rdx
mov    %rax,%rdi
call   1050 <fscanf@plt>
mov    0x2e28(%rip),%rbp
cmp    0x0(%rbp),%rax
jne    121a <main+0xaa>
mov    %r15,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    1208 <main+0x98>
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
lea    0xe1e(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    1208 <main+0x98>
mov    0x2de3(%rip),%rax
mov    (%rax),%edi
lea    0xe1e(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0xfffffffe,%eax
add    $0x808,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe15(%rip),%r14
lea    0x400(%rsp),%rbx
mov    %rsp,%r12
lea    0xe00(%rip),%r13
jmp    1261 <main+0xf1>
cs nopw 0x0(%rax,%rax,1)
nop
call   1040 <system@plt>
movb   $0x0,(%rsp)
mov    %r15,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   1050 <fscanf@plt>
cmp    0x0(%rbp),%rax
je     11c6 <main+0x56>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <strcmp@plt>
mov    %r12,%rdi
test   %rax,%rax
je     1240 <main+0xd0>
mov    %rbx,%rsi
call   1090 <strcat@plt>
mov    %r12,%rdi
lea    0xdb4(%rip),%rsi
call   1090 <strcat@plt>
jmp    1249 <main+0xd9>

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"
@.str.5 = [2 x i8] c" \00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [1024 x i8]
%8 = alloca [1024 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %49
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %18, i32** %6
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %23
20: ; preds = %14
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
store i32 -2, i32* %3
br label %49
23: ; preds = %14
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
store i8 0, i8* %24
br label %25
25: ; preds = %45, %23
%26 = load i32*, i32** %6
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%28 = call i64 @fscanf(i32* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %27)
%29 = load i64, i64* @EOF
%30 = icmp ne i64 %28, %29
br i1 %30, label %31, label %46
31: ; preds = %25
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%33 = call i64 @strcmp(i8* %32, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %41
35: ; preds = %31
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%37 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%38 = call i32 @strcat(i8* %36, i8* %37)
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%40 = call i32 @strcat(i8* %39, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %45
41: ; preds = %31
%42 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%43 = call i32 @system(i8* %42)
%44 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
store i8 0, i8* %44
br label %45
45: ; preds = %41, %35
br label %25
46: ; preds = %25
%47 = load i32*, i32** %6
%48 = call i32 @fclose(i32* %47)
store i32 0, i32* %3
br label %49
49: ; preds = %46, %20, %11
%50 = load i32, i32* %3
ret i32 %50
}

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"
@.str.5 = [2 x i8] c" \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = icmp eq i32 %0, 2
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %37
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = tail call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = load i32, i32* @stderr
%18 = tail call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
br label %37
19: ; preds = %11
store i8 0, i8* %6
%20 = call i64 @fscanf(i32* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %5)
%21 = load i64, i64* @EOF
%22 = icmp eq i64 %20, %21
br i1 %22, label %35, label %23
23: ; preds = %19, %31
%24 = call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
br i1 %25, label %29, label %26
26: ; preds = %23
%27 = call i32 @strcat(i8* %6, i8* %5)
%28 = call i32 @strcat(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %31
29: ; preds = %23
%30 = call i32 @system(i8* %6)
store i8 0, i8* %6
br label %31
31: ; preds = %29, %26
%32 = call i64 @fscanf(i32* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %5)
%33 = load i64, i64* @EOF
%34 = icmp eq i64 %32, %33
br i1 %34, label %35, label %23
35: ; preds = %31, %19
%36 = call i32 @fclose(i32* %14)
br label %37
37: ; preds = %35, %16, %8
%38 = phi i32 [ -1, %8 ], [ -2, %16 ], [ 0, %35 ]
ret i32 %38
}