#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ F_OK;
scalar_t__ access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
char getonechar();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ read_snapshot(char *, char *);
scalar_t__ same_file(char *, char *);
int /*<<< orphan*/ usage(char *);
int main(int argc, char *argv[]) {
  FILE *src;
  char *src_name;
  char *dst_name;
  if (argc < 2) {
    usage(argv[0]);
    return EXIT_FAILURE;
  }
  if (access(argv[1], F_OK)) {
    printf("Input file doesn't exist.\n");
    usage(argv[0]);
    return EXIT_FAILURE;
  }
  src_name = argv[1];
  src = fopen(src_name, "r");
  if (argc > 2) {
    if (!access(argv[2], F_OK)) {
      if (same_file(argv[1], argv[2])) {
        printf("You don't want <src_snapshot> and <dst_snaphot> to be the same "
               "file. Trust me.\n");
        printf("Exiting...\n");
        return EXIT_FAILURE;
      }
      printf("The file exists! Do you want to overwrite? (y/n): ");
      if (getonechar() != 'y') {
        printf("\nExiting...\n");
        return EXIT_FAILURE;
      }
    }
    dst_name = argv[2];
  } else
    dst_name = NULL;
  fclose(src);
  read_snapshot(dst_name, src_name);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11bd <main+0x3d>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1060 <usage@plt>
mov    0x2e2d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1314 <main+0x194>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2dfc(%rip),%rax
mov    (%rax),%esi
call   1080 <access@plt>
cmp    $0x0,%rax
je     1206 <main+0x86>
lea    0xe1c(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1060 <usage@plt>
mov    0x2de4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1314 <main+0x194>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xdfe(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    12ea <main+0x16a>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2d89(%rip),%rax
mov    (%rax),%esi
call   1080 <access@plt>
cmp    $0x0,%rax
jne    12d9 <main+0x159>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   10a0 <same_file@plt>
cmp    $0x0,%rax
je     1298 <main+0x118>
lea    0xda7(%rip),%rdi
call   1050 <printf@plt>
lea    0xe1f(%rip),%rdi
call   1050 <printf@plt>
mov    0x2d52(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1314 <main+0x194>
lea    0xdce(%rip),%rdi
call   1050 <printf@plt>
mov    $0x0,%al
call   1070 <getonechar@plt>
movsbl %al,%eax
cmp    $0x79,%eax
je     12d4 <main+0x154>
lea    0xde2(%rip),%rdi
call   1050 <printf@plt>
mov    0x2d16(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1314 <main+0x194>
jmp    12d9 <main+0x159>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x28(%rbp)
jmp    12f2 <main+0x172>
movq   $0x0,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <read_snapshot@plt>
mov    0x2cc9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%rbx
cmp    $0x1,%edi
jle    11c7 <main+0x37>
mov    %edi,%ebp
mov    0x8(%rbx),%rdi
mov    0x2e1b(%rip),%r12
mov    (%r12),%esi
call   1090 <access@plt>
test   %rax,%rax
je     11e1 <main+0x51>
lea    0xece(%rip),%rdi
call   1030 <puts@plt>
mov    (%rbx),%rdi
call   1070 <usage@plt>
mov    0x2e0a(%rip),%rax
mov    (%rax),%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x8(%rbx),%r14
lea    0xe14(%rip),%rsi
mov    %r14,%rdi
call   10a0 <fopen@plt>
mov    %rax,%r15
cmp    $0x3,%ebp
jb     1214 <main+0x84>
mov    0x10(%rbx),%rdi
mov    (%r12),%esi
call   1090 <access@plt>
test   %rax,%rax
je     1232 <main+0xa2>
mov    0x10(%rbx),%rbx
jmp    1216 <main+0x86>
xor    %ebx,%ebx
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <read_snapshot@plt>
mov    0x2da8(%rip),%rax
jmp    11d6 <main+0x46>
mov    0x8(%rbx),%rdi
mov    0x10(%rbx),%rsi
call   10b0 <same_file@plt>
test   %rax,%rax
je     1259 <main+0xc9>
lea    0xdf6(%rip),%rdi
call   1030 <puts@plt>
lea    0xddf(%rip),%rdi
jmp    1277 <main+0xe7>
lea    0xda2(%rip),%rdi
call   1060 <printf@plt>
xor    %eax,%eax
call   1080 <getonechar@plt>
cmp    $0x79,%al
je     120e <main+0x7e>
lea    0xdbe(%rip),%rdi
call   1030 <puts@plt>
jmp    11cf <main+0x3f>

LLVM IR (-O0):
@EXIT_FAILURE = global i32 0
@F_OK = global i32 0
@.str = [27 x i8] c"Input file doesn't exist.\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [80 x i8] c"You don't want <src_snapshot> and <dst_snaphot> to be the same file. Trust me.\0A\00"
@.str.3 = [12 x i8] c"Exiting...\0A\00"
@.str.4 = [51 x i8] c"The file exists! Do you want to overwrite? (y/n): \00"
@.str.5 = [13 x i8] c"\0AExiting...\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %17
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 @usage(i8* %14)
%16 = load i32, i32* @EXIT_FAILURE
store i32 %16, i32* %3
br label %80
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = load i32, i32* @F_OK
%22 = call i64 @access(i8* %20, i32 %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %31
24: ; preds = %17
%25 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 0
%28 = load i8*, i8** %27
%29 = call i32 @usage(i8* %28)
%30 = load i32, i32* @EXIT_FAILURE
store i32 %30, i32* %3
br label %80
31: ; preds = %17
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
store i8* %34, i8** %7
%35 = load i8*, i8** %7
%36 = call i32* @fopen(i8* %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %36, i32** %6
%37 = load i32, i32* %4
%38 = icmp sgt i32 %37, 2
br i1 %38, label %39, label %72
39: ; preds = %31
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 2
%42 = load i8*, i8** %41
%43 = load i32, i32* @F_OK
%44 = call i64 @access(i8* %42, i32 %43)
%45 = icmp ne i64 %44, 0
br i1 %45, label %68, label %46
46: ; preds = %39
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 1
%49 = load i8*, i8** %48
%50 = load i8**, i8*** %5
%51 = getelementptr inbounds i8*, i8** %50, i64 2
%52 = load i8*, i8** %51
%53 = call i64 @same_file(i8* %49, i8* %52)
%54 = icmp ne i64 %53, 0
br i1 %54, label %55, label %59
55: ; preds = %46
%56 = call i32 @printf(i8* getelementptr inbounds ([80 x i8], [80 x i8]* @.str.2, i64 0, i64 0))
%57 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%58 = load i32, i32* @EXIT_FAILURE
store i32 %58, i32* %3
br label %80
59: ; preds = %46
%60 = call i32 @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.4, i64 0, i64 0))
%61 = call signext i8 (...) @getonechar()
%62 = sext i8 %61 to i32
%63 = icmp ne i32 %62, 121
br i1 %63, label %64, label %67
64: ; preds = %59
%65 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%66 = load i32, i32* @EXIT_FAILURE
store i32 %66, i32* %3
br label %80
67: ; preds = %59
br label %68
68: ; preds = %67, %39
%69 = load i8**, i8*** %5
%70 = getelementptr inbounds i8*, i8** %69, i64 2
%71 = load i8*, i8** %70
store i8* %71, i8** %8
br label %73
72: ; preds = %31
store i8* null, i8** %8
br label %73
73: ; preds = %72, %68
%74 = load i32*, i32** %6
%75 = call i32 @fclose(i32* %74)
%76 = load i8*, i8** %8
%77 = load i8*, i8** %7
%78 = call i32 @read_snapshot(i8* %76, i8* %77)
%79 = load i32, i32* @EXIT_SUCCESS
store i32 %79, i32* %3
br label %80
80: ; preds = %73, %64, %55, %24, %11
%81 = load i32, i32* %3
ret i32 %81
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@F_OK = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.4 = [51 x i8] c"The file exists! Do you want to overwrite? (y/n): \00"
@EXIT_SUCCESS = global i32 0
@str = [12 x i8] c"\0AExiting...\00"
@str.6 = [79 x i8] c"You don't want <src_snapshot> and <dst_snaphot> to be the same file. Trust me.\00"
@str.7 = [11 x i8] c"Exiting...\00"
@str.8 = [26 x i8] c"Input file doesn't exist.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 @usage(i8* %5)
br label %47
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = load i32, i32* @F_OK
%11 = tail call i64 @access(i8* %9, i32 %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %17, label %13
13: ; preds = %7
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.8, i64 0, i64 0))
%15 = load i8*, i8** %1
%16 = tail call i32 @usage(i8* %15)
br label %47
17: ; preds = %7
%18 = load i8*, i8** %8
%19 = tail call i32* @fopen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp ugt i32 %0, 2
br i1 %20, label %21, label %43
21: ; preds = %17
%22 = getelementptr inbounds i8*, i8** %1, i64 2
%23 = load i8*, i8** %22
%24 = load i32, i32* @F_OK
%25 = tail call i64 @access(i8* %23, i32 %24)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %41
27: ; preds = %21
%28 = load i8*, i8** %8
%29 = load i8*, i8** %22
%30 = tail call i64 @same_file(i8* %28, i8* %29)
%31 = icmp eq i64 %30, 0
br i1 %31, label %35, label %32
32: ; preds = %27
%33 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([79 x i8], [79 x i8]* @str.6, i64 0, i64 0))
%34 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.7, i64 0, i64 0))
br label %47
35: ; preds = %27
%36 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str.4, i64 0, i64 0))
%37 = tail call signext i8 (...) @getonechar()
%38 = icmp eq i8 %37, 121
br i1 %38, label %41, label %39
39: ; preds = %35
%40 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
br label %47
41: ; preds = %35, %21
%42 = load i8*, i8** %22
br label %43
43: ; preds = %17, %41
%44 = phi i8* [ %42, %41 ], [ null, %17 ]
%45 = tail call i32 @fclose(i32* %19)
%46 = tail call i32 @read_snapshot(i8* %44, i8* %18)
br label %47
47: ; preds = %43, %39, %32, %13, %4
%48 = phi i32* [ @EXIT_FAILURE, %4 ], [ @EXIT_FAILURE, %13 ], [ @EXIT_SUCCESS, %43 ], [ @EXIT_FAILURE, %32 ], [ @EXIT_FAILURE, %39 ]
%49 = load i32, i32* %48
ret i32 %49
}