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


x86 assembly (clang, -O0):
<handle_transition_snap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%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   1060 <getopt@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
je     11ec <handle_transition_snap+0x8c>
mov    -0x18(%rbp),%eax
sub    $0x66,%eax
jne    11d0 <handle_transition_snap+0x70>
jmp    11a7 <handle_transition_snap+0x47>
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
call   1040 <parse_ul@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11cb <handle_transition_snap+0x6b>
jmp    1278 <handle_transition_snap+0x118>
jmp    11e7 <handle_transition_snap+0x87>
mov    0x2df1(%rip),%rax
mov    (%rax),%ecx
mov    0x2df0(%rip),%rax
mov    %ecx,(%rax)
jmp    1278 <handle_transition_snap+0x118>
jmp    1177 <handle_transition_snap+0x17>
mov    -0x8(%rbp),%eax
mov    0x2dea(%rip),%rcx
sub    (%rcx),%eax
cmp    $0x2,%eax
je     1218 <handle_transition_snap+0xb8>
mov    0x2dc0(%rip),%rax
mov    (%rax),%ecx
mov    0x2dbf(%rip),%rax
mov    %ecx,(%rax)
jmp    1278 <handle_transition_snap+0x118>
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),%rdi
lea    -0x1c(%rbp),%rsi
call   1030 <parse_ui@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1260 <handle_transition_snap+0x100>
jmp    1278 <handle_transition_snap+0x118>
mov    -0x1c(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1080 <transition_snapshot@plt>
mov    %eax,-0x4(%rbp)
jmp    1295 <handle_transition_snap+0x135>
lea    0xd84(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%edi
call   1070 <print_help@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_transition_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   1060 <getopt@plt>
cmp    $0x66,%eax
jne    11b4 <handle_transition_snap+0x54>
mov    (%r12),%edi
mov    %r15,%rsi
call   1040 <parse_ul@plt>
test   %eax,%eax
je     1190 <handle_transition_snap+0x30>
jmp    1206 <handle_transition_snap+0xa6>
cmp    $0xffffffff,%eax
jne    11f4 <handle_transition_snap+0x94>
mov    0x2e20(%rip),%rax
movslq (%rax),%rax
sub    %eax,%ebp
cmp    $0x2,%ebp
jne    11f4 <handle_transition_snap+0x94>
mov    (%rbx,%rax,8),%rbp
mov    0x8(%rbx,%rax,8),%rdi
lea    0x4(%rsp),%rsi
call   1030 <parse_ui@plt>
test   %eax,%eax
jne    1206 <handle_transition_snap+0xa6>
mov    0x4(%rsp),%edi
mov    0x8(%rsp),%rdx
mov    %rbp,%rsi
call   1080 <transition_snapshot@plt>
jmp    121e <handle_transition_snap+0xbe>
mov    0x2dcd(%rip),%rax
mov    (%rax),%eax
mov    0x2dcc(%rip),%rcx
mov    %eax,(%rcx)
lea    0xdf6(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%edi
call   1070 <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"f:\00"
@optarg = global i32 0
@EINVAL = global i32 0
@errno = global i32 0
@optind = global i32 0
@.str.1 = [53 x i8] c"error interpreting transition to snapshot parameters\00"
define i32 @handle_transition_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*
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 0, i64* %9
br label %11
11: ; preds = %27, %2
%12 = load i32, i32* %4
%13 = load i8**, i8*** %5
%14 = call i32 @getopt(i32 %12, i8** %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32 %14, i32* %7
%15 = icmp ne i32 %14, -1
br i1 %15, label %16, label %28
16: ; preds = %11
%17 = load i32, i32* %7
switch i32 %17, label %25 [
i32 102, label %18
]
18: ; preds = %16
%19 = load i32, i32* @optarg
%20 = call i32 @parse_ul(i32 %19, i64* %9)
store i32 %20, i32* %6
%21 = load i32, i32* %6
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %18
br label %56
24: ; preds = %18
br label %27
25: ; preds = %16
%26 = load i32, i32* @EINVAL
store i32 %26, i32* @errno
br label %56
27: ; preds = %24
br label %11
28: ; preds = %11
%29 = load i32, i32* %4
%30 = load i32, i32* @optind
%31 = sub nsw i32 %29, %30
%32 = icmp ne i32 %31, 2
br i1 %32, label %33, label %35
33: ; preds = %28
%34 = load i32, i32* @EINVAL
store i32 %34, i32* @errno
br label %56
35: ; preds = %28
%36 = load i8**, i8*** %5
%37 = load i32, i32* @optind
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8*, i8** %36, i64 %38
%40 = load i8*, i8** %39
store i8* %40, i8** %10
%41 = load i8**, i8*** %5
%42 = load i32, i32* @optind
%43 = add nsw i32 %42, 1
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8*, i8** %41, i64 %44
%46 = load i8*, i8** %45
%47 = call i32 @parse_ui(i8* %46, i32* %8)
store i32 %47, i32* %6
%48 = load i32, i32* %6
%49 = icmp ne i32 %48, 0
br i1 %49, label %50, label %51
50: ; preds = %35
br label %56
51: ; preds = %35
%52 = load i32, i32* %8
%53 = load i8*, i8** %10
%54 = load i64, i64* %9
%55 = call i32 @transition_snapshot(i32 %52, i8* %53, i64 %54)
store i32 %55, i32* %3
br label %59
56: ; preds = %50, %33, %25, %23
%57 = call i32 @perror(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0))
%58 = call i32 @print_help(i32 -1)
store i32 0, i32* %3
br label %59
59: ; preds = %56, %51
%60 = load i32, i32* %3
ret i32 %60
}

LLVM IR (-O2):
@.str = [3 x i8] c"f:\00"
@optarg = global i32 0
@EINVAL = global i32 0
@errno = global i32 0
@optind = global i32 0
@.str.1 = [53 x i8] c"error interpreting transition to snapshot parameters\00"
define i32 @handle_transition_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 %31 [
i32 -1, label %13
i32 102, 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 %33
13: ; preds = %7
%14 = load i32, i32* @optind
%15 = sub nsw i32 %0, %14
%16 = icmp eq i32 %15, 2
br i1 %16, label %17, label %31
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 = call i32 @parse_ui(i8* %24, i32* %3)
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %33
27: ; preds = %17
%28 = load i32, i32* %3
%29 = load i64, i64* %4
%30 = call i32 @transition_snapshot(i32 %28, i8* %20, i64 %29)
br label %36
31: ; preds = %7, %13
%32 = load i32, i32* @EINVAL
store i32 %32, i32* @errno
br label %33
33: ; preds = %9, %31, %17
%34 = call i32 @perror(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0))
%35 = call i32 @print_help(i32 -1)
br label %36
36: ; preds = %33, %27
%37 = phi i32 [ 0, %33 ], [ %30, %27 ]
ret i32 %37
}