#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*/ execve(char *, char **, char **);
char *get_serv(char const *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strcmp(char const *, char *);
int main(int argc, const char *argv[], char *env[]) {
  const char *new_argv[] = {"/sbin/ngc", NULL, NULL, NULL};
  char **environ = {NULL};
  if (!argv[1] || argc != 3) {
    argv[1] = "ifile";
    goto print_usage;
  }
  char *fixed_path = get_serv(argv[1]);
  if (!fixed_path) {
    printf("unkown service\n");
    return 1;
  }
  if (strcmp(argv[2], "start") == 0) {
    new_argv[1] = "-u";
  } else if (strcmp(argv[2], "stop") == 0) {
    new_argv[1] = "-d";
  } else if (strcmp(argv[2], "status") == 0) {
    new_argv[1] = "-s";
  } else if (strcmp(argv[2], "zap") == 0) {
    new_argv[1] = "-z";
  } else if (strcmp(argv[2], "restart") == 0) {
    new_argv[1] = "-r";
  } else {
    goto print_usage;
  }
  new_argv[2] = fixed_path;
  execve((char *)new_argv[0], (char **)new_argv, environ);
  return 0;
print_usage:
  printf("Usage: %s %s {start|stop|restart|status|zap}\n", argv[0], argv[1]);
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    0x2c9f(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0x2c9c(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0x2c99(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0x2c96(%rip),%rax
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x48(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
je     11a7 <main+0x67>
cmpl   $0x3,-0x8(%rbp)
je     11bb <main+0x7b>
mov    -0x10(%rbp),%rax
lea    0xe58(%rip),%rcx
mov    %rcx,0x8(%rax)
jmp    1315 <main+0x1d5>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <get_serv@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
jne    11f1 <main+0xb1>
lea    0xe32(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1339 <main+0x1f9>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe3e(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    121f <main+0xdf>
lea    0xe0a(%rip),%rax
mov    %rax,-0x38(%rbp)
jmp    12f0 <main+0x1b0>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xdf5(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    124d <main+0x10d>
lea    0xde4(%rip),%rax
mov    %rax,-0x38(%rbp)
jmp    12eb <main+0x1ab>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xdcf(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    127b <main+0x13b>
lea    0xdc0(%rip),%rax
mov    %rax,-0x38(%rbp)
jmp    12e6 <main+0x1a6>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xdab(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    12a9 <main+0x169>
lea    0xd99(%rip),%rax
mov    %rax,-0x38(%rbp)
jmp    12e1 <main+0x1a1>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xd84(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    12d7 <main+0x197>
lea    0xd76(%rip),%rax
mov    %rax,-0x38(%rbp)
jmp    12dc <main+0x19c>
jmp    1315 <main+0x1d5>
jmp    12e1 <main+0x1a1>
jmp    12e6 <main+0x1a6>
jmp    12eb <main+0x1ab>
jmp    12f0 <main+0x1b0>
mov    -0x50(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x40(%rbp),%rdi
lea    -0x40(%rbp),%rsi
mov    -0x48(%rbp),%rdx
call   1050 <execve@plt>
movl   $0x0,-0x4(%rbp)
jmp    1339 <main+0x1f9>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xd1c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rbx
movaps 0x2caf(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0x2c93(%rip),%xmm0
movaps %xmm0,(%rsp)
cmp    $0x3,%edi
jne    120b <main+0xbb>
mov    0x8(%rbx),%rdi
test   %rdi,%rdi
je     120b <main+0xbb>
call   1050 <get_serv@plt>
test   %rax,%rax
je     1229 <main+0xd9>
mov    %rax,%r14
mov    0x10(%rbx),%rdi
lea    0xe8b(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     123c <main+0xec>
mov    0x10(%rbx),%rdi
lea    0xe57(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1245 <main+0xf5>
mov    0x10(%rbx),%rdi
lea    0xe4a(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     124e <main+0xfe>
mov    0x10(%rbx),%rdi
lea    0xe3f(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1257 <main+0x107>
mov    0x10(%rbx),%rdi
lea    0xe31(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1260 <main+0x110>
mov    0x8(%rbx),%rdx
jmp    1216 <main+0xc6>
lea    0xdf8(%rip),%rdx
mov    %rdx,0x8(%rbx)
mov    (%rbx),%rsi
lea    0xe17(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1235 <main+0xe5>
lea    0xe35(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebx
jmp    1284 <main+0x134>
lea    0xdcd(%rip),%rax
jmp    1267 <main+0x117>
lea    0xdcc(%rip),%rax
jmp    1267 <main+0x117>
lea    0xdcd(%rip),%rax
jmp    1267 <main+0x117>
lea    0xdcb(%rip),%rax
jmp    1267 <main+0x117>
lea    0xdcd(%rip),%rax
mov    %rax,0x8(%rsp)
mov    %r14,0x10(%rsp)
lea    0xd88(%rip),%rdi
xor    %ebx,%ebx
mov    %rsp,%rsi
xor    %edx,%edx
call   1060 <execve@plt>
mov    %ebx,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [10 x i8] c"/sbin/ngc\00"
@__const.main.new_argv = [4 x i8*] [i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i32 0, i32 0), i8* null, i8* null, i8* null]
@.str.1 = [6 x i8] c"ifile\00"
@.str.2 = [16 x i8] c"unkown service\0A\00"
@.str.3 = [6 x i8] c"start\00"
@.str.4 = [3 x i8] c"-u\00"
@.str.5 = [5 x i8] c"stop\00"
@.str.6 = [3 x i8] c"-d\00"
@.str.7 = [7 x i8] c"status\00"
@.str.8 = [3 x i8] c"-s\00"
@.str.9 = [4 x i8] c"zap\00"
@.str.10 = [3 x i8] c"-z\00"
@.str.11 = [8 x i8] c"restart\00"
@.str.12 = [3 x i8] c"-r\00"
@.str.13 = [46 x i8] c"Usage: %s %s {start|stop|restart|status|zap}\0A\00"
define i32 @main(i32 %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca [4 x i8*]
%9 = alloca i8**
%10 = alloca i8*
store i32 0, i32* %4
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
%11 = bitcast [4 x i8*]* %8 to i8*
store i8** null, i8*** %9
%12 = load i8**, i8*** %6
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %19
16: ; preds = %3
%17 = load i32, i32* %5
%18 = icmp ne i32 %17, 3
br i1 %18, label %19, label %22
19: ; preds = %16, %3
%20 = load i8**, i8*** %6
%21 = getelementptr inbounds i8*, i8** %20, i64 1
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8** %21
br label %84
22: ; preds = %16
%23 = load i8**, i8*** %6
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i8* @get_serv(i8* %25)
store i8* %26, i8** %10
%27 = load i8*, i8** %10
%28 = icmp ne i8* %27, null
br i1 %28, label %31, label %29
29: ; preds = %22
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %4
br label %92
31: ; preds = %22
%32 = load i8**, i8*** %6
%33 = getelementptr inbounds i8*, i8** %32, i64 2
%34 = load i8*, i8** %33
%35 = call i64 @strcmp(i8* %34, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %31
%38 = getelementptr inbounds [4 x i8*], [4 x i8*]* %8, i64 0, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8** %38
br label %76
39: ; preds = %31
%40 = load i8**, i8*** %6
%41 = getelementptr inbounds i8*, i8** %40, i64 2
%42 = load i8*, i8** %41
%43 = call i64 @strcmp(i8* %42, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %39
%46 = getelementptr inbounds [4 x i8*], [4 x i8*]* %8, i64 0, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8** %46
br label %75
47: ; preds = %39
%48 = load i8**, i8*** %6
%49 = getelementptr inbounds i8*, i8** %48, i64 2
%50 = load i8*, i8** %49
%51 = call i64 @strcmp(i8* %50, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
%52 = icmp eq i64 %51, 0
br i1 %52, label %53, label %55
53: ; preds = %47
%54 = getelementptr inbounds [4 x i8*], [4 x i8*]* %8, i64 0, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i8** %54
br label %74
55: ; preds = %47
%56 = load i8**, i8*** %6
%57 = getelementptr inbounds i8*, i8** %56, i64 2
%58 = load i8*, i8** %57
%59 = call i64 @strcmp(i8* %58, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0))
%60 = icmp eq i64 %59, 0
br i1 %60, label %61, label %63
61: ; preds = %55
%62 = getelementptr inbounds [4 x i8*], [4 x i8*]* %8, i64 0, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0), i8** %62
br label %73
63: ; preds = %55
%64 = load i8**, i8*** %6
%65 = getelementptr inbounds i8*, i8** %64, i64 2
%66 = load i8*, i8** %65
%67 = call i64 @strcmp(i8* %66, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.11, i64 0, i64 0))
%68 = icmp eq i64 %67, 0
br i1 %68, label %69, label %71
69: ; preds = %63
%70 = getelementptr inbounds [4 x i8*], [4 x i8*]* %8, i64 0, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.12, i64 0, i64 0), i8** %70
br label %72
71: ; preds = %63
br label %84
72: ; preds = %69
br label %73
73: ; preds = %72, %61
br label %74
74: ; preds = %73, %53
br label %75
75: ; preds = %74, %45
br label %76
76: ; preds = %75, %37
%77 = load i8*, i8** %10
%78 = getelementptr inbounds [4 x i8*], [4 x i8*]* %8, i64 0, i64 2
store i8* %77, i8** %78
%79 = getelementptr inbounds [4 x i8*], [4 x i8*]* %8, i64 0, i64 0
%80 = load i8*, i8** %79
%81 = getelementptr inbounds [4 x i8*], [4 x i8*]* %8, i64 0, i64 0
%82 = load i8**, i8*** %9
%83 = call i32 @execve(i8* %80, i8** %81, i8** %82)
store i32 0, i32* %4
br label %92
84: ; preds = %71, %19
%85 = load i8**, i8*** %6
%86 = getelementptr inbounds i8*, i8** %85, i64 0
%87 = load i8*, i8** %86
%88 = load i8**, i8*** %6
%89 = getelementptr inbounds i8*, i8** %88, i64 1
%90 = load i8*, i8** %89
%91 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.13, i64 0, i64 0), i8* %87, i8* %90)
store i32 1, i32* %4
br label %92
92: ; preds = %84, %76, %29
%93 = load i32, i32* %4
ret i32 %93
}

LLVM IR (-O2):
@.str = [10 x i8] c"/sbin/ngc\00"
@__const.main.new_argv = [4 x i8*] [i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i32 0, i32 0), i8* null, i8* null, i8* null]
@.str.1 = [6 x i8] c"ifile\00"
@.str.3 = [6 x i8] c"start\00"
@.str.4 = [3 x i8] c"-u\00"
@.str.5 = [5 x i8] c"stop\00"
@.str.6 = [3 x i8] c"-d\00"
@.str.7 = [7 x i8] c"status\00"
@.str.8 = [3 x i8] c"-s\00"
@.str.9 = [4 x i8] c"zap\00"
@.str.10 = [3 x i8] c"-z\00"
@.str.11 = [8 x i8] c"restart\00"
@.str.12 = [3 x i8] c"-r\00"
@.str.13 = [46 x i8] c"Usage: %s %s {start|stop|restart|status|zap}\0A\00"
@str = [15 x i8] c"unkown service\00"
define i32 @main(i32 %0, i8** nocapture %1, i8** nocapture readnone %2) {
%4 = alloca [4 x i8*]
%5 = bitcast [4 x i8*]* %4 to i8*
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = icmp eq i8* %7, null
%9 = icmp ne i32 %0, 3
%10 = or i1 %9, %8
br i1 %10, label %11, label %12
11: ; preds = %3
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8** %6
br label %46
12: ; preds = %3
%13 = tail call i8* @get_serv(i8* %7)
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
br label %50
17: ; preds = %12
%18 = getelementptr inbounds i8*, i8** %1, i64 2
%19 = load i8*, i8** %18
%20 = tail call i64 @strcmp(i8* %19, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %40, label %22
22: ; preds = %17
%23 = load i8*, i8** %18
%24 = tail call i64 @strcmp(i8* %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
br i1 %25, label %40, label %26
26: ; preds = %22
%27 = load i8*, i8** %18
%28 = tail call i64 @strcmp(i8* %27, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
%29 = icmp eq i64 %28, 0
br i1 %29, label %40, label %30
30: ; preds = %26
%31 = load i8*, i8** %18
%32 = tail call i64 @strcmp(i8* %31, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0))
%33 = icmp eq i64 %32, 0
br i1 %33, label %40, label %34
34: ; preds = %30
%35 = load i8*, i8** %18
%36 = tail call i64 @strcmp(i8* %35, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.11, i64 0, i64 0))
%37 = icmp eq i64 %36, 0
br i1 %37, label %40, label %38
38: ; preds = %34
%39 = load i8*, i8** %6
br label %46
40: ; preds = %34, %30, %26, %22, %17
%41 = phi i8* [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), %17 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), %22 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), %26 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0), %30 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.12, i64 0, i64 0), %34 ]
%42 = getelementptr inbounds [4 x i8*], [4 x i8*]* %4, i64 0, i64 1
store i8* %41, i8** %42
%43 = getelementptr inbounds [4 x i8*], [4 x i8*]* %4, i64 0, i64 2
store i8* %13, i8** %43
%44 = getelementptr inbounds [4 x i8*], [4 x i8*]* %4, i64 0, i64 0
%45 = call i32 @execve(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %44, i8** null)
br label %50
46: ; preds = %38, %11
%47 = phi i8* [ %39, %38 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), %11 ]
%48 = load i8*, i8** %1
%49 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.13, i64 0, i64 0), i8* %48, i8* %47)
br label %50
50: ; preds = %46, %40, %15
%51 = phi i32 [ 1, %46 ], [ 0, %40 ], [ 1, %15 ]
ret i32 %51
}