#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 setup_snapshot(unsigned int, char *, char *, unsigned long, unsigned long);
int handle_setup_snap(int argc, char **argv) {
  int ret, c;
  unsigned int minor;
  unsigned long cache_size = 0, fallocated_space = 0;
  char *bdev, *cow;
  while ((c = getopt(argc, argv, "c:f:")) != -1) {
    switch (c) {
    case 'c':
      ret = parse_ul(optarg, &cache_size);
      if (ret)
        goto handle_setup_snap_error;
      break;
    case 'f':
      ret = parse_ul(optarg, &fallocated_space);
      if (ret)
        goto handle_setup_snap_error;
      break;
    default:
      errno = EINVAL;
      goto handle_setup_snap_error;
    }
  }
  if (argc - optind != 3) {
    errno = EINVAL;
    goto handle_setup_snap_error;
  }
  bdev = argv[optind];
  cow = argv[optind + 1];
  ret = parse_ui(argv[optind + 2], &minor);
  if (ret)
    goto handle_setup_snap_error;
  return setup_snapshot(minor, bdev, cow, fallocated_space, cache_size);
handle_setup_snap_error:
  perror("error interpreting setup snapshot parameters");
  print_help(-1);
  return 0;
}


x86 assembly (clang, -O0):
<handle_setup_snap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe73(%rip),%rdx
call   1070 <getopt@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
je     1231 <handle_setup_snap+0xd1>
mov    -0x18(%rbp),%eax
mov    %eax,-0x44(%rbp)
sub    $0x63,%eax
je     11c3 <handle_setup_snap+0x63>
jmp    11b2 <handle_setup_snap+0x52>
mov    -0x44(%rbp),%eax
sub    $0x66,%eax
je     11ec <handle_setup_snap+0x8c>
jmp    1215 <handle_setup_snap+0xb5>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
call   1050 <parse_ul@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11e7 <handle_setup_snap+0x87>
jmp    12e0 <handle_setup_snap+0x180>
jmp    122c <handle_setup_snap+0xcc>
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rsi
call   1050 <parse_ul@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1210 <handle_setup_snap+0xb0>
jmp    12e0 <handle_setup_snap+0x180>
jmp    122c <handle_setup_snap+0xcc>
mov    0x2dac(%rip),%rax
mov    (%rax),%ecx
mov    0x2dab(%rip),%rax
mov    %ecx,(%rax)
jmp    12e0 <handle_setup_snap+0x180>
jmp    117f <handle_setup_snap+0x1f>
mov    -0x8(%rbp),%eax
mov    0x2da5(%rip),%rcx
sub    (%rcx),%eax
cmp    $0x3,%eax
je     125d <handle_setup_snap+0xfd>
mov    0x2d7b(%rip),%rax
mov    (%rax),%ecx
mov    0x2d7a(%rip),%rax
mov    %ecx,(%rax)
jmp    12e0 <handle_setup_snap+0x180>
mov    -0x10(%rbp),%rax
mov    0x2d78(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2d62(%rip),%rcx
mov    (%rcx),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2d47(%rip),%rcx
mov    (%rcx),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
lea    -0x1c(%rbp),%rsi
call   1040 <parse_ui@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     12c0 <handle_setup_snap+0x160>
jmp    12e0 <handle_setup_snap+0x180>
mov    -0x1c(%rbp),%edi
mov    -0x38(%rbp),%rsi
mov    -0x40(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x28(%rbp),%r8
call   1030 <setup_snapshot@plt>
mov    %eax,-0x4(%rbp)
jmp    12fd <handle_setup_snap+0x19d>
lea    0xd1e(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%edi
call   1080 <print_help@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_setup_snap>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
movq   $0x0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
lea    0xe74(%rip),%r14
mov    0x2e65(%rip),%r13
lea    0x10(%rsp),%r15
lea    0x8(%rsp),%r12
jmp    11b0 <handle_setup_snap+0x50>
nop
mov    0x0(%r13),%edi
mov    %r15,%rsi
call   1050 <parse_ul@plt>
test   %eax,%eax
jne    122f <handle_setup_snap+0xcf>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1070 <getopt@plt>
cmp    $0x63,%eax
je     11a0 <handle_setup_snap+0x40>
cmp    $0x66,%eax
jne    11d0 <handle_setup_snap+0x70>
mov    0x0(%r13),%edi
mov    %r12,%rsi
jmp    11a7 <handle_setup_snap+0x47>
cmp    $0xffffffff,%eax
jne    121d <handle_setup_snap+0xbd>
mov    0x2e04(%rip),%rax
movslq (%rax),%rax
sub    %eax,%ebp
cmp    $0x3,%ebp
jne    121d <handle_setup_snap+0xbd>
mov    (%rbx,%rax,8),%rbp
mov    0x10(%rbx,%rax,8),%rdi
mov    0x8(%rbx,%rax,8),%rbx
lea    0x4(%rsp),%rsi
call   1040 <parse_ui@plt>
test   %eax,%eax
jne    122f <handle_setup_snap+0xcf>
mov    0x4(%rsp),%edi
mov    0x8(%rsp),%rcx
mov    0x10(%rsp),%r8
mov    %rbp,%rsi
mov    %rbx,%rdx
call   1030 <setup_snapshot@plt>
jmp    1247 <handle_setup_snap+0xe7>
mov    0x2da4(%rip),%rax
mov    (%rax),%eax
mov    0x2da3(%rip),%rcx
mov    %eax,(%rcx)
lea    0xdcf(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%edi
call   1080 <print_help@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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