#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 */
typedef int uint8_t;
struct multi_config {
  int dummy;
};
typedef int int32_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ abort();
int daemon(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ *freopen(char *, char *, int /*<<< orphan*/);
scalar_t__ geteuid();
int getopt(int, char **, char *);
struct multi_config *multi_core_initialize_config(char *, int);
int /*<<< orphan*/ multi_test_visible_loop(struct multi_config *);
char *optarg;
scalar_t__ opterr;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int32_t c;
  char *conf_file = NULL;
  struct multi_config *mc = NULL;
  uint8_t daemon_mode = 0;
  uint8_t unique_mode = 0;
  if (geteuid() != 0) {
    fprintf(stderr, "Application MUST be run as root\n");
    exit(EXIT_FAILURE);
  }
  opterr = 0;
  while ((c = getopt(argc, argv, "c:du")) != -1) {
    switch (c) {
    case 'c':
      conf_file = optarg;
      break;
    case 'd':
      daemon_mode = 1;
      break;
    case 'u':
      unique_mode = 1;
      break;
    default:
      abort();
    }
  }
  if ((mc = multi_core_initialize_config(conf_file, unique_mode)) == NULL) {
    printf("Could not initialize configuration struct\n");
    abort();
  }
  if (daemon_mode) {
    if (daemon(0, 0) == -1) {
      perror("Could not daemonize MULTI: ");
      exit(EXIT_FAILURE);
    }
    if (freopen("/var/log/multi.log", "a", stderr) == NULL) {
      perror("freopen failed: ");
      exit(EXIT_FAILURE);
    }
  }
  multi_test_visible_loop(mc);
}


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)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
mov    $0x0,%al
call   1050 <geteuid@plt>
cmp    $0x0,%rax
je     1218 <main+0x68>
mov    0x2ddc(%rip),%rax
mov    (%rax),%edi
lea    0xdfb(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2dbf(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    0x2da9(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xded(%rip),%rdx
call   10b0 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     12b2 <main+0x102>
mov    -0x14(%rbp),%eax
mov    %eax,-0x34(%rbp)
sub    $0x63,%eax
je     127b <main+0xcb>
jmp    1259 <main+0xa9>
mov    -0x34(%rbp),%eax
sub    $0x64,%eax
je     128e <main+0xde>
jmp    126a <main+0xba>
mov    -0x34(%rbp),%eax
sub    $0x75,%eax
je     129a <main+0xea>
jmp    12a6 <main+0xf6>
mov    0x2d76(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    12ad <main+0xfd>
movl   $0x1,-0x2c(%rbp)
jmp    12ad <main+0xfd>
movl   $0x1,-0x30(%rbp)
jmp    12ad <main+0xfd>
mov    $0x0,%al
call   1030 <abort@plt>
jmp    1226 <main+0x76>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%esi
call   1090 <multi_core_initialize_config@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    12df <main+0x12f>
lea    0xd53(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
cmpl   $0x0,-0x2c(%rbp)
je     135a <main+0x1aa>
xor    %esi,%esi
mov    %esi,%edi
call   1080 <daemon@plt>
cmp    $0xffffffff,%eax
jne    1315 <main+0x165>
lea    0xd4f(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2cc2(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    0x2cbc(%rip),%rax
mov    (%rax),%edx
lea    0xd48(%rip),%rdi
lea    0xd54(%rip),%rsi
call   1060 <freopen@plt>
cmp    $0x0,%rax
jne    1355 <main+0x1a5>
lea    0xd40(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2c82(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
jmp    135a <main+0x1aa>
mov    -0x28(%rbp),%rdi
call   10d0 <multi_test_visible_loop@plt>
mov    -0x4(%rbp),%eax
add    $0x40,%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,%r12
mov    %edi,%ebp
xor    %eax,%eax
call   1050 <geteuid@plt>
test   %rax,%rax
jne    129e <main+0xee>
mov    0x2df1(%rip),%rax
movq   $0x0,(%rax)
xor    %r15d,%r15d
lea    0xe39(%rip),%r14
xor    %r13d,%r13d
xor    %ebx,%ebx
mov    %ebx,%ecx
nop
mov    %ecx,%ebx
mov    %ebp,%edi
mov    %r12,%rsi
mov    %r14,%rdx
call   10b0 <getopt@plt>
mov    $0x1,%ecx
cmp    $0x75,%eax
je     11f0 <main+0x40>
cmp    $0xffffffff,%eax
je     1238 <main+0x88>
cmp    $0x64,%eax
je     1230 <main+0x80>
cmp    $0x63,%eax
jne    1297 <main+0xe7>
mov    0x2dd9(%rip),%rax
mov    (%rax),%r15
jmp    11ed <main+0x3d>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    $0x1,%r13d
jmp    11ed <main+0x3d>
mov    %r15,%rdi
mov    %ebx,%esi
call   1090 <multi_core_initialize_config@plt>
test   %rax,%rax
je     12b5 <main+0x105>
mov    %rax,%rbx
test   %r13d,%r13d
je     127e <main+0xce>
xor    %edi,%edi
xor    %esi,%esi
call   1080 <daemon@plt>
cmp    $0xffffffff,%eax
je     12c8 <main+0x118>
mov    0x2d74(%rip),%rax
mov    (%rax),%edx
lea    0xdd5(%rip),%rdi
lea    0xde1(%rip),%rsi
call   1060 <freopen@plt>
test   %rax,%rax
je     12d1 <main+0x121>
mov    %rbx,%rdi
call   10d0 <multi_test_visible_loop@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
call   1030 <abort@plt>
mov    0x2d33(%rip),%rax
mov    (%rax),%edi
lea    0xd52(%rip),%rsi
call   1070 <fprintf@plt>
jmp    12dd <main+0x12d>
lea    0xdac(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1030 <abort@plt>
lea    0xd57(%rip),%rdi
jmp    12d8 <main+0x128>
lea    0xd7f(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2cec(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
%struct.multi_config = type { i32 }
@stderr = global i32 0
@.str = [33 x i8] c"Application MUST be run as root\0A\00"
@EXIT_FAILURE = global i32 0
@opterr = global i64 0
@.str.1 = [5 x i8] c"c:du\00"
@optarg = global i8* null
@.str.2 = [43 x i8] c"Could not initialize configuration struct\0A\00"
@.str.3 = [28 x i8] c"Could not daemonize MULTI: \00"
@.str.4 = [19 x i8] c"/var/log/multi.log\00"
@.str.5 = [2 x i8] c"a\00"
@.str.6 = [17 x i8] c"freopen failed: \00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca %struct.multi_config*
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %7
store %struct.multi_config* null, %struct.multi_config** %8
store i32 0, i32* %9
store i32 0, i32* %10
%11 = call i64 (...) @geteuid()
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%16 = load i32, i32* @EXIT_FAILURE
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %2
store i64 0, i64* @opterr
br label %19
19: ; preds = %32, %18
%20 = load i32, i32* %4
%21 = load i8**, i8*** %5
%22 = call i32 @getopt(i32 %20, i8** %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i32 %22, i32* %6
%23 = icmp ne i32 %22, -1
br i1 %23, label %24, label %33
24: ; preds = %19
%25 = load i32, i32* %6
switch i32 %25, label %30 [
i32 99, label %26
i32 100, label %28
i32 117, label %29
]
26: ; preds = %24
%27 = load i8*, i8** @optarg
store i8* %27, i8** %7
br label %32
28: ; preds = %24
store i32 1, i32* %9
br label %32
29: ; preds = %24
store i32 1, i32* %10
br label %32
30: ; preds = %24
%31 = call i32 (...) @abort()
unreachable
32: ; preds = %29, %28, %26
br label %19
33: ; preds = %19
%34 = load i8*, i8** %7
%35 = load i32, i32* %10
%36 = call %struct.multi_config* @multi_core_initialize_config(i8* %34, i32 %35)
store %struct.multi_config* %36, %struct.multi_config** %8
%37 = icmp eq %struct.multi_config* %36, null
br i1 %37, label %38, label %41
38: ; preds = %33
%39 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0))
%40 = call i32 (...) @abort()
unreachable
41: ; preds = %33
%42 = load i32, i32* %9
%43 = icmp ne i32 %42, 0
br i1 %43, label %44, label %60
44: ; preds = %41
%45 = call i32 @daemon(i32 0, i32 0)
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %51
47: ; preds = %44
%48 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
%49 = load i32, i32* @EXIT_FAILURE
%50 = call i32 @exit(i32 %49)
unreachable
51: ; preds = %44
%52 = load i32, i32* @stderr
%53 = call i32* @freopen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i32 %52)
%54 = icmp eq i32* %53, null
br i1 %54, label %55, label %59
55: ; preds = %51
%56 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0))
%57 = load i32, i32* @EXIT_FAILURE
%58 = call i32 @exit(i32 %57)
unreachable
59: ; preds = %51
br label %60
60: ; preds = %59, %41
%61 = load %struct.multi_config*, %struct.multi_config** %8
%62 = call i32 @multi_test_visible_loop(%struct.multi_config* %61)
%63 = load i32, i32* %3
ret i32 %63
}

LLVM IR (-O2):
%struct.multi_config = type { i32 }
@stderr = global i32 0
@.str = [33 x i8] c"Application MUST be run as root\0A\00"
@EXIT_FAILURE = global i32 0
@opterr = global i64 0
@.str.1 = [5 x i8] c"c:du\00"
@optarg = global i8* null
@.str.3 = [28 x i8] c"Could not daemonize MULTI: \00"
@.str.4 = [19 x i8] c"/var/log/multi.log\00"
@.str.5 = [2 x i8] c"a\00"
@.str.6 = [17 x i8] c"freopen failed: \00"
@str = [42 x i8] c"Could not initialize configuration struct\00"
define i32 @main(i32 %0, i8** %1) {
%3 = tail call i64 (...) @geteuid()
%4 = icmp eq i64 %3, 0
br i1 %4, label %10, label %5
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %2
store i64 0, i64* @opterr
br label %11
11: ; preds = %21, %10
%12 = phi i8* [ %22, %21 ], [ null, %10 ]
%13 = phi i32 [ %16, %21 ], [ 0, %10 ]
%14 = phi i32 [ %19, %21 ], [ 0, %10 ]
br label %15
15: ; preds = %18, %11
%16 = phi i32 [ %13, %11 ], [ 1, %18 ]
%17 = phi i32 [ %14, %11 ], [ %19, %18 ]
br label %18
18: ; preds = %18, %15
%19 = phi i32 [ %17, %15 ], [ 1, %18 ]
%20 = 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 %20, label %23 [
i32 -1, label %25
i32 99, label %21
i32 100, label %15
i32 117, label %18
]
21: ; preds = %18
%22 = load i8*, i8** @optarg
br label %11
23: ; preds = %18
%24 = tail call i32 (...) @abort()
unreachable
25: ; preds = %18
%26 = tail call %struct.multi_config* @multi_core_initialize_config(i8* %12, i32 %19)
%27 = icmp eq %struct.multi_config* %26, null
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str, i64 0, i64 0))
%30 = tail call i32 (...) @abort()
unreachable
31: ; preds = %25
%32 = icmp eq i32 %16, 0
br i1 %32, label %48, label %33
33: ; preds = %31
%34 = tail call i32 @daemon(i32 0, i32 0)
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %40
36: ; preds = %33
%37 = tail call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
%38 = load i32, i32* @EXIT_FAILURE
%39 = tail call i32 @exit(i32 %38)
unreachable
40: ; preds = %33
%41 = load i32, i32* @stderr
%42 = tail call i32* @freopen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i32 %41)
%43 = icmp eq i32* %42, null
br i1 %43, label %44, label %48
44: ; preds = %40
%45 = tail call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0))
%46 = load i32, i32* @EXIT_FAILURE
%47 = tail call i32 @exit(i32 %46)
unreachable
48: ; preds = %40, %31
%49 = tail call i32 @multi_test_visible_loop(%struct.multi_config* %26)
ret i32 0
}