#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 */
struct option {
  char *member_0;
  int member_1;
  unsigned char member_3;
  int /*<<< orphan*/ *member_2;
};

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int getopt_long(int, char **, char *, struct option *, int *);
int /*<<< orphan*/ optarg;
int optind;
int /*<<< orphan*/ print_usage(int, char **);
int /*<<< orphan*/ printf(char *, char *);
char *strdup(int /*<<< orphan*/);
int strlen(int /*<<< orphan*/);
void parse_options(int argc, char **argv, char **to_device_id,
                   bool *to_is_debug) {
  static struct option longopts[] = {{"uuid", 1, NULL, 'U'},
                                     {"debug", 0, NULL, 'd'},
                                     {"help", 0, NULL, 'h'},
                                     {"udid", 1, NULL, 'u'},
                                     {NULL, 0, NULL, 0}};
  *to_device_id = NULL;
  *to_is_debug = false;
  while (1) {
    int c = getopt_long(argc, argv, "U:dhu:", longopts, (int *)0);
    if (c == -1) {
      break;
    }
    switch (c) {
    case 'h':
      print_usage(argc, argv);
      exit(0);
    case 'U':
    case 'u':
      if (strlen(optarg) != 40) {
        printf("%s: invalid UUID specified (length != 40)\n", argv[0]);
        print_usage(argc, argv);
        exit(2);
      }
      *to_device_id = strdup(optarg);
      break;
    case 'd':
      *to_is_debug = true;
      break;
    default:
      print_usage(argc, argv);
      exit(2);
    }
  }
  if ((argc - optind) > 0) {
    print_usage(argc, argv);
    exit(2);
  }
}


