#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*/ AF_LOCAL;
int EXIT_FAILURE;
int SOCK_CLOEXEC;
int SOCK_STREAM;
int /*<<< orphan*/ assert(int);
int atoi(int /*<<< orphan*/);
int /*<<< orphan*/ dbus_run(int, char *);
int /*<<< orphan*/ dht_run(int, int);
int /*<<< orphan*/ exit(int);
int fork();
int getopt(int, char **, char *);
int /*<<< orphan*/ optarg;
int /*<<< orphan*/ printf(char *, char *);
int socketpair(int /*<<< orphan*/, int, int /*<<< orphan*/, int *);
char *strdup(int /*<<< orphan*/);
int /*<<< orphan*/ wait(int *);
int main(int argc, char *argv[]) {
  int port = 7786;
  int sock[2];
  char *dbus_name = "org.manuel.LunaDHT";
  int res;
  int pid;
  int opt;
  while ((opt = getopt(argc, argv, "b:p:")) != -1) {
    switch (opt) {
    default:
      printf("Usage: %s [-b dbus_busname] [-p udp_port]\n", argv[0]);
      exit(1);
      break;
    case 'b':
      dbus_name = strdup(optarg);
      break;
    case 'p':
      port = atoi(optarg);
      break;
    }
  }
  res = socketpair(AF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC, 0, sock);
  do {
    assert(res > -1);
    if (!(res > -1)) {
      exit(EXIT_FAILURE);
    }
  } while (0);
  pid = fork();
  if (pid == 0)
    dht_run(sock[0], port);
  else
    dbus_run(sock[1], dbus_name);
  wait(&res);
  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)
