#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;
  char member_3;
  int /*<<< orphan*/ member_2;
};

/* Variables and functions */
int getopt_long(int, char **, char *, struct option *, int /*<<< orphan*/ *);
int /*<<< orphan*/ optarg;
int optind;
int /*<<< orphan*/ set_configfile(int /*<<< orphan*/);
int /*<<< orphan*/ set_nodaemon(int);
int /*<<< orphan*/ set_pidfile(int /*<<< orphan*/);
int /*<<< orphan*/ set_prog(char *);
int /*<<< orphan*/ usage_and_exit();
void cmdline_parse(int argc, char *argv[]) {
  static struct option long_options[] = {
      {"help", 0, 0, 'h'},    {"version", 0, 0, 'v'}, {"config", 1, 0, 'c'},
      {"pidfile", 1, 0, 'p'}, {"no-fork", 0, 0, 'f'}, {0, 0, 0, 0},
  };
  set_prog(argv[0]);
  for (;;) {
    int i = getopt_long(argc, argv, "hvc:p:f", long_options, NULL);
    if (i == -1)
      break;
    switch (i) {
    case 'h':
    case 'v':
      usage_and_exit();
    case 'c':
      set_configfile(optarg);
      break;
    case 'p':
      set_pidfile(optarg);
      break;
    case 'f':
      set_nodaemon(1);
      break;
    default:
      usage_and_exit();
    }
  }
  if (optind < argc)
    usage_and_exit();
}


x86 assembly (clang, -O0):
<cmdline_parse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1040 <set_prog@plt>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xeeb(%rip),%rdx
lea    0x2ed0(%rip),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   1030 <getopt_long@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11ac <cmdline_parse+0x4c>
jmp    121d <cmdline_parse+0xbd>
mov    -0x14(%rbp),%eax
add    $0xffffff9d,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x13,%eax
ja     1211 <cmdline_parse+0xb1>
mov    -0x20(%rbp),%rax
lea    0xe34(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    $0x0,%al
call   1070 <usage_and_exit@plt>
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
call   1050 <set_configfile@plt>
jmp    1218 <cmdline_parse+0xb8>
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
call   1060 <set_pidfile@plt>
jmp    1218 <cmdline_parse+0xb8>
mov    $0x1,%edi
call   1080 <set_nodaemon@plt>
jmp    1218 <cmdline_parse+0xb8>
mov    $0x0,%al
call   1070 <usage_and_exit@plt>
jmp    117b <cmdline_parse+0x1b>
mov    0x2dbc(%rip),%rax
mov    (%rax),%eax
cmp    -0x4(%rbp),%eax
jge    1236 <cmdline_parse+0xd6>
mov    $0x0,%al
call   1070 <usage_and_exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmdline_parse>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%r12d
mov    (%rsi),%rdi
call   1040 <set_prog@plt>
lea    0xef4(%rip),%r14
lea    0x2ed9(%rip),%r15
lea    0xe72(%rip),%rbp
mov    0x2e63(%rip),%r13
jmp    11b0 <cmdline_parse+0x50>
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1070 <usage_and_exit@plt>
mov    0x0(%r13),%edi
call   1050 <set_configfile@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
mov    %r15,%rcx
xor    %r8d,%r8d
call   1030 <getopt_long@plt>
lea    -0x63(%rax),%ecx
cmp    $0x13,%ecx
ja     11ed <cmdline_parse+0x8d>
movslq 0x0(%rbp,%rcx,4),%rax
add    %rbp,%rax
jmp    *%rax
mov    $0x1,%edi
call   1080 <set_nodaemon@plt>
jmp    11b0 <cmdline_parse+0x50>
mov    0x0(%r13),%edi
call   1060 <set_pidfile@plt>
jmp    11b0 <cmdline_parse+0x50>
cmp    $0xffffffff,%eax
je     11fb <cmdline_parse+0x9b>
xor    %eax,%eax
call   1070 <usage_and_exit@plt>
jmp    11b0 <cmdline_parse+0x50>
mov    0x2dde(%rip),%rax
cmp    %r12d,(%rax)
jge    121c <cmdline_parse+0xbc>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <usage_and_exit@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.option = type { i8*, i32, i8, i32 }
@cmdline_parse.long_options = internal global [6 x %struct.option] [%struct.option { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0), i32 0, i8 0, i32 104 }, %struct.option { i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i32 0, i32 0), i32 0, i8 0, i32 118 }, %struct.option { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i32 0, i32 0), i32 1, i8 0, i32 99 }, %struct.option { i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i32 0, i32 0), i32 1, i8 0, i32 112 }, %struct.option { i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i32 0, i32 0), i32 0, i8 0, i32 102 }, %struct.option zeroinitializer]
@.str = [5 x i8] c"help\00"
@.str.1 = [8 x i8] c"version\00"
@.str.2 = [7 x i8] c"config\00"
@.str.3 = [8 x i8] c"pidfile\00"
@.str.4 = [8 x i8] c"no-fork\00"
@.str.5 = [8 x i8] c"hvc:p:f\00"
@optarg = global i32 0
@optind = global i32 0
define void @cmdline_parse(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
%6 = load i8**, i8*** %4
%7 = getelementptr inbounds i8*, i8** %6, i64 0
%8 = load i8*, i8** %7
%9 = call i32 @set_prog(i8* %8)
br label %10
10: ; preds = %31, %2
%11 = load i32, i32* %3
%12 = load i8**, i8*** %4
%13 = call i32 @getopt_long(i32 %11, i8** %12, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), %struct.option* getelementptr inbounds ([6 x %struct.option], [6 x %struct.option]* @cmdline_parse.long_options, i64 0, i64 0), i32* null)
store i32 %13, i32* %5
%14 = load i32, i32* %5
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %17
16: ; preds = %10
br label %32
17: ; preds = %10
%18 = load i32, i32* %5
switch i32 %18, label %29 [
i32 104, label %19
i32 118, label %19
i32 99, label %21
i32 112, label %24
i32 102, label %27
]
19: ; preds = %17, %17
%20 = call i32 (...) @usage_and_exit()
br label %21
21: ; preds = %17, %19
%22 = load i32, i32* @optarg
%23 = call i32 @set_configfile(i32 %22)
br label %31
24: ; preds = %17
%25 = load i32, i32* @optarg
%26 = call i32 @set_pidfile(i32 %25)
br label %31
27: ; preds = %17
%28 = call i32 @set_nodaemon(i32 1)
br label %31
29: ; preds = %17
%30 = call i32 (...) @usage_and_exit()
br label %31
31: ; preds = %29, %27, %24, %21
br label %10
32: ; preds = %16
%33 = load i32, i32* @optind
%34 = load i32, i32* %3
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %38
36: ; preds = %32
%37 = call i32 (...) @usage_and_exit()
br label %38
38: ; preds = %36, %32
ret void
}

