#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*/ raw_buffer;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
size_t fread(char *, int, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fwrite(char *, int, size_t, int /*<<< orphan*/ *);
scalar_t__ malloc(size_t);
scalar_t__ stb_feq(char *, char *);
int stb_copyfile(char *src, char *dest) {
  char raw_buffer[1024];
  char *buffer;
  size_t buf_size = 65536;
  FILE *f, *g;
  if (stb_feq(src, dest))
    return 1;
  f = fopen(src, "rb");
  if (f == NULL)
    return 0;
  g = fopen(dest, "wb");
  if (g == NULL) {
    fclose(f);
    return 0;
  }
  buffer = (char *)malloc(buf_size);
  if (buffer == NULL) {
    buffer = raw_buffer;
    buf_size = sizeof(raw_buffer);
  }
  while (!feof(f)) {
    size_t n = fread(buffer, 1, buf_size, f);
    if (n != 0)
      fwrite(buffer, 1, n, g);
  }
  fclose(f);
  if (buffer != raw_buffer)
    free(buffer);
  fclose(g);
  return 1;
}


x86 assembly (clang, -O0):
<stb_copyfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x10000,-0x430(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1080 <stb_feq@plt>
cmp    $0x0,%rax
je     11c1 <stb_copyfile+0x41>
movl   $0x1,-0x4(%rbp)
jmp    1329 <stb_copyfile+0x1a9>
mov    -0x10(%rbp),%rdi
lea    0xe34(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x438(%rbp)
cmpq   $0x0,-0x438(%rbp)
jne    11f2 <stb_copyfile+0x72>
movl   $0x0,-0x4(%rbp)
jmp    1329 <stb_copyfile+0x1a9>
mov    -0x18(%rbp),%rdi
lea    0xe06(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x440(%rbp)
cmpq   $0x0,-0x440(%rbp)
jne    122f <stb_copyfile+0xaf>
mov    -0x438(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    1329 <stb_copyfile+0x1a9>
mov    -0x430(%rbp),%rdi
call   1070 <malloc@plt>
mov    %rax,-0x428(%rbp)
cmpq   $0x0,-0x428(%rbp)
jne    1269 <stb_copyfile+0xe9>
lea    -0x420(%rbp),%rax
mov    %rax,-0x428(%rbp)
movq   $0x400,-0x430(%rbp)
jmp    126e <stb_copyfile+0xee>
mov    -0x438(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    128f <stb_copyfile+0x10f>
jmp    12e7 <stb_copyfile+0x167>
mov    -0x428(%rbp),%rdi
mov    -0x430(%rbp),%rdx
mov    -0x438(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    %rax,-0x448(%rbp)
cmpq   $0x0,-0x448(%rbp)
je     12e2 <stb_copyfile+0x162>
mov    -0x428(%rbp),%rdi
mov    -0x448(%rbp),%rdx
mov    -0x440(%rbp),%rcx
mov    $0x1,%esi
call   10a0 <fwrite@plt>
jmp    126e <stb_copyfile+0xee>
mov    -0x438(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x428(%rbp),%rax
lea    -0x420(%rbp),%rcx
cmp    %rcx,%rax
je     1316 <stb_copyfile+0x196>
mov    -0x428(%rbp),%rdi
call   1030 <free@plt>
mov    -0x440(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stb_copyfile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %rsi,%rbp
mov    %rdi,%rbx
call   1080 <stb_feq@plt>
mov    $0x1,%r14d
test   %rax,%rax
je     11bc <stb_copyfile+0x3c>
mov    %r14d,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe3d(%rip),%rsi
mov    %rbx,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     127b <stb_copyfile+0xfb>
mov    %rax,%rbx
lea    0xe25(%rip),%rsi
mov    %rbp,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     1283 <stb_copyfile+0x103>
mov    %rax,%r15
mov    $0x10000,%r13d
mov    $0x10000,%edi
call   1070 <malloc@plt>
mov    %rax,%rbp
test   %rax,%rax
mov    $0x400,%r12d
cmovne %r13,%r12
mov    %rsp,%r13
cmove  %r13,%rbp
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %eax,%eax
jne    1259 <stb_copyfile+0xd9>
mov    %rbp,%rdi
mov    $0x1,%esi
mov    %r12,%rdx
mov    %rbx,%rcx
call   1040 <fread@plt>
test   %rax,%rax
je     1220 <stb_copyfile+0xa0>
mov    %rbp,%rdi
mov    $0x1,%esi
mov    %rax,%rdx
mov    %r15,%rcx
call   10a0 <fwrite@plt>
jmp    1220 <stb_copyfile+0xa0>
mov    %rbx,%rdi
call   1050 <fclose@plt>
cmp    %r13,%rbp
je     126e <stb_copyfile+0xee>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1050 <fclose@plt>
jmp    11a7 <stb_copyfile+0x27>
xor    %r14d,%r14d
jmp    11a7 <stb_copyfile+0x27>
mov    %rbx,%rdi
call   1050 <fclose@plt>
xor    %r14d,%r14d
jmp    11a7 <stb_copyfile+0x27>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [3 x i8] c"wb\00"
define i32 @stb_copyfile(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [1024 x i8]
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 65536, i64* %8
%12 = load i8*, i8** %4
%13 = load i8*, i8** %5
%14 = call i64 @stb_feq(i8* %12, i8* %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %2
store i32 1, i32* %3
br label %70
17: ; preds = %2
%18 = load i8*, i8** %4
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %19, i32** %9
%20 = load i32*, i32** %9
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %23
22: ; preds = %17
store i32 0, i32* %3
br label %70
23: ; preds = %17
%24 = load i8*, i8** %5
%25 = call i32* @fopen(i8* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %25, i32** %10
%26 = load i32*, i32** %10
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %31
28: ; preds = %23
%29 = load i32*, i32** %9
%30 = call i32 @fclose(i32* %29)
store i32 0, i32* %3
br label %70
31: ; preds = %23
%32 = load i64, i64* %8
%33 = call i64 @malloc(i64 %32)
%34 = inttoptr i64 %33 to i8*
store i8* %34, i8** %7
%35 = load i8*, i8** %7
%36 = icmp eq i8* %35, null
br i1 %36, label %37, label %39
37: ; preds = %31
%38 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
store i8* %38, i8** %7
store i64 1024, i64* %8
br label %39
39: ; preds = %37, %31
br label %40
40: ; preds = %57, %39
%41 = load i32*, i32** %9
%42 = call i32 @feof(i32* %41)
%43 = icmp ne i32 %42, 0
%44 = xor i1 %43, true
br i1 %44, label %45, label %58
45: ; preds = %40
%46 = load i8*, i8** %7
%47 = load i64, i64* %8
%48 = load i32*, i32** %9
%49 = call i64 @fread(i8* %46, i32 1, i64 %47, i32* %48)
store i64 %49, i64* %11
%50 = load i64, i64* %11
%51 = icmp ne i64 %50, 0
br i1 %51, label %52, label %57
52: ; preds = %45
%53 = load i8*, i8** %7
%54 = load i64, i64* %11
%55 = load i32*, i32** %10
%56 = call i32 @fwrite(i8* %53, i32 1, i64 %54, i32* %55)
br label %57
57: ; preds = %52, %45
br label %40
58: ; preds = %40
%59 = load i32*, i32** %9
%60 = call i32 @fclose(i32* %59)
%61 = load i8*, i8** %7
%62 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%63 = icmp ne i8* %61, %62
br i1 %63, label %64, label %67
64: ; preds = %58
%65 = load i8*, i8** %7
%66 = call i32 @free(i8* %65)
br label %67
67: ; preds = %64, %58
%68 = load i32*, i32** %10
%69 = call i32 @fclose(i32* %68)
store i32 1, i32* %3
br label %70
70: ; preds = %67, %28, %22, %16
%71 = load i32, i32* %3
ret i32 %71
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [3 x i8] c"wb\00"
define i32 @stb_copyfile(i8* %0, i8* %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = tail call i64 @stb_feq(i8* %0, i8* %1)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %38
7: ; preds = %2
%8 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %38, label %10
10: ; preds = %7
%11 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = tail call i32 @fclose(i32* %8)
br label %38
15: ; preds = %10
%16 = tail call i64 @malloc(i64 65536)
%17 = inttoptr i64 %16 to i8*
%18 = icmp eq i64 %16, 0
%19 = select i1 %18, i64 1024, i64 65536
%20 = select i1 %18, i8* %4, i8* %17
%21 = tail call i32 @feof(i32* %8)
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %31
23: ; preds = %15, %28
%24 = call i64 @fread(i8* %20, i32 1, i64 %19, i32* %8)
%25 = icmp eq i64 %24, 0
br i1 %25, label %28, label %26
26: ; preds = %23
%27 = call i32 @fwrite(i8* %20, i32 1, i64 %24, i32* %11)
br label %28
28: ; preds = %26, %23
%29 = tail call i32 @feof(i32* %8)
%30 = icmp eq i32 %29, 0
br i1 %30, label %23, label %31
31: ; preds = %28, %15
%32 = tail call i32 @fclose(i32* %8)
%33 = icmp eq i8* %20, %4
br i1 %33, label %36, label %34
34: ; preds = %31
%35 = call i32 @free(i8* %20)
br label %36
36: ; preds = %34, %31
%37 = call i32 @fclose(i32* %11)
br label %38
38: ; preds = %7, %2, %36, %13
%39 = phi i32 [ 0, %13 ], [ 1, %36 ], [ 1, %2 ], [ 0, %7 ]
ret i32 %39
}