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

/* Variables and functions */
scalar_t__ EOF;
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *strrchr(char *, char);
int file_copy(char *src_path, char *dest_dir) {
  FILE *src, *dest;
  char *dest_path, ch, *src_filename;
  if ((src_filename = strrchr(src_path, '/')) == NULL) {
    printf("Source path is not complete (i.e. Could not find '/' ('\' on "
           "windows) in the path)!, source path = %s\n",
           src_path);
    return 1;
  }
  dest_path = (char *)malloc(sizeof(char) *
                             (strlen(dest_dir) + strlen(src_filename) + 10));
  strcpy(dest_path, dest_dir);
  strcat(dest_path, src_filename);
  if ((src = fopen(src_path, "rb")) == NULL) {
    printf("Cannot open source file, %s.\n", src_path);
    return 1;
  }
  if ((dest = fopen(dest_path, "wb")) == NULL) {
    printf("Cannot open destination file, %s.\n", dest_path);
    return 1;
  }
  while (!feof(src)) {
    ch = fgetc(src);
    if (ferror(src)) {
      printf("Error reading source file.\n");
      return 1;
    }
    if (!feof(src))
      fputc(ch, dest);
    {
      if (ferror(dest)) {
        printf("Error writing destination file.\n");
        return 1;
      }
    }
  }
  if (fclose(src) == EOF) {
    printf("Error closing source file.\n");
    return 1;
  }
  if (fclose(dest) == EOF) {
    printf("Error closing destination file.\n");
    return 1;
  }
  free(dest_path);
  return 0;
}


