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

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
scalar_t__ copy_file(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int fseek(int /*<<< orphan*/ *, int /*<<< orphan*/, int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int conf_copy_file(const char *src_file, const char *dst_file) {
  FILE *src = fopen(src_file, "rb");
  if (src == NULL) {
    fprintf(stderr, "Failed to open input file %s: %s\n", src_file,
            strerror(errno));
    return 1;
  }
  uint32_t src_size = fseek(src, 0, SEEK_END);
  src_size = ftell(src);
  if (src_size > 2 * 1048576) {
    fprintf(stderr, "Size of file (%d) exceeds MAX_FILE_SIZE(%d)\n", src_size,
            2 * 1048576);
    fclose(src);
    return -1;
  }
  rewind(src);
  FILE *dst = fopen(dst_file, "wb+");
  if (dst == NULL) {
    fprintf(stderr, "Failed to open output file %s: %s\n", dst_file,
            strerror(errno));
    fclose(src);
    return 1;
  }
  if (copy_file(src, dst, src_size) != 0) {
    fprintf(stderr, "Failed to copy %s to %s:%s\n", src_file, dst_file,
            strerror(errno));
    fclose(src);
    fclose(dst);
    return 1;
  }
  fclose(src);
  fclose(dst);
  return 0;
}


x86 assembly (clang, -O0):
<conf_copy_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe65(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11f5 <conf_copy_file+0x75>
mov    0x2e22(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rdx
mov    %rax,%rcx
lea    0xe21(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1367 <conf_copy_file+0x1e7>
mov    -0x20(%rbp),%rdi
mov    0x2de8(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1070 <ftell@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x200000,-0x24(%rbp)
jle    1259 <conf_copy_file+0xd9>
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
mov    -0x24(%rbp),%edx
lea    0xded(%rip),%rsi
mov    $0x200000,%ecx
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1367 <conf_copy_file+0x1e7>
mov    -0x20(%rbp),%rdi
call   1050 <rewind@plt>
mov    -0x18(%rbp),%rdi
lea    0xde5(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    12d0 <conf_copy_file+0x150>
mov    0x2d50(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    0x2d34(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%rdx
mov    %rax,%rcx
lea    0xda2(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    1367 <conf_copy_file+0x1e7>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1030 <copy_file@plt>
cmp    $0x0,%rax
je     134e <conf_copy_file+0x1ce>
mov    0x2ce7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x64(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    0x2cc3(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x64(%rbp),%edi
mov    -0x60(%rbp),%rdx
mov    -0x58(%rbp),%rcx
mov    %rax,%r8
lea    0xd50(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    1367 <conf_copy_file+0x1e7>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<conf_copy_file>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xe6b(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     11f6 <conf_copy_file+0x76>
mov    %rax,%rbx
mov    0x2e3f(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
mov    %rbx,%rdi
call   1070 <ftell@plt>
mov    %eax,%ebp
cmp    $0x200001,%eax
jl     122d <conf_copy_file+0xad>
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
lea    0xe4f(%rip),%rsi
mov    %ebp,%edx
mov    $0x200000,%ecx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    $0xffffffff,%eax
jmp    12e9 <conf_copy_file+0x169>
mov    0x2ddb(%rip),%rax
mov    (%rax),%ebx
mov    0x2dca(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xdef(%rip),%rsi
mov    %ebx,%edi
mov    %r15,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%eax
jmp    12e9 <conf_copy_file+0x169>
mov    %rbx,%rdi
call   1050 <rewind@plt>
lea    0xe16(%rip),%rsi
mov    %r14,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     129b <conf_copy_file+0x11b>
mov    %rax,%r12
mov    %rbx,%rdi
mov    %rax,%rsi
mov    %ebp,%edx
call   1030 <copy_file@plt>
test   %rax,%rax
je     12d7 <conf_copy_file+0x157>
mov    0x2d73(%rip),%rax
mov    (%rax),%ebp
mov    0x2d62(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xdfd(%rip),%rsi
mov    %ebp,%edi
mov    %r15,%rdx
mov    %r14,%rcx
mov    %rax,%r8
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r12,%rdi
jmp    12cb <conf_copy_file+0x14b>
mov    0x2d36(%rip),%rax
mov    (%rax),%ebp
mov    0x2d25(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xd9d(%rip),%rsi
mov    %ebp,%edi
mov    %r14,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    $0x1,%eax
jmp    12e9 <conf_copy_file+0x169>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r12,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [34 x i8] c"Failed to open input file %s: %s\0A\00"
@errno = global i32 0
@SEEK_END = global i32 0
@.str.2 = [45 x i8] c"Size of file (%d) exceeds MAX_FILE_SIZE(%d)\0A\00"
@.str.3 = [4 x i8] c"wb+\00"
@.str.4 = [35 x i8] c"Failed to open output file %s: %s\0A\00"
@.str.5 = [28 x i8] c"Failed to copy %s to %s:%s\0A\00"
define i32 @conf_copy_file(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32*
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %4
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %6
%11 = load i32*, i32** %6
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %19
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %4
%16 = load i32, i32* @errno
%17 = call i8* @strerror(i32 %16)
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %15, i8* %17)
store i32 1, i32* %3
br label %70
19: ; preds = %2
%20 = load i32*, i32** %6
%21 = load i32, i32* @SEEK_END
%22 = call i32 @fseek(i32* %20, i32 0, i32 %21)
store i32 %22, i32* %7
%23 = load i32*, i32** %6
%24 = call i32 @ftell(i32* %23)
store i32 %24, i32* %7
%25 = load i32, i32* %7
%26 = icmp sgt i32 %25, 2097152
br i1 %26, label %27, label %33
27: ; preds = %19
%28 = load i32, i32* @stderr
%29 = load i32, i32* %7
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i32 %29, i32 2097152)
%31 = load i32*, i32** %6
%32 = call i32 @fclose(i32* %31)
store i32 -1, i32* %3
br label %70
33: ; preds = %19
%34 = load i32*, i32** %6
%35 = call i32 @rewind(i32* %34)
%36 = load i8*, i8** %5
%37 = call i32* @fopen(i8* %36, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
store i32* %37, i32** %8
%38 = load i32*, i32** %8
%39 = icmp eq i32* %38, null
br i1 %39, label %40, label %48
40: ; preds = %33
%41 = load i32, i32* @stderr
%42 = load i8*, i8** %5
%43 = load i32, i32* @errno
%44 = call i8* @strerror(i32 %43)
%45 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i8* %42, i8* %44)
%46 = load i32*, i32** %6
%47 = call i32 @fclose(i32* %46)
store i32 1, i32* %3
br label %70
48: ; preds = %33
%49 = load i32*, i32** %6
%50 = load i32*, i32** %8
%51 = load i32, i32* %7
%52 = call i64 @copy_file(i32* %49, i32* %50, i32 %51)
%53 = icmp ne i64 %52, 0
br i1 %53, label %54, label %65
54: ; preds = %48
%55 = load i32, i32* @stderr
%56 = load i8*, i8** %4
%57 = load i8*, i8** %5
%58 = load i32, i32* @errno
%59 = call i8* @strerror(i32 %58)
%60 = call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i8* %56, i8* %57, i8* %59)
%61 = load i32*, i32** %6
%62 = call i32 @fclose(i32* %61)
%63 = load i32*, i32** %8
%64 = call i32 @fclose(i32* %63)
store i32 1, i32* %3
br label %70
65: ; preds = %48
%66 = load i32*, i32** %6
%67 = call i32 @fclose(i32* %66)
%68 = load i32*, i32** %8
%69 = call i32 @fclose(i32* %68)
store i32 0, i32* %3
br label %70
70: ; preds = %65, %54, %40, %27, %13
%71 = load i32, i32* %3
ret i32 %71
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [34 x i8] c"Failed to open input file %s: %s\0A\00"
@errno = global i32 0
@SEEK_END = global i32 0
@.str.2 = [45 x i8] c"Size of file (%d) exceeds MAX_FILE_SIZE(%d)\0A\00"
@.str.3 = [4 x i8] c"wb+\00"
@.str.4 = [35 x i8] c"Failed to open output file %s: %s\0A\00"
@.str.5 = [28 x i8] c"Failed to copy %s to %s:%s\0A\00"
define i32 @conf_copy_file(i8* %0, i8* %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %10
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = load i32, i32* @errno
%8 = tail call i8* @strerror(i32 %7)
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %8)
br label %42
10: ; preds = %2
%11 = load i32, i32* @SEEK_END
%12 = tail call i32 @fseek(i32* %3, i32 0, i32 %11)
%13 = tail call i32 @ftell(i32* %3)
%14 = icmp sgt i32 %13, 2097152
br i1 %14, label %15, label %19
15: ; preds = %10
%16 = load i32, i32* @stderr
%17 = tail call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i32 %13, i32 2097152)
%18 = tail call i32 @fclose(i32* %3)
br label %42
19: ; preds = %10
%20 = tail call i32 @rewind(i32* %3)
%21 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %29
23: ; preds = %19
%24 = load i32, i32* @stderr
%25 = load i32, i32* @errno
%26 = tail call i8* @strerror(i32 %25)
%27 = tail call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i8* %1, i8* %26)
%28 = tail call i32 @fclose(i32* %3)
br label %42
29: ; preds = %19
%30 = tail call i64 @copy_file(i32* %3, i32* %21, i32 %13)
%31 = icmp eq i64 %30, 0
br i1 %31, label %39, label %32
32: ; preds = %29
%33 = load i32, i32* @stderr
%34 = load i32, i32* @errno
%35 = tail call i8* @strerror(i32 %34)
%36 = tail call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i8* %0, i8* %1, i8* %35)
%37 = tail call i32 @fclose(i32* %3)
%38 = tail call i32 @fclose(i32* %21)
br label %42
39: ; preds = %29
%40 = tail call i32 @fclose(i32* %3)
%41 = tail call i32 @fclose(i32* %21)
br label %42
42: ; preds = %15, %39, %32, %23, %5
%43 = phi i32 [ 1, %5 ], [ -1, %15 ], [ 1, %23 ], [ 1, %32 ], [ 0, %39 ]
ret i32 %43
}