x86 assembly (clang, -O0):
<parse_options>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xeff(%rip),%rdx
lea    0x2ebf(%rip),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   1040 <getopt_long@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    11bd <parse_options+0x5d>
jmp    1280 <parse_options+0x120>
mov    -0x24(%rbp),%eax
add    $0xffffffab,%eax
mov    %eax,%ecx
mov    %rcx,-0x30(%rbp)
sub    $0x20,%eax
ja     1265 <parse_options+0x105>
mov    -0x30(%rbp),%rax
lea    0xe23(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1070 <print_usage@plt>
xor    %edi,%edi
call   1060 <exit@plt>
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
call   1030 <strlen@plt>
cmp    $0x28,%eax
je     1239 <parse_options+0xd9>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe82(%rip),%rdi
call   1050 <printf@plt>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1070 <print_usage@plt>
mov    $0x2,%edi
call   1060 <exit@plt>
mov    0x2db8(%rip),%rax
mov    (%rax),%edi
call   1080 <strdup@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
jmp    127b <parse_options+0x11b>
mov    -0x20(%rbp),%rax
movl   $0x1,(%rax)
jmp    127b <parse_options+0x11b>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1070 <print_usage@plt>
mov    $0x2,%edi
call   1060 <exit@plt>
jmp    118c <parse_options+0x2c>
mov    -0x4(%rbp),%eax
mov    0x2d56(%rip),%rcx
sub    (%rcx),%eax
cmp    $0x0,%eax
jle    12ab <parse_options+0x14b>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1070 <print_usage@plt>
mov    $0x2,%edi
call   1060 <exit@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_options>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %edi,%ebp
movq   $0x0,(%rdx)
mov    %rcx,(%rsp)
movl   $0x0,(%rcx)
lea    0x2ed5(%rip),%r13
lea    0xe6e(%rip),%r14
mov    0x2e5f(%rip),%r12
jmp    11aa <parse_options+0x4a>
nopl   0x0(%rax,%rax,1)
mov    (%rsp),%rax
movl   $0x1,(%rax)
mov    %ebp,%edi
mov    %rbx,%rsi
lea    0xee3(%rip),%rdx
mov    %r13,%rcx
xor    %r8d,%r8d
call   1040 <getopt_long@plt>
lea    -0x55(%rax),%ecx
cmp    $0x20,%ecx
ja     11ee <parse_options+0x8e>
movslq (%r14,%rcx,4),%rax
add    %r14,%rax
jmp    *%rax
mov    (%r12),%edi
call   1030 <strlen@plt>
cmp    $0x28,%eax
jne    120d <parse_options+0xad>
mov    (%r12),%edi
call   1080 <strdup@plt>
mov    %rax,(%r15)
jmp    11aa <parse_options+0x4a>
cmp    $0xffffffff,%eax
jne    121c <parse_options+0xbc>
mov    0x2de6(%rip),%rax
cmp    %ebp,(%rax)
jl     121c <parse_options+0xbc>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%rbx),%rsi
lea    0xe89(%rip),%rdi
call   1050 <printf@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1070 <print_usage@plt>
mov    $0x2,%edi
call   1060 <exit@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1070 <print_usage@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.option = type { i8*, i32, i8, i32* }
@parse_options.longopts = internal global [5 x %struct.option] [%struct.option { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0), i32 1, i8 0, i32* inttoptr (i64 85 to i32*) }, %struct.option { i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i32 0, i32 0), i32 0, i8 0, i32* inttoptr (i64 100 to i32*) }, %struct.option { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i32 0, i32 0), i32 0, i8 0, i32* inttoptr (i64 104 to i32*) }, %struct.option { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i32 0, i32 0), i32 1, i8 0, i32* inttoptr (i64 117 to i32*) }, %struct.option zeroinitializer]
@.str = [5 x i8] c"uuid\00"
@.str.1 = [6 x i8] c"debug\00"
@.str.2 = [5 x i8] c"help\00"
@.str.3 = [5 x i8] c"udid\00"
@.str.4 = [7 x i8] c"U:dhu:\00"
@optarg = global i32 0
@.str.5 = [43 x i8] c"%s: invalid UUID specified (length != 40)\0A\00"
@optind = global i32 0
define void @parse_options(i32 %0, i8** %1, i8** %2, i32* %3) {
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca i32*
%9 = alloca i32
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
store i32* %3, i32** %8
%10 = load i8**, i8*** %7
store i8* null, i8** %10
%11 = load i32*, i32** %8
store i32 0, i32* %11
br label %12
12: ; preds = %4, %50
%13 = load i32, i32* %5
%14 = load i8**, i8*** %6
%15 = call i32 @getopt_long(i32 %13, i8** %14, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), %struct.option* getelementptr inbounds ([5 x %struct.option], [5 x %struct.option]* @parse_options.longopts, i64 0, i64 0), i32* null)
store i32 %15, i32* %9
%16 = load i32, i32* %9
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %19
18: ; preds = %12
br label %51
19: ; preds = %12
%20 = load i32, i32* %9
switch i32 %20, label %45 [
i32 104, label %21
i32 85, label %26
i32 117, label %26
i32 100, label %43
]
21: ; preds = %19
%22 = load i32, i32* %5
%23 = load i8**, i8*** %6
%24 = call i32 @print_usage(i32 %22, i8** %23)
%25 = call i32 @exit(i32 0)
unreachable
26: ; preds = %19, %19
%27 = load i32, i32* @optarg
%28 = call i32 @strlen(i32 %27)
%29 = icmp ne i32 %28, 40
br i1 %29, label %30, label %39
30: ; preds = %26
%31 = load i8**, i8*** %6
%32 = getelementptr inbounds i8*, i8** %31, i64 0
%33 = load i8*, i8** %32
%34 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0), i8* %33)
%35 = load i32, i32* %5
%36 = load i8**, i8*** %6
%37 = call i32 @print_usage(i32 %35, i8** %36)
%38 = call i32 @exit(i32 2)
unreachable
39: ; preds = %26
%40 = load i32, i32* @optarg
%41 = call i8* @strdup(i32 %40)
%42 = load i8**, i8*** %7
store i8* %41, i8** %42
br label %50
43: ; preds = %19
%44 = load i32*, i32** %8
store i32 1, i32* %44
br label %50
45: ; preds = %19
%46 = load i32, i32* %5
%47 = load i8**, i8*** %6
%48 = call i32 @print_usage(i32 %46, i8** %47)
%49 = call i32 @exit(i32 2)
unreachable
50: ; preds = %43, %39
br label %12
51: ; preds = %18
%52 = load i32, i32* %5
%53 = load i32, i32* @optind
%54 = sub nsw i32 %52, %53
%55 = icmp sgt i32 %54, 0
br i1 %55, label %56, label %61
56: ; preds = %51
%57 = load i32, i32* %5
%58 = load i8**, i8*** %6
%59 = call i32 @print_usage(i32 %57, i8** %58)
%60 = call i32 @exit(i32 2)
unreachable
61: ; preds = %51
ret void
}

