#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 */
struct stat {
  int /*<<< orphan*/ st_size;
};
typedef size_t off_t;
typedef int int32_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int S_IFREG;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
size_t fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
char *malloc(int);
scalar_t__ stat(char const *, struct stat *);
int32_t DIRLIST_CopyFile(const char *aSource, const char *aDest,
                         void (*aProgress)(off_t aNow, off_t aTotal)) {
  char *copybuffer = 0;
  off_t currentsize = 0;
  struct stat statbuffer;
  FILE *source;
  FILE *target;
  if (stat(aSource, &statbuffer) || !statbuffer.st_size & S_IFREG) {
    return 1;
  }
  source = fopen(aSource, "rb");
  target = fopen(aDest, "wb");
  if (source && target) {
    copybuffer = malloc(64 * 1024);
    while (copybuffer && !feof(source)) {
      size_t count = fread(copybuffer, 1, 64 * 1024, source);
      fwrite(copybuffer, 1, 64 * 1024, target);
      currentsize += count;
      if (aProgress) {
        aProgress(currentsize, statbuffer.st_size);
      }
    }
    free(copybuffer);
  }
  if (source) {
    fclose(source);
  }
  if (target) {
    fclose(target);
  }
  return 0;
}


x86 assembly (clang, -O0):
<DIRLIST_CopyFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   1070 <stat@plt>
cmp    $0x0,%rax
jne    11db <DIRLIST_CopyFile+0x5b>
cmpl   $0x0,-0x38(%rbp)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    0x2e18(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     11e7 <DIRLIST_CopyFile+0x67>
movl   $0x1,-0x4(%rbp)
jmp    12fb <DIRLIST_CopyFile+0x17b>
mov    -0x10(%rbp),%rdi
lea    0xe0e(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xdfd(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     12cc <DIRLIST_CopyFile+0x14c>
cmpq   $0x0,-0x48(%rbp)
je     12cc <DIRLIST_CopyFile+0x14c>
mov    $0x10000,%edi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x28(%rbp)
mov    %al,-0x51(%rbp)
je     1257 <DIRLIST_CopyFile+0xd7>
mov    -0x40(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x51(%rbp)
mov    -0x51(%rbp),%al
test   $0x1,%al
jne    1267 <DIRLIST_CopyFile+0xe7>
jmp    12c3 <DIRLIST_CopyFile+0x143>
mov    -0x28(%rbp),%rdi
mov    -0x40(%rbp),%rcx
mov    $0x1,%esi
mov    $0x10000,%edx
call   1040 <fread@plt>
mov    %rax,-0x50(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x48(%rbp),%rcx
mov    $0x1,%esi
mov    $0x10000,%edx
call   10a0 <fwrite@plt>
mov    -0x50(%rbp),%rax
add    -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     12be <DIRLIST_CopyFile+0x13e>
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%rdi
movslq -0x38(%rbp),%rsi
call   *%rax
jmp    1233 <DIRLIST_CopyFile+0xb3>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x40(%rbp)
je     12e0 <DIRLIST_CopyFile+0x160>
mov    -0x40(%rbp),%rdi
call   1050 <fclose@plt>
cmpq   $0x0,-0x48(%rbp)
je     12f4 <DIRLIST_CopyFile+0x174>
mov    -0x48(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DIRLIST_CopyFile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsp,%rsi
call   1070 <stat@plt>
mov    $0x1,%ebp
test   %rax,%rax
jne    122c <DIRLIST_CopyFile+0xac>
cmpl   $0x0,(%rsp)
sete   %al
mov    0x2e30(%rip),%rcx
test   %al,(%rcx)
jne    122c <DIRLIST_CopyFile+0xac>
lea    0xe3d(%rip),%rsi
mov    %rbx,%rdi
call   1090 <fopen@plt>
mov    %rax,%r15
lea    0xe2e(%rip),%rsi
mov    %r14,%rdi
call   1090 <fopen@plt>
mov    %rax,%r14
test   %r15,%r15
je     1210 <DIRLIST_CopyFile+0x90>
test   %r14,%r14
je     1210 <DIRLIST_CopyFile+0x90>
mov    $0x10000,%edi
call   1080 <malloc@plt>
mov    %rax,%r13
test   %rax,%rax
je     1208 <DIRLIST_CopyFile+0x88>
mov    %r15,%rdi
call   1060 <feof@plt>
test   %eax,%eax
je     123d <DIRLIST_CopyFile+0xbd>
mov    %r13,%rdi
call   1030 <free@plt>
test   %r15,%r15
je     121d <DIRLIST_CopyFile+0x9d>
mov    %r15,%rdi
call   1050 <fclose@plt>
xor    %ebp,%ebp
test   %r14,%r14
je     122c <DIRLIST_CopyFile+0xac>
mov    %r14,%rdi
call   1050 <fclose@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ebx,%ebx
jmp    125c <DIRLIST_CopyFile+0xdc>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1060 <feof@plt>
test   %eax,%eax
jne    1208 <DIRLIST_CopyFile+0x88>
mov    %rbx,%rbp
mov    %r13,%rdi
mov    $0x1,%esi
mov    $0x10000,%edx
mov    %r15,%rcx
call   1040 <fread@plt>
mov    %rax,%rbx
mov    %r13,%rdi
mov    $0x1,%esi
mov    $0x10000,%edx
mov    %r14,%rcx
call   10a0 <fwrite@plt>
add    %rbp,%rbx
test   %r12,%r12
je     1250 <DIRLIST_CopyFile+0xd0>
movslq (%rsp),%rsi
mov    %rbx,%rdi
call   *%r12
jmp    1250 <DIRLIST_CopyFile+0xd0>

LLVM IR (-O0):
%struct.stat = type { i32 }
@S_IFREG = global i32 0
@.str = [3 x i8] c"rb\00"
@.str.1 = [3 x i8] c"wb\00"
define i32 @DIRLIST_CopyFile(i8* %0, i8* %1, void (i64, i64)* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca void (i64, i64)*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca %struct.stat
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i64
store i8* %0, i8** %5
store i8* %1, i8** %6
store void (i64, i64)* %2, void (i64, i64)** %7
store i8* null, i8** %8
store i64 0, i64* %9
%14 = load i8*, i8** %5
%15 = call i64 @stat(i8* %14, %struct.stat* %10)
%16 = icmp ne i64 %15, 0
br i1 %16, label %26, label %17
17: ; preds = %3
%18 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%19 = load i32, i32* %18
%20 = icmp ne i32 %19, 0
%21 = xor i1 %20, true
%22 = zext i1 %21 to i32
%23 = load i32, i32* @S_IFREG
%24 = and i32 %22, %23
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %17, %3
store i32 1, i32* %4
br label %84
27: ; preds = %17
%28 = load i8*, i8** %5
%29 = call i32* @fopen(i8* %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %29, i32** %11
%30 = load i8*, i8** %6
%31 = call i32* @fopen(i8* %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %31, i32** %12
%32 = load i32*, i32** %11
%33 = icmp ne i32* %32, null
br i1 %33, label %34, label %71
34: ; preds = %27
%35 = load i32*, i32** %12
%36 = icmp ne i32* %35, null
br i1 %36, label %37, label %71
37: ; preds = %34
%38 = call i8* @malloc(i32 65536)
store i8* %38, i8** %8
br label %39
39: ; preds = %67, %37
%40 = load i8*, i8** %8
%41 = icmp ne i8* %40, null
br i1 %41, label %42, label %47
42: ; preds = %39
%43 = load i32*, i32** %11
%44 = call i32 @feof(i32* %43)
%45 = icmp ne i32 %44, 0
%46 = xor i1 %45, true
br label %47
47: ; preds = %42, %39
%48 = phi i1 [ false, %39 ], [ %46, %42 ]
br i1 %48, label %49, label %68
49: ; preds = %47
%50 = load i8*, i8** %8
%51 = load i32*, i32** %11
%52 = call i64 @fread(i8* %50, i32 1, i32 65536, i32* %51)
store i64 %52, i64* %13
%53 = load i8*, i8** %8
%54 = load i32*, i32** %12
%55 = call i32 @fwrite(i8* %53, i32 1, i32 65536, i32* %54)
%56 = load i64, i64* %13
%57 = load i64, i64* %9
%58 = add i64 %57, %56
store i64 %58, i64* %9
%59 = load void (i64, i64)*, void (i64, i64)** %7
%60 = icmp ne void (i64, i64)* %59, null
br i1 %60, label %61, label %67
61: ; preds = %49
%62 = load void (i64, i64)*, void (i64, i64)** %7
%63 = load i64, i64* %9
%64 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%65 = load i32, i32* %64
%66 = sext i32 %65 to i64
br label %67
67: ; preds = %61, %49
br label %39
68: ; preds = %47
%69 = load i8*, i8** %8
%70 = call i32 @free(i8* %69)
br label %71
71: ; preds = %68, %34, %27
%72 = load i32*, i32** %11
%73 = icmp ne i32* %72, null
br i1 %73, label %74, label %77
74: ; preds = %71
%75 = load i32*, i32** %11
%76 = call i32 @fclose(i32* %75)
br label %77
77: ; preds = %74, %71
%78 = load i32*, i32** %12
%79 = icmp ne i32* %78, null
br i1 %79, label %80, label %83
80: ; preds = %77
%81 = load i32*, i32** %12
%82 = call i32 @fclose(i32* %81)
br label %83
83: ; preds = %80, %77
store i32 0, i32* %4
br label %84
84: ; preds = %83, %26
%85 = load i32, i32* %4
ret i32 %85
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@S_IFREG = global i32 0
@.str = [3 x i8] c"rb\00"
@.str.1 = [3 x i8] c"wb\00"
define i32 @DIRLIST_CopyFile(i8* %0, i8* nocapture %1, void (i64, i64)* %2) {
%4 = alloca %struct.stat
%5 = bitcast %struct.stat* %4 to i8*
%6 = call i64 @stat(i8* %0, %struct.stat* %4)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %48
8: ; preds = %3
%9 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%10 = load i32, i32* %9
%11 = icmp eq i32 %10, 0
%12 = zext i1 %11 to i32
%13 = load i32, i32* @S_IFREG
%14 = and i32 %13, %12
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %48
16: ; preds = %8
%17 = call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%18 = call i32* @fopen(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp ne i32* %17, null
%20 = icmp ne i32* %18, null
%21 = and i1 %19, %20
br i1 %21, label %22, label %42
22: ; preds = %16
%23 = call dereferenceable_or_null(65536) i8* @malloc(i32 65536)
%24 = icmp eq i8* %23, null
br i1 %24, label %40, label %25
25: ; preds = %22
%26 = icmp eq void (i64, i64)* %2, null
%27 = call i32 @feof(i32* %17)
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %40
29: ; preds = %25, %37
%30 = phi i64 [ %33, %37 ], [ 0, %25 ]
%31 = call i64 @fread(i8* %23, i32 1, i32 65536, i32* %17)
%32 = call i32 @fwrite(i8* %23, i32 1, i32 65536, i32* %18)
%33 = add i64 %31, %30
br i1 %26, label %37, label %34
34: ; preds = %29
%35 = load i32, i32* %9
%36 = sext i32 %35 to i64
br label %37
37: ; preds = %34, %29
%38 = call i32 @feof(i32* %17)
%39 = icmp eq i32 %38, 0
br i1 %39, label %29, label %40
40: ; preds = %37, %25, %22
%41 = call i32 @free(i8* %23)
br label %42
42: ; preds = %40, %16
br i1 %19, label %43, label %45
43: ; preds = %42
%44 = call i32 @fclose(i32* %17)
br label %45
45: ; preds = %43, %42
br i1 %20, label %46, label %48
46: ; preds = %45
%47 = call i32 @fclose(i32* %18)
br label %48
48: ; preds = %45, %46, %3, %8
%49 = phi i32 [ 1, %8 ], [ 1, %3 ], [ 0, %46 ], [ 0, %45 ]
ret i32 %49
}