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

/* Variables and functions */
int BUFSIZ;
scalar_t__ read(int, char **, int);
int /*<<< orphan*/ write(int, char **, size_t);
void copyFile(int from, int to) {
  size_t bytesRead;
  char *buf[BUFSIZ];
  while (1) {
    bytesRead = (size_t)read(from, buf, sizeof(buf));
    if (!bytesRead)
      return;
    write(to, buf, bytesRead);
  }
}


x86 assembly (clang, -O0):
<copyFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    0x2eab(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x30(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
jmp    1164 <copyFile+0x44>
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rax
mov    -0x4(%rbp),%edi
shl    $0x3,%rax
mov    %eax,%edx
call   1040 <read@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1195 <copyFile+0x75>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret
mov    -0x28(%rbp),%rsi
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rdx
call   1030 <write@plt>
jmp    115f <copyFile+0x3f>

x86 assembly (clang, -O2):
<copyFile>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r14d
mov    %edi,%r15d
mov    0x2ea8(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
lea    0xf(,%rax,8),%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%rbx
mov    %rbx,%rsp
lea    0x0(,%rax,8),%r12d
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rsi
mov    %r12d,%edx
call   1040 <read@plt>
test   %rax,%rax
je     1183 <copyFile+0x63>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1030 <write@plt>
mov    %r15d,%edi
jmp    1160 <copyFile+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 @copyFile(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
%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 = %22, %2
br label %13
13: ; preds = %12
%14 = load i32, i32* %3
%15 = mul nuw i64 8, %9
%16 = trunc i64 %15 to i32
%17 = call i64 @read(i32 %14, i8** %11, i32 %16)
store i64 %17, i64* %5
%18 = load i64, i64* %5
%19 = icmp ne i64 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %13
%21 = load i8*, i8** %6
ret void
22: ; preds = %13
%23 = load i32, i32* %4
%24 = load i64, i64* %5
%25 = call i32 @write(i32 %23, i8** %11, i64 %24)
br label %12
}

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