#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 /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int trace_open(const char *filename) {
  FILE *fp;
  char line[80];
  char *p;
  fp = fopen(filename, "r");
  for (;;) {
    fgets(line, 79, fp);
    if (feof(fp))
      break;
    p = line;
    switch (*p++) {}
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<trace_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea9(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x4f,%esi
call   1040 <fgets@plt>
mov    -0x10(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%rax
je     118a <trace_open+0x4a>
jmp    11a3 <trace_open+0x63>
lea    -0x60(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x68(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x68(%rbp)
jmp    1160 <trace_open+0x20>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trace_open>:
push   %r14
push   %rbx
sub    $0x58,%rsp
lea    0xeb2(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
mov    %rsp,%r14
nopl   0x0(%rax)
mov    %r14,%rdi
mov    $0x4f,%esi
mov    %rbx,%rdx
call   1040 <fgets@plt>
mov    %rbx,%rdi
call   1050 <feof@plt>
test   %rax,%rax
je     1160 <trace_open+0x20>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define i32 @trace_open(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca [80 x i8]
%5 = alloca i8*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %3
br label %8
8: ; preds = %22, %1
%9 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%10 = load i32*, i32** %3
%11 = call i32 @fgets(i8* %9, i32 79, i32* %10)
%12 = load i32*, i32** %3
%13 = call i64 @feof(i32* %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %8
br label %23
16: ; preds = %8
%17 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
store i8* %17, i8** %5
%18 = load i8*, i8** %5
%19 = getelementptr inbounds i8, i8* %18, i32 1
store i8* %19, i8** %5
%20 = load i8, i8* %18
%21 = sext i8 %20 to i32
switch i32 %21, label %22 [
]
22: ; preds = %16
br label %8
23: ; preds = %15
%24 = load i32*, i32** %3
%25 = call i32 @fclose(i32* %24)
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define i32 @trace_open(i8* nocapture %0) {
%2 = alloca [80 x i8]
%3 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %5
5: ; preds = %5, %1
%6 = call i32 @fgets(i8* %3, i32 79, i32* %4)
%7 = call i64 @feof(i32* %4)
%8 = icmp eq i64 %7, 0
br i1 %8, label %5, label %9
9: ; preds = %5
%10 = call i32 @fclose(i32* %4)
ret i32 0
}