LLVM IR (-O2):
%struct.option = type { i8*, i32, i8, i32 }
@cmdline_parse.long_options = internal global [6 x %struct.option] [%struct.option { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0), i32 0, i8 0, i32 104 }, %struct.option { i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i32 0, i32 0), i32 0, i8 0, i32 118 }, %struct.option { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i32 0, i32 0), i32 1, i8 0, i32 99 }, %struct.option { i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i32 0, i32 0), i32 1, i8 0, i32 112 }, %struct.option { i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i32 0, i32 0), i32 0, i8 0, i32 102 }, %struct.option zeroinitializer]
@.str = [5 x i8] c"help\00"
@.str.1 = [8 x i8] c"version\00"
@.str.2 = [7 x i8] c"config\00"
@.str.3 = [8 x i8] c"pidfile\00"
@.str.4 = [8 x i8] c"no-fork\00"
@.str.5 = [8 x i8] c"hvc:p:f\00"
@optarg = global i32 0
@optind = global i32 0
define void @cmdline_parse(i32 %0, i8** %1) {
%3 = load i8*, i8** %1
%4 = tail call i32 @set_prog(i8* %3)
br label %5
5: ; preds = %12, %2
%6 = tail call i32 @getopt_long(i32 %0, i8** %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), %struct.option* getelementptr inbounds ([6 x %struct.option], [6 x %struct.option]* @cmdline_parse.long_options, i64 0, i64 0), i32* null)
switch i32 %6, label %18 [
i32 -1, label %20
i32 104, label %7
i32 118, label %7
i32 99, label %9
i32 112, label %13
i32 102, label %16
]
7: ; preds = %5, %5
%8 = tail call i32 (...) @usage_and_exit()
br label %9
9: ; preds = %5, %7
%10 = load i32, i32* @optarg
%11 = tail call i32 @set_configfile(i32 %10)
br label %12
12: ; preds = %9, %13, %16, %18
br label %5
13: ; preds = %5
%14 = load i32, i32* @optarg
%15 = tail call i32 @set_pidfile(i32 %14)
br label %12
16: ; preds = %5
%17 = tail call i32 @set_nodaemon(i32 1)
br label %12
18: ; preds = %5
%19 = tail call i32 (...) @usage_and_exit()
br label %12
20: ; preds = %5
%21 = load i32, i32* @optind
%22 = icmp slt i32 %21, %0
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = tail call i32 (...) @usage_and_exit()
br label %25
25: ; preds = %23, %20
ret void
}