#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 BUFSIZ;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int read(int, unsigned char *, int);
int write(int /*<<< orphan*/, unsigned char *, int);
int main(int argc, char *argv[]) {
  int fd;
  unsigned char buf[BUFSIZ];
  int n;
  fd = open(argv[1], O_RDONLY);
  for (;;) {
    n = read(fd, buf, BUFSIZ);
    if (n == 0)
      break;
    n = write(STDOUT_FILENO, buf, n);
  }
  close(fd);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e63(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e3f(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
mov    -0x38(%rbp),%rsi
mov    -0x14(%rbp),%edi
mov    0x2e17(%rip),%rax
mov    (%rax),%edx
call   1050 <read@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jne    11d2 <main+0x82>
jmp    11ef <main+0x9f>
mov    -0x38(%rbp),%rsi
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
mov    -0x2c(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0x2c(%rbp)
jmp    11ab <main+0x5b>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
xor    %edi,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    0x2e6e(%rip),%r15
mov    (%r15),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    0x8(%rsi),%rdi
mov    0x2e5f(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,%r14d
mov    (%r15),%edx
mov    %eax,%edi
mov    %rbx,%rsi
call   1050 <read@plt>
test   %eax,%eax
je     11d0 <main+0x80>
mov    0x2e4d(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r12),%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    (%r15),%edx
mov    %r14d,%edi
mov    %rbx,%rsi
call   1050 <read@plt>
test   %eax,%eax
jne    11b0 <main+0x60>
mov    %r14d,%edi
call   1040 <close@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@BUFSIZ = global i32 0
@O_RDONLY = global i32 0
@STDOUT_FILENO = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* @BUFSIZ
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %7
%13 = alloca i8, i64 %11
store i64 %11, i64* %8
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = load i32, i32* @O_RDONLY
%18 = call i32 @open(i8* %16, i32 %17)
store i32 %18, i32* %6
br label %19
19: ; preds = %26, %2
%20 = load i32, i32* %6
%21 = load i32, i32* @BUFSIZ
%22 = call i32 @read(i32 %20, i8* %13, i32 %21)
store i32 %22, i32* %9
%23 = load i32, i32* %9
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %19
br label %30
26: ; preds = %19
%27 = load i32, i32* @STDOUT_FILENO
%28 = load i32, i32* %9
%29 = call i32 @write(i32 %27, i8* %13, i32 %28)
store i32 %29, i32* %9
br label %19
30: ; preds = %25
%31 = load i32, i32* %6
%32 = call i32 @close(i32 %31)
%33 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@O_RDONLY = global i32 0
@STDOUT_FILENO = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i32, i32* @BUFSIZ
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = load i32, i32* @O_RDONLY
%9 = tail call i32 @open(i8* %7, i32 %8)
%10 = load i32, i32* @BUFSIZ
%11 = call i32 @read(i32 %9, i8* %5, i32 %10)
%12 = icmp eq i32 %11, 0
br i1 %12, label %20, label %13
13: ; preds = %2, %13
%14 = phi i32 [ %18, %13 ], [ %11, %2 ]
%15 = load i32, i32* @STDOUT_FILENO
%16 = call i32 @write(i32 %15, i8* %5, i32 %14)
%17 = load i32, i32* @BUFSIZ
%18 = call i32 @read(i32 %9, i8* %5, i32 %17)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %13
20: ; preds = %13, %2
%21 = tail call i32 @close(i32 %9)
%22 = tail call i32 @exit(i32 0)
unreachable
}