#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 *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read_snapshot_v1(char *);
int /*<<< orphan*/ read_snapshot_v2(char *, char *);
int snapformat(int /*<<< orphan*/ *);
int read_snapshot(char *dst_name, char *src_name) {
  int format;
  FILE *src;
  src = fopen(src_name, "r");
  format = snapformat(src);
  fclose(src);
  printf("SnapFormat = %d\n", format);
  switch (format) {
  case 0:
    printf("SnapFormat UNKNOWN!\n");
    break;
  case 1:
    read_snapshot_v1(src_name);
    break;
  case 2:
    read_snapshot_v2(dst_name, src_name);
    break;
  }
  return 0;
}


x86 assembly (clang, -O0):
<read_snapshot>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe85(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <snapformat@plt>
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x14(%rbp),%esi
lea    0xe5f(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
test   %eax,%eax
je     11df <read_snapshot+0x7f>
jmp    11bd <read_snapshot+0x5d>
mov    -0x24(%rbp),%eax
sub    $0x1,%eax
je     11f2 <read_snapshot+0x92>
jmp    11ce <read_snapshot+0x6e>
mov    -0x24(%rbp),%eax
sub    $0x2,%eax
je     1200 <read_snapshot+0xa0>
jmp    120d <read_snapshot+0xad>
lea    0xe2d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    120d <read_snapshot+0xad>
mov    -0x10(%rbp),%rdi
call   1080 <read_snapshot_v1@plt>
jmp    120d <read_snapshot+0xad>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <read_snapshot_v2@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_snapshot>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
lea    0xe7c(%rip),%rsi
mov    %r15,%rdi
call   1080 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <snapformat@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xe5a(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    $0x2,%ebp
je     11cd <read_snapshot+0x5d>
cmp    $0x1,%ebp
je     11da <read_snapshot+0x6a>
test   %ebp,%ebp
jne    11e2 <read_snapshot+0x72>
lea    0xe4d(%rip),%rdi
call   1030 <puts@plt>
jmp    11e2 <read_snapshot+0x72>
mov    %r14,%rdi
mov    %r15,%rsi
call   1070 <read_snapshot_v2@plt>
jmp    11e2 <read_snapshot+0x72>
mov    %r15,%rdi
call   1090 <read_snapshot_v1@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [17 x i8] c"SnapFormat = %d\0A\00"
@.str.2 = [21 x i8] c"SnapFormat UNKNOWN!\0A\00"
define i32 @read_snapshot(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %4
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %6
%9 = load i32*, i32** %6
%10 = call i32 @snapformat(i32* %9)
store i32 %10, i32* %5
%11 = load i32*, i32** %6
%12 = call i32 @fclose(i32* %11)
%13 = load i32, i32* %5
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = load i32, i32* %5
switch i32 %15, label %25 [
i32 0, label %16
i32 1, label %18
i32 2, label %21
]
16: ; preds = %2
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %25
18: ; preds = %2
%19 = load i8*, i8** %4
%20 = call i32 @read_snapshot_v1(i8* %19)
br label %25
21: ; preds = %2
%22 = load i8*, i8** %3
%23 = load i8*, i8** %4
%24 = call i32 @read_snapshot_v2(i8* %22, i8* %23)
br label %25
25: ; preds = %2, %21, %18, %16
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [17 x i8] c"SnapFormat = %d\0A\00"
@str = [20 x i8] c"SnapFormat UNKNOWN!\00"
define i32 @read_snapshot(i8* %0, i8* %1) {
%3 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 @snapformat(i32* %3)
%5 = tail call i32 @fclose(i32* %3)
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %4)
switch i32 %4, label %13 [
i32 0, label %7
i32 1, label %9
i32 2, label %11
]
7: ; preds = %2
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
br label %13
9: ; preds = %2
%10 = tail call i32 @read_snapshot_v1(i8* %1)
br label %13
11: ; preds = %2
%12 = tail call i32 @read_snapshot_v2(i8* %0, i8* %1)
br label %13
13: ; preds = %2, %11, %9, %7
ret i32 0
}