#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 */
char EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
char *gettext(char *);
int /*<<< orphan*/ stderr;
int copy_file(char path1[], char path2[]) {
  char chr;
  FILE *stream_for_write, *stream_for_read;
  if ((stream_for_write = fopen(path1, "w")) == NULL) {
    fprintf(stderr, "%s: %s\n", gettext("Impossible to create a file"), path1);
    return -1;
  }
  if ((stream_for_read = fopen(path2, "r")) == NULL) {
    fprintf(stderr, "%s: %s\n", gettext("Impossible to read a file"), path2);
    return -1;
  }
  while ((chr = fgetc(stream_for_read)) != EOF) {
    fputc(chr, stream_for_write);
  }
  fclose(stream_for_write);
  fclose(stream_for_read);
  return 0;
}


x86 assembly (clang, -O0):
<copy_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe85(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11c8 <copy_file+0x68>
mov    0x2e43(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
lea    0xe69(%rip),%rdi
call   1040 <gettext@plt>
mov    -0x34(%rbp),%edi
mov    %rax,%rdx
mov    -0x10(%rbp),%rcx
lea    0xe4b(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1273 <copy_file+0x113>
mov    -0x18(%rbp),%rdi
lea    0xe53(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    1220 <copy_file+0xc0>
mov    0x2deb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
lea    0xe2f(%rip),%rdi
call   1040 <gettext@plt>
mov    -0x38(%rbp),%edi
mov    %rax,%rdx
mov    -0x18(%rbp),%rcx
lea    0xdf3(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1273 <copy_file+0x113>
jmp    1225 <copy_file+0xc5>
mov    -0x30(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x19(%rbp)
movsbl %al,%eax
mov    0x2dad(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     125a <copy_file+0xfa>
mov    -0x19(%rbp),%al
mov    -0x28(%rbp),%rsi
movsbl %al,%edi
call   1060 <fputc@plt>
jmp    1225 <copy_file+0xc5>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy_file>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%rbx
lea    0xe8c(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11dc <copy_file+0x7c>
mov    %rax,%r14
lea    0xe9e(%rip),%rsi
mov    %r15,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     1202 <copy_file+0xa2>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <fgetc@plt>
mov    0x2e41(%rip),%rbp
cmp    0x0(%rbp),%al
je     11c8 <copy_file+0x68>
nopl   0x0(%rax)
movsbl %al,%edi
mov    %r14,%rsi
call   1060 <fputc@plt>
mov    %rbx,%rdi
call   1050 <fgetc@plt>
cmp    0x0(%rbp),%al
jne    11b0 <copy_file+0x50>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    1230 <copy_file+0xd0>
mov    0x2df5(%rip),%rax
mov    (%rax),%ebp
lea    0xe1e(%rip),%rdi
call   1040 <gettext@plt>
lea    0xe0a(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
mov    %rbx,%rcx
jmp    1226 <copy_file+0xc6>
mov    0x2dcf(%rip),%rax
mov    (%rax),%ebx
lea    0xe16(%rip),%rdi
call   1040 <gettext@plt>
lea    0xde4(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
mov    %r15,%rcx
call   1070 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.1 = [8 x i8] c"%s: %s\0A\00"
@.str.2 = [28 x i8] c"Impossible to create a file\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [26 x i8] c"Impossible to read a file\00"
@EOF = global i8 0
define i32 @copy_file(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8
%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 ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %7
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i8* @gettext(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%15 = load i8*, i8** %4
%16 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %14, i8* %15)
store i32 -1, i32* %3
br label %43
17: ; preds = %2
%18 = load i8*, i8** %5
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %19, i32** %8
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %26
21: ; preds = %17
%22 = load i32, i32* @stderr
%23 = call i8* @gettext(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
%24 = load i8*, i8** %5
%25 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %23, i8* %24)
store i32 -1, i32* %3
br label %43
26: ; preds = %17
br label %27
27: ; preds = %34, %26
%28 = load i32*, i32** %8
%29 = call signext i8 @fgetc(i32* %28)
store i8 %29, i8* %6
%30 = sext i8 %29 to i32
%31 = load i8, i8* @EOF
%32 = sext i8 %31 to i32
%33 = icmp ne i32 %30, %32
br i1 %33, label %34, label %38
34: ; preds = %27
%35 = load i8, i8* %6
%36 = load i32*, i32** %7
%37 = call i32 @fputc(i8 signext %35, i32* %36)
br label %27
38: ; preds = %27
%39 = load i32*, i32** %7
%40 = call i32 @fclose(i32* %39)
%41 = load i32*, i32** %8
%42 = call i32 @fclose(i32* %41)
store i32 0, i32* %3
br label %43
43: ; preds = %38, %21, %12
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.1 = [8 x i8] c"%s: %s\0A\00"
@.str.2 = [28 x i8] c"Impossible to create a file\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [26 x i8] c"Impossible to read a file\00"
@EOF = global i8 0
define i32 @copy_file(i8* %0, i8* %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i8* @gettext(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%8 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %7, i8* %0)
br label %29
9: ; preds = %2
%10 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %16, label %12
12: ; preds = %9
%13 = tail call signext i8 @fgetc(i32* %10)
%14 = load i8, i8* @EOF
%15 = icmp eq i8 %13, %14
br i1 %15, label %26, label %20
16: ; preds = %9
%17 = load i32, i32* @stderr
%18 = tail call i8* @gettext(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
%19 = tail call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %18, i8* %1)
br label %29
20: ; preds = %12, %20
%21 = phi i8 [ %23, %20 ], [ %13, %12 ]
%22 = tail call i32 @fputc(i8 signext %21, i32* %3)
%23 = tail call signext i8 @fgetc(i32* %10)
%24 = load i8, i8* @EOF
%25 = icmp eq i8 %23, %24
br i1 %25, label %26, label %20
26: ; preds = %20, %12
%27 = tail call i32 @fclose(i32* %3)
%28 = tail call i32 @fclose(i32* %10)
br label %29
29: ; preds = %26, %16, %5
%30 = phi i32 [ -1, %5 ], [ -1, %16 ], [ 0, %26 ]
ret i32 %30
}