#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 */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ parseScriptCmd(char *, int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ stderr;
void exec_script(char *fname, int itrc) {
  FILE *fp;
  char buf[1000];
  if ((fp = fopen(fname, "r")) == NULL) {
    fprintf(stderr, "Cannot open script %s.\n", fname);
    return;
  }
  printf("*** TRACE %d\n", itrc);
  while (fgets(buf, 1000, fp) != NULL)
    parseScriptCmd(buf, itrc);
  fclose(fp);
}


x86 assembly (clang, -O0):
<exec_script>:
push   %rbp
mov    %rsp,%rbp
sub    $0x400,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe83(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11ae <exec_script+0x4e>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe5e(%rip),%rsi
call   1070 <fprintf@plt>
jmp    11f9 <exec_script+0x99>
mov    -0xc(%rbp),%esi
lea    0xe62(%rip),%rdi
call   1050 <printf@plt>
lea    -0x400(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x3e8,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     11f0 <exec_script+0x90>
lea    -0x400(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <parseScriptCmd@plt>
jmp    11bd <exec_script+0x5d>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x400,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<exec_script>:
push   %rbp
push   %r14
push   %rbx
sub    $0x3f0,%rsp
mov    %esi,%r14d
mov    %rdi,%rbp
lea    0xe88(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11e4 <exec_script+0x84>
mov    %rax,%rbx
lea    0xe8e(%rip),%rdi
mov    %r14d,%esi
call   1050 <printf@plt>
mov    %rsp,%rdi
mov    $0x3e8,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     11d0 <exec_script+0x70>
mov    %rsp,%rbp
nopl   0x0(%rax)
mov    %rbp,%rdi
mov    %r14d,%esi
call   1040 <parseScriptCmd@plt>
mov    %rbp,%rdi
mov    $0x3e8,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
jne    11b0 <exec_script+0x50>
mov    %rbx,%rdi
call   1030 <fclose@plt>
add    $0x3f0,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
lea    0xe0e(%rip),%rsi
mov    %rbp,%rdx
add    $0x3f0,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1070 <fprintf@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [24 x i8] c"Cannot open script %s.\0A\00"
@.str.2 = [14 x i8] c"*** TRACE %d\0A\00"
define void @exec_script(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32*
%6 = alloca [1000 x i8]
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = load i8*, i8** %3
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %5
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i8*, i8** %3
%13 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %12)
br label %29
14: ; preds = %2
%15 = load i32, i32* %4
%16 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %15)
br label %17
17: ; preds = %22, %14
%18 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%19 = load i32*, i32** %5
%20 = call i32* @fgets(i8* %18, i32 1000, i32* %19)
%21 = icmp ne i32* %20, null
br i1 %21, label %22, label %26
22: ; preds = %17
%23 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%24 = load i32, i32* %4
%25 = call i32 @parseScriptCmd(i8* %23, i32 %24)
br label %17
26: ; preds = %17
%27 = load i32*, i32** %5
%28 = call i32 @fclose(i32* %27)
br label %29
29: ; preds = %26, %10
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [24 x i8] c"Cannot open script %s.\0A\00"
@.str.2 = [14 x i8] c"*** TRACE %d\0A\00"
define void @exec_script(i8* %0, i32 %1) {
%3 = alloca [1000 x i8]
%4 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %20
10: ; preds = %2
%11 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %1)
%12 = call i32* @fgets(i8* %4, i32 1000, i32* %5)
%13 = icmp eq i32* %12, null
br i1 %13, label %18, label %14
14: ; preds = %10, %14
%15 = call i32 @parseScriptCmd(i8* %4, i32 %1)
%16 = call i32* @fgets(i8* %4, i32 1000, i32* %5)
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %14
18: ; preds = %14, %10
%19 = call i32 @fclose(i32* %5)
br label %20
20: ; preds = %18, %7
ret void
}