#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 *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
scalar_t__ malloc(int);
scalar_t__ stb_feq(char *, char *);
int stb_copyfile(char *src, char *dest) {
  char raw_buffer[1024];
  char *buffer;
  int 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)) {
    int 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)
movl   $0x10000,-0x42c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1080 <stb_feq@plt>
cmp    $0x0,%rax
je     11c0 <stb_copyfile+0x40>
movl   $0x1,-0x4(%rbp)
jmp    1322 <stb_copyfile+0x1a2>
mov    -0x10(%rbp),%rdi
lea    0xe35(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x438(%rbp)
cmpq   $0x0,-0x438(%rbp)
jne    11f1 <stb_copyfile+0x71>
movl   $0x0,-0x4(%rbp)
jmp    1322 <stb_copyfile+0x1a2>
mov    -0x18(%rbp),%rdi
lea    0xe07(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x440(%rbp)
cmpq   $0x0,-0x440(%rbp)
jne    122e <stb_copyfile+0xae>
mov    -0x438(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    1322 <stb_copyfile+0x1a2>
mov    -0x42c(%rbp),%edi
call   1070 <malloc@plt>
mov    %rax,-0x428(%rbp)
cmpq   $0x0,-0x428(%rbp)
jne    1266 <stb_copyfile+0xe6>
lea    -0x420(%rbp),%rax
mov    %rax,-0x428(%rbp)
movl   $0x400,-0x42c(%rbp)
jmp    126b <stb_copyfile+0xeb>
mov    -0x438(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    128c <stb_copyfile+0x10c>
jmp    12e0 <stb_copyfile+0x160>
mov    -0x428(%rbp),%rdi
mov    -0x42c(%rbp),%edx
mov    -0x438(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    %eax,-0x444(%rbp)
cmpl   $0x0,-0x444(%rbp)
je     12db <stb_copyfile+0x15b>
mov    -0x428(%rbp),%rdi
mov    -0x444(%rbp),%edx
mov    -0x440(%rbp),%rcx
mov    $0x1,%esi
call   10a0 <fwrite@plt>
jmp    126b <stb_copyfile+0xeb>
mov    -0x438(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x428(%rbp),%rax
lea    -0x420(%rbp),%rcx
cmp    %rcx,%rax
je     130f <stb_copyfile+0x18f>
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     1279 <stb_copyfile+0xf9>
mov    %rax,%rbx
lea    0xe25(%rip),%rsi
mov    %rbp,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     1281 <stb_copyfile+0x101>
mov    %rax,%r15
mov    $0x10000,%r13d
mov    $0x10000,%edi
call   1070 <malloc@plt>
mov    %rax,%rbp
test   %rax,%rax
mov    $0x400,%r12d
cmovne %r13d,%r12d
mov    %rsp,%r13
cmove  %r13,%rbp
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %eax,%eax
jne    1257 <stb_copyfile+0xd7>
mov    %rbp,%rdi
mov    $0x1,%esi
mov    %r12d,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
test   %eax,%eax
je     1220 <stb_copyfile+0xa0>
mov    %rbp,%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    %r15,%rcx
call   10a0 <fwrite@plt>
jmp    1220 <stb_copyfile+0xa0>
mov    %rbx,%rdi
call   1050 <fclose@plt>
cmp    %r13,%rbp
je     126c <stb_copyfile+0xec>
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 i32
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 65536, i32* %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 i32, i32* %8
%33 = call i64 @malloc(i32 %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 i32 1024, i32* %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 i32, i32* %8
%48 = load i32*, i32** %9
%49 = call i32 @fread(i8* %46, i32 1, i32 %47, i32* %48)
store i32 %49, i32* %11
%50 = load i32, i32* %11
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %57
52: ; preds = %45
%53 = load i8*, i8** %7
%54 = load i32, i32* %11
%55 = load i32*, i32** %10
%56 = call i32 @fwrite(i8* %53, i32 1, i32 %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(i32 65536)
%17 = inttoptr i64 %16 to i8*
%18 = icmp eq i64 %16, 0
%19 = select i1 %18, i32 1024, i32 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 i32 @fread(i8* %20, i32 1, i32 %19, i32* %8)
%25 = icmp eq i32 %24, 0
br i1 %25, label %28, label %26
26: ; preds = %23
%27 = call i32 @fwrite(i8* %20, i32 1, i32 %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
}