#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 EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  char *fname;
  int count;
  printf("There were %d files on the command line.\n", argc - 1);
  if (argc < 2) {
    printf("\n\tusage: %s filename\n", argv[1]);
  } else {
    for (count = argc; count > 0; count--) {
      fname = argv[count];
      printf("Opening file %s\n", fname);
      FILE *file = fopen(fname, "r");
      if (file == 0) {
        printf("Could not open file\n");
      } else {
        int x;
        while ((x = fgetc(file)) != EOF) {
          printf("%c", x);
        }
        fclose(file);
        printf("%s\n", fname);
      }
    }
  }
}


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)
mov    -0x8(%rbp),%esi
sub    $0x1,%esi
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x2,-0x8(%rbp)
jge    118f <main+0x4f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    125c <main+0x11c>
mov    -0x8(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jle    1257 <main+0x117>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
lea    0xe85(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11f3 <main+0xb3>
lea    0xe6c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1244 <main+0x104>
jmp    11f8 <main+0xb8>
mov    -0x28(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x2c(%rbp)
mov    0x2ddd(%rip),%rcx
cmp    (%rcx),%eax
je     1229 <main+0xe9>
mov    -0x2c(%rbp),%esi
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11f8 <main+0xb8>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rsi
lea    0xe10(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1249 <main+0x109>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    1195 <main+0x55>
jmp    125c <main+0x11c>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    %edi,%ebx
lea    -0x1(%rbx),%esi
lea    0xe86(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
cmp    $0x2,%ebx
jge    11aa <main+0x4a>
mov    0x8(%r12),%rsi
lea    0xe98(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %ebx,%ebp
lea    0xea0(%rip),%r14
mov    0x2e2e(%rip),%r15
jmp    11dd <main+0x7d>
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    %r13,%rdi
call   1040 <puts@plt>
lea    -0x1(%rbp),%rax
cmp    $0x1,%rbp
mov    %rax,%rbp
jle    1199 <main+0x39>
mov    (%r12,%rbp,8),%r13
lea    0xe58(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r13,%rdi
lea    0xe55(%rip),%rsi
call   1080 <fopen@plt>
mov    %r14,%rdi
test   %rax,%rax
je     11cb <main+0x6b>
mov    %rax,%rbx
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1070 <fgetc@plt>
cmp    (%r15),%eax
je     11c0 <main+0x60>
mov    %eax,%edi
call   1030 <putchar@plt>
jmp    1210 <main+0xb0>

LLVM IR (-O0):
@.str = [42 x i8] c"There were %d files on the command line.\0A\00"
@.str.1 = [22 x i8] c"\0A\09usage: %s filename\0A\00"
@.str.2 = [17 x i8] c"Opening file %s\0A\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [21 x i8] c"Could not open file\0A\00"
@EOF = global i32 0
@.str.5 = [3 x i8] c"%c\00"
@.str.6 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = sub nsw i32 %10, 1
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 2
br i1 %14, label %15, label %20
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %18)
br label %58
20: ; preds = %2
%21 = load i32, i32* %4
store i32 %21, i32* %7
br label %22
22: ; preds = %54, %20
%23 = load i32, i32* %7
%24 = icmp sgt i32 %23, 0
br i1 %24, label %25, label %57
25: ; preds = %22
%26 = load i8**, i8*** %5
%27 = load i32, i32* %7
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8*, i8** %26, i64 %28
%30 = load i8*, i8** %29
store i8* %30, i8** %6
%31 = load i8*, i8** %6
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %31)
%33 = load i8*, i8** %6
%34 = call i32* @fopen(i8* %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %34, i32** %8
%35 = load i32*, i32** %8
%36 = icmp eq i32* %35, null
br i1 %36, label %37, label %39
37: ; preds = %25
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
br label %53
39: ; preds = %25
br label %40
40: ; preds = %45, %39
%41 = load i32*, i32** %8
%42 = call i32 @fgetc(i32* %41)
store i32 %42, i32* %9
%43 = load i32, i32* @EOF
%44 = icmp ne i32 %42, %43
br i1 %44, label %45, label %48
45: ; preds = %40
%46 = load i32, i32* %9
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 %46)
br label %40
48: ; preds = %40
%49 = load i32*, i32** %8
%50 = call i32 @fclose(i32* %49)
%51 = load i8*, i8** %6
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %51)
br label %53
53: ; preds = %48, %37
br label %54
54: ; preds = %53
%55 = load i32, i32* %7
%56 = add nsw i32 %55, -1
store i32 %56, i32* %7
br label %22
57: ; preds = %22
br label %58
58: ; preds = %57, %15
%59 = load i32, i32* %3
ret i32 %59
}

LLVM IR (-O2):
@.str = [42 x i8] c"There were %d files on the command line.\0A\00"
@.str.1 = [22 x i8] c"\0A\09usage: %s filename\0A\00"
@.str.2 = [17 x i8] c"Opening file %s\0A\00"
@.str.3 = [2 x i8] c"r\00"
@EOF = global i32 0
@str = [20 x i8] c"Could not open file\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = add nsw i32 %0, -1
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp slt i32 %0, 2
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = zext i32 %0 to i64
br label %12
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %10)
br label %36
12: ; preds = %6, %31
%13 = phi i64 [ %7, %6 ], [ %34, %31 ]
%14 = getelementptr inbounds i8*, i8** %1, i64 %13
%15 = load i8*, i8** %14
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %15)
%17 = tail call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%18 = icmp eq i32* %17, null
br i1 %18, label %31, label %19
19: ; preds = %12
%20 = tail call i32 @fgetc(i32* %17)
%21 = load i32, i32* @EOF
%22 = icmp eq i32 %20, %21
br i1 %22, label %29, label %23
23: ; preds = %19, %23
%24 = phi i32 [ %26, %23 ], [ %20, %19 ]
%25 = tail call i32 @putchar(i32 %24)
%26 = tail call i32 @fgetc(i32* %17)
%27 = load i32, i32* @EOF
%28 = icmp eq i32 %26, %27
br i1 %28, label %29, label %23
29: ; preds = %23, %19
%30 = tail call i32 @fclose(i32* %17)
br label %31
31: ; preds = %12, %29
%32 = phi i8* [ %15, %29 ], [ getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0), %12 ]
%33 = tail call i32 @puts(i8* dereferenceable(1) %32)
%34 = add nsw i64 %13, -1
%35 = icmp sgt i64 %13, 1
br i1 %35, label %12, label %36
36: ; preds = %31, %8
ret i32 0
}