#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 */
scalar_t__ g_getuid();
scalar_t__ g_strcasecmp(char *, char *);
int /*<<< orphan*/ g_writeln(char *);
int key_gen(char *);
int key_gen_auto();
int key_test();
int /*<<< orphan*/ out_params();
int main(int argc, char **argv) {
  if (argc > 1) {
    if (g_strcasecmp(argv[1], "xrdp") == 0) {
      if (argc > 2) {
        if (g_strcasecmp(argv[2], "auto") == 0) {
          if (g_getuid() != 0) {
            g_writeln("must run as root");
            return 0;
          }
          return key_gen_auto();
        } else {
          return key_gen(argv[2]);
        }
      } else {
        return key_gen(0);
      }
    } else if (g_strcasecmp(argv[1], "test") == 0) {
      return key_test();
    }
  }
  out_params();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    126b <main+0xfb>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe61(%rip),%rsi
call   1080 <g_strcasecmp@plt>
cmp    $0x0,%rax
jne    1234 <main+0xc4>
cmpl   $0x2,-0x8(%rbp)
jle    1223 <main+0xb3>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe3e(%rip),%rsi
call   1080 <g_strcasecmp@plt>
cmp    $0x0,%rax
jne    120e <main+0x9e>
mov    $0x0,%al
call   1070 <g_getuid@plt>
cmp    $0x0,%rax
je     11ff <main+0x8f>
lea    0xe1c(%rip),%rdi
call   1060 <g_writeln@plt>
movl   $0x0,-0x4(%rbp)
jmp    1279 <main+0x109>
mov    $0x0,%al
call   1050 <key_gen_auto@plt>
mov    %eax,-0x4(%rbp)
jmp    1279 <main+0x109>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1030 <key_gen@plt>
mov    %eax,-0x4(%rbp)
jmp    1279 <main+0x109>
xor    %eax,%eax
mov    %eax,%edi
call   1030 <key_gen@plt>
mov    %eax,-0x4(%rbp)
jmp    1279 <main+0x109>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdd8(%rip),%rsi
call   1080 <g_strcasecmp@plt>
cmp    $0x0,%rax
jne    1261 <main+0xf1>
mov    $0x0,%al
call   1040 <key_test@plt>
mov    %eax,-0x4(%rbp)
jmp    1279 <main+0x109>
jmp    1266 <main+0xf6>
jmp    126b <main+0xfb>
mov    $0x0,%al
call   1090 <out_params@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
cmp    $0x2,%edi
jl     11a7 <main+0x37>
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x8(%rsi),%rdi
lea    0xe78(%rip),%rsi
call   1080 <g_strcasecmp@plt>
test   %rax,%rax
je     11b7 <main+0x47>
mov    0x8(%rbx),%rdi
lea    0xe7e(%rip),%rsi
call   1080 <g_strcasecmp@plt>
test   %rax,%rax
je     11d7 <main+0x67>
xor    %eax,%eax
call   1090 <out_params@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
cmp    $0x3,%ebp
jb     11e4 <main+0x74>
mov    0x10(%rbx),%rdi
lea    0xe3e(%rip),%rsi
call   1080 <g_strcasecmp@plt>
test   %rax,%rax
je     11f1 <main+0x81>
mov    0x10(%rbx),%rdi
jmp    11e6 <main+0x76>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <key_test@plt>
xor    %edi,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <key_gen@plt>
xor    %eax,%eax
call   1070 <g_getuid@plt>
test   %rax,%rax
je     120b <main+0x9b>
lea    0xe06(%rip),%rdi
call   1060 <g_writeln@plt>
jmp    11ae <main+0x3e>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <key_gen_auto@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"xrdp\00"
@.str.1 = [5 x i8] c"auto\00"
@.str.2 = [17 x i8] c"must run as root\00"
@.str.3 = [5 x i8] c"test\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%6 = load i32, i32* %4
%7 = icmp sgt i32 %6, 1
br i1 %7, label %8, label %47
8: ; preds = %2
%9 = load i8**, i8*** %5
%10 = getelementptr inbounds i8*, i8** %9, i64 1
%11 = load i8*, i8** %10
%12 = call i64 @g_strcasecmp(i8* %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %37
14: ; preds = %8
%15 = load i32, i32* %4
%16 = icmp sgt i32 %15, 2
br i1 %16, label %17, label %35
17: ; preds = %14
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 2
%20 = load i8*, i8** %19
%21 = call i64 @g_strcasecmp(i8* %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %30
23: ; preds = %17
%24 = call i64 (...) @g_getuid()
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %23
%27 = call i32 @g_writeln(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %49
28: ; preds = %23
%29 = call i32 (...) @key_gen_auto()
store i32 %29, i32* %3
br label %49
30: ; preds = %17
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 2
%33 = load i8*, i8** %32
%34 = call i32 @key_gen(i8* %33)
store i32 %34, i32* %3
br label %49
35: ; preds = %14
%36 = call i32 @key_gen(i8* null)
store i32 %36, i32* %3
br label %49
37: ; preds = %8
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 1
%40 = load i8*, i8** %39
%41 = call i64 @g_strcasecmp(i8* %40, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%42 = icmp eq i64 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %37
%44 = call i32 (...) @key_test()
store i32 %44, i32* %3
br label %49
45: ; preds = %37
br label %46
46: ; preds = %45
br label %47
47: ; preds = %46, %2
%48 = call i32 (...) @out_params()
store i32 0, i32* %3
br label %49
49: ; preds = %47, %43, %35, %30, %28, %26
%50 = load i32, i32* %3
ret i32 %50
}

LLVM IR (-O2):
@.str = [5 x i8] c"xrdp\00"
@.str.1 = [5 x i8] c"auto\00"
@.str.2 = [17 x i8] c"must run as root\00"
@.str.3 = [5 x i8] c"test\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %34
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i64 @g_strcasecmp(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %28
9: ; preds = %4
%10 = icmp ugt i32 %0, 2
br i1 %10, label %11, label %26
11: ; preds = %9
%12 = getelementptr inbounds i8*, i8** %1, i64 2
%13 = load i8*, i8** %12
%14 = tail call i64 @g_strcasecmp(i8* %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %23
16: ; preds = %11
%17 = tail call i64 (...) @g_getuid()
%18 = icmp eq i64 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %16
%20 = tail call i32 @g_writeln(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %36
21: ; preds = %16
%22 = tail call i32 (...) @key_gen_auto()
br label %36
23: ; preds = %11
%24 = load i8*, i8** %12
%25 = tail call i32 @key_gen(i8* %24)
br label %36
26: ; preds = %9
%27 = tail call i32 @key_gen(i8* null)
br label %36
28: ; preds = %4
%29 = load i8*, i8** %5
%30 = tail call i64 @g_strcasecmp(i8* %29, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %28
%33 = tail call i32 (...) @key_test()
br label %36
34: ; preds = %28, %2
%35 = tail call i32 (...) @out_params()
br label %36
36: ; preds = %34, %32, %26, %23, %21, %19
%37 = phi i32 [ 0, %19 ], [ %22, %21 ], [ %25, %23 ], [ %27, %26 ], [ %33, %32 ], [ 0, %34 ]
ret i32 %37
}