#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 BUFSIZ;
int add_file_to_queue(char *);
int commit();
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ printf(char *, ...);
char *strerror(int /*<<< orphan*/);
void copy_file(char *destination, char *source) {
  int err;
  err = add_file_to_queue(destination);
  if (err)
    printf("Add before revert failed.\n");
  err = commit();
  if (err)
    printf("Commit before revert failed.\n");
  FILE *sfp = fopen(source, "r");
  FILE *dfp = fopen(destination, "w");
  if (!sfp) {
    printf("ERROR (fopen) on line %d: %s\n", 71, strerror(errno));
    return;
  }
  if (!dfp) {
    printf("ERROR (fopen) on line %d: %s\n", 75, strerror(errno));
    return;
  }
  char buffer[BUFSIZ], *res;
  for (;;) {
    res = fgets(buffer, BUFSIZ, sfp);
    if (!res)
      break;
    fprintf(dfp, "%s", buffer);
  }
  fclose(sfp);
  fclose(dfp);
}


x86 assembly (clang, -O0):
<copy_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   10a0 <add_file_to_queue@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11b4 <copy_file+0x34>
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1070 <commit@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11d6 <copy_file+0x56>
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
lea    0xe58(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe46(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1232 <copy_file+0xb2>
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    %rax,%rdx
lea    0xe1c(%rip),%rdi
mov    $0x47,%esi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12ee <copy_file+0x16e>
cmpq   $0x0,-0x28(%rbp)
jne    1266 <copy_file+0xe6>
mov    0x2d94(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    %rax,%rdx
lea    0xde8(%rip),%rdi
mov    $0x4b,%esi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12ee <copy_file+0x16e>
mov    0x2d73(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
mov    -0x48(%rbp),%rdi
mov    0x2d43(%rip),%rax
mov    (%rax),%esi
mov    -0x20(%rbp),%rdx
call   1050 <fgets@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    12bc <copy_file+0x13c>
jmp    12d5 <copy_file+0x155>
mov    -0x48(%rbp),%rdx
mov    -0x28(%rbp),%rdi
lea    0xd90(%rip),%rsi
call   1060 <fprintf@plt>
jmp    1292 <copy_file+0x112>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy_file>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
call   10b0 <add_file_to_queue@plt>
test   %eax,%eax
je     11b9 <copy_file+0x29>
lea    0xe8b(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1080 <commit@plt>
test   %eax,%eax
je     11d0 <copy_file+0x40>
lea    0xe57(%rip),%rdi
call   1030 <puts@plt>
lea    0xe29(%rip),%rsi
mov    %rbx,%rdi
call   1090 <fopen@plt>
mov    %rax,%r15
lea    0xe19(%rip),%rsi
mov    %r14,%rdi
call   1090 <fopen@plt>
test   %r15,%r15
je     1273 <copy_file+0xe3>
mov    %rax,%r14
test   %rax,%rax
je     128f <copy_file+0xff>
mov    %rsp,%r12
mov    0x2dd4(%rip),%r13
mov    0x0(%r13),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x0(%r13),%esi
mov    %rbx,%rdi
mov    %r15,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     1251 <copy_file+0xc1>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <fputs@plt>
jmp    1230 <copy_file+0xa0>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %r12,%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d5e(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xd7c(%rip),%rdi
mov    $0x47,%esi
jmp    12a9 <copy_file+0x119>
mov    0x2d42(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xd60(%rip),%rdi
mov    $0x4b,%esi
mov    %rax,%rdx
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <printf@plt>

LLVM IR (-O0):
@.str = [27 x i8] c"Add before revert failed.\0A\00"
@.str.1 = [30 x i8] c"Commit before revert failed.\0A\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [30 x i8] c"ERROR (fopen) on line %d: %s\0A\00"
@errno = global i32 0
@BUFSIZ = global i32 0
@.str.5 = [3 x i8] c"%s\00"
define void @copy_file(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
%10 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%11 = load i8*, i8** %3
%12 = call i32 @add_file_to_queue(i8* %11)
store i32 %12, i32* %5
%13 = load i32, i32* %5
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %15, %2
%18 = call i32 (...) @commit()
store i32 %18, i32* %5
%19 = load i32, i32* %5
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %21, %17
%24 = load i8*, i8** %4
%25 = call i32* @fopen(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %25, i32** %6
%26 = load i8*, i8** %3
%27 = call i32* @fopen(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %27, i32** %7
%28 = load i32*, i32** %6
%29 = icmp ne i32* %28, null
br i1 %29, label %34, label %30
30: ; preds = %23
%31 = load i32, i32* @errno
%32 = call i8* @strerror(i32 %31)
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i32 71, i8* %32)
br label %62
34: ; preds = %23
%35 = load i32*, i32** %7
%36 = icmp ne i32* %35, null
br i1 %36, label %41, label %37
37: ; preds = %34
%38 = load i32, i32* @errno
%39 = call i8* @strerror(i32 %38)
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i32 75, i8* %39)
br label %62
41: ; preds = %34
%42 = load i32, i32* @BUFSIZ
%43 = zext i32 %42 to i64
%44 = call i8* @llvm.stacksave()
store i8* %44, i8** %8
%45 = alloca i8, i64 %43
store i64 %43, i64* %9
br label %46
46: ; preds = %53, %41
%47 = load i32, i32* @BUFSIZ
%48 = load i32*, i32** %6
%49 = call i8* @fgets(i8* %45, i32 %47, i32* %48)
store i8* %49, i8** %10
%50 = load i8*, i8** %10
%51 = icmp ne i8* %50, null
br i1 %51, label %53, label %52
52: ; preds = %46
br label %56
53: ; preds = %46
%54 = load i32*, i32** %7
%55 = call i32 @fprintf(i32* %54, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %45)
br label %46
56: ; preds = %52
%57 = load i32*, i32** %6
%58 = call i32 @fclose(i32* %57)
%59 = load i32*, i32** %7
%60 = call i32 @fclose(i32* %59)
%61 = load i8*, i8** %8
br label %62
62: ; preds = %56, %37, %30
ret void
}

LLVM IR (-O2):
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [30 x i8] c"ERROR (fopen) on line %d: %s\0A\00"
@errno = global i32 0
@BUFSIZ = global i32 0
@str = [29 x i8] c"Commit before revert failed.\00"
@str.6 = [26 x i8] c"Add before revert failed.\00"
define void @copy_file(i8* %0, i8* nocapture %1) {
%3 = tail call i32 @add_file_to_queue(i8* %0)
%4 = icmp eq i32 %3, 0
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.6, i64 0, i64 0))
br label %7
7: ; preds = %5, %2
%8 = tail call i32 (...) @commit()
%9 = icmp eq i32 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
br label %12
12: ; preds = %10, %7
%13 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%14 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%15 = icmp eq i32* %13, null
br i1 %15, label %16, label %20
16: ; preds = %12
%17 = load i32, i32* @errno
%18 = tail call i8* @strerror(i32 %17)
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i32 71, i8* %18)
br label %42
20: ; preds = %12
%21 = icmp eq i32* %14, null
br i1 %21, label %22, label %26
22: ; preds = %20
%23 = load i32, i32* @errno
%24 = tail call i8* @strerror(i32 %23)
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i32 75, i8* %24)
br label %42
26: ; preds = %20
%27 = load i32, i32* @BUFSIZ
%28 = zext i32 %27 to i64
%29 = tail call i8* @llvm.stacksave()
%30 = alloca i8, i64 %28
%31 = load i32, i32* @BUFSIZ
%32 = call i8* @fgets(i8* %30, i32 %31, i32* %13)
%33 = icmp eq i8* %32, null
br i1 %33, label %39, label %34
34: ; preds = %26, %34
%35 = call i32 @fputs(i8* %30, i32* %14)
%36 = load i32, i32* @BUFSIZ
%37 = call i8* @fgets(i8* %30, i32 %36, i32* %13)
%38 = icmp eq i8* %37, null
br i1 %38, label %39, label %34
39: ; preds = %34, %26
%40 = call i32 @fclose(i32* %13)
%41 = call i32 @fclose(i32* %14)
br label %42
42: ; preds = %39, %22, %16
ret void
}