#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 drcom_handle {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ daemonize();
struct drcom_handle *drcom_create_handle();
scalar_t__ drcom_init(struct drcom_handle *);
int /*<<< orphan*/ drcomd_daemon(struct drcom_handle *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ load_kernel_module();
int /*<<< orphan*/ logerr(char *);
int /*<<< orphan*/ logging_close();
int /*<<< orphan*/ logging_init(char *, int);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ usage();
int main(int argc, char **argv) {
  struct drcom_handle *h;
  int daemon = 1;
  int i;
  if (argc > 2)
    usage();
  for (i = 1; i < argc; i++) {
    char *arg = argv[i];
    if (strcmp(arg, "--nodaemon") == 0 || strcmp(arg, "-n") == 0) {
      printf("%s: log to stderr.\n", argv[0]);
      daemon = 0;
    }
  }
  h = drcom_create_handle();
  if (drcom_init(h) < 0) {
    logerr("conf file err\n");
    exit(-1);
  }
  load_kernel_module();
  if (daemon)
    daemonize();
  logging_init("drcomd", daemon);
  drcomd_daemon(h);
  logging_close();
  return 0;
}


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   $0x1,-0x1c(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    11ee <main+0x2e>
mov    $0x0,%al
call   10c0 <usage@plt>
movl   $0x1,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1272 <main+0xb2>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xde4(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     1245 <main+0x85>
mov    -0x28(%rbp),%rdi
lea    0xdd5(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    125f <main+0x9f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xdbb(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x1c(%rbp)
jmp    1264 <main+0xa4>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11f5 <main+0x35>
mov    $0x0,%al
call   10b0 <drcom_create_handle@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <drcom_init@plt>
cmp    $0x0,%rax
jge    12a6 <main+0xe6>
lea    0xd8b(%rip),%rdi
call   1080 <logerr@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
mov    $0x0,%al
call   10a0 <load_kernel_module@plt>
cmpl   $0x0,-0x1c(%rbp)
je     12be <main+0xfe>
mov    $0x0,%al
call   1030 <daemonize@plt>
mov    -0x1c(%rbp),%esi
lea    0xd69(%rip),%rdi
call   10e0 <logging_init@plt>
mov    -0x18(%rbp),%rdi
call   1090 <drcomd_daemon@plt>
mov    $0x0,%al
call   1050 <logging_close@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
cmp    $0x3,%edi
jl     11de <main+0x1e>
xor    %eax,%eax
call   10c0 <usage@plt>
jmp    11e9 <main+0x29>
mov    $0x1,%r14d
cmp    $0x2,%ebp
jne    1255 <main+0x95>
mov    %ebp,%r15d
mov    $0x1,%r14d
mov    $0x1,%r12d
lea    0xe01(%rip),%r13
jmp    122b <main+0x6b>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%rbx),%rsi
lea    0xdf4(%rip),%rdi
call   1040 <printf@plt>
xor    %r14d,%r14d
add    $0x1,%r12
cmp    %r12,%r15
je     1255 <main+0x95>
mov    (%rbx,%r12,8),%rbp
mov    %rbp,%rdi
mov    %r13,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1210 <main+0x50>
mov    %rbp,%rdi
lea    0xdc2(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
jne    1222 <main+0x62>
jmp    1210 <main+0x50>
xor    %eax,%eax
call   10b0 <drcom_create_handle@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <drcom_init@plt>
test   %rax,%rax
js     12ae <main+0xee>
xor    %eax,%eax
call   10a0 <load_kernel_module@plt>
test   %r14d,%r14d
je     127f <main+0xbf>
xor    %eax,%eax
call   1030 <daemonize@plt>
lea    0xdab(%rip),%rdi
mov    %r14d,%esi
call   10e0 <logging_init@plt>
mov    %rbx,%rdi
call   1090 <drcomd_daemon@plt>
xor    %eax,%eax
call   1050 <logging_close@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd6d(%rip),%rdi
call   1080 <logerr@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
%struct.drcom_handle = type { i32 }
@.str = [11 x i8] c"--nodaemon\00"
@.str.1 = [3 x i8] c"-n\00"
@.str.2 = [20 x i8] c"%s: log to stderr.\0A\00"
@.str.3 = [15 x i8] c"conf file err\0A\00"
@.str.4 = [7 x i8] c"drcomd\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.drcom_handle*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %7
%10 = load i32, i32* %4
%11 = icmp sgt i32 %10, 2
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 (...) @usage()
br label %14
14: ; preds = %12, %2
store i32 1, i32* %8
br label %15
15: ; preds = %38, %14
%16 = load i32, i32* %8
%17 = load i32, i32* %4
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %41
19: ; preds = %15
%20 = load i8**, i8*** %5
%21 = load i32, i32* %8
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8*, i8** %20, i64 %22
%24 = load i8*, i8** %23
store i8* %24, i8** %9
%25 = load i8*, i8** %9
%26 = call i64 @strcmp(i8* %25, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br i1 %27, label %32, label %28
28: ; preds = %19
%29 = load i8*, i8** %9
%30 = call i64 @strcmp(i8* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %37
32: ; preds = %28, %19
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 0
%35 = load i8*, i8** %34
%36 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %35)
store i32 0, i32* %7
br label %37
37: ; preds = %32, %28
br label %38
38: ; preds = %37
%39 = load i32, i32* %8
%40 = add nsw i32 %39, 1
store i32 %40, i32* %8
br label %15
41: ; preds = %15
%42 = call %struct.drcom_handle* (...) @drcom_create_handle()
store %struct.drcom_handle* %42, %struct.drcom_handle** %6
%43 = load %struct.drcom_handle*, %struct.drcom_handle** %6
%44 = call i64 @drcom_init(%struct.drcom_handle* %43)
%45 = icmp slt i64 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %41
%47 = call i32 @logerr(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%48 = call i32 @exit(i32 -1)
unreachable
49: ; preds = %41
%50 = call i32 (...) @load_kernel_module()
%51 = load i32, i32* %7
%52 = icmp ne i32 %51, 0
br i1 %52, label %53, label %55
53: ; preds = %49
%54 = call i32 (...) @daemonize()
br label %55
55: ; preds = %53, %49
%56 = load i32, i32* %7
%57 = call i32 @logging_init(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %56)
%58 = load %struct.drcom_handle*, %struct.drcom_handle** %6
%59 = call i32 @drcomd_daemon(%struct.drcom_handle* %58)
%60 = call i32 (...) @logging_close()
ret i32 0
}

LLVM IR (-O2):
%struct.drcom_handle = type { i32 }
@.str = [11 x i8] c"--nodaemon\00"
@.str.1 = [3 x i8] c"-n\00"
@.str.2 = [20 x i8] c"%s: log to stderr.\0A\00"
@.str.3 = [15 x i8] c"conf file err\0A\00"
@.str.4 = [7 x i8] c"drcomd\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 2
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 (...) @usage()
br label %8
6: ; preds = %2
%7 = icmp eq i32 %0, 2
br i1 %7, label %8, label %27
8: ; preds = %4, %6
%9 = zext i32 %0 to i64
br label %10
10: ; preds = %8, %23
%11 = phi i64 [ 1, %8 ], [ %25, %23 ]
%12 = phi i32 [ 1, %8 ], [ %24, %23 ]
%13 = getelementptr inbounds i8*, i8** %1, i64 %11
%14 = load i8*, i8** %13
%15 = tail call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %10
%18 = tail call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %17, %10
%21 = load i8*, i8** %1
%22 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %21)
br label %23
23: ; preds = %20, %17
%24 = phi i32 [ 0, %20 ], [ %12, %17 ]
%25 = add nuw nsw i64 %11, 1
%26 = icmp eq i64 %25, %9
br i1 %26, label %27, label %10
27: ; preds = %23, %6
%28 = phi i32 [ 1, %6 ], [ %24, %23 ]
%29 = tail call %struct.drcom_handle* (...) @drcom_create_handle()
%30 = tail call i64 @drcom_init(%struct.drcom_handle* %29)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %27
%33 = tail call i32 @logerr(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%34 = tail call i32 @exit(i32 -1)
unreachable
35: ; preds = %27
%36 = tail call i32 (...) @load_kernel_module()
%37 = icmp eq i32 %28, 0
br i1 %37, label %40, label %38
38: ; preds = %35
%39 = tail call i32 (...) @daemonize()
br label %40
40: ; preds = %38, %35
%41 = tail call i32 @logging_init(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %28)
%42 = tail call i32 @drcomd_daemon(%struct.drcom_handle* %29)
%43 = tail call i32 (...) @logging_close()
ret i32 0
}