movl   $0x1e6a,-0x14(%rbp)
lea    0xe2c(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe2d(%rip),%rdx
call   1070 <getopt@plt>
mov    %eax,-0x34(%rbp)
cmp    $0xffffffff,%eax
je     1266 <main+0xb6>
mov    -0x34(%rbp),%eax
mov    %eax,-0x38(%rbp)
sub    $0x62,%eax
je     1239 <main+0x89>
jmp    120b <main+0x5b>
mov    -0x38(%rbp),%eax
sub    $0x70,%eax
je     1250 <main+0xa0>
jmp    121c <main+0x6c>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xdee(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x2db8(%rip),%rax
mov    (%rax),%edi
call   10a0 <strdup@plt>
mov    %rax,-0x28(%rbp)
jmp    1261 <main+0xb1>
mov    0x2da1(%rip),%rax
mov    (%rax),%edi
call   1080 <atoi@plt>
mov    %eax,-0x14(%rbp)
jmp    11d8 <main+0x28>
mov    0x2d6b(%rip),%rax
mov    (%rax),%edi
mov    0x2d52(%rip),%rax
mov    (%rax),%esi
mov    0x2d69(%rip),%rax
or     (%rax),%esi
lea    -0x1c(%rbp),%rcx
xor    %edx,%edx
call   1050 <socketpair@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
cmpl   $0xffffffff,-0x2c(%rbp)
jg     12b8 <main+0x108>
mov    0x2d0f(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
jmp    12bd <main+0x10d>
mov    $0x0,%al
call   10d0 <fork@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jne    12e1 <main+0x131>
mov    -0x1c(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1060 <dht_run@plt>
jmp    12ed <main+0x13d>
mov    -0x18(%rbp),%edi
mov    -0x28(%rbp),%rsi
call   10b0 <dbus_run@plt>
lea    -0x2c(%rbp),%rdi
call   10c0 <wait@plt>
xor    %eax,%eax
add    $0x40,%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,%rbx
mov    %edi,%ebp
mov    $0x1e6a,%r15d
lea    0xe30(%rip),%r14
lea    0xe3c(%rip),%r12
mov    0x2e1a(%rip),%r13
jmp    11ec <main+0x3c>
mov    0x0(%r13),%edi
call   1080 <atoi@plt>
mov    %eax,%r15d
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1070 <getopt@plt>
cmp    $0x70,%eax
je     11e0 <main+0x30>
cmp    $0xffffffff,%eax
je     121a <main+0x6a>
cmp    $0x62,%eax
jne    1297 <main+0xe7>
mov    0x0(%r13),%edi
call   10a0 <strdup@plt>
mov    %rax,%r14
jmp    11ec <main+0x3c>
mov    0x2db7(%rip),%rax
mov    (%rax),%edi
mov    0x2d9e(%rip),%rax
mov    0x2db7(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0x10(%rsp),%rcx
xor    %edx,%edx
call   1050 <socketpair@plt>
mov    %eax,%ebx
mov    %eax,0xc(%rsp)
mov    %eax,%edi
not    %edi
shr    $0x1f,%edi
call   1040 <assert@plt>
test   %ebx,%ebx
js     12b0 <main+0x100>
xor    %eax,%eax
call   10d0 <fork@plt>
test   %eax,%eax
je     1270 <main+0xc0>
mov    0x14(%rsp),%edi
mov    %r14,%rsi
call   10b0 <dbus_run@plt>
jmp    127c <main+0xcc>
mov    0x10(%rsp),%edi
mov    %r15d,%esi
call   1060 <dht_run@plt>
lea    0xc(%rsp),%rdi
call   10c0 <wait@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%rbx),%rsi
lea    0xd77(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x2d09(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [19 x i8] c"org.manuel.LunaDHT\00"
@.str.1 = [5 x i8] c"b:p:\00"
@.str.2 = [43 x i8] c"Usage: %s [-b dbus_busname] [-p udp_port]\0A\00"
@optarg = global i32 0
@AF_LOCAL = global i32 0
@SOCK_STREAM = global i32 0
@SOCK_CLOEXEC = global i32 0
@EXIT_FAILURE = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [2 x i32]
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 7786, i32* %6
store i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8** %8
br label %12
12: ; preds = %31, %2
%13 = load i32, i32* %4
%14 = load i8**, i8*** %5
%15 = call i32 @getopt(i32 %13, i8** %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i32 %15, i32* %11
%16 = icmp ne i32 %15, -1
br i1 %16, label %17, label %32
17: ; preds = %12
%18 = load i32, i32* %11
switch i32 %18, label %19 [
i32 98, label %25
i32 112, label %28
]
19: ; preds = %17
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 0
%22 = load i8*, i8** %21
%23 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i8* %22)
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %17
%26 = load i32, i32* @optarg
%27 = call i8* @strdup(i32 %26)
store i8* %27, i8** %8
br label %31
28: ; preds = %17
%29 = load i32, i32* @optarg
%30 = call i32 @atoi(i32 %29)
store i32 %30, i32* %6
br label %31
31: ; preds = %28, %25
br label %12
32: ; preds = %12
%33 = load i32, i32* @AF_LOCAL
%34 = load i32, i32* @SOCK_STREAM
%35 = load i32, i32* @SOCK_CLOEXEC
%36 = or i32 %34, %35
%37 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%38 = call i32 @socketpair(i32 %33, i32 %36, i32 0, i32* %37)
store i32 %38, i32* %9
br label %39
39: ; preds = %32
%40 = load i32, i32* %9
%41 = icmp sgt i32 %40, -1
%42 = zext i1 %41 to i32
%43 = call i32 @assert(i32 %42)
%44 = load i32, i32* %9
%45 = icmp sgt i32 %44, -1
br i1 %45, label %49, label %46
46: ; preds = %39
%47 = load i32, i32* @EXIT_FAILURE
%48 = call i32 @exit(i32 %47)
unreachable
49: ; preds = %39
br label %50
50: ; preds = %49
%51 = call i32 (...) @fork()
store i32 %51, i32* %10
%52 = load i32, i32* %10
%53 = icmp eq i32 %52, 0
br i1 %53, label %54, label %59
54: ; preds = %50
%55 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%56 = load i32, i32* %55
%57 = load i32, i32* %6
%58 = call i32 @dht_run(i32 %56, i32 %57)
br label %64
59: ; preds = %50
%60 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%61 = load i32, i32* %60
%62 = load i8*, i8** %8
%63 = call i32 @dbus_run(i32 %61, i8* %62)
br label %64
64: ; preds = %59, %54
%65 = call i32 @wait(i32* %9)
ret i32 0
}

LLVM IR (-O2):
@.str = [19 x i8] c"org.manuel.LunaDHT\00"
@.str.1 = [5 x i8] c"b:p:\00"
@.str.2 = [43 x i8] c"Usage: %s [-b dbus_busname] [-p udp_port]\0A\00"
@optarg = global i32 0
@AF_LOCAL = global i32 0
@SOCK_STREAM = global i32 0
@SOCK_CLOEXEC = global i32 0
@EXIT_FAILURE = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [2 x i32]
%4 = alloca i32
%5 = bitcast [2 x i32]* %3 to i8*
%6 = bitcast i32* %4 to i8*
br label %7
7: ; preds = %17, %2
%8 = phi i8* [ %19, %17 ], [ getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), %2 ]
%9 = phi i32 [ %11, %17 ], [ 7786, %2 ]
br label %10
10: ; preds = %7, %20
%11 = phi i32 [ %22, %20 ], [ %9, %7 ]
%12 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
switch i32 %12, label %13 [
i32 -1, label %23
i32 98, label %17
i32 112, label %20
]
13: ; preds = %10
%14 = load i8*, i8** %1
%15 = tail call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i8* %14)
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %10
%18 = load i32, i32* @optarg
%19 = tail call i8* @strdup(i32 %18)
br label %7
20: ; preds = %10
%21 = load i32, i32* @optarg
%22 = tail call i32 @atoi(i32 %21)
br label %10
23: ; preds = %10
%24 = load i32, i32* @AF_LOCAL
%25 = load i32, i32* @SOCK_STREAM
%26 = load i32, i32* @SOCK_CLOEXEC
%27 = or i32 %26, %25
%28 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%29 = call i32 @socketpair(i32 %24, i32 %27, i32 0, i32* %28)
store i32 %29, i32* %4
%30 = xor i32 %29, -1
%31 = lshr i32 %30, 31
%32 = call i32 @assert(i32 %31)
%33 = icmp sgt i32 %29, -1
br i1 %33, label %37, label %34
34: ; preds = %23
%35 = load i32, i32* @EXIT_FAILURE
%36 = call i32 @exit(i32 %35)
unreachable
37: ; preds = %23
%38 = call i32 (...) @fork()
%39 = icmp eq i32 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %37
%41 = load i32, i32* %28
%42 = call i32 @dht_run(i32 %41, i32 %11)
br label %47
43: ; preds = %37
%44 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%45 = load i32, i32* %44
%46 = call i32 @dbus_run(i32 %45, i8* %8)
br label %47
47: ; preds = %43, %40
%48 = call i32 @wait(i32* %4)
ret i32 0
}