x86 assembly (clang, -O0):
<file_copy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1090 <strrchr@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
jne    121a <file_copy+0x4a>
mov    -0x10(%rbp),%rsi
lea    0xdf9(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1401 <file_copy+0x231>
mov    -0x18(%rbp),%rdi
call   1070 <strlen@plt>
mov    %eax,-0x44(%rbp)
mov    -0x40(%rbp),%rdi
call   1070 <strlen@plt>
mov    %eax,%ecx
mov    -0x44(%rbp),%eax
add    %ecx,%eax
add    $0xa,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   10d0 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x30(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   10f0 <strcat@plt>
mov    -0x10(%rbp),%rdi
lea    0xdf7(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    12a0 <file_copy+0xd0>
mov    -0x10(%rbp),%rsi
lea    0xddc(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1401 <file_copy+0x231>
mov    -0x30(%rbp),%rdi
lea    0xddc(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    12dc <file_copy+0x10c>
mov    -0x30(%rbp),%rsi
lea    0xdc1(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1401 <file_copy+0x231>
jmp    12e1 <file_copy+0x111>
mov    -0x20(%rbp),%rdi
call   10c0 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    12ff <file_copy+0x12f>
jmp    138b <file_copy+0x1bb>
mov    -0x20(%rbp),%rdi
call   10a0 <fgetc@plt>
mov    %al,-0x31(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <ferror@plt>
cmp    $0x0,%rax
je     1338 <file_copy+0x168>
lea    0xd88(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1401 <file_copy+0x231>
mov    -0x20(%rbp),%rdi
call   10c0 <feof@plt>
cmp    $0x0,%eax
jne    1359 <file_copy+0x189>
mov    -0x31(%rbp),%al
mov    -0x28(%rbp),%rsi
movsbl %al,%edi
call   10b0 <fputc@plt>
mov    -0x28(%rbp),%rdi
call   1050 <ferror@plt>
cmp    $0x0,%rax
je     1386 <file_copy+0x1b6>
lea    0xd56(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1401 <file_copy+0x231>
jmp    12e1 <file_copy+0x111>
mov    -0x20(%rbp),%rdi
call   1060 <fclose@plt>
mov    0x2c4d(%rip),%rcx
cmp    (%rcx),%rax
jne    13be <file_copy+0x1ee>
lea    0xd3f(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1401 <file_copy+0x231>
mov    -0x28(%rbp),%rdi
call   1060 <fclose@plt>
mov    0x2c1a(%rip),%rcx
cmp    (%rcx),%rax
jne    13f1 <file_copy+0x221>
lea    0xd28(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1401 <file_copy+0x231>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_copy>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    %rdi,%r15
mov    $0x2f,%esi
call   10a0 <strrchr@plt>
test   %rax,%rax
je     12bd <file_copy+0xdd>
mov    %rax,%rbx
mov    %r12,%rdi
call   1080 <strlen@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
call   1080 <strlen@plt>
lea    (%r14,%rax,1),%edi
add    $0xa,%edi
call   10e0 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %r12,%rsi
call   1040 <strcpy@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1100 <strcat@plt>
lea    0xe23(%rip),%rsi
mov    %r15,%rdi
call   10f0 <fopen@plt>
test   %rax,%rax
je     12c6 <file_copy+0xe6>
mov    %rax,%r12
lea    0xe2d(%rip),%rsi
mov    %r14,%rdi
call   10f0 <fopen@plt>
test   %rax,%rax
je     12d9 <file_copy+0xf9>
mov    %rax,%r15
jmp    1281 <file_copy+0xa1>
nopl   0x0(%rax)
mov    %r15,%rdi
call   1060 <ferror@plt>
test   %rax,%rax
jne    130b <file_copy+0x12b>
mov    %r12,%rdi
call   10d0 <feof@plt>
test   %eax,%eax
jne    12e5 <file_copy+0x105>
mov    %r12,%rdi
call   10b0 <fgetc@plt>
mov    %eax,%ebx
mov    %r12,%rdi
call   1060 <ferror@plt>
test   %rax,%rax
jne    1302 <file_copy+0x122>
mov    %r12,%rdi
call   10d0 <feof@plt>
test   %eax,%eax
jne    1270 <file_copy+0x90>
movsbl %bl,%edi
mov    %r15,%rsi
call   10c0 <fputc@plt>
jmp    1270 <file_copy+0x90>
lea    0xd3c(%rip),%rdi
jmp    12cd <file_copy+0xed>
lea    0xd9c(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
jmp    132d <file_copy+0x14d>
lea    0xdaa(%rip),%rdi
mov    %r14,%rsi
jmp    12d0 <file_copy+0xf0>
mov    %r12,%rdi
call   1070 <fclose@plt>
mov    0x2cf4(%rip),%rbx
cmp    (%rbx),%rax
jne    1314 <file_copy+0x134>
lea    0xdcd(%rip),%rdi
jmp    1328 <file_copy+0x148>
lea    0xdff(%rip),%rdi
jmp    1328 <file_copy+0x148>
lea    0xdd6(%rip),%rdi
jmp    1328 <file_copy+0x148>
mov    %r15,%rdi
call   1070 <fclose@plt>
cmp    (%rbx),%rax
jne    133e <file_copy+0x15e>
lea    0xd85(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
jmp    1332 <file_copy+0x152>

LLVM IR (-O0):
@.str = [102 x i8] c"Source path is not complete (i.e. Could not find '/' ('' on windows) in the path)!, source path = %s\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [30 x i8] c"Cannot open source file, %s.\0A\00"
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [35 x i8] c"Cannot open destination file, %s.\0A\00"
@.str.5 = [28 x i8] c"Error reading source file.\0A\00"
@.str.6 = [33 x i8] c"Error writing destination file.\0A\00"
@EOF = global i64 0
@.str.7 = [28 x i8] c"Error closing source file.\0A\00"
@.str.8 = [33 x i8] c"Error closing destination file.\0A\00"
define i32 @file_copy(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i8
%10 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%11 = load i8*, i8** %4
%12 = call i8* @strrchr(i8* %11, i8 signext 47)
store i8* %12, i8** %10
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = load i8*, i8** %4
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([102 x i8], [102 x i8]* @.str, i64 0, i64 0), i8* %15)
store i32 1, i32* %3
br label %94
17: ; preds = %2
%18 = load i8*, i8** %5
%19 = call i32 @strlen(i8* %18)
%20 = load i8*, i8** %10
%21 = call i32 @strlen(i8* %20)
%22 = add nsw i32 %19, %21
%23 = add nsw i32 %22, 10
%24 = sext i32 %23 to i64
%25 = mul i64 1, %24
%26 = trunc i64 %25 to i32
%27 = call i64 @malloc(i32 %26)
%28 = inttoptr i64 %27 to i8*
store i8* %28, i8** %8
%29 = load i8*, i8** %8
%30 = load i8*, i8** %5
%31 = call i32 @strcpy(i8* %29, i8* %30)
%32 = load i8*, i8** %8
%33 = load i8*, i8** %10
%34 = call i32 @strcat(i8* %32, i8* %33)
%35 = load i8*, i8** %4
%36 = call i32* @fopen(i8* %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %36, i32** %6
%37 = icmp eq i32* %36, null
br i1 %37, label %38, label %41
38: ; preds = %17
%39 = load i8*, i8** %4
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %39)
store i32 1, i32* %3
br label %94
41: ; preds = %17
%42 = load i8*, i8** %8
%43 = call i32* @fopen(i8* %42, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %43, i32** %7
%44 = icmp eq i32* %43, null
br i1 %44, label %45, label %48
45: ; preds = %41
%46 = load i8*, i8** %8
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i8* %46)
store i32 1, i32* %3
br label %94
48: ; preds = %41
br label %49
49: ; preds = %76, %48
%50 = load i32*, i32** %6
%51 = call i32 @feof(i32* %50)
%52 = icmp ne i32 %51, 0
%53 = xor i1 %52, true
br i1 %53, label %54, label %77
54: ; preds = %49
%55 = load i32*, i32** %6
%56 = call signext i8 @fgetc(i32* %55)
store i8 %56, i8* %9
%57 = load i32*, i32** %6
%58 = call i64 @ferror(i32* %57)
%59 = icmp ne i64 %58, 0
br i1 %59, label %60, label %62
60: ; preds = %54
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %3
br label %94
62: ; preds = %54
%63 = load i32*, i32** %6
%64 = call i32 @feof(i32* %63)
%65 = icmp ne i32 %64, 0
br i1 %65, label %70, label %66
66: ; preds = %62
%67 = load i8, i8* %9
%68 = load i32*, i32** %7
%69 = call i32 @fputc(i8 signext %67, i32* %68)
br label %70
70: ; preds = %66, %62
%71 = load i32*, i32** %7
%72 = call i64 @ferror(i32* %71)
%73 = icmp ne i64 %72, 0
br i1 %73, label %74, label %76
74: ; preds = %70
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %3
br label %94
76: ; preds = %70
br label %49
77: ; preds = %49
%78 = load i32*, i32** %6
%79 = call i64 @fclose(i32* %78)
%80 = load i64, i64* @EOF
%81 = icmp eq i64 %79, %80
br i1 %81, label %82, label %84
82: ; preds = %77
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0))
store i32 1, i32* %3
br label %94
84: ; preds = %77
%85 = load i32*, i32** %7
%86 = call i64 @fclose(i32* %85)
%87 = load i64, i64* @EOF
%88 = icmp eq i64 %86, %87
br i1 %88, label %89, label %91
89: ; preds = %84
%90 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0))
store i32 1, i32* %3
br label %94
91: ; preds = %84
%92 = load i8*, i8** %8
%93 = call i32 @free(i8* %92)
store i32 0, i32* %3
br label %94
94: ; preds = %91, %89, %82, %74, %60, %45, %38, %14
%95 = load i32, i32* %3
ret i32 %95
}

LLVM IR (-O2):
@.str = [102 x i8] c"Source path is not complete (i.e. Could not find '/' ('' on windows) in the path)!, source path = %s\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [30 x i8] c"Cannot open source file, %s.\0A\00"
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [35 x i8] c"Cannot open destination file, %s.\0A\00"
@EOF = global i64 0
@str = [32 x i8] c"Error closing destination file.\00"
@str.9 = [27 x i8] c"Error closing source file.\00"
@str.10 = [32 x i8] c"Error writing destination file.\00"
@str.11 = [27 x i8] c"Error reading source file.\00"
define i32 @file_copy(i8* %0, i8* %1) {
%3 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([102 x i8], [102 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %58
7: ; preds = %2
%8 = tail call i32 @strlen(i8* %1)
%9 = tail call i32 @strlen(i8* %3)
%10 = add i32 %8, 10
%11 = add i32 %10, %9
%12 = tail call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to i8*
%14 = tail call i32 @strcpy(i8* %13, i8* %1)
%15 = tail call i32 @strcat(i8* %13, i8* %3)
%16 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %20
18: ; preds = %7
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %58
20: ; preds = %7
%21 = tail call i32* @fopen(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i8* %13)
br label %58
25: ; preds = %20, %39
%26 = tail call i32 @feof(i32* %16)
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %44
28: ; preds = %25
%29 = tail call signext i8 @fgetc(i32* %16)
%30 = tail call i64 @ferror(i32* %16)
%31 = icmp eq i64 %30, 0
br i1 %31, label %34, label %32
32: ; preds = %28
%33 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.11, i64 0, i64 0))
br label %58
34: ; preds = %28
%35 = tail call i32 @feof(i32* %16)
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %34
%38 = tail call i32 @fputc(i8 signext %29, i32* %21)
br label %39
39: ; preds = %37, %34
%40 = tail call i64 @ferror(i32* %21)
%41 = icmp eq i64 %40, 0
br i1 %41, label %25, label %42
42: ; preds = %39
%43 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.10, i64 0, i64 0))
br label %58
44: ; preds = %25
%45 = tail call i64 @fclose(i32* %16)
%46 = load i64, i64* @EOF
%47 = icmp eq i64 %45, %46
br i1 %47, label %48, label %50
48: ; preds = %44
%49 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.9, i64 0, i64 0))
br label %58
50: ; preds = %44
%51 = tail call i64 @fclose(i32* %21)
%52 = load i64, i64* @EOF
%53 = icmp eq i64 %51, %52
br i1 %53, label %54, label %56
54: ; preds = %50
%55 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
br label %58
56: ; preds = %50
%57 = tail call i32 @free(i8* %13)
br label %58
58: ; preds = %56, %54, %48, %42, %32, %23, %18, %5
%59 = phi i32 [ 1, %5 ], [ 1, %18 ], [ 1, %23 ], [ 1, %32 ], [ 1, %42 ], [ 1, %48 ], [ 1, %54 ], [ 0, %56 ]
ret i32 %59
}