#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*/ exit(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ run_tcpcryptd(char *);
scalar_t__ setuid(int /*<<< orphan*/);
int /*<<< orphan*/ setup_ipfw_rules();
int /*<<< orphan*/ stop_tcpcryptd();
int /*<<< orphan*/ strlen(char *);
scalar_t__ strncmp(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ teardown_ipfw_rules();
int main(int argc, char **argv) {
  static char *start = "start", *stop = "stop";
  char *action = argv[1];
  if (setuid(0) != 0) {
    printf("must be root\n");
    exit(1);
  }
  if (strncmp(action, start, strlen(start)) == 0) {
    setup_ipfw_rules();
    run_tcpcryptd(argv[0]);
  } else if (strncmp(action, stop, strlen(stop)) == 0) {
    teardown_ipfw_rules();
    stop_tcpcryptd();
  } else {
    printf("usage: %s start|stop\n", argv[0]);
    exit(1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
xor    %edi,%edi
call   10b0 <setuid@plt>
cmp    $0x0,%rax
je     11db <main+0x4b>
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e7e(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e73(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    122b <main+0x9b>
mov    $0x0,%al
call   1070 <setup_ipfw_rules@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10a0 <run_tcpcryptd@plt>
jmp    129a <main+0x10a>
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    0x2e36(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0x2e2b(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1276 <main+0xe6>
mov    $0x0,%al
call   1060 <teardown_ipfw_rules@plt>
mov    $0x0,%al
call   1080 <stop_tcpcryptd@plt>
jmp    1295 <main+0x105>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xd95(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    129a <main+0x10a>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    0x8(%rsi),%r15
xor    %edi,%edi
call   10c0 <setuid@plt>
test   %rax,%rax
jne    1221 <main+0x81>
lea    0xe41(%rip),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     120a <main+0x6a>
lea    0xe26(%rip),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    1237 <main+0x97>
xor    %eax,%eax
call   1070 <teardown_ipfw_rules@plt>
xor    %eax,%eax
call   1090 <stop_tcpcryptd@plt>
jmp    1219 <main+0x79>
xor    %eax,%eax
call   1080 <setup_ipfw_rules@plt>
mov    (%r14),%rdi
call   10b0 <run_tcpcryptd@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xdf9(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    (%r14),%rsi
lea    0xdca(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@main.start = internal global i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i32 0, i32 0)
@.str = [6 x i8] c"start\00"
@main.stop = internal global i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i32 0, i32 0)
@.str.1 = [5 x i8] c"stop\00"
@.str.2 = [14 x i8] c"must be root\0A\00"
@.str.3 = [22 x i8] c"usage: %s start|stop\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i8**, i8*** %5
%8 = getelementptr inbounds i8*, i8** %7, i64 1
%9 = load i8*, i8** %8
store i8* %9, i8** %6
%10 = call i64 @setuid(i32 0)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = load i8*, i8** %6
%17 = load i8*, i8** @main.start
%18 = load i8*, i8** @main.start
%19 = call i32 @strlen(i8* %18)
%20 = call i64 @strncmp(i8* %16, i8* %17, i32 %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %28
22: ; preds = %15
%23 = call i32 (...) @setup_ipfw_rules()
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 0
%26 = load i8*, i8** %25
%27 = call i32 @run_tcpcryptd(i8* %26)
br label %45
28: ; preds = %15
%29 = load i8*, i8** %6
%30 = load i8*, i8** @main.stop
%31 = load i8*, i8** @main.stop
%32 = call i32 @strlen(i8* %31)
%33 = call i64 @strncmp(i8* %29, i8* %30, i32 %32)
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %28
%36 = call i32 (...) @teardown_ipfw_rules()
%37 = call i32 (...) @stop_tcpcryptd()
br label %44
38: ; preds = %28
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 0
%41 = load i8*, i8** %40
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %41)
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %35
br label %45
45: ; preds = %44, %22
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"start\00"
@.str.1 = [5 x i8] c"stop\00"
@.str.3 = [22 x i8] c"usage: %s start|stop\0A\00"
@str = [13 x i8] c"must be root\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = tail call i64 @setuid(i32 0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = tail call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%12 = tail call i64 @strncmp(i8* %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %10
%15 = tail call i32 (...) @setup_ipfw_rules()
%16 = load i8*, i8** %1
%17 = tail call i32 @run_tcpcryptd(i8* %16)
br label %29
18: ; preds = %10
%19 = tail call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%20 = tail call i64 @strncmp(i8* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = tail call i32 (...) @teardown_ipfw_rules()
%24 = tail call i32 (...) @stop_tcpcryptd()
br label %29
25: ; preds = %18
%26 = load i8*, i8** %1
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %26)
%28 = tail call i32 @exit(i32 1)
unreachable
29: ; preds = %22, %14
ret i32 0
}