#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 */

/* Variables and functions */
int /*<<< orphan*/ printf(char *, char);
int read(int, char *, int);
void display_file(int fd) {
  char buf[(1024 * 1024)];
  int i, n = read(fd, buf, (1024 * 1024));
  for (i = 0; i < n; i++)
    printf("%c", buf[i]);
}


x86 assembly (clang, -O0):
<display_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100020,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x100010(%rbp),%rsi
mov    $0x100000,%edx
call   1040 <read@plt>
mov    %eax,-0x100018(%rbp)
movl   $0x0,-0x100014(%rbp)
mov    -0x100014(%rbp),%eax
cmp    -0x100018(%rbp),%eax
jge    1193 <display_file+0x73>
movslq -0x100014(%rbp),%rax
lea    0xe8e(%rip),%rdi
movsbl -0x100010(%rbp,%rax,1),%esi
ff
call   1030 <printf@plt>
mov    -0x100014(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x100014(%rbp)
jmp    1152 <display_file+0x32>
add    $0x100020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<display_file>:
push   %r15
push   %r14
push   %rbx
sub    $0x100000,%rsp
mov    %rsp,%rsi
mov    $0x100000,%edx
call   1040 <read@plt>
test   %eax,%eax
jle    1165 <display_file+0x45>
mov    %eax,%r15d
xor    %ebx,%ebx
lea    0xeb7(%rip),%r14
nopl   0x0(%rax)
movsbl (%rsp,%rbx,1),%esi
mov    %r14,%rdi
call   1030 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1150 <display_file+0x30>
add    $0x100000,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%c\00"
define void @display_file(i32 %0) {
%2 = alloca i32
%3 = alloca [1048576 x i8]
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
%6 = load i32, i32* %2
%7 = getelementptr inbounds [1048576 x i8], [1048576 x i8]* %3, i64 0, i64 0
%8 = call i32 @read(i32 %6, i8* %7, i32 1048576)
store i32 %8, i32* %5
store i32 0, i32* %4
br label %9
9: ; preds = %19, %1
%10 = load i32, i32* %4
%11 = load i32, i32* %5
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %22
13: ; preds = %9
%14 = load i32, i32* %4
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [1048576 x i8], [1048576 x i8]* %3, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %17)
br label %19
19: ; preds = %13
%20 = load i32, i32* %4
%21 = add nsw i32 %20, 1
store i32 %21, i32* %4
br label %9
22: ; preds = %9
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%c\00"
define void @display_file(i32 %0) {
%2 = alloca [1048576 x i8]
%3 = getelementptr inbounds [1048576 x i8], [1048576 x i8]* %2, i64 0, i64 0
%4 = call i32 @read(i32 %0, i8* %3, i32 1048576)
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %15
6: ; preds = %1
%7 = zext i32 %4 to i64
br label %8
8: ; preds = %6, %8
%9 = phi i64 [ 0, %6 ], [ %13, %8 ]
%10 = getelementptr inbounds [1048576 x i8], [1048576 x i8]* %2, i64 0, i64 %9
%11 = load i8, i8* %10
%12 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %11)
%13 = add nuw nsw i64 %9, 1
%14 = icmp eq i64 %13, %7
br i1 %14, label %15, label %8
15: ; preds = %8, %1
ret void
}