#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 *, char *);
size_t fread(char *, int, int const, int /*<<< orphan*/ *);
size_t fwrite(char *, int, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
void copyFileTo(char *source, char *dest) {
  FILE *fs = fopen(source, "r");
  FILE *fd = fopen(dest, "w");
  const int BufferSize = 1024;
  char buffer[BufferSize];
  size_t n_chars;
  if (fs && fd) {
    while ((n_chars = fread(buffer, 1, BufferSize, fs)) > 0)
      if (fwrite(buffer, 1, n_chars, fd) != n_chars)
        printf("Something wrong with writing");
    if (n_chars == -1)
      printf("Something wrong with reading");
    fclose(fs);
    fclose(fd);
  }
}


x86 assembly (clang, -O0):
<copyFileTo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe92(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe80(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
movl   $0x400,-0x24(%rbp)
mov    %rsp,%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1239 <copyFileTo+0xe9>
cmpq   $0x0,-0x20(%rbp)
je     1239 <copyFileTo+0xe9>
jmp    11b4 <copyFileTo+0x64>
mov    -0x18(%rbp),%rcx
lea    -0x440(%rbp),%rdi
mov    $0x1,%esi
mov    $0x400,%edx
call   1030 <fread@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jbe    1210 <copyFileTo+0xc0>
mov    -0x38(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    -0x440(%rbp),%rdi
mov    $0x1,%esi
call   1070 <fwrite@plt>
cmp    -0x38(%rbp),%rax
je     120b <copyFileTo+0xbb>
lea    0xdfe(%rip),%rdi
call   1050 <printf@plt>
jmp    11b4 <copyFileTo+0x64>
cmpq   $0xffffffffffffffff,-0x38(%rbp)
jne    1227 <copyFileTo+0xd7>
lea    0xdff(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copyFileTo>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x400,%rsp
mov    %rsi,%rbx
lea    0xe96(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r15
lea    0xe89(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fopen@plt>
test   %r15,%r15
je     11ff <copyFileTo+0xaf>
mov    %rax,%r14
test   %rax,%rax
je     11ff <copyFileTo+0xaf>
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x400,%edx
mov    %r15,%rcx
call   1030 <fread@plt>
test   %rax,%rax
je     1210 <copyFileTo+0xc0>
mov    %rax,%rbx
mov    %rsp,%r13
lea    0xe4f(%rip),%r12
jmp    11dd <copyFileTo+0x8d>
nopw   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    $0x1,%esi
mov    $0x400,%edx
mov    %r15,%rcx
call   1030 <fread@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1210 <copyFileTo+0xc0>
mov    %r13,%rdi
mov    $0x1,%esi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1070 <fwrite@plt>
cmp    %rbx,%rax
je     11c0 <copyFileTo+0x70>
mov    %r12,%rdi
call   1050 <printf@plt>
jmp    11c0 <copyFileTo+0x70>
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    %r14,%rdi
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1040 <fclose@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [29 x i8] c"Something wrong with writing\00"
@.str.3 = [29 x i8] c"Something wrong with reading\00"
define void @copyFileTo(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
store i8* %0, i8** %3
store i8* %1, i8** %4
%10 = load i8*, i8** %3
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %5
%12 = load i8*, i8** %4
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %13, i32** %6
store i32 1024, i32* %7
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %8
%15 = alloca i8, i64 1024
%16 = load i32*, i32** %5
%17 = icmp ne i32* %16, null
br i1 %17, label %18, label %45
18: ; preds = %2
%19 = load i32*, i32** %6
%20 = icmp ne i32* %19, null
br i1 %20, label %21, label %45
21: ; preds = %18
br label %22
22: ; preds = %34, %21
%23 = load i32*, i32** %5
%24 = call i64 @fread(i8* %15, i32 1, i32 1024, i32* %23)
store i64 %24, i64* %9
%25 = icmp ugt i64 %24, 0
br i1 %25, label %26, label %35
26: ; preds = %22
%27 = load i64, i64* %9
%28 = load i32*, i32** %6
%29 = call i64 @fwrite(i8* %15, i32 1, i64 %27, i32* %28)
%30 = load i64, i64* %9
%31 = icmp ne i64 %29, %30
br i1 %31, label %32, label %34
32: ; preds = %26
%33 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
br label %34
34: ; preds = %32, %26
br label %22
35: ; preds = %22
%36 = load i64, i64* %9
%37 = icmp eq i64 %36, -1
br i1 %37, label %38, label %40
38: ; preds = %35
%39 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
br label %40
40: ; preds = %38, %35
%41 = load i32*, i32** %5
%42 = call i32 @fclose(i32* %41)
%43 = load i32*, i32** %6
%44 = call i32 @fclose(i32* %43)
br label %45
45: ; preds = %40, %18, %2
%46 = load i8*, i8** %8
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [29 x i8] c"Something wrong with writing\00"
define void @copyFileTo(i8* nocapture %0, i8* nocapture %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = alloca [1024 x i8]
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%7 = icmp ne i32* %3, null
%8 = icmp ne i32* %4, null
%9 = and i1 %7, %8
br i1 %9, label %10, label %25
10: ; preds = %2
%11 = call i64 @fread(i8* %6, i32 1, i32 1024, i32* %3)
%12 = icmp eq i64 %11, 0
br i1 %12, label %22, label %13
13: ; preds = %10, %19
%14 = phi i64 [ %20, %19 ], [ %11, %10 ]
%15 = call i64 @fwrite(i8* %6, i32 1, i64 %14, i32* %4)
%16 = icmp eq i64 %15, %14
br i1 %16, label %19, label %17
17: ; preds = %13
%18 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
br label %19
19: ; preds = %17, %13
%20 = call i64 @fread(i8* %6, i32 1, i32 1024, i32* %3)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %13
22: ; preds = %19, %10
%23 = tail call i32 @fclose(i32* %3)
%24 = tail call i32 @fclose(i32* %4)
br label %25
25: ; preds = %22, %2
ret void
}