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

/* Variables and functions */
int BUFSIZ;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ write(int /*<<< orphan*/, char *, int /*<<< orphan*/);
void print_file_contents(int fd) {
  ssize_t b;
  char buf[BUFSIZ];
  while ((b = read(fd, buf, BUFSIZ)) != 0) {
    write(STDOUT_FILENO, buf, b);
  }
}


x86 assembly (clang, -O0):
<print_file_contents>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2ea6(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rsi
mov    -0x4(%rbp),%edi
mov    0x2e73(%rip),%rax
mov    (%rax),%edx
call   1040 <read@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
je     1192 <print_file_contents+0x72>
mov    -0x20(%rbp),%rsi
mov    0x2e6d(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%edx
call   1030 <write@plt>
jmp    1157 <print_file_contents+0x37>
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_file_contents>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edi,%r14d
mov    0x2ea3(%rip),%r15
mov    (%r15),%edx
mov    %rsp,%rbx
mov    %rdx,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rsi
call   1040 <read@plt>
test   %eax,%eax
je     1180 <print_file_contents+0x60>
mov    0x2e91(%rip),%r12
nop
mov    (%r12),%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    (%r15),%edx
mov    %r14d,%edi
mov    %rbx,%rsi
call   1040 <read@plt>
test   %eax,%eax
jne    1160 <print_file_contents+0x40>
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@BUFSIZ = global i32 0
@STDOUT_FILENO = global i32 0
define void @print_file_contents(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
store i32 %0, i32* %2
%6 = load i32, i32* @BUFSIZ
%7 = zext i32 %6 to i64
%8 = call i8* @llvm.stacksave()
store i8* %8, i8** %4
%9 = alloca i8, i64 %7
store i64 %7, i64* %5
br label %10
10: ; preds = %15, %1
%11 = load i32, i32* %2
%12 = load i32, i32* @BUFSIZ
%13 = call i32 @read(i32 %11, i8* %9, i32 %12)
store i32 %13, i32* %3
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %10
%16 = load i32, i32* @STDOUT_FILENO
%17 = load i32, i32* %3
%18 = call i32 @write(i32 %16, i8* %9, i32 %17)
br label %10
19: ; preds = %10
%20 = load i8*, i8** %4
ret void
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@STDOUT_FILENO = global i32 0
define void @print_file_contents(i32 %0) {
%2 = load i32, i32* @BUFSIZ
%3 = zext i32 %2 to i64
%4 = alloca i8, i64 %3
%5 = call i32 @read(i32 %0, i8* %4, i32 %2)
%6 = icmp eq i32 %5, 0
br i1 %6, label %14, label %7
7: ; preds = %1, %7
%8 = phi i32 [ %12, %7 ], [ %5, %1 ]
%9 = load i32, i32* @STDOUT_FILENO
%10 = call i32 @write(i32 %9, i8* %4, i32 %8)
%11 = load i32, i32* @BUFSIZ
%12 = call i32 @read(i32 %0, i8* %4, i32 %11)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %7
14: ; preds = %7, %1
ret void
}