#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_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ restart_network();
scalar_t__ setuid(int /*<<< orphan*/);
int /*<<< orphan*/ show_usage();
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin_to_cfgfile(int);
scalar_t__ strcmp(char *, char *);
int main(int argc, char **argv) {
  if (setuid(0) != 0) {
    fprintf(stderr, "Unable to setuid(%d)\n", 0);
    exit(EXIT_FAILURE);
  }
  if (argc != 2)
    show_usage();
  if (strcmp("restart", argv[1]) == 0) {
    printf("Restarting network\n");
    exit(restart_network());
  } else if (strcmp("resolv", argv[1]) == 0)
    stdin_to_cfgfile(1);
  else if (strcmp("netconfig", argv[1]) == 0)
    stdin_to_cfgfile(2);
  else
    show_usage();
  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)
xor    %edi,%edi
call   10a0 <setuid@plt>
cmp    $0x0,%rax
je     11cc <main+0x4c>
mov    0x2e32(%rip),%rax
mov    (%rax),%edi
lea    0xe49(%rip),%rsi
xor    %edx,%edx
call   1070 <fprintf@plt>
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
cmpl   $0x2,-0x8(%rbp)
je     11dd <main+0x5d>
mov    $0x0,%al
call   1080 <show_usage@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe2a(%rip),%rdi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1215 <main+0x95>
lea    0xe1c(%rip),%rdi
call   1050 <printf@plt>
mov    $0x0,%al
call   1030 <restart_network@plt>
mov    %eax,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe0e(%rip),%rdi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1242 <main+0xc2>
mov    $0x1,%edi
call   1040 <stdin_to_cfgfile@plt>
jmp    127b <main+0xfb>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xde8(%rip),%rdi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    126f <main+0xef>
mov    $0x2,%edi
call   1040 <stdin_to_cfgfile@plt>
jmp    1276 <main+0xf6>
mov    $0x0,%al
call   1080 <show_usage@plt>
jmp    127b <main+0xfb>
jmp    1280 <main+0x100>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %edi,%edi
call   10a0 <setuid@plt>
test   %rax,%rax
jne    1202 <main+0x82>
cmp    $0x2,%ebp
je     11a0 <main+0x20>
xor    %eax,%eax
call   1080 <show_usage@plt>
mov    0x8(%rbx),%rsi
lea    0xe6b(%rip),%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1227 <main+0xa7>
mov    0x8(%rbx),%rsi
lea    0xe5e(%rip),%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11e8 <main+0x68>
mov    0x8(%rbx),%rsi
lea    0xe50(%rip),%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11ef <main+0x6f>
xor    %eax,%eax
call   1080 <show_usage@plt>
jmp    11f9 <main+0x79>
mov    $0x1,%edi
jmp    11f4 <main+0x74>
mov    $0x2,%edi
call   1050 <stdin_to_cfgfile@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2dd7(%rip),%rax
mov    (%rax),%edi
lea    0xdee(%rip),%rsi
xor    %edx,%edx
call   1070 <fprintf@plt>
mov    0x2db8(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
lea    0xe01(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1030 <restart_network@plt>
mov    %eax,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [22 x i8] c"Unable to setuid(%d)\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [8 x i8] c"restart\00"
@.str.2 = [20 x i8] c"Restarting network\0A\00"
@.str.3 = [7 x i8] c"resolv\00"
@.str.4 = [10 x i8] c"netconfig\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 = call i64 @setuid(i32 0)
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %13
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 0)
%11 = load i32, i32* @EXIT_FAILURE
%12 = call i32 @exit(i32 %11)
unreachable
13: ; preds = %2
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 2
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = call i32 (...) @show_usage()
br label %18
18: ; preds = %16, %13
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i64 @strcmp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %21)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %18
%25 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%26 = call i32 (...) @restart_network()
%27 = call i32 @exit(i32 %26)
unreachable
28: ; preds = %18
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = call i64 @strcmp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %31)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %28
%35 = call i32 @stdin_to_cfgfile(i32 1)
br label %47
36: ; preds = %28
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 1
%39 = load i8*, i8** %38
%40 = call i64 @strcmp(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %39)
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %36
%43 = call i32 @stdin_to_cfgfile(i32 2)
br label %46
44: ; preds = %36
%45 = call i32 (...) @show_usage()
br label %46
46: ; preds = %44, %42
br label %47
47: ; preds = %46, %34
br label %48
48: ; preds = %47
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [22 x i8] c"Unable to setuid(%d)\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [8 x i8] c"restart\00"
@.str.3 = [7 x i8] c"resolv\00"
@.str.4 = [10 x i8] c"netconfig\00"
@str = [19 x i8] c"Restarting network\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i64 @setuid(i32 0)
%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 ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 0)
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %2
%11 = icmp eq i32 %0, 2
br i1 %11, label %14, label %12
12: ; preds = %10
%13 = tail call i32 (...) @show_usage()
br label %14
14: ; preds = %12, %10
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = tail call i64 @strcmp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %14
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%21 = tail call i32 (...) @restart_network()
%22 = tail call i32 @exit(i32 %21)
unreachable
23: ; preds = %14
%24 = load i8*, i8** %15
%25 = tail call i64 @strcmp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %24)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %23
%28 = tail call i32 @stdin_to_cfgfile(i32 1)
br label %37
29: ; preds = %23
%30 = load i8*, i8** %15
%31 = tail call i64 @strcmp(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %30)
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %29
%34 = tail call i32 @stdin_to_cfgfile(i32 2)
br label %37
35: ; preds = %29
%36 = tail call i32 (...) @show_usage()
br label %37
37: ; preds = %27, %35, %33
ret i32 0
}