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

/* Variables and functions */
int /*<<< orphan*/ config_load(char *);
int /*<<< orphan*/ daemon(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int getopt_long(int, char **, char *, struct option *, int *);
char *optarg;
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ strcmp(int /*<<< orphan*/, char *);
void lib_common_option_handling(int argc, char **argv) {
  int c, debug = 0;
  char *filename = NULL;
  while (1) {
    int option_index = 0;
    static struct option long_options[] = {
        {"debug", 0, 0, 0}, {"config", 1, 0, 0}, {0, 0, 0, 0}};
    c = getopt_long(argc, argv, "", long_options, &option_index);
    if (c == -1) {
      break;
    }
    switch (c) {
    case 0:
      if (!strcmp(long_options[option_index].name, "debug")) {
        debug = 1;
      } else if (!strcmp(long_options[option_index].name, "config")) {
        filename = optarg;
      }
      break;
    default:
      exit(0);
    }
  }
  if (filename == NULL) {
    printf("Missing filename\n");
    exit(1);
  }
  if (!config_load(filename)) {
    printf("Failed to load configuration file\n");
    exit(0);
  }
  if (!debug) {
    daemon(0, 0);
  }
}


x86 assembly (clang, -O0):
<lib_common_option_handling>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xeae(%rip),%rdx
lea    0x2ec6(%rip),%rcx
lea    -0x24(%rbp),%r8
call   1040 <getopt_long@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11b5 <lib_common_option_handling+0x55>
jmp    1249 <lib_common_option_handling+0xe9>
mov    -0x14(%rbp),%eax
test   %eax,%eax
jne    123d <lib_common_option_handling+0xdd>
jmp    11c5 <lib_common_option_handling+0x65>
movslq -0x24(%rbp),%rcx
lea    0x2e90(%rip),%rax
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
mov    0xc(%rax),%edi
lea    0xe1f(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    11fb <lib_common_option_handling+0x9b>
movl   $0x1,-0x18(%rbp)
jmp    1238 <lib_common_option_handling+0xd8>
movslq -0x24(%rbp),%rcx
lea    0x2e5a(%rip),%rax
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
mov    0xc(%rax),%edi
lea    0xdef(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    1233 <lib_common_option_handling+0xd3>
mov    0x2dcc(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    1238 <lib_common_option_handling+0xd8>
jmp    1244 <lib_common_option_handling+0xe4>
xor    %edi,%edi
call   1080 <exit@plt>
jmp    117e <lib_common_option_handling+0x1e>
cmpq   $0x0,-0x20(%rbp)
jne    126a <lib_common_option_handling+0x10a>
lea    0xdb2(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x20(%rbp),%rdi
call   1030 <config_load@plt>
cmp    $0x0,%eax
jne    128f <lib_common_option_handling+0x12f>
lea    0xd9c(%rip),%rdi
call   1050 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>
cmpl   $0x0,-0x18(%rbp)
jne    12a2 <lib_common_option_handling+0x142>
xor    %esi,%esi
mov    %esi,%edi
call   1070 <daemon@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lib_common_option_handling>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r12
mov    %edi,%ebp
xor    %eax,%eax
mov    %rax,0x10(%rsp)
lea    0xead(%rip),%r15
lea    0x2ed8(%rip),%rbx
lea    0x4(%rsp),%r13
lea    0xe6c(%rip),%r14
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
mov    %rax,0x8(%rsp)
jmp    11ba <lib_common_option_handling+0x5a>
nopw   0x0(%rax,%rax,1)
mov    $0x1,%eax
mov    %rax,0x10(%rsp)
movl   $0x0,0x4(%rsp)
mov    %ebp,%edi
mov    %r12,%rsi
mov    %r15,%rdx
mov    %rbx,%rcx
mov    %r13,%r8
call   1050 <getopt_long@plt>
test   %eax,%eax
jne    121b <lib_common_option_handling+0xbb>
movslq 0x4(%rsp),%rax
lea    (%rax,%rax,2),%rax
mov    0xc(%rbx,%rax,8),%edi
mov    %r14,%rsi
call   1060 <strcmp@plt>
test   %eax,%eax
je     11b0 <lib_common_option_handling+0x50>
movslq 0x4(%rsp),%rax
lea    (%rax,%rax,2),%rax
mov    0xc(%rbx,%rax,8),%edi
lea    0xe00(%rip),%rsi
call   1060 <strcmp@plt>
test   %eax,%eax
jne    11ba <lib_common_option_handling+0x5a>
mov    0x2de2(%rip),%rax
mov    (%rax),%rax
jmp    11a0 <lib_common_option_handling+0x40>
cmp    $0xffffffff,%eax
jne    1252 <lib_common_option_handling+0xf2>
mov    0x8(%rsp),%rdi
test   %rdi,%rdi
je     1259 <lib_common_option_handling+0xf9>
call   1040 <config_load@plt>
test   %eax,%eax
je     126f <lib_common_option_handling+0x10f>
cmpl   $0x0,0x10(%rsp)
jne    1243 <lib_common_option_handling+0xe3>
xor    %edi,%edi
xor    %esi,%esi
call   1070 <daemon@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %edi,%edi
call   1080 <exit@plt>
lea    0xdcf(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    0xd97(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.option = type { i8*, i32, i32, i32, i32 }
@lib_common_option_handling.long_options = internal global [3 x %struct.option] [%struct.option { i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i32 0, i32 0), i32 0, i32 0, i32 0, i32 0 }, %struct.option { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i32 0, i32 0), i32 1, i32 0, i32 0, i32 0 }, %struct.option zeroinitializer]
@.str = [6 x i8] c"debug\00"
@.str.1 = [7 x i8] c"config\00"
@.str.2 = [1 x i8] zeroinitializer
@optarg = global i8* null
@.str.3 = [18 x i8] c"Missing filename\0A\00"
@.str.4 = [35 x i8] c"Failed to load configuration file\0A\00"
define void @lib_common_option_handling(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
store i32 0, i32* %6
store i8* null, i8** %7
br label %9
9: ; preds = %2, %41
store i32 0, i32* %8
%10 = load i32, i32* %3
%11 = load i8**, i8*** %4
%12 = call i32 @getopt_long(i32 %10, i8** %11, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), %struct.option* getelementptr inbounds ([3 x %struct.option], [3 x %struct.option]* @lib_common_option_handling.long_options, i64 0, i64 0), i32* %8)
store i32 %12, i32* %5
%13 = load i32, i32* %5
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %16
15: ; preds = %9
br label %42
16: ; preds = %9
%17 = load i32, i32* %5
switch i32 %17, label %39 [
i32 0, label %18
]
18: ; preds = %16
%19 = load i32, i32* %8
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [3 x %struct.option], [3 x %struct.option]* @lib_common_option_handling.long_options, i64 0, i64 %20
%22 = getelementptr inbounds %struct.option, %struct.option* %21, i32 0, i32 2
%23 = load i32, i32* %22
%24 = call i32 @strcmp(i32 %23, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%25 = icmp ne i32 %24, 0
br i1 %25, label %27, label %26
26: ; preds = %18
store i32 1, i32* %6
br label %38
27: ; preds = %18
%28 = load i32, i32* %8
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [3 x %struct.option], [3 x %struct.option]* @lib_common_option_handling.long_options, i64 0, i64 %29
%31 = getelementptr inbounds %struct.option, %struct.option* %30, i32 0, i32 2
%32 = load i32, i32* %31
%33 = call i32 @strcmp(i32 %32, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%34 = icmp ne i32 %33, 0
br i1 %34, label %37, label %35
35: ; preds = %27
%36 = load i8*, i8** @optarg
store i8* %36, i8** %7
br label %37
37: ; preds = %35, %27
br label %38
38: ; preds = %37, %26
br label %41
39: ; preds = %16
%40 = call i32 @exit(i32 0)
unreachable
41: ; preds = %38
br label %9
42: ; preds = %15
%43 = load i8*, i8** %7
%44 = icmp eq i8* %43, null
br i1 %44, label %45, label %48
45: ; preds = %42
%46 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %42
%49 = load i8*, i8** %7
%50 = call i32 @config_load(i8* %49)
%51 = icmp ne i32 %50, 0
br i1 %51, label %55, label %52
52: ; preds = %48
%53 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0))
%54 = call i32 @exit(i32 0)
unreachable
55: ; preds = %48
%56 = load i32, i32* %6
%57 = icmp ne i32 %56, 0
br i1 %57, label %60, label %58
58: ; preds = %55
%59 = call i32 @daemon(i32 0, i32 0)
br label %60
60: ; preds = %58, %55
ret void
}

LLVM IR (-O2):
%struct.option = type { i8*, i32, i32, i32, i32 }
@lib_common_option_handling.long_options = internal global [3 x %struct.option] [%struct.option { i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i32 0, i32 0), i32 0, i32 0, i32 0, i32 0 }, %struct.option { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i32 0, i32 0), i32 1, i32 0, i32 0, i32 0 }, %struct.option zeroinitializer]
@.str = [6 x i8] c"debug\00"
@.str.1 = [7 x i8] c"config\00"
@.str.2 = [1 x i8] zeroinitializer
@optarg = global i8* null
@str = [34 x i8] c"Failed to load configuration file\00"
@str.5 = [17 x i8] c"Missing filename\00"
define void @lib_common_option_handling(i32 %0, i8** %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
br label %5
5: ; preds = %27, %2
%6 = phi i32 [ 0, %2 ], [ %28, %27 ]
%7 = phi i8* [ null, %2 ], [ %29, %27 ]
store i32 0, i32* %3
%8 = call i32 @getopt_long(i32 %0, i8** %1, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), %struct.option* getelementptr inbounds ([3 x %struct.option], [3 x %struct.option]* @lib_common_option_handling.long_options, i64 0, i64 0), i32* %3)
switch i32 %8, label %25 [
i32 -1, label %30
i32 0, label %9
]
9: ; preds = %5
%10 = load i32, i32* %3
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds [3 x %struct.option], [3 x %struct.option]* @lib_common_option_handling.long_options, i64 0, i64 %11, i32 2
%13 = load i32, i32* %12
%14 = call i32 @strcmp(i32 %13, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%15 = icmp eq i32 %14, 0
br i1 %15, label %27, label %16
16: ; preds = %9
%17 = load i32, i32* %3
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [3 x %struct.option], [3 x %struct.option]* @lib_common_option_handling.long_options, i64 0, i64 %18, i32 2
%20 = load i32, i32* %19
%21 = call i32 @strcmp(i32 %20, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%22 = icmp eq i32 %21, 0
%23 = load i8*, i8** @optarg
%24 = select i1 %22, i8* %23, i8* %7
br label %27
25: ; preds = %5
%26 = call i32 @exit(i32 0)
unreachable
27: ; preds = %16, %9
%28 = phi i32 [ 1, %9 ], [ %6, %16 ]
%29 = phi i8* [ %7, %9 ], [ %24, %16 ]
br label %5
30: ; preds = %5
%31 = icmp eq i8* %7, null
br i1 %31, label %32, label %35
32: ; preds = %30
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.5, i64 0, i64 0))
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %30
%36 = call i32 @config_load(i8* %7)
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %35
%39 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
%40 = call i32 @exit(i32 0)
unreachable
41: ; preds = %35
%42 = icmp eq i32 %6, 0
br i1 %42, label %43, label %45
43: ; preds = %41
%44 = call i32 @daemon(i32 0, i32 0)
br label %45
45: ; preds = %43, %41
ret void
}