#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 open(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char const *argv[]) {
  int fd, n;
  char buf[BUFSIZ];
  fd = open("main.c", O_RDONLY, 0);
  while ((n = read(fd, buf, BUFSIZ)) > 0)
    write(1, buf, n);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e8b(%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,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
mov    0x2e6f(%rip),%rax
mov    (%rax),%esi
lea    0xe7e(%rip),%rdi
xor    %edx,%edx
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
mov    -0x30(%rbp),%rsi
mov    -0x14(%rbp),%edi
mov    0x2e3e(%rip),%rax
mov    (%rax),%edx
call   1040 <read@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jle    11c3 <main+0x93>
mov    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%edx
mov    $0x1,%edi
call   1030 <write@plt>
jmp    118c <main+0x5c>
movl   $0x0,-0x4(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x2e97(%rip),%r15
mov    (%r15),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    0x2e8c(%rip),%rax
mov    (%rax),%esi
lea    0xe9b(%rip),%rdi
xor    %edx,%edx
call   1050 <open@plt>
mov    %eax,%r14d
mov    (%r15),%edx
mov    %eax,%edi
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rsi
call   1040 <read@plt>
test   %eax,%eax
jle    11a3 <main+0x73>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    (%r15),%edx
mov    %r14d,%edi
jmp    1180 <main+0x50>
xor    %eax,%eax
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@BUFSIZ = global i32 0
@.str = [7 x i8] c"main.c\00"
@O_RDONLY = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
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** %8
%13 = alloca i8, i64 %11
store i64 %11, i64* %9
%14 = load i32, i32* @O_RDONLY
%15 = call i32 @open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %14, i32 0)
store i32 %15, i32* %6
br label %16
16: ; preds = %21, %2
%17 = load i32, i32* %6
%18 = load i32, i32* @BUFSIZ
%19 = call i32 @read(i32 %17, i8* %13, i32 %18)
store i32 %19, i32* %7
%20 = icmp sgt i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %16
%22 = load i32, i32* %7
%23 = call i32 @write(i32 1, i8* %13, i32 %22)
br label %16
24: ; preds = %16
store i32 0, i32* %3
%25 = load i8*, i8** %8
%26 = load i32, i32* %3
ret i32 %26
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@.str = [7 x i8] c"main.c\00"
@O_RDONLY = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @BUFSIZ
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = load i32, i32* @O_RDONLY
%7 = tail call i32 @open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %6, i32 0)
%8 = load i32, i32* @BUFSIZ
%9 = call i32 @read(i32 %7, i8* %5, i32 %8)
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %2, %11
%12 = phi i32 [ %15, %11 ], [ %9, %2 ]
%13 = call i32 @write(i32 1, i8* %5, i32 %12)
%14 = load i32, i32* @BUFSIZ
%15 = call i32 @read(i32 %7, i8* %5, i32 %14)
%16 = icmp sgt i32 %15, 0
br i1 %16, label %11, label %17
17: ; preds = %11, %2
ret i32 0
}