#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 EXIT_SUCCESS;
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int read(int, char *, int);
int sendAll(int, char *, int);
int transferFile(int source, int destination, char *buffer) {
  memset(buffer, 0, 4096);
  int bytes_read;
  while ((bytes_read = read(source, buffer, 4096)) > 0) {
    if (sendAll(destination, buffer, bytes_read) == -1)
      return -1;
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<transferFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1030 <memset@plt>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    $0x1000,%edx
call   1040 <read@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jle    1198 <transferFile+0x68>
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1050 <sendAll@plt>
cmp    $0xffffffff,%eax
jne    1193 <transferFile+0x63>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a4 <transferFile+0x74>
jmp    1152 <transferFile+0x22>
mov    0x2e41(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<transferFile>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%rbx
mov    %esi,%r14d
mov    %edi,%ebp
mov    %rdx,%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1030 <memset@plt>
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x1000,%edx
call   1040 <read@plt>
test   %eax,%eax
jle    117c <transferFile+0x4c>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <sendAll@plt>
cmp    $0xffffffff,%eax
jne    1150 <transferFile+0x20>
mov    $0xffffffff,%eax
jmp    1185 <transferFile+0x55>
mov    0x2e5d(%rip),%rax
mov    (%rax),%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@EXIT_SUCCESS = global i32 0
define i32 @transferFile(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8* %2, i8** %7
%9 = load i8*, i8** %7
%10 = call i32 @memset(i8* %9, i32 0, i32 4096)
br label %11
11: ; preds = %23, %3
%12 = load i32, i32* %5
%13 = load i8*, i8** %7
%14 = call i32 @read(i32 %12, i8* %13, i32 4096)
store i32 %14, i32* %8
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %24
16: ; preds = %11
%17 = load i32, i32* %6
%18 = load i8*, i8** %7
%19 = load i32, i32* %8
%20 = call i32 @sendAll(i32 %17, i8* %18, i32 %19)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %23
22: ; preds = %16
store i32 -1, i32* %4
br label %26
23: ; preds = %16
br label %11
24: ; preds = %11
%25 = load i32, i32* @EXIT_SUCCESS
store i32 %25, i32* %4
br label %26
26: ; preds = %24, %22
%27 = load i32, i32* %4
ret i32 %27
}

LLVM IR (-O2):
@EXIT_SUCCESS = global i32 0
define i32 @transferFile(i32 %0, i32 %1, i8* %2) {
%4 = tail call i32 @memset(i8* %2, i32 0, i32 4096)
br label %5
5: ; preds = %8, %3
%6 = tail call i32 @read(i32 %0, i8* %2, i32 4096)
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %5
%9 = tail call i32 @sendAll(i32 %1, i8* %2, i32 %6)
%10 = icmp eq i32 %9, -1
br i1 %10, label %13, label %5
11: ; preds = %5
%12 = load i32, i32* @EXIT_SUCCESS
br label %13
13: ; preds = %8, %11
%14 = phi i32 [ %12, %11 ], [ -1, %8 ]
ret i32 %14
}