#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 /*<<< orphan*/ freeMem(char *);
int /*<<< orphan*/ mustWriteFd(int, char *, int);
char *needMem(int);
int read(int, char *, int);
void cpFile(int s, int d) {
  int bufSize = 64 * 1024, readSize;
  char *buf = needMem(bufSize);
  for (;;) {
    readSize = read(s, buf, bufSize);
    if (readSize > 0)
      mustWriteFd(d, buf, readSize);
    if (readSize <= 0)
      break;
  }
  freeMem(buf);
}


x86 assembly (clang, -O0):
<cpFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x10000,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1060 <needMem@plt>
mov    %rax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1050 <read@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jle    118c <cpFile+0x4c>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%edx
call   1030 <mustWriteFd@plt>
cmpl   $0x0,-0x10(%rbp)
jg     119b <cpFile+0x5b>
jmp    11a0 <cpFile+0x60>
jmp    1161 <cpFile+0x21>
mov    -0x18(%rbp),%rdi
call   1040 <freeMem@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cpFile>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %edi,%ebp
mov    $0x10000,%edi
call   1060 <needMem@plt>
mov    %rax,%rbx
mov    %ebp,%edi
mov    %rax,%rsi
nopl   0x0(%rax,%rax,1)
mov    $0x10000,%edx
call   1050 <read@plt>
test   %eax,%eax
jle    1182 <cpFile+0x42>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <mustWriteFd@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
jmp    1160 <cpFile+0x20>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <freeMem@plt>

LLVM IR (-O0):
define void @cpFile(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 65536, i32* %5
%8 = load i32, i32* %5
%9 = call i8* @needMem(i32 %8)
store i8* %9, i8** %7
br label %10
10: ; preds = %26, %2
%11 = load i32, i32* %3
%12 = load i8*, i8** %7
%13 = load i32, i32* %5
%14 = call i32 @read(i32 %11, i8* %12, i32 %13)
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %10
%18 = load i32, i32* %4
%19 = load i8*, i8** %7
%20 = load i32, i32* %6
%21 = call i32 @mustWriteFd(i32 %18, i8* %19, i32 %20)
br label %22
22: ; preds = %17, %10
%23 = load i32, i32* %6
%24 = icmp sle i32 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %22
br label %27
26: ; preds = %22
br label %10
27: ; preds = %25
%28 = load i8*, i8** %7
%29 = call i32 @freeMem(i8* %28)
ret void
}

LLVM IR (-O2):
define void @cpFile(i32 %0, i32 %1) {
%3 = tail call i8* @needMem(i32 65536)
%4 = tail call i32 @read(i32 %0, i8* %3, i32 65536)
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %11
6: ; preds = %2, %6
%7 = phi i32 [ %9, %6 ], [ %4, %2 ]
%8 = tail call i32 @mustWriteFd(i32 %1, i8* %3, i32 %7)
%9 = tail call i32 @read(i32 %0, i8* %3, i32 65536)
%10 = icmp sgt i32 %9, 0
br i1 %10, label %6, label %11
11: ; preds = %6, %2
%12 = tail call i32 @freeMem(i8* %3)
ret void
}