#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[]) {
  printf("\n The argc %d", argc);
  printf("\n The argv %s", argv[0]);
  printf("\n The argv %s", argv[1]);
  printf("\n The argv %s\n", argv[2]);
  if (argc < 2) {
    printf("usage: %s filename", argv[0]);
  } else {
    FILE *file = fopen(argv[2], "r");
    if (file == 0) {
      printf("Could not open file\n");
    } else {
      int x;
      while ((x = fgetc(file)) != EOF) {
        printf("%c", x);
      }
      fclose(file);
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%esi
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x2,-0x8(%rbp)
jge    11cc <main+0x8c>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1246 <main+0x106>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe63(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1202 <main+0xc2>
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1241 <main+0x101>
jmp    1207 <main+0xc7>
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2dce(%rip),%rcx
cmp    (%rcx),%eax
je     1238 <main+0xf8>
mov    -0x1c(%rbp),%esi
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1207 <main+0xc7>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
jmp    1246 <main+0x106>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe90(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    (%rbx),%rsi
lea    0xe8b(%rip),%r14
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x8(%rbx),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x10(%rbx),%rsi
lea    0xe76(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
cmp    $0x1,%ebp
jg     11c5 <main+0x65>
mov    (%rbx),%rsi
lea    0xe6f(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    122a <main+0xca>
mov    0x10(%rbx),%rdi
lea    0xe6e(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     121e <main+0xbe>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <fgetc@plt>
mov    0x2dfc(%rip),%rbp
cmp    0x0(%rbp),%eax
je     1214 <main+0xb4>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %eax,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
call   1070 <fgetc@plt>
cmp    0x0(%rbp),%eax
jne    1200 <main+0xa0>
mov    %rbx,%rdi
call   1050 <fclose@plt>
jmp    122a <main+0xca>
lea    0xe1b(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [14 x i8] c"\0A The argc %d\00"
@.str.1 = [14 x i8] c"\0A The argv %s\00"
@.str.2 = [15 x i8] c"\0A The argv %s\0A\00"
@.str.3 = [19 x i8] c"usage: %s filename\00"
@.str.4 = [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 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %0)
%4 = load i8*, i8** %1
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%9 = getelementptr inbounds i8*, i8** %1, i64 2
%10 = load i8*, i8** %9
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %10)
%12 = icmp slt i32 %0, 2
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = load i8*, i8** %1
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %14)
br label %34
16: ; preds = %2
%17 = load i8*, i8** %9
%18 = tail call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%19 = icmp eq i32* %18, null
br i1 %19, label %24, label %20
20: ; preds = %16
%21 = tail call i32 @fgetc(i32* %18)
%22 = load i32, i32* @EOF
%23 = icmp eq i32 %21, %22
br i1 %23, label %32, label %26
24: ; preds = %16
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
br label %34
26: ; preds = %20, %26
%27 = phi i32 [ %29, %26 ], [ %21, %20 ]
%28 = tail call i32 @putchar(i32 %27)
%29 = tail call i32 @fgetc(i32* %18)
%30 = load i32, i32* @EOF
%31 = icmp eq i32 %29, %30
br i1 %31, label %32, label %26
32: ; preds = %26, %20
%33 = tail call i32 @fclose(i32* %18)
br label %34
34: ; preds = %24, %32, %13
ret i32 0
}