#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*/ buff;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, char **);
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ printf(char *, char *);
main(int argc, char *argv[]) {
  FILE *fp;
  char buff[255];
  if (argc != 2) {
    printf("usage: %s foo.km", argv[0]);
  } else {
    fp = fopen(argv[1], "r");
    if (fp != NULL) {
      while (!feof(fp)) {
        memset(buff, '\0', sizeof(buff));
        fscanf(fp, "%s", &buff);
        printf("%s\n", buff);
      }
      fclose(fp);
    } else {
      printf("Could not open file '%s'", argv[1]);
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     119b <main+0x3b>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe6f(%rip),%rdi
call   1040 <printf@plt>
jmp    124a <main+0xea>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe67(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1231 <main+0xd1>
jmp    11c3 <main+0x63>
mov    -0x18(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11e1 <main+0x81>
jmp    1223 <main+0xc3>
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0xff,%edx
call   1050 <memset@plt>
mov    -0x18(%rbp),%rdi
lea    -0x120(%rbp),%rdx
lea    0xe0d(%rip),%rsi
call   1060 <fscanf@plt>
lea    -0x120(%rbp),%rsi
lea    0xdfd(%rip),%rdi
call   1040 <printf@plt>
jmp    11c3 <main+0x63>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
jmp    1245 <main+0xe5>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xdda(%rip),%rdi
call   1040 <printf@plt>
jmp    124a <main+0xea>
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    %rsi,%r14
cmp    $0x2,%edi
jne    11ee <main+0x8e>
mov    0x8(%r14),%rdi
lea    0xe90(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11fa <main+0x9a>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    11e4 <main+0x84>
mov    %rsp,%r14
lea    0xe6f(%rip),%r15
lea    0xe6b(%rip),%r12
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xff,%edx
call   1050 <memset@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1060 <fscanf@plt>
mov    %r12,%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %eax,%eax
je     11b0 <main+0x50>
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    120a <main+0xaa>
mov    (%r14),%rsi
lea    0xe08(%rip),%rdi
jmp    1205 <main+0xa5>
mov    0x8(%r14),%rsi
lea    0xe15(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [17 x i8] c"usage: %s foo.km\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [4 x i8] c"%s\0A\00"
@.str.4 = [25 x i8] c"Could not open file '%s'\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [255 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %13)
br label %45
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %19, i32** %6
%20 = load i32*, i32** %6
%21 = icmp ne i32* %20, null
br i1 %21, label %22, label %39
22: ; preds = %15
br label %23
23: ; preds = %28, %22
%24 = load i32*, i32** %6
%25 = call i32 @feof(i32* %24)
%26 = icmp ne i32 %25, 0
%27 = xor i1 %26, true
br i1 %27, label %28, label %36
28: ; preds = %23
%29 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 0
%30 = call i32 @memset(i8* %29, i8 signext 0, i32 255)
%31 = load i32*, i32** %6
%32 = bitcast [255 x i8]* %7 to i8**
%33 = call i32 @fscanf(i32* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %32)
%34 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 0
%35 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %34)
br label %23
36: ; preds = %23
%37 = load i32*, i32** %6
%38 = call i32 @fclose(i32* %37)
br label %44
39: ; preds = %15
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 1
%42 = load i8*, i8** %41
%43 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i8* %42)
br label %44
44: ; preds = %39, %36
br label %45
45: ; preds = %44, %10
%46 = load i32, i32* %3
ret i32 %46
}

LLVM IR (-O2):
@.str = [17 x i8] c"usage: %s foo.km\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [4 x i8] c"%s\0A\00"
@.str.4 = [25 x i8] c"Could not open file '%s'\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [255 x i8]
%4 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 2
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %7)
br label %30
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %27, label %14
14: ; preds = %9
%15 = call i32 @feof(i32* %12)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %25
17: ; preds = %14
%18 = bitcast [255 x i8]* %3 to i8**
br label %19
19: ; preds = %17, %19
%20 = call i32 @memset(i8* %4, i8 signext 0, i32 255)
%21 = call i32 @fscanf(i32* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %18)
%22 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%23 = call i32 @feof(i32* %12)
%24 = icmp eq i32 %23, 0
br i1 %24, label %19, label %25
25: ; preds = %19, %14
%26 = call i32 @fclose(i32* %12)
br label %30
27: ; preds = %9
%28 = load i8*, i8** %10
%29 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i8* %28)
br label %30
30: ; preds = %25, %27, %6
ret i32 0
}