#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 read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
void filecopy(int from, int to) {
  int n;
  char buf[BUFSIZ];
  while ((n = read(from, buf, BUFSIZ)) > 0) {
    write(to, buf, n);
  }
}


x86 assembly (clang, -O0):
<filecopy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    0x2eab(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rsi
mov    -0x4(%rbp),%edi
mov    0x2e78(%rip),%rax
mov    (%rax),%edx
call   1040 <read@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jle    118f <filecopy+0x6f>
mov    -0x28(%rbp),%rsi
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%edx
call   1030 <write@plt>
jmp    115a <filecopy+0x3a>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<filecopy>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r14d
mov    %edi,%r15d
mov    0x2ea8(%rip),%r12
mov    (%r12),%edx
mov    %rsp,%rbx
mov    %rdx,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rsi
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
call   1040 <read@plt>
test   %eax,%eax
jle    1182 <filecopy+0x62>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    (%r12),%edx
mov    %r15d,%edi
mov    %rbx,%rsi
jmp    1160 <filecopy+0x40>
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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