#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*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  int i = 0;
  for (i = 0; i < argc; ++i)
    printf("argv[%d] = %s\n", i, argv[i]);
  printf("Reading my script %s\n", argv[argc - 1]);
  FILE *fd = fopen(argv[argc - 1], "r");
  char buff[10];
  while (!feof(fd)) {
    memset(buff, 0, 10);
    fread(buff, 1, 10, fd);
    fwrite(buff, 1, 10, stdout);
  }
  fclose(fd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11cb <main+0x5b>
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1194 <main+0x24>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe23(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1229 <main+0xb9>
jmp    1271 <main+0x101>
lea    -0x2a(%rbp),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1060 <memset@plt>
lea    -0x2a(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0xa,%edx
call   1030 <fread@plt>
lea    -0x2a(%rbp),%rdi
mov    0x2d85(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
mov    $0xa,%edx
call   1090 <fwrite@plt>
jmp    120b <main+0x9b>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r12
mov    %edi,%r14d
test   %edi,%edi
jle    11b9 <main+0x49>
mov    %r14d,%ebx
lea    0xe70(%rip),%r15
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%r12,%rbp,8),%rdx
mov    %r15,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    11a0 <main+0x30>
movslq %r14d,%rbx
mov    -0x8(%r12,%rbx,8),%rsi
lea    0xe47(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    -0x8(%r12,%rbx,8),%rdi
lea    0xe4a(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    1245 <main+0xd5>
lea    0x6(%rsp),%r14
mov    0x2de5(%rip),%rbp
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1060 <memset@plt>
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0xa,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    0x0(%rbp),%ecx
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0xa,%edx
call   1090 <fwrite@plt>
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %eax,%eax
je     1200 <main+0x90>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"argv[%d] = %s\0A\00"
@.str.1 = [22 x i8] c"Reading my script %s\0A\00"
@.str.2 = [2 x i8] c"r\00"
@stdout = 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 [10 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 0, i32* %6
br label %9
9: ; preds = %21, %2
%10 = load i32, i32* %6
%11 = load i32, i32* %4
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %24
13: ; preds = %9
%14 = load i32, i32* %6
%15 = load i8**, i8*** %5
%16 = load i32, i32* %6
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8*, i8** %15, i64 %17
%19 = load i8*, i8** %18
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %14, i8* %19)
br label %21
21: ; preds = %13
%22 = load i32, i32* %6
%23 = add nsw i32 %22, 1
store i32 %23, i32* %6
br label %9
24: ; preds = %9
%25 = load i8**, i8*** %5
%26 = load i32, i32* %4
%27 = sub nsw i32 %26, 1
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8*, i8** %25, i64 %28
%30 = load i8*, i8** %29
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %30)
%32 = load i8**, i8*** %5
%33 = load i32, i32* %4
%34 = sub nsw i32 %33, 1
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8*, i8** %32, i64 %35
%37 = load i8*, i8** %36
%38 = call i32* @fopen(i8* %37, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %38, i32** %7
br label %39
39: ; preds = %44, %24
%40 = load i32*, i32** %7
%41 = call i32 @feof(i32* %40)
%42 = icmp ne i32 %41, 0
%43 = xor i1 %42, true
br i1 %43, label %44, label %53
44: ; preds = %39
%45 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
%46 = call i32 @memset(i8* %45, i32 0, i32 10)
%47 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
%48 = load i32*, i32** %7
%49 = call i32 @fread(i8* %47, i32 1, i32 10, i32* %48)
%50 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
%51 = load i32, i32* @stdout
%52 = call i32 @fwrite(i8* %50, i32 1, i32 10, i32 %51)
br label %39
53: ; preds = %39
%54 = load i32*, i32** %7
%55 = call i32 @fclose(i32* %54)
%56 = load i32, i32* %3
ret i32 %56
}

LLVM IR (-O2):
@.str = [15 x i8] c"argv[%d] = %s\0A\00"
@.str.1 = [22 x i8] c"Reading my script %s\0A\00"
@.str.2 = [2 x i8] c"r\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [10 x i8]
%4 = icmp sgt i32 %0, 0
br i1 %4, label %5, label %15
5: ; preds = %2
%6 = zext i32 %0 to i64
br label %7
7: ; preds = %5, %7
%8 = phi i64 [ 0, %5 ], [ %13, %7 ]
%9 = getelementptr inbounds i8*, i8** %1, i64 %8
%10 = load i8*, i8** %9
%11 = trunc i64 %8 to i32
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %11, i8* %10)
%13 = add nuw nsw i64 %8, 1
%14 = icmp eq i64 %13, %6
br i1 %14, label %15, label %7
15: ; preds = %7, %2
%16 = add nsw i32 %0, -1
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8*, i8** %1, i64 %17
%19 = load i8*, i8** %18
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %19)
%21 = load i8*, i8** %18
%22 = tail call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%23 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%24 = call i32 @feof(i32* %22)
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %33
26: ; preds = %15, %26
%27 = call i32 @memset(i8* %23, i32 0, i32 10)
%28 = call i32 @fread(i8* %23, i32 1, i32 10, i32* %22)
%29 = load i32, i32* @stdout
%30 = call i32 @fwrite(i8* %23, i32 1, i32 10, i32 %29)
%31 = call i32 @feof(i32* %22)
%32 = icmp eq i32 %31, 0
br i1 %32, label %26, label %33
33: ; preds = %26, %15
%34 = call i32 @fclose(i32* %22)
ret i32 0
}