#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*/ Daemonize(char const *, int, char const *, char *, char **);
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ errx(int /*<<< orphan*/, char *, ...);
int getopt(int, char **, char *);
char *optarg;
scalar_t__ optind;
int /*<<< orphan*/ optopt;
int main(int argc, char **argv) {
  bool log_append = false;
  const char *log_path = NULL;
  const char *pid_path = NULL;
  int opt;
  while ((opt = getopt(argc, argv, ":al:p:")) != -1) {
    switch (opt) {
    case 'a':
      log_append = true;
      break;
    case 'l':
      log_path = optarg;
      break;
    case 'p':
      pid_path = optarg;
      break;
    case ':':
      errx(EXIT_FAILURE, "Option -%c requires an argument", optopt);
    case '?':
    default:
      errx(EXIT_FAILURE, "Unknown option -%c", optopt);
    }
  }
  argc -= optind;
  argv += optind;
  if (log_path == NULL) {
    errx(EXIT_FAILURE, "Must specify a log file with -l");
  }
  if (pid_path == NULL) {
    errx(EXIT_FAILURE, "Must specify a pid file with -p");
  }
  if (argc < 2) {
    errx(EXIT_FAILURE, "Must provide at least an executable name and arg0");
  }
  Daemonize(log_path, log_append, pid_path, argv[0], argv + 1);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe95(%rip),%rdx
call   1050 <getopt@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0xffffffff,%eax
je     1250 <main+0x120>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x30(%rbp)
sub    $0x3a,%eax
je     1206 <main+0xd6>
jmp    1190 <main+0x60>
mov    -0x30(%rbp),%eax
sub    $0x3f,%eax
je     1226 <main+0xf6>
jmp    11a1 <main+0x71>
mov    -0x30(%rbp),%eax
sub    $0x61,%eax
je     11d4 <main+0xa4>
jmp    11b2 <main+0x82>
mov    -0x30(%rbp),%eax
sub    $0x6c,%eax
je     11e0 <main+0xb0>
jmp    11c3 <main+0x93>
mov    -0x30(%rbp),%eax
sub    $0x70,%eax
je     11f3 <main+0xc3>
jmp    122b <main+0xfb>
movl   $0x1,-0x14(%rbp)
jmp    124b <main+0x11b>
mov    0x2e11(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    124b <main+0x11b>
mov    0x2dfe(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
jmp    124b <main+0x11b>
mov    0x2dbb(%rip),%rax
mov    (%rax),%edi
mov    0x2dca(%rip),%rax
mov    (%rax),%edx
lea    0xde8(%rip),%rsi
mov    $0x0,%al
call   1040 <errx@plt>
jmp    122b <main+0xfb>
mov    0x2d96(%rip),%rax
mov    (%rax),%edi
mov    0x2da5(%rip),%rax
mov    (%rax),%edx
lea    0xde3(%rip),%rsi
mov    $0x0,%al
call   1040 <errx@plt>
jmp    115d <main+0x2d>
mov    0x2d81(%rip),%rax
mov    (%rax),%rcx
movslq -0x8(%rbp),%rax
sub    %rcx,%rax
mov    %eax,-0x8(%rbp)
mov    0x2d6d(%rip),%rax
mov    (%rax),%rax
shl    $0x3,%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    129c <main+0x16c>
mov    0x2d3c(%rip),%rax
mov    (%rax),%edi
lea    0xda5(%rip),%rsi
mov    $0x0,%al
call   1040 <errx@plt>
cmpq   $0x0,-0x28(%rbp)
jne    12be <main+0x18e>
mov    0x2d1a(%rip),%rax
mov    (%rax),%edi
lea    0xda3(%rip),%rsi
mov    $0x0,%al
call   1040 <errx@plt>
cmpl   $0x2,-0x8(%rbp)
jge    12df <main+0x1af>
mov    0x2cf9(%rip),%rax
mov    (%rax),%edi
lea    0xda2(%rip),%rsi
mov    $0x0,%al
call   1040 <errx@plt>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x28(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
mov    -0x10(%rbp),%r8
add    $0x8,%r8
call   1030 <Daemonize@plt>
mov    0x2cbb(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbp
mov    %edi,%ebx
lea    0xeb6(%rip),%r13
mov    0x2e77(%rip),%r12
mov    0x2e88(%rip),%r14
lea    0xec8(%rip),%r15
movl   $0x0,0x4(%rsp)
xor    %eax,%eax
mov    %rax,0x8(%rsp)
xor    %eax,%eax
mov    %rax,0x10(%rsp)
jmp    11a6 <main+0x76>
nopw   0x0(%rax,%rax,1)
mov    (%r12),%edi
mov    (%r14),%edx
lea    0xe79(%rip),%rsi
xor    %eax,%eax
call   1040 <errx@plt>
mov    (%r12),%edi
mov    (%r14),%edx
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <errx@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %r13,%rdx
call   1050 <getopt@plt>
cmp    $0x60,%eax
jg     11d0 <main+0xa0>
cmp    $0x3a,%eax
je     1180 <main+0x50>
cmp    $0xffffffff,%eax
jne    1195 <main+0x65>
jmp    120b <main+0xdb>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmp    $0x61,%eax
je     11f0 <main+0xc0>
cmp    $0x70,%eax
je     11fa <main+0xca>
cmp    $0x6c,%eax
jne    1195 <main+0x65>
mov    0x2e12(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x8(%rsp)
jmp    11a6 <main+0x76>
movl   $0x1,0x4(%rsp)
jmp    11a6 <main+0x76>
mov    0x2df7(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x10(%rsp)
jmp    11a6 <main+0x76>
mov    0x2dc6(%rip),%rax
mov    (%rax),%r14
mov    0x8(%rsp),%r13
test   %r13,%r13
jne    1231 <main+0x101>
mov    (%r12),%edi
lea    0xe10(%rip),%rsi
xor    %eax,%eax
call   1040 <errx@plt>
sub    %r14d,%ebx
mov    0x10(%rsp),%r15
test   %r15,%r15
jne    1250 <main+0x120>
mov    (%r12),%edi
lea    0xe11(%rip),%rsi
xor    %eax,%eax
call   1040 <errx@plt>
lea    0x0(%rbp,%r14,8),%rbp
cmp    $0x1,%ebx
jg     126c <main+0x13c>
mov    (%r12),%edi
lea    0xe15(%rip),%rsi
xor    %eax,%eax
call   1040 <errx@plt>
mov    0x0(%rbp),%rcx
add    $0x8,%rbp
mov    %r13,%rdi
mov    0x4(%rsp),%esi
mov    %r15,%rdx
mov    %rbp,%r8
call   1030 <Daemonize@plt>
mov    0x2d33(%rip),%rax
mov    (%rax),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c":al:p:\00"
@optarg = global i8* null
@EXIT_FAILURE = global i32 0
@.str.1 = [32 x i8] c"Option -%c requires an argument\00"
@optopt = global i32 0
@.str.2 = [19 x i8] c"Unknown option -%c\00"
@optind = global i64 0
@.str.3 = [32 x i8] c"Must specify a log file with -l\00"
@.str.4 = [32 x i8] c"Must specify a pid file with -p\00"
@.str.5 = [50 x i8] c"Must provide at least an executable name and arg0\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i8* null, i8** %7
store i8* null, i8** %8
br label %10
10: ; preds = %31, %2
%11 = load i32, i32* %4
%12 = load i8**, i8*** %5
%13 = call i32 @getopt(i32 %11, i8** %12, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 %13, i32* %9
%14 = icmp ne i32 %13, -1
br i1 %14, label %15, label %32
15: ; preds = %10
%16 = load i32, i32* %9
switch i32 %16, label %27 [
i32 97, label %17
i32 108, label %18
i32 112, label %20
i32 58, label %22
i32 63, label %26
]
17: ; preds = %15
store i32 1, i32* %6
br label %31
18: ; preds = %15
%19 = load i8*, i8** @optarg
store i8* %19, i8** %7
br label %31
20: ; preds = %15
%21 = load i8*, i8** @optarg
store i8* %21, i8** %8
br label %31
22: ; preds = %15
%23 = load i32, i32* @EXIT_FAILURE
%24 = load i32, i32* @optopt
%25 = call i32 (i32, i8*, ...) @errx(i32 %23, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 %24)
br label %26
26: ; preds = %15, %22
br label %27
27: ; preds = %15, %26
%28 = load i32, i32* @EXIT_FAILURE
%29 = load i32, i32* @optopt
%30 = call i32 (i32, i8*, ...) @errx(i32 %28, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %29)
br label %31
31: ; preds = %27, %20, %18, %17
br label %10
32: ; preds = %10
%33 = load i64, i64* @optind
%34 = load i32, i32* %4
%35 = sext i32 %34 to i64
%36 = sub nsw i64 %35, %33
%37 = trunc i64 %36 to i32
store i32 %37, i32* %4
%38 = load i64, i64* @optind
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 %38
store i8** %40, i8*** %5
%41 = load i8*, i8** %7
%42 = icmp eq i8* %41, null
br i1 %42, label %43, label %46
43: ; preds = %32
%44 = load i32, i32* @EXIT_FAILURE
%45 = call i32 (i32, i8*, ...) @errx(i32 %44, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
br label %46
46: ; preds = %43, %32
%47 = load i8*, i8** %8
%48 = icmp eq i8* %47, null
br i1 %48, label %49, label %52
49: ; preds = %46
%50 = load i32, i32* @EXIT_FAILURE
%51 = call i32 (i32, i8*, ...) @errx(i32 %50, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0))
br label %52
52: ; preds = %49, %46
%53 = load i32, i32* %4
%54 = icmp slt i32 %53, 2
br i1 %54, label %55, label %58
55: ; preds = %52
%56 = load i32, i32* @EXIT_FAILURE
%57 = call i32 (i32, i8*, ...) @errx(i32 %56, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.5, i64 0, i64 0))
br label %58
58: ; preds = %55, %52
%59 = load i8*, i8** %7
%60 = load i32, i32* %6
%61 = load i8*, i8** %8
%62 = load i8**, i8*** %5
%63 = getelementptr inbounds i8*, i8** %62, i64 0
%64 = load i8*, i8** %63
%65 = load i8**, i8*** %5
%66 = getelementptr inbounds i8*, i8** %65, i64 1
%67 = call i32 @Daemonize(i8* %59, i32 %60, i8* %61, i8* %64, i8** %66)
%68 = load i32, i32* @EXIT_SUCCESS
ret i32 %68
}

LLVM IR (-O2):
@.str = [7 x i8] c":al:p:\00"
@optarg = global i8* null
@EXIT_FAILURE = global i32 0
@.str.1 = [32 x i8] c"Option -%c requires an argument\00"
@optopt = global i32 0
@.str.2 = [19 x i8] c"Unknown option -%c\00"
@optind = global i64 0
@.str.3 = [32 x i8] c"Must specify a log file with -l\00"
@.str.4 = [32 x i8] c"Must specify a pid file with -p\00"
@.str.5 = [50 x i8] c"Must provide at least an executable name and arg0\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
br label %3
3: ; preds = %12, %2
%4 = phi i32 [ 0, %2 ], [ 1, %12 ]
%5 = phi i8* [ null, %2 ], [ %8, %12 ]
%6 = phi i8* [ null, %2 ], [ %11, %12 ]
br label %7
7: ; preds = %3, %14
%8 = phi i8* [ %5, %3 ], [ %15, %14 ]
%9 = phi i8* [ %6, %3 ], [ %11, %14 ]
br label %10
10: ; preds = %7, %16
%11 = phi i8* [ %9, %7 ], [ %17, %16 ]
br label %12
12: ; preds = %10, %22
%13 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
switch i32 %13, label %22 [
i32 -1, label %26
i32 97, label %3
i32 108, label %14
i32 112, label %16
i32 58, label %18
]
14: ; preds = %12
%15 = load i8*, i8** @optarg
br label %7
16: ; preds = %12
%17 = load i8*, i8** @optarg
br label %10
18: ; preds = %12
%19 = load i32, i32* @EXIT_FAILURE
%20 = load i32, i32* @optopt
%21 = tail call i32 (i32, i8*, ...) @errx(i32 %19, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 %20)
br label %22
22: ; preds = %12, %18
%23 = load i32, i32* @EXIT_FAILURE
%24 = load i32, i32* @optopt
%25 = tail call i32 (i32, i8*, ...) @errx(i32 %23, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %24)
br label %12
26: ; preds = %12
%27 = load i64, i64* @optind
%28 = trunc i64 %27 to i32
%29 = sub i32 %0, %28
%30 = getelementptr inbounds i8*, i8** %1, i64 %27
%31 = icmp eq i8* %8, null
br i1 %31, label %32, label %35
32: ; preds = %26
%33 = load i32, i32* @EXIT_FAILURE
%34 = tail call i32 (i32, i8*, ...) @errx(i32 %33, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
br label %35
35: ; preds = %32, %26
%36 = icmp eq i8* %11, null
br i1 %36, label %37, label %40
37: ; preds = %35
%38 = load i32, i32* @EXIT_FAILURE
%39 = tail call i32 (i32, i8*, ...) @errx(i32 %38, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0))
br label %40
40: ; preds = %37, %35
%41 = icmp slt i32 %29, 2
br i1 %41, label %42, label %45
42: ; preds = %40
%43 = load i32, i32* @EXIT_FAILURE
%44 = tail call i32 (i32, i8*, ...) @errx(i32 %43, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.5, i64 0, i64 0))
br label %45
45: ; preds = %42, %40
%46 = load i8*, i8** %30
%47 = getelementptr inbounds i8*, i8** %30, i64 1
%48 = tail call i32 @Daemonize(i8* %8, i32 %4, i8* %11, i8* %46, i8** %47)
%49 = load i32, i32* @EXIT_SUCCESS
ret i32 %49
}