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

/* Variables and functions */
int errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ lreply(int, char *, char *);
int /*<<< orphan*/ stdout;
char *strchr(char *, char);
int display_file(const char *name, int code) {
  char *cp, line[2048];
  FILE *fp = fopen(name, "r");
  if (fp != NULL) {
    while (fgets(line, sizeof(line), fp) != NULL) {
      cp = strchr(line, '\n');
      if (cp != NULL)
        *cp = '\0';
      lreply(code, "%s", line);
    }
    fflush(stdout);
    fclose(fp);
    return 0;
  }
  return errno;
}


x86 assembly (clang, -O0):
<display_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x830,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe83(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x828(%rbp)
cmpq   $0x0,-0x828(%rbp)
je     1226 <display_file+0xc6>
jmp    119c <display_file+0x3c>
lea    -0x820(%rbp),%rdi
mov    -0x828(%rbp),%rdx
mov    $0x800,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1200 <display_file+0xa0>
lea    -0x820(%rbp),%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11e5 <display_file+0x85>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x14(%rbp),%edi
lea    -0x820(%rbp),%rdx
lea    0xe0c(%rip),%rsi
call   1080 <lreply@plt>
jmp    119c <display_file+0x3c>
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
mov    -0x828(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    1232 <display_file+0xd2>
mov    0x2db3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<display_file>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x808,%rsp
mov    %esi,%r14d
lea    0xe89(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1204 <display_file+0xa4>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x800,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11ea <display_file+0x8a>
mov    %rsp,%rbp
lea    0xe5b(%rip),%r15
jmp    11d3 <display_file+0x73>
nopl   0x0(%rax)
mov    %r14d,%edi
mov    %r15,%rsi
mov    %rbp,%rdx
call   1080 <lreply@plt>
mov    %rbp,%rdi
mov    $0x800,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11ea <display_file+0x8a>
mov    %rbp,%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11b0 <display_file+0x50>
movb   $0x0,(%rax)
jmp    11b0 <display_file+0x50>
mov    0x2de7(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    120d <display_file+0xad>
mov    0x2dd5(%rip),%rax
mov    (%rax),%eax
add    $0x808,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%s\00"
@stdout = global i32 0
@errno = global i32 0
define i32 @display_file(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca [2048 x i8]
%8 = alloca i32*
store i8* %0, i8** %4
store i32 %1, i32* %5
%9 = load i8*, i8** %4
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %8
%11 = load i32*, i32** %8
%12 = icmp ne i32* %11, null
br i1 %12, label %13, label %35
13: ; preds = %2
br label %14
14: ; preds = %26, %13
%15 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%16 = load i32*, i32** %8
%17 = call i32* @fgets(i8* %15, i32 2048, i32* %16)
%18 = icmp ne i32* %17, null
br i1 %18, label %19, label %30
19: ; preds = %14
%20 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%21 = call i8* @strchr(i8* %20, i8 signext 10)
store i8* %21, i8** %6
%22 = load i8*, i8** %6
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %26
24: ; preds = %19
%25 = load i8*, i8** %6
store i8 0, i8* %25
br label %26
26: ; preds = %24, %19
%27 = load i32, i32* %5
%28 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%29 = call i32 @lreply(i32 %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %28)
br label %14
30: ; preds = %14
%31 = load i32, i32* @stdout
%32 = call i32 @fflush(i32 %31)
%33 = load i32*, i32** %8
%34 = call i32 @fclose(i32* %33)
store i32 0, i32* %3
br label %37
35: ; preds = %2
%36 = load i32, i32* @errno
store i32 %36, i32* %3
br label %37
37: ; preds = %35, %30
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%s\00"
@stdout = global i32 0
@errno = global i32 0
define i32 @display_file(i8* nocapture %0, i32 %1) {
%3 = alloca [2048 x i8]
%4 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %22, label %7
7: ; preds = %2
%8 = call i32* @fgets(i8* %4, i32 2048, i32* %5)
%9 = icmp eq i32* %8, null
br i1 %9, label %18, label %10
10: ; preds = %7, %14
%11 = call i8* @strchr(i8* %4, i8 signext 10)
%12 = icmp eq i8* %11, null
br i1 %12, label %14, label %13
13: ; preds = %10
store i8 0, i8* %11
br label %14
14: ; preds = %13, %10
%15 = call i32 @lreply(i32 %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%16 = call i32* @fgets(i8* %4, i32 2048, i32* %5)
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %10
18: ; preds = %14, %7
%19 = load i32, i32* @stdout
%20 = call i32 @fflush(i32 %19)
%21 = call i32 @fclose(i32* %5)
br label %24
22: ; preds = %2
%23 = load i32, i32* @errno
br label %24
24: ; preds = %22, %18
%25 = phi i32 [ 0, %18 ], [ %23, %22 ]
ret i32 %25
}