#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 */
struct file {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ abort();
int /*<<< orphan*/ fclose(struct file *);
char *fgets(char *, int, struct file *);
struct file *fopen(char *, char *);
int /*<<< orphan*/ free(void *);
char *malloc(int);
int /*<<< orphan*/ puts(char *);
int main(int argc, char **argv) {
  struct file *fp = 0;
  char *buffer = 0;
  char *res = 0;
  if (argc < 2) {
    puts("Enter a file name.");
    return -1;
  }
  fp = fopen(*(argv + 1), "r");
  buffer = malloc(sizeof(char) * 100);
  res = 0;
  if (fp == 0 || buffer == 0) {
    abort();
  }
  res = fgets(buffer, 100, fp);
  while (res != 0) {
    puts(buffer);
    res = fgets(buffer, 100, fp);
  }
  free((void *)buffer);
  fclose(fp);
  return 0;
}


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)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11c0 <main+0x50>
lea    0xe51(%rip),%rdi
call   1050 <puts@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1269 <main+0xf9>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe44(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    $0x64,%edi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1204 <main+0x94>
cmpq   $0x0,-0x20(%rbp)
jne    120b <main+0x9b>
mov    $0x0,%al
call   1040 <abort@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x64,%esi
call   1070 <fgets@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1250 <main+0xe0>
mov    -0x20(%rbp),%rdi
call   1050 <puts@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x64,%esi
call   1070 <fgets@plt>
mov    %rax,-0x28(%rbp)
jmp    1221 <main+0xb1>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1060 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
cmp    $0x1,%edi
jg     118c <main+0x1c>
lea    0xe80(%rip),%rdi
call   1050 <puts@plt>
mov    $0xffffffff,%eax
jmp    11f1 <main+0x81>
mov    0x8(%rsi),%rdi
lea    0xe7c(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%r14
mov    $0x64,%edi
call   1080 <malloc@plt>
test   %r14,%r14
je     11f9 <main+0x89>
mov    %rax,%rbx
test   %rax,%rax
je     11f9 <main+0x89>
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x64,%esi
mov    %r14,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     11df <main+0x6f>
mov    %rbx,%rdi
call   1050 <puts@plt>
jmp    11c0 <main+0x50>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1060 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
xor    %eax,%eax
call   1040 <abort@plt>

LLVM IR (-O0):
%struct.file = type { i32 }
@.str = [19 x i8] c"Enter a file name.\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.file*
%7 = alloca i8*
%8 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store %struct.file* null, %struct.file** %6
store i8* null, i8** %7
store i8* null, i8** %8
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @puts(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %44
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call %struct.file* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store %struct.file* %17, %struct.file** %6
%18 = call i8* @malloc(i32 100)
store i8* %18, i8** %7
store i8* null, i8** %8
%19 = load %struct.file*, %struct.file** %6
%20 = icmp eq %struct.file* %19, null
br i1 %20, label %24, label %21
21: ; preds = %13
%22 = load i8*, i8** %7
%23 = icmp eq i8* %22, null
br i1 %23, label %24, label %26
24: ; preds = %21, %13
%25 = call i32 (...) @abort()
unreachable
26: ; preds = %21
%27 = load i8*, i8** %7
%28 = load %struct.file*, %struct.file** %6
%29 = call i8* @fgets(i8* %27, i32 100, %struct.file* %28)
store i8* %29, i8** %8
br label %30
30: ; preds = %33, %26
%31 = load i8*, i8** %8
%32 = icmp ne i8* %31, null
br i1 %32, label %33, label %39
33: ; preds = %30
%34 = load i8*, i8** %7
%35 = call i32 @puts(i8* %34)
%36 = load i8*, i8** %7
%37 = load %struct.file*, %struct.file** %6
%38 = call i8* @fgets(i8* %36, i32 100, %struct.file* %37)
store i8* %38, i8** %8
br label %30
39: ; preds = %30
%40 = load i8*, i8** %7
%41 = call i32 @free(i8* %40)
%42 = load %struct.file*, %struct.file** %6
%43 = call i32 @fclose(%struct.file* %42)
store i32 0, i32* %3
br label %44
44: ; preds = %39, %11
%45 = load i32, i32* %3
ret i32 %45
}

LLVM IR (-O2):
%struct.file = type { i32 }
@.str = [19 x i8] c"Enter a file name.\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %26
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call %struct.file* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = tail call dereferenceable_or_null(100) i8* @malloc(i32 100)
%11 = icmp eq %struct.file* %9, null
%12 = icmp eq i8* %10, null
%13 = or i1 %11, %12
br i1 %13, label %14, label %16
14: ; preds = %6
%15 = tail call i32 (...) @abort()
unreachable
16: ; preds = %6
%17 = tail call i8* @fgets(i8* %10, i32 100, %struct.file* %9)
%18 = icmp eq i8* %17, null
br i1 %18, label %23, label %19
19: ; preds = %16, %19
%20 = tail call i32 @puts(i8* dereferenceable(1) %10)
%21 = tail call i8* @fgets(i8* %10, i32 100, %struct.file* %9)
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %19
23: ; preds = %19, %16
%24 = tail call i32 @free(i8* %10)
%25 = tail call i32 @fclose(%struct.file* %9)
br label %26
26: ; preds = %23, %4
%27 = phi i32 [ -1, %4 ], [ 0, %23 ]
ret i32 %27
}