#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*/ check_root();
scalar_t__ digsig_is_initialized();
scalar_t__ digsig_is_loaded();
int dsng_start(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ print_help(char *);
int /*<<< orphan*/ print_usage(char *);
int /*<<< orphan*/ printf(char *, char *, char *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  int ret = 0;
  if (argc < 2) {
    print_usage(argv[0]);
    return 1;
  } else if (argc >= 2 && (strcmp(argv[1], "help") == 0)) {
    print_help(argv[0]);
    return 0;
  } else if (argc >= 2 && (strcmp(argv[1], "start") == 0)) {
    if (argc < 3) {
      fprintf(stderr,
              "dsngctl: invalid number of parameters for start command\n");
      return 1;
    }
    if (!check_root()) {
      fprintf(stderr, "dsngctl: start command must be run as root\n");
      return 1;
    }
    ret = dsng_start(argv[2]);
  } else if (argc >= 2 && (strcmp(argv[1], "status") == 0)) {
    if (!check_root()) {
      fprintf(stderr, "dsngctl: status command must be run as root\n");
      return 1;
    }
    printf("dsngctl: digsig-ng status\n\t"
           "module loaded:\t\t%s\n\t"
           "module initialized:\t%s\n",
           digsig_is_loaded() ? "loaded" : "not loaded",
           digsig_is_initialized() ? "initialized" : "not initialized");
    return 0;
  } else {
    fprintf(stderr, "dsngctl: unrecognized argument\n");
  }
  return ret;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11cf <main+0x3f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10b0 <print_usage@plt>
movl   $0x1,-0x4(%rbp)
jmp    138b <main+0x1fb>
cmpl   $0x2,-0x8(%rbp)
jl     120f <main+0x7f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe18(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    120f <main+0x7f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10a0 <print_help@plt>
movl   $0x0,-0x4(%rbp)
jmp    138b <main+0x1fb>
cmpl   $0x2,-0x8(%rbp)
jl     12a8 <main+0x118>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xddd(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    12a8 <main+0x118>
cmpl   $0x3,-0x8(%rbp)
jge    1262 <main+0xd2>
mov    0x2d98(%rip),%rax
mov    (%rax),%edi
lea    0xdba(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    138b <main+0x1fb>
mov    $0x0,%al
call   1050 <check_root@plt>
cmp    $0x0,%eax
jne    1293 <main+0x103>
mov    0x2d67(%rip),%rax
mov    (%rax),%edi
lea    0xdc2(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    138b <main+0x1fb>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1080 <dsng_start@plt>
mov    %eax,-0x14(%rbp)
jmp    137b <main+0x1eb>
cmpl   $0x2,-0x8(%rbp)
jl     1361 <main+0x1d1>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdaf(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1361 <main+0x1d1>
mov    $0x0,%al
call   1050 <check_root@plt>
cmp    $0x0,%eax
jne    1301 <main+0x171>
mov    0x2cf9(%rip),%rax
mov    (%rax),%edi
lea    0xd87(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    138b <main+0x1fb>
mov    $0x0,%al
call   1040 <digsig_is_loaded@plt>
mov    %rax,%rdx
lea    0xdd9(%rip),%rax
lea    0xdd6(%rip),%rcx
cmp    $0x0,%rdx
cmovne %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1090 <digsig_is_initialized@plt>
mov    -0x20(%rbp),%rsi
mov    %rax,%rcx
lea    0xdbc(%rip),%rdx
lea    0xdb9(%rip),%rax
cmp    $0x0,%rcx
cmovne %rax,%rdx
lea    0xd54(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    138b <main+0x1fb>
mov    0x2c78(%rip),%rax
mov    (%rax),%edi
lea    0xd95(%rip),%rsi
call   1070 <fprintf@plt>
jmp    137b <main+0x1eb>
jmp    1380 <main+0x1f0>
jmp    1385 <main+0x1f5>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x1,%edi
jg     11aa <main+0x1a>
mov    (%rbx),%rdi
call   10b0 <print_usage@plt>
mov    $0x1,%ebx
jmp    120c <main+0x7c>
mov    %edi,%ebp
mov    0x8(%rbx),%rdi
lea    0xe49(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1202 <main+0x72>
mov    0x8(%rbx),%rdi
lea    0xe39(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1215 <main+0x85>
mov    0x8(%rbx),%rdi
lea    0xe8f(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     122f <main+0x9f>
mov    0x2dee(%rip),%rax
mov    (%rax),%edi
lea    0xf0b(%rip),%rsi
call   1070 <fprintf@plt>
jmp    120a <main+0x7a>
mov    (%rbx),%rdi
call   10a0 <print_help@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
cmp    $0x2,%ebp
ja     1285 <main+0xf5>
mov    0x2dbf(%rip),%rax
mov    (%rax),%edi
lea    0xde1(%rip),%rsi
jmp    12c1 <main+0x131>
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <check_root@plt>
test   %eax,%eax
je     129f <main+0x10f>
xor    %eax,%eax
call   1040 <digsig_is_loaded@plt>
test   %rax,%rax
lea    0xe9e(%rip),%rax
lea    0xe9b(%rip),%rbp
cmove  %rax,%rbp
xor    %eax,%eax
call   1090 <digsig_is_initialized@plt>
test   %rax,%rax
lea    0xe8d(%rip),%rax
lea    0xe8a(%rip),%rdx
cmove  %rax,%rdx
lea    0xe29(%rip),%rdi
mov    %rbp,%rsi
call   1030 <printf@plt>
jmp    120c <main+0x7c>
xor    %eax,%eax
call   1050 <check_root@plt>
test   %eax,%eax
je     12b1 <main+0x121>
mov    0x10(%rbx),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1080 <dsng_start@plt>
mov    0x2d3a(%rip),%rax
mov    (%rax),%edi
lea    0xdc8(%rip),%rsi
jmp    12c1 <main+0x131>
mov    0x2d28(%rip),%rax
mov    (%rax),%edi
lea    0xd83(%rip),%rsi
call   1070 <fprintf@plt>
jmp    11a3 <main+0x13>

LLVM IR (-O0):
@.str = [5 x i8] c"help\00"
@.str.1 = [6 x i8] c"start\00"
@stderr = global i32 0
@.str.2 = [57 x i8] c"dsngctl: invalid number of parameters for start command\0A\00"
@.str.3 = [44 x i8] c"dsngctl: start command must be run as root\0A\00"
@.str.4 = [7 x i8] c"status\00"
@.str.5 = [45 x i8] c"dsngctl: status command must be run as root\0A\00"
@.str.6 = [71 x i8] c"dsngctl: digsig-ng status\0A\09module loaded:\09\09%s\0A\09module initialized:\09%s\0A\00"
@.str.7 = [7 x i8] c"loaded\00"
@.str.8 = [11 x i8] c"not loaded\00"
@.str.9 = [12 x i8] c"initialized\00"
@.str.10 = [16 x i8] c"not initialized\00"
@.str.11 = [32 x i8] c"dsngctl: unrecognized argument\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 2
br i1 %8, label %9, label %14
9: ; preds = %2
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 0
%12 = load i8*, i8** %11
%13 = call i32 @print_usage(i8* %12)
store i32 1, i32* %3
br label %87
14: ; preds = %2
%15 = load i32, i32* %4
%16 = icmp sge i32 %15, 2
br i1 %16, label %17, label %28
17: ; preds = %14
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i64 @strcmp(i8* %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %28
23: ; preds = %17
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 0
%26 = load i8*, i8** %25
%27 = call i32 @print_help(i8* %26)
store i32 0, i32* %3
br label %87
28: ; preds = %17, %14
%29 = load i32, i32* %4
%30 = icmp sge i32 %29, 2
br i1 %30, label %31, label %54
31: ; preds = %28
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = call i64 @strcmp(i8* %34, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %54
37: ; preds = %31
%38 = load i32, i32* %4
%39 = icmp slt i32 %38, 3
br i1 %39, label %40, label %43
40: ; preds = %37
%41 = load i32, i32* @stderr
%42 = call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %87
43: ; preds = %37
%44 = call i32 (...) @check_root()
%45 = icmp ne i32 %44, 0
br i1 %45, label %49, label %46
46: ; preds = %43
%47 = load i32, i32* @stderr
%48 = call i32 @fprintf(i32 %47, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %87
49: ; preds = %43
%50 = load i8**, i8*** %5
%51 = getelementptr inbounds i8*, i8** %50, i64 2
%52 = load i8*, i8** %51
%53 = call i32 @dsng_start(i8* %52)
store i32 %53, i32* %6
br label %83
54: ; preds = %31, %28
%55 = load i32, i32* %4
%56 = icmp sge i32 %55, 2
br i1 %56, label %57, label %79
57: ; preds = %54
%58 = load i8**, i8*** %5
%59 = getelementptr inbounds i8*, i8** %58, i64 1
%60 = load i8*, i8** %59
%61 = call i64 @strcmp(i8* %60, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%62 = icmp eq i64 %61, 0
br i1 %62, label %63, label %79
63: ; preds = %57
%64 = call i32 (...) @check_root()
%65 = icmp ne i32 %64, 0
br i1 %65, label %69, label %66
66: ; preds = %63
%67 = load i32, i32* @stderr
%68 = call i32 @fprintf(i32 %67, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %3
br label %87
69: ; preds = %63
%70 = call i64 (...) @digsig_is_loaded()
%71 = icmp ne i64 %70, 0
%72 = zext i1 %71 to i64
%73 = select i1 %71, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0)
%74 = call i64 (...) @digsig_is_initialized()
%75 = icmp ne i64 %74, 0
%76 = zext i1 %75 to i64
%77 = select i1 %75, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.10, i64 0, i64 0)
%78 = call i32 @printf(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.6, i64 0, i64 0), i8* %73, i8* %77)
store i32 0, i32* %3
br label %87
79: ; preds = %57, %54
%80 = load i32, i32* @stderr
%81 = call i32 @fprintf(i32 %80, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.11, i64 0, i64 0))
br label %82
82: ; preds = %79
br label %83
83: ; preds = %82, %49
br label %84
84: ; preds = %83
br label %85
85: ; preds = %84
%86 = load i32, i32* %6
store i32 %86, i32* %3
br label %87
87: ; preds = %85, %69, %66, %46, %40, %23, %9
%88 = load i32, i32* %3
ret i32 %88
}

LLVM IR (-O2):
@.str = [5 x i8] c"help\00"
@.str.1 = [6 x i8] c"start\00"
@stderr = global i32 0
@.str.2 = [57 x i8] c"dsngctl: invalid number of parameters for start command\0A\00"
@.str.3 = [44 x i8] c"dsngctl: start command must be run as root\0A\00"
@.str.4 = [7 x i8] c"status\00"
@.str.5 = [45 x i8] c"dsngctl: status command must be run as root\0A\00"
@.str.6 = [71 x i8] c"dsngctl: digsig-ng status\0A\09module loaded:\09\09%s\0A\09module initialized:\09%s\0A\00"
@.str.7 = [7 x i8] c"loaded\00"
@.str.8 = [11 x i8] c"not loaded\00"
@.str.9 = [12 x i8] c"initialized\00"
@.str.10 = [16 x i8] c"not initialized\00"
@.str.11 = [32 x i8] c"dsngctl: unrecognized argument\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 @print_usage(i8* %5)
br label %55
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i64 @strcmp(i8* %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %7
%13 = load i8*, i8** %1
%14 = tail call i32 @print_help(i8* %13)
br label %55
15: ; preds = %7
%16 = load i8*, i8** %8
%17 = tail call i64 @strcmp(i8* %16, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %34
19: ; preds = %15
%20 = icmp ult i32 %0, 3
br i1 %20, label %21, label %24
21: ; preds = %19
%22 = load i32, i32* @stderr
%23 = tail call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.2, i64 0, i64 0))
br label %55
24: ; preds = %19
%25 = tail call i32 (...) @check_root()
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %24
%28 = load i32, i32* @stderr
%29 = tail call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0))
br label %55
30: ; preds = %24
%31 = getelementptr inbounds i8*, i8** %1, i64 2
%32 = load i8*, i8** %31
%33 = tail call i32 @dsng_start(i8* %32)
br label %55
34: ; preds = %15
%35 = load i8*, i8** %8
%36 = tail call i64 @strcmp(i8* %35, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %52
38: ; preds = %34
%39 = tail call i32 (...) @check_root()
%40 = icmp eq i32 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %38
%42 = load i32, i32* @stderr
%43 = tail call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.5, i64 0, i64 0))
br label %55
44: ; preds = %38
%45 = tail call i64 (...) @digsig_is_loaded()
%46 = icmp eq i64 %45, 0
%47 = select i1 %46, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0)
%48 = tail call i64 (...) @digsig_is_initialized()
%49 = icmp eq i64 %48, 0
%50 = select i1 %49, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.9, i64 0, i64 0)
%51 = tail call i32 @printf(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.6, i64 0, i64 0), i8* %47, i8* %50)
br label %55
52: ; preds = %34
%53 = load i32, i32* @stderr
%54 = tail call i32 @fprintf(i32 %53, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.11, i64 0, i64 0))
br label %55
55: ; preds = %30, %52, %44, %41, %27, %21, %12, %4
%56 = phi i32 [ 1, %4 ], [ 0, %12 ], [ 1, %21 ], [ 1, %27 ], [ 0, %44 ], [ 1, %41 ], [ %33, %30 ], [ 0, %52 ]
ret i32 %56
}