#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 */

/* Variables and functions */
int /*<<< orphan*/ EINVAL;
int /*<<< orphan*/ errno;
int getopt(int, char **, char *);
int /*<<< orphan*/ optarg;
int optind;
int parse_ui(char *, unsigned int *);
int parse_ul(int /*<<< orphan*/, unsigned long *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ print_help(int);
int reload_snapshot(unsigned int, char *, char *, unsigned long);
int handle_reload_snap(int argc, char **argv) {
  int ret, c;
  unsigned int minor;
  unsigned long cache_size = 0;
  char *bdev, *cow;
  while ((c = getopt(argc, argv, "c:")) != -1) {
    switch (c) {
    case 'c':
      ret = parse_ul(optarg, &cache_size);
      if (ret)
        goto handle_reload_snap_error;
      break;
    default:
      errno = EINVAL;
      goto handle_reload_snap_error;
    }
  }
  if (argc - optind != 3) {
    errno = EINVAL;
    goto handle_reload_snap_error;
  }
  bdev = argv[optind];
  cow = argv[optind + 1];
  ret = parse_ui(argv[optind + 2], &minor);
  if (ret)
    goto handle_reload_snap_error;
  return reload_snapshot(minor, bdev, cow, cache_size);
handle_reload_snap_error:
  perror("error interpreting reload snapshot parameters");
  print_help(-1);
  return 0;
}


x86 assembly (clang, -O0):
<handle_reload_snap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe7b(%rip),%rdx
call   1070 <getopt@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
je     11ec <handle_reload_snap+0x8c>
mov    -0x18(%rbp),%eax
sub    $0x63,%eax
jne    11d0 <handle_reload_snap+0x70>
jmp    11a7 <handle_reload_snap+0x47>
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
call   1050 <parse_ul@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11cb <handle_reload_snap+0x6b>
jmp    1297 <handle_reload_snap+0x137>
jmp    11e7 <handle_reload_snap+0x87>
mov    0x2df1(%rip),%rax
mov    (%rax),%ecx
mov    0x2df0(%rip),%rax
mov    %ecx,(%rax)
jmp    1297 <handle_reload_snap+0x137>
jmp    1177 <handle_reload_snap+0x17>
mov    -0x8(%rbp),%eax
mov    0x2dea(%rip),%rcx
sub    (%rcx),%eax
cmp    $0x3,%eax
je     1218 <handle_reload_snap+0xb8>
mov    0x2dc0(%rip),%rax
mov    (%rax),%ecx
mov    0x2dbf(%rip),%rax
mov    %ecx,(%rax)
jmp    1297 <handle_reload_snap+0x137>
mov    -0x10(%rbp),%rax
mov    0x2dbd(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2da7(%rip),%rcx
mov    (%rcx),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2d8c(%rip),%rcx
mov    (%rcx),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
lea    -0x1c(%rbp),%rsi
call   1030 <parse_ui@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     127b <handle_reload_snap+0x11b>
jmp    1297 <handle_reload_snap+0x137>
mov    -0x1c(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1040 <reload_snapshot@plt>
mov    %eax,-0x4(%rbp)
jmp    12b4 <handle_reload_snap+0x154>
lea    0xd65(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%edi
call   1080 <print_help@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_reload_snap>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
movq   $0x0,0x8(%rsp)
lea    0xe7f(%rip),%r14
mov    0x2e70(%rip),%r12
lea    0x8(%rsp),%r15
nopl   (%rax)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1070 <getopt@plt>
cmp    $0x63,%eax
jne    11b4 <handle_reload_snap+0x54>
mov    (%r12),%edi
mov    %r15,%rsi
call   1050 <parse_ul@plt>
test   %eax,%eax
je     1190 <handle_reload_snap+0x30>
jmp    120e <handle_reload_snap+0xae>
cmp    $0xffffffff,%eax
jne    11fc <handle_reload_snap+0x9c>
mov    0x2e20(%rip),%rax
movslq (%rax),%rax
sub    %eax,%ebp
cmp    $0x3,%ebp
jne    11fc <handle_reload_snap+0x9c>
mov    (%rbx,%rax,8),%rbp
mov    0x10(%rbx,%rax,8),%rdi
mov    0x8(%rbx,%rax,8),%rbx
lea    0x4(%rsp),%rsi
call   1030 <parse_ui@plt>
test   %eax,%eax
jne    120e <handle_reload_snap+0xae>
mov    0x4(%rsp),%edi
mov    0x8(%rsp),%rcx
mov    %rbp,%rsi
mov    %rbx,%rdx
call   1040 <reload_snapshot@plt>
jmp    1226 <handle_reload_snap+0xc6>
mov    0x2dc5(%rip),%rax
mov    (%rax),%eax
mov    0x2dc4(%rip),%rcx
mov    %eax,(%rcx)
lea    0xdee(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%edi
call   1080 <print_help@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"c:\00"
@optarg = global i32 0
@EINVAL = global i32 0
@errno = global i32 0
@optind = global i32 0
@.str.1 = [46 x i8] c"error interpreting reload snapshot parameters\00"
define i32 @handle_reload_snap(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i8*
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 0, i64* %9
br label %12
12: ; preds = %28, %2
%13 = load i32, i32* %4
%14 = load i8**, i8*** %5
%15 = call i32 @getopt(i32 %13, i8** %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32 %15, i32* %7
%16 = icmp ne i32 %15, -1
br i1 %16, label %17, label %29
17: ; preds = %12
%18 = load i32, i32* %7
switch i32 %18, label %26 [
i32 99, label %19
]
19: ; preds = %17
%20 = load i32, i32* @optarg
%21 = call i32 @parse_ul(i32 %20, i64* %9)
store i32 %21, i32* %6
%22 = load i32, i32* %6
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %19
br label %64
25: ; preds = %19
br label %28
26: ; preds = %17
%27 = load i32, i32* @EINVAL
store i32 %27, i32* @errno
br label %64
28: ; preds = %25
br label %12
29: ; preds = %12
%30 = load i32, i32* %4
%31 = load i32, i32* @optind
%32 = sub nsw i32 %30, %31
%33 = icmp ne i32 %32, 3
br i1 %33, label %34, label %36
34: ; preds = %29
%35 = load i32, i32* @EINVAL
store i32 %35, i32* @errno
br label %64
36: ; preds = %29
%37 = load i8**, i8*** %5
%38 = load i32, i32* @optind
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8*, i8** %37, i64 %39
%41 = load i8*, i8** %40
store i8* %41, i8** %10
%42 = load i8**, i8*** %5
%43 = load i32, i32* @optind
%44 = add nsw i32 %43, 1
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8*, i8** %42, i64 %45
%47 = load i8*, i8** %46
store i8* %47, i8** %11
%48 = load i8**, i8*** %5
%49 = load i32, i32* @optind
%50 = add nsw i32 %49, 2
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8*, i8** %48, i64 %51
%53 = load i8*, i8** %52
%54 = call i32 @parse_ui(i8* %53, i32* %8)
store i32 %54, i32* %6
%55 = load i32, i32* %6
%56 = icmp ne i32 %55, 0
br i1 %56, label %57, label %58
57: ; preds = %36
br label %64
58: ; preds = %36
%59 = load i32, i32* %8
%60 = load i8*, i8** %10
%61 = load i8*, i8** %11
%62 = load i64, i64* %9
%63 = call i32 @reload_snapshot(i32 %59, i8* %60, i8* %61, i64 %62)
store i32 %63, i32* %3
br label %67
64: ; preds = %57, %34, %26, %24
%65 = call i32 @perror(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0))
%66 = call i32 @print_help(i32 -1)
store i32 0, i32* %3
br label %67
67: ; preds = %64, %58
%68 = load i32, i32* %3
ret i32 %68
}

LLVM IR (-O2):
@.str = [3 x i8] c"c:\00"
@optarg = global i32 0
@EINVAL = global i32 0
@errno = global i32 0
@optind = global i32 0
@.str.1 = [46 x i8] c"error interpreting reload snapshot parameters\00"
define i32 @handle_reload_snap(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i64
%5 = bitcast i32* %3 to i8*
%6 = bitcast i64* %4 to i8*
store i64 0, i64* %4
br label %7
7: ; preds = %9, %2
%8 = call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
switch i32 %8, label %35 [
i32 -1, label %13
i32 99, label %9
]
9: ; preds = %7
%10 = load i32, i32* @optarg
%11 = call i32 @parse_ul(i32 %10, i64* %4)
%12 = icmp eq i32 %11, 0
br i1 %12, label %7, label %37
13: ; preds = %7
%14 = load i32, i32* @optind
%15 = sub nsw i32 %0, %14
%16 = icmp eq i32 %15, 3
br i1 %16, label %17, label %35
17: ; preds = %13
%18 = sext i32 %14 to i64
%19 = getelementptr inbounds i8*, i8** %1, i64 %18
%20 = load i8*, i8** %19
%21 = add nsw i32 %14, 1
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8*, i8** %1, i64 %22
%24 = load i8*, i8** %23
%25 = add nsw i32 %14, 2
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8*, i8** %1, i64 %26
%28 = load i8*, i8** %27
%29 = call i32 @parse_ui(i8* %28, i32* %3)
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %37
31: ; preds = %17
%32 = load i32, i32* %3
%33 = load i64, i64* %4
%34 = call i32 @reload_snapshot(i32 %32, i8* %20, i8* %24, i64 %33)
br label %40
35: ; preds = %7, %13
%36 = load i32, i32* @EINVAL
store i32 %36, i32* @errno
br label %37
37: ; preds = %9, %35, %17
%38 = call i32 @perror(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0))
%39 = call i32 @print_help(i32 -1)
br label %40
40: ; preds = %37, %31
%41 = phi i32 [ 0, %37 ], [ %34, %31 ]
ret i32 %41
}