LLVM IR (-O2):
%struct.option = type { i8*, i32, i8, i32* }
@parse_options.longopts = internal global [5 x %struct.option] [%struct.option { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0), i32 1, i8 0, i32* inttoptr (i64 85 to i32*) }, %struct.option { i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i32 0, i32 0), i32 0, i8 0, i32* inttoptr (i64 100 to i32*) }, %struct.option { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i32 0, i32 0), i32 0, i8 0, i32* inttoptr (i64 104 to i32*) }, %struct.option { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i32 0, i32 0), i32 1, i8 0, i32* inttoptr (i64 117 to i32*) }, %struct.option zeroinitializer]
@.str = [5 x i8] c"uuid\00"
@.str.1 = [6 x i8] c"debug\00"
@.str.2 = [5 x i8] c"help\00"
@.str.3 = [5 x i8] c"udid\00"
@.str.4 = [7 x i8] c"U:dhu:\00"
@optarg = global i32 0
@.str.5 = [43 x i8] c"%s: invalid UUID specified (length != 40)\0A\00"
@optind = global i32 0
define void @parse_options(i32 %0, i8** %1, i8** nocapture writeonly %2, i32* nocapture writeonly %3) {
store i8* null, i8** %2
store i32 0, i32* %3
br label %5
5: ; preds = %22, %4
%6 = tail call i32 @getopt_long(i32 %0, i8** %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), %struct.option* getelementptr inbounds ([5 x %struct.option], [5 x %struct.option]* @parse_options.longopts, i64 0, i64 0), i32* null)
switch i32 %6, label %24 [
i32 -1, label %27
i32 104, label %7
i32 85, label %10
i32 117, label %10
i32 100, label %23
]
7: ; preds = %5
%8 = tail call i32 @print_usage(i32 %0, i8** %1)
%9 = tail call i32 @exit(i32 0)
unreachable
10: ; preds = %5, %5
%11 = load i32, i32* @optarg
%12 = tail call i32 @strlen(i32 %11)
%13 = icmp eq i32 %12, 40
br i1 %13, label %19, label %14
14: ; preds = %10
%15 = load i8*, i8** %1
%16 = tail call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0), i8* %15)
%17 = tail call i32 @print_usage(i32 %0, i8** %1)
%18 = tail call i32 @exit(i32 2)
unreachable
19: ; preds = %10
%20 = load i32, i32* @optarg
%21 = tail call i8* @strdup(i32 %20)
store i8* %21, i8** %2
br label %22
22: ; preds = %19, %23
br label %5
23: ; preds = %5
store i32 1, i32* %3
br label %22
24: ; preds = %5
%25 = tail call i32 @print_usage(i32 %0, i8** %1)
%26 = tail call i32 @exit(i32 2)
unreachable
27: ; preds = %5
%28 = load i32, i32* @optind
%29 = icmp slt i32 %28, %0
br i1 %29, label %30, label %33
30: ; preds = %27
%31 = tail call i32 @print_usage(i32 %0, i8** %1)
%32 = tail call i32 @exit(i32 2)
unreachable
33: ; preds = %27
ret void
}