#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 */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
scalar_t__ fs_exsists(char const *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char const *, char const *);
int fs_cp(const char *restrict src, const char *restrict dst) {
  char buffer[4096];
  int size;
  FILE *src_file;
  FILE *dst_file;
  if (fs_exsists(src)) {
    printf("%s -> %s\n", src, dst);
    src_file = fopen(src, "r");
    dst_file = fopen(dst, "w");
    while ((size = fread(buffer, 1, 4096, src_file)) > 0)
      fwrite(buffer, 1, size, dst_file);
    fclose(src_file);
    fclose(dst_file);
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<fs_cp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1040,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1080 <fs_exsists@plt>
cmp    $0x0,%rax
je     123b <fs_cp+0xdb>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe6b(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
lea    0xe65(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x1030(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe50(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x1038(%rbp)
lea    -0x1020(%rbp),%rdi
mov    -0x1030(%rbp),%rcx
mov    $0x1,%esi
mov    $0x1000,%edx
call   1030 <fread@plt>
mov    %eax,-0x1024(%rbp)
cmp    $0x0,%eax
jle    1217 <fs_cp+0xb7>
lea    -0x1020(%rbp),%rdi
mov    -0x1024(%rbp),%edx
mov    -0x1038(%rbp),%rcx
mov    $0x1,%esi
call   1070 <fwrite@plt>
jmp    11c8 <fs_cp+0x68>
mov    -0x1030(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x1038(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    1242 <fs_cp+0xe2>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fs_cp>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x1008,%rsp
mov    %rsi,%rbp
mov    %rdi,%rbx
call   1080 <fs_exsists@plt>
test   %rax,%rax
je     121d <fs_cp+0xbd>
lea    0xe78(%rip),%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   1050 <printf@plt>
lea    0xe70(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fopen@plt>
mov    %rax,%r15
lea    0xe60(%rip),%rsi
mov    %rbp,%rdi
call   1060 <fopen@plt>
mov    %rax,%rbp
mov    %rsp,%rdi
mov    $0x1,%r14d
mov    $0x1,%esi
mov    $0x1000,%edx
mov    %r15,%rcx
call   1030 <fread@plt>
test   %eax,%eax
jle    120b <fs_cp+0xab>
mov    %rsp,%rbx
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    %rbp,%rcx
call   1070 <fwrite@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x1000,%edx
mov    %r15,%rcx
call   1030 <fread@plt>
test   %eax,%eax
jg     11e0 <fs_cp+0x80>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    %rbp,%rdi
call   1040 <fclose@plt>
jmp    1220 <fs_cp+0xc0>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x1008,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"%s -> %s\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c"w\00"
define i32 @fs_cp(i8* noalias %0, i8* noalias %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [4096 x i8]
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32*
store i8* %0, i8** %4
store i8* %1, i8** %5
%10 = load i8*, i8** %4
%11 = call i64 @fs_exsists(i8* %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %36
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = load i8*, i8** %5
%16 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %14, i8* %15)
%17 = load i8*, i8** %4
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %18, i32** %8
%19 = load i8*, i8** %5
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %20, i32** %9
br label %21
21: ; preds = %26, %13
%22 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%23 = load i32*, i32** %8
%24 = call i32 @fread(i8* %22, i32 1, i32 4096, i32* %23)
store i32 %24, i32* %7
%25 = icmp sgt i32 %24, 0
br i1 %25, label %26, label %31
26: ; preds = %21
%27 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%28 = load i32, i32* %7
%29 = load i32*, i32** %9
%30 = call i32 @fwrite(i8* %27, i32 1, i32 %28, i32* %29)
br label %21
31: ; preds = %21
%32 = load i32*, i32** %8
%33 = call i32 @fclose(i32* %32)
%34 = load i32*, i32** %9
%35 = call i32 @fclose(i32* %34)
store i32 1, i32* %3
br label %37
36: ; preds = %2
store i32 0, i32* %3
br label %37
37: ; preds = %36, %31
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
@.str = [10 x i8] c"%s -> %s\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c"w\00"
define i32 @fs_cp(i8* noalias %0, i8* noalias %1) {
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%5 = tail call i64 @fs_exsists(i8* %0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %21, label %7
7: ; preds = %2
%8 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
%9 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 @fread(i8* %4, i32 1, i32 4096, i32* %9)
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %7, %13
%14 = phi i32 [ %16, %13 ], [ %11, %7 ]
%15 = call i32 @fwrite(i8* %4, i32 1, i32 %14, i32* %10)
%16 = call i32 @fread(i8* %4, i32 1, i32 4096, i32* %9)
%17 = icmp sgt i32 %16, 0
br i1 %17, label %13, label %18
18: ; preds = %13, %7
%19 = tail call i32 @fclose(i32* %9)
%20 = tail call i32 @fclose(i32* %10)
br label %21
21: ; preds = %2, %18
%22 = phi i32 [ 1, %18 ], [ 0, %2 ]
ret i32 %22
}