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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
int write(int, char *, int);
int CopyFile(int iSourceFd, int iTargetFd) {
  int iSourceFileSize;
  int iRead;
  int iWrite;
  char vcBuffer[512];
  iSourceFileSize = 0;
  while (1) {
    iRead = read(iSourceFd, vcBuffer, sizeof(vcBuffer));
    iWrite = write(iTargetFd, vcBuffer, iRead);
    if (iRead != iWrite) {
      fprintf(stderr, "[ERROR] iRead != iWrite.. \n");
      exit(-1);
    }
    iSourceFileSize += iRead;
    if (iRead != sizeof(vcBuffer)) {
      break;
    }
  }
  return iSourceFileSize;
}


x86 assembly (clang, -O0):
<CopyFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x220(%rbp),%rsi
mov    $0x200,%edx
call   1040 <read@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x220(%rbp),%rsi
mov    -0x10(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
je     11af <CopyFile+0x6f>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
lea    0xe60(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
movslq -0x10(%rbp),%rax
cmp    $0x200,%rax
je     11cd <CopyFile+0x8d>
jmp    11d2 <CopyFile+0x92>
jmp    1158 <CopyFile+0x18>
mov    -0xc(%rbp),%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CopyFile>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x200,%rsp
mov    %esi,%r14d
mov    %edi,%r15d
xor    %ebp,%ebp
mov    %rsp,%r12
nopw   0x0(%rax,%rax,1)
mov    %r15d,%edi
mov    %r12,%rsi
mov    $0x200,%edx
call   1040 <read@plt>
mov    %eax,%ebx
mov    %r14d,%edi
mov    %r12,%rsi
mov    %eax,%edx
call   1030 <write@plt>
cmp    %eax,%ebx
jne    119f <CopyFile+0x5f>
add    %ebx,%ebp
cmp    $0x200,%ebx
je     1160 <CopyFile+0x20>
mov    %ebp,%eax
add    $0x200,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
lea    0xe51(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [28 x i8] c"[ERROR] iRead != iWrite.. \0A\00"
define i32 @CopyFile(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca [512 x i8]
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 0, i32* %5
br label %9
9: ; preds = %2, %32
%10 = load i32, i32* %3
%11 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%12 = call i32 @read(i32 %10, i8* %11, i32 512)
store i32 %12, i32* %6
%13 = load i32, i32* %4
%14 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%15 = load i32, i32* %6
%16 = call i32 @write(i32 %13, i8* %14, i32 %15)
store i32 %16, i32* %7
%17 = load i32, i32* %6
%18 = load i32, i32* %7
%19 = icmp ne i32 %17, %18
br i1 %19, label %20, label %24
20: ; preds = %9
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%23 = call i32 @exit(i32 -1)
unreachable
24: ; preds = %9
%25 = load i32, i32* %6
%26 = load i32, i32* %5
%27 = add nsw i32 %26, %25
store i32 %27, i32* %5
%28 = load i32, i32* %6
%29 = sext i32 %28 to i64
%30 = icmp ne i64 %29, 512
br i1 %30, label %31, label %32
31: ; preds = %24
br label %33
32: ; preds = %24
br label %9
33: ; preds = %31
%34 = load i32, i32* %5
ret i32 %34
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [28 x i8] c"[ERROR] iRead != iWrite.. \0A\00"
define i32 @CopyFile(i32 %0, i32 %1) {
%3 = alloca [512 x i8]
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
br label %5
5: ; preds = %14, %2
%6 = phi i32 [ 0, %2 ], [ %15, %14 ]
%7 = call i32 @read(i32 %0, i8* %4, i32 512)
%8 = call i32 @write(i32 %1, i8* %4, i32 %7)
%9 = icmp eq i32 %7, %8
br i1 %9, label %14, label %10
10: ; preds = %5
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 @exit(i32 -1)
unreachable
14: ; preds = %5
%15 = add nsw i32 %7, %6
%16 = icmp eq i32 %7, 512
br i1 %16, label %5, label %17
17: ; preds = %14
ret i32 %15
}