#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*/ output;
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*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  if (argc != 2) {
    printf("Usage: %s [name of document]\n", argv[0]);
    return 1;
  }
  FILE *fp = fopen(argv[1], "r");
  if (fp == NULL) {
    printf("Could not open %s\n", argv[1]);
    return 2;
  }
  char output[256];
  for (int i = 1; fgets(output, sizeof(output), fp) != NULL; i++) {
    printf("Line %02d: %s", i, output);
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1184 <main+0x44>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1231 <main+0xf1>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe8b(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11c9 <main+0x89>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1231 <main+0xf1>
movl   $0x1,-0x124(%rbp)
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x100,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1221 <main+0xe1>
mov    -0x124(%rbp),%esi
lea    -0x120(%rbp),%rdx
lea    0xe2d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x124(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x124(%rbp)
jmp    11d3 <main+0x93>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    11d3 <main+0x93>
mov    0x8(%rbx),%rdi
lea    0xebe(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11eb <main+0xab>
mov    %rax,%r15
mov    %rsp,%rdi
mov    $0x100,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11c7 <main+0x87>
mov    $0x1,%ebp
lea    0xea1(%rip),%r14
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
mov    %ebp,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%ebp
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %r15,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
jne    11a0 <main+0x60>
mov    %r15,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    1202 <main+0xc2>
mov    (%rbx),%rsi
lea    0xe23(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%eax
jmp    1202 <main+0xc2>
mov    0x8(%rbx),%rsi
lea    0xe2a(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x2,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [30 x i8] c"Usage: %s [name of document]\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [19 x i8] c"Could not open %s\0A\00"
@.str.3 = [14 x i8] c"Line %02d: %s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [256 x i8]
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %14)
store i32 1, i32* %3
br label %44
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %20, i32** %6
%21 = load i32*, i32** %6
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %28
23: ; preds = %16
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %26)
store i32 2, i32* %3
br label %44
28: ; preds = %16
store i32 1, i32* %8
br label %29
29: ; preds = %38, %28
%30 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%31 = load i32*, i32** %6
%32 = call i32* @fgets(i8* %30, i32 256, i32* %31)
%33 = icmp ne i32* %32, null
br i1 %33, label %34, label %41
34: ; preds = %29
%35 = load i32, i32* %8
%36 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %35, i8* %36)
br label %38
38: ; preds = %34
%39 = load i32, i32* %8
%40 = add nsw i32 %39, 1
store i32 %40, i32* %8
br label %29
41: ; preds = %29
%42 = load i32*, i32** %6
%43 = call i32 @fclose(i32* %42)
store i32 0, i32* %3
br label %44
44: ; preds = %41, %23, %11
%45 = load i32, i32* %3
ret i32 %45
}

LLVM IR (-O2):
@.str = [30 x i8] c"Usage: %s [name of document]\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [19 x i8] c"Could not open %s\0A\00"
@.str.3 = [14 x i8] c"Line %02d: %s\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = icmp eq i32 %0, 2
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = load i8*, i8** %1
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %28
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = load i8*, i8** %9
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %14)
br label %28
16: ; preds = %8
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%18 = call i32* @fgets(i8* %17, i32 256, i32* %11)
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %22
20: ; preds = %22, %16
%21 = call i32 @fclose(i32* %11)
br label %28
22: ; preds = %16, %22
%23 = phi i32 [ %25, %22 ], [ 1, %16 ]
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %23, i8* %17)
%25 = add nuw nsw i32 %23, 1
%26 = call i32* @fgets(i8* %17, i32 256, i32* %11)
%27 = icmp eq i32* %26, null
br i1 %27, label %20, label %22
28: ; preds = %13, %20, %5
%29 = phi i32 [ 1, %5 ], [ 2, %13 ], [ 0, %20 ]
ret i32 %29
}