#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 /*<<< orphan*/ updateScript;

/* Variables and functions */
int WEXITSTATUS(int);
int /*<<< orphan*/ dirname(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ setuid(int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strncat(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
int system(char *);
int main(int argc, char *argv[]) {
  setuid(0);
  char cmd[255];
  if (argc > 1) {
    if ((strcmp(argv[1], "stop") == 0) || (strcmp(argv[1], "start") == 0) ||
        (strcmp(argv[1], "restart") == 0) || (strcmp(argv[1], "debug") == 0)) {
      sprintf(cmd, "/etc/init.d/mycodo %s", argv[1]);
      system(cmd);
    } else if (strcmp(argv[1], "restore") == 0 && (argc > 2)) {
      char updateScript[255];
      strncpy(updateScript, argv[0], sizeof(updateScript));
      dirname(updateScript);
      sprintf(cmd, "/../restore-mycodo.sh restore %s", argv[2]);
      strncat(updateScript, cmd, sizeof(updateScript));
      system(updateScript);
    } else if (strcmp(argv[1], "delete") == 0 && (argc > 2)) {
      sprintf(cmd, "rm -rf %s", argv[2]);
      system(cmd);
    } else if (strcmp(argv[1], "backup") == 0) {
      char updateScript[255];
      strncpy(updateScript, argv[0], sizeof(updateScript));
      dirname(updateScript);
      strncat(updateScript, "/../update-mycodo.sh backup",
              sizeof(updateScript));
      system(updateScript);
    } else if (strcmp(argv[1], "update") == 0) {
      char updateScript[255];
      strncpy(updateScript, argv[0], sizeof(updateScript));
      dirname(updateScript);
      strncat(updateScript, "/../update-mycodo.sh update",
              sizeof(updateScript));
      system(updateScript);
    } else if (strcmp(argv[1], "updatecheck") == 0) {
      char updateScript[255];
      strncpy(updateScript, argv[0], sizeof(updateScript));
      dirname(updateScript);
      strncat(updateScript, "/../update-mycodo.sh updatecheck",
              sizeof(updateScript));
      int status;
      if ((status = system(updateScript)) != -1) {
        return WEXITSTATUS(status);
      }
    } else if (strcmp(argv[1], "fetchorigin") == 0) {
      char updateScript[255];
      strncpy(updateScript, argv[0], sizeof(updateScript));
      dirname(updateScript);
      strncat(updateScript, "/../update-mycodo.sh fetchorigin",
              sizeof(updateScript));
      system(updateScript);
    }
  } else {
    printf("mycodo-wrapper: A wrapper to allow the mycodo web interface\n");
    printf("                to stop and start the daemon and update the\n");
    printf("                mycodo system to the latest version.\n\n");
    printf("Usage: mycodo-wrapper stop|start|restart|debug|update|restore "
           "[commit]\n\n");
    printf("Options:\n");
    printf("   stop:             Stop the mycodo daemon\n");
    printf("   start:            Start the mycodo daemon\n");
    printf("   restart:          Restart the mycodo daemon in normal mode\n");
    printf("   debug:            Restart the mycodo daemon in debug mode\n");
    printf(
        "   update:           Update Mycodo to the latest version on github\n");
    printf("   restore [commit]: Restore Mycodo to a backed up version\n");
    printf("   updatecheck:      Check for a newer version of Mycodo on "
           "github\n\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x620,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %edi,%edi
call   10b0 <setuid@plt>
cmpl   $0x1,-0x8(%rbp)
jle    152e <main+0x39e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe37(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
je     1232 <main+0xa2>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe20(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
je     1232 <main+0xa2>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe00(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
je     1232 <main+0xa2>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdea(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    125e <main+0xce>
lea    -0x110(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xdcb(%rip),%rsi
call   10a0 <sprintf@plt>
lea    -0x110(%rbp),%rdi
call   1040 <system@plt>
jmp    1529 <main+0x399>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdbc(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    12ee <main+0x15e>
cmpl   $0x2,-0x8(%rbp)
jle    12ee <main+0x15e>
lea    -0x210(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    $0xff,%edx
call   1030 <strncpy@plt>
lea    -0x210(%rbp),%rdi
call   1060 <dirname@plt>
lea    -0x110(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xd71(%rip),%rsi
call   10a0 <sprintf@plt>
lea    -0x210(%rbp),%rdi
lea    -0x110(%rbp),%rsi
mov    $0xff,%edx
call   1070 <strncat@plt>
lea    -0x210(%rbp),%rdi
call   1040 <system@plt>
jmp    1524 <main+0x394>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd55(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    1342 <main+0x1b2>
cmpl   $0x2,-0x8(%rbp)
jle    1342 <main+0x1b2>
lea    -0x110(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xd2d(%rip),%rsi
call   10a0 <sprintf@plt>
lea    -0x110(%rbp),%rdi
call   1040 <system@plt>
jmp    151f <main+0x38f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd27(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    13ad <main+0x21d>
lea    -0x310(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    $0xff,%edx
call   1030 <strncpy@plt>
lea    -0x310(%rbp),%rdi
call   1060 <dirname@plt>
lea    -0x310(%rbp),%rdi
lea    0xcd1(%rip),%rsi
mov    $0xff,%edx
call   1070 <strncat@plt>
lea    -0x310(%rbp),%rdi
call   1040 <system@plt>
jmp    151a <main+0x38a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xcd8(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    1418 <main+0x288>
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    $0xff,%edx
call   1030 <strncpy@plt>
lea    -0x410(%rbp),%rdi
call   1060 <dirname@plt>
lea    -0x410(%rbp),%rdi
lea    0xc82(%rip),%rsi
mov    $0xff,%edx
call   1070 <strncat@plt>
lea    -0x410(%rbp),%rdi
call   1040 <system@plt>
jmp    1515 <main+0x385>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xc89(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    14a5 <main+0x315>
lea    -0x510(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    $0xff,%edx
call   1030 <strncpy@plt>
lea    -0x510(%rbp),%rdi
call   1060 <dirname@plt>
lea    -0x510(%rbp),%rdi
lea    0xc33(%rip),%rsi
mov    $0xff,%edx
call   1070 <strncat@plt>
lea    -0x510(%rbp),%rdi
call   1040 <system@plt>
mov    %eax,-0x514(%rbp)
cmp    $0xffffffff,%eax
je     14a0 <main+0x310>
mov    -0x514(%rbp),%edi
call   1090 <WEXITSTATUS@plt>
mov    %eax,-0x4(%rbp)
jmp    15c5 <main+0x435>
jmp    1510 <main+0x380>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xc1d(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    150b <main+0x37b>
lea    -0x620(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    $0xff,%edx
call   1030 <strncpy@plt>
lea    -0x620(%rbp),%rdi
call   1060 <dirname@plt>
lea    -0x620(%rbp),%rdi
lea    0xbc7(%rip),%rsi
mov    $0xff,%edx
call   1070 <strncat@plt>
lea    -0x620(%rbp),%rdi
call   1040 <system@plt>
jmp    1510 <main+0x380>
jmp    1515 <main+0x385>
jmp    151a <main+0x38a>
jmp    151f <main+0x38f>
jmp    1524 <main+0x394>
jmp    1529 <main+0x399>
jmp    15be <main+0x42e>
lea    0xba8(%rip),%rdi
call   1050 <printf@plt>
lea    0xbd9(%rip),%rdi
call   1050 <printf@plt>
lea    0xc0a(%rip),%rdi
call   1050 <printf@plt>
lea    0xc35(%rip),%rdi
call   1050 <printf@plt>
lea    0xc72(%rip),%rdi
call   1050 <printf@plt>
lea    0xc70(%rip),%rdi
call   1050 <printf@plt>
lea    0xc91(%rip),%rdi
call   1050 <printf@plt>
lea    0xcb3(%rip),%rdi
call   1050 <printf@plt>
lea    0xce6(%rip),%rdi
call   1050 <printf@plt>
lea    0xd18(%rip),%rdi
call   1050 <printf@plt>
lea    0xd50(%rip),%rdi
call   1050 <printf@plt>
lea    0xd80(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x620,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x200,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %r14d,%r14d
xor    %edi,%edi
call   10b0 <setuid@plt>
cmp    $0x2,%ebp
jl     1287 <main+0xf7>
mov    0x8(%rbx),%rdi
lea    0xe42(%rip),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1319 <main+0x189>
mov    0x8(%rbx),%rdi
lea    0xe30(%rip),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1319 <main+0x189>
mov    0x8(%rbx),%rdi
lea    0xe15(%rip),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1319 <main+0x189>
mov    0x8(%rbx),%rdi
lea    0xe04(%rip),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1319 <main+0x189>
mov    0x8(%rbx),%rdi
lea    0xe07(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x3,%ebp
jb     1346 <main+0x1b6>
test   %rax,%rax
jne    1346 <main+0x1b6>
mov    (%rbx),%rsi
lea    0x100(%rsp),%rbp
mov    %rbp,%rdi
mov    $0xff,%edx
call   1030 <strncpy@plt>
mov    %rbp,%rdi
call   1060 <dirname@plt>
mov    0x10(%rbx),%rdx
lea    0xdcd(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   10a0 <sprintf@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    $0xff,%edx
call   1070 <strncat@plt>
mov    %rbp,%rdi
jmp    1332 <main+0x1a2>
lea    0xe4f(%rip),%rdi
call   1040 <puts@plt>
lea    0xe7f(%rip),%rdi
call   1040 <puts@plt>
lea    0xeaf(%rip),%rdi
call   1040 <puts@plt>
lea    0xed9(%rip),%rdi
call   1040 <puts@plt>
lea    0xf15(%rip),%rdi
call   1040 <puts@plt>
lea    0xf12(%rip),%rdi
call   1040 <puts@plt>
lea    0xf32(%rip),%rdi
call   1040 <puts@plt>
lea    0xf53(%rip),%rdi
call   1040 <puts@plt>
lea    0xf85(%rip),%rdi
call   1040 <puts@plt>
lea    0xfb6(%rip),%rdi
call   1040 <puts@plt>
lea    0xfed(%rip),%rdi
call   1040 <puts@plt>
lea    0x101c(%rip),%rdi
call   1040 <puts@plt>
jmp    1337 <main+0x1a7>
mov    0x8(%rbx),%rdx
lea    0xcef(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   10a0 <sprintf@plt>
mov    %rbx,%rdi
call   1050 <system@plt>
mov    %r14d,%eax
add    $0x200,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x8(%rbx),%rdi
lea    0xd01(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x3,%ebp
jb     136d <main+0x1dd>
test   %rax,%rax
jne    136d <main+0x1dd>
mov    0x10(%rbx),%rdx
lea    0xcee(%rip),%rsi
jmp    1324 <main+0x194>
mov    0x8(%rbx),%rdi
lea    0xd00(%rip),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     13ed <main+0x25d>
mov    0x8(%rbx),%rdi
lea    0xd07(%rip),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1411 <main+0x281>
mov    0x8(%rbx),%rdi
lea    0xd0e(%rip),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1445 <main+0x2b5>
mov    0x8(%rbx),%rdi
lea    0xd16(%rip),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
jne    1337 <main+0x1a7>
mov    (%rbx),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0xff,%edx
call   1030 <strncpy@plt>
mov    %rbx,%rdi
call   1060 <dirname@plt>
lea    0xcd1(%rip),%rsi
jmp    1433 <main+0x2a3>
mov    (%rbx),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0xff,%edx
call   1030 <strncpy@plt>
mov    %rbx,%rdi
call   1060 <dirname@plt>
lea    0xc54(%rip),%rsi
jmp    1433 <main+0x2a3>
mov    (%rbx),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0xff,%edx
call   1030 <strncpy@plt>
mov    %rbx,%rdi
call   1060 <dirname@plt>
lea    0xc4c(%rip),%rsi
mov    %rbx,%rdi
mov    $0xff,%edx
call   1070 <strncat@plt>
jmp    132f <main+0x19f>
mov    (%rbx),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0xff,%edx
call   1030 <strncpy@plt>
mov    %rbx,%rdi
call   1060 <dirname@plt>
lea    0xc34(%rip),%rsi
mov    %rbx,%rdi
mov    $0xff,%edx
call   1070 <strncat@plt>
mov    %rbx,%rdi
call   1050 <system@plt>
cmp    $0xffffffff,%eax
je     1337 <main+0x1a7>
mov    %eax,%edi
call   1090 <WEXITSTATUS@plt>
mov    %eax,%r14d
jmp    1337 <main+0x1a7>

LLVM IR (-O0):
@.str = [5 x i8] c"stop\00"
@.str.1 = [6 x i8] c"start\00"
@.str.2 = [8 x i8] c"restart\00"
@.str.3 = [6 x i8] c"debug\00"
@.str.4 = [22 x i8] c"/etc/init.d/mycodo %s\00"
@.str.5 = [8 x i8] c"restore\00"
@.str.6 = [33 x i8] c"/../restore-mycodo.sh restore %s\00"
@.str.7 = [7 x i8] c"delete\00"
@.str.8 = [10 x i8] c"rm -rf %s\00"
@.str.9 = [7 x i8] c"backup\00"
@.str.10 = [28 x i8] c"/../update-mycodo.sh backup\00"
@.str.11 = [7 x i8] c"update\00"
@.str.12 = [28 x i8] c"/../update-mycodo.sh update\00"
@.str.13 = [12 x i8] c"updatecheck\00"
@.str.14 = [33 x i8] c"/../update-mycodo.sh updatecheck\00"
@.str.15 = [12 x i8] c"fetchorigin\00"
@.str.16 = [33 x i8] c"/../update-mycodo.sh fetchorigin\00"
@.str.17 = [61 x i8] c"mycodo-wrapper: A wrapper to allow the mycodo web interface\0A\00"
@.str.18 = [61 x i8] c" to stop and start the daemon and update the\0A\00"
@.str.19 = [55 x i8] c" mycodo system to the latest version.\0A\0A\00"
@.str.20 = [73 x i8] c"Usage: mycodo-wrapper stop|start|restart|debug|update|restore [commit]\0A\0A\00"
@.str.21 = [10 x i8] c"Options:\0A\00"
@.str.22 = [45 x i8] c" stop: Stop the mycodo daemon\0A\00"
@.str.23 = [46 x i8] c" start: Start the mycodo daemon\0A\00"
@.str.24 = [63 x i8] c" restart: Restart the mycodo daemon in normal mode\0A\00"
@.str.25 = [62 x i8] c" debug: Restart the mycodo daemon in debug mode\0A\00"
@.str.26 = [68 x i8] c" update: Update Mycodo to the latest version on github\0A\00"
@.str.27 = [60 x i8] c" restore [commit]: Restore Mycodo to a backed up version\0A\00"
@.str.28 = [69 x i8] c" updatecheck: Check for a newer version of Mycodo on github\0A\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [255 x i8]
%7 = alloca [255 x i8]
%8 = alloca [255 x i8]
%9 = alloca [255 x i8]
%10 = alloca [255 x i8]
%11 = alloca i32
%12 = alloca [255 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = call i32 @setuid(i32 0)
%14 = load i32, i32* %4
%15 = icmp sgt i32 %14, 1
br i1 %15, label %16, label %176
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i64 @strcmp(i8* %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %40, label %22
22: ; preds = %16
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i64 @strcmp(i8* %25, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br i1 %27, label %40, label %28
28: ; preds = %22
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = call i64 @strcmp(i8* %31, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%33 = icmp eq i64 %32, 0
br i1 %33, label %40, label %34
34: ; preds = %28
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 1
%37 = load i8*, i8** %36
%38 = call i64 @strcmp(i8* %37, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %48
40: ; preds = %34, %28, %22, %16
%41 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 1
%44 = load i8*, i8** %43
%45 = call i32 @sprintf(i8* %41, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i8* %44)
%46 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%47 = call i32 @system(i8* %46)
br label %175
48: ; preds = %34
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i64 1
%51 = load i8*, i8** %50
%52 = call i64 @strcmp(i8* %51, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
%53 = icmp eq i64 %52, 0
br i1 %53, label %54, label %75
54: ; preds = %48
%55 = load i32, i32* %4
%56 = icmp sgt i32 %55, 2
br i1 %56, label %57, label %75
57: ; preds = %54
%58 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 0
%59 = load i8**, i8*** %5
%60 = getelementptr inbounds i8*, i8** %59, i64 0
%61 = load i8*, i8** %60
%62 = call i32 @strncpy(i8* %58, i8* %61, i32 255)
%63 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 0
%64 = call i32 @dirname(i8* %63)
%65 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%66 = load i8**, i8*** %5
%67 = getelementptr inbounds i8*, i8** %66, i64 2
%68 = load i8*, i8** %67
%69 = call i32 @sprintf(i8* %65, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0), i8* %68)
%70 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 0
%71 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%72 = call i32 @strncat(i8* %70, i8* %71, i32 255)
%73 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 0
%74 = call i32 @system(i8* %73)
br label %174
75: ; preds = %54, %48
%76 = load i8**, i8*** %5
%77 = getelementptr inbounds i8*, i8** %76, i64 1
%78 = load i8*, i8** %77
%79 = call i64 @strcmp(i8* %78, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
%80 = icmp eq i64 %79, 0
br i1 %80, label %81, label %92
81: ; preds = %75
%82 = load i32, i32* %4
%83 = icmp sgt i32 %82, 2
br i1 %83, label %84, label %92
84: ; preds = %81
%85 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%86 = load i8**, i8*** %5
%87 = getelementptr inbounds i8*, i8** %86, i64 2
%88 = load i8*, i8** %87
%89 = call i32 @sprintf(i8* %85, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i8* %88)
%90 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%91 = call i32 @system(i8* %90)
br label %173
92: ; preds = %81, %75
%93 = load i8**, i8*** %5
%94 = getelementptr inbounds i8*, i8** %93, i64 1
%95 = load i8*, i8** %94
%96 = call i64 @strcmp(i8* %95, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0))
%97 = icmp eq i64 %96, 0
br i1 %97, label %98, label %110
98: ; preds = %92
%99 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%100 = load i8**, i8*** %5
%101 = getelementptr inbounds i8*, i8** %100, i64 0
%102 = load i8*, i8** %101
%103 = call i32 @strncpy(i8* %99, i8* %102, i32 255)
%104 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%105 = call i32 @dirname(i8* %104)
%106 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%107 = call i32 @strncat(i8* %106, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.10, i64 0, i64 0), i32 255)
%108 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%109 = call i32 @system(i8* %108)
br label %172
110: ; preds = %92
%111 = load i8**, i8*** %5
%112 = getelementptr inbounds i8*, i8** %111, i64 1
%113 = load i8*, i8** %112
%114 = call i64 @strcmp(i8* %113, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i64 0, i64 0))
%115 = icmp eq i64 %114, 0
br i1 %115, label %116, label %128
116: ; preds = %110
%117 = getelementptr inbounds [255 x i8], [255 x i8]* %9, i64 0, i64 0
%118 = load i8**, i8*** %5
%119 = getelementptr inbounds i8*, i8** %118, i64 0
%120 = load i8*, i8** %119
%121 = call i32 @strncpy(i8* %117, i8* %120, i32 255)
%122 = getelementptr inbounds [255 x i8], [255 x i8]* %9, i64 0, i64 0
%123 = call i32 @dirname(i8* %122)
%124 = getelementptr inbounds [255 x i8], [255 x i8]* %9, i64 0, i64 0
%125 = call i32 @strncat(i8* %124, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.12, i64 0, i64 0), i32 255)
%126 = getelementptr inbounds [255 x i8], [255 x i8]* %9, i64 0, i64 0
%127 = call i32 @system(i8* %126)
br label %171
128: ; preds = %110
%129 = load i8**, i8*** %5
%130 = getelementptr inbounds i8*, i8** %129, i64 1
%131 = load i8*, i8** %130
%132 = call i64 @strcmp(i8* %131, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.13, i64 0, i64 0))
%133 = icmp eq i64 %132, 0
br i1 %133, label %134, label %151
134: ; preds = %128
%135 = getelementptr inbounds [255 x i8], [255 x i8]* %10, i64 0, i64 0
%136 = load i8**, i8*** %5
%137 = getelementptr inbounds i8*, i8** %136, i64 0
%138 = load i8*, i8** %137
%139 = call i32 @strncpy(i8* %135, i8* %138, i32 255)
%140 = getelementptr inbounds [255 x i8], [255 x i8]* %10, i64 0, i64 0
%141 = call i32 @dirname(i8* %140)
%142 = getelementptr inbounds [255 x i8], [255 x i8]* %10, i64 0, i64 0
%143 = call i32 @strncat(i8* %142, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.14, i64 0, i64 0), i32 255)
%144 = getelementptr inbounds [255 x i8], [255 x i8]* %10, i64 0, i64 0
%145 = call i32 @system(i8* %144)
store i32 %145, i32* %11
%146 = icmp ne i32 %145, -1
br i1 %146, label %147, label %150
147: ; preds = %134
%148 = load i32, i32* %11
%149 = call i32 @WEXITSTATUS(i32 %148)
store i32 %149, i32* %3
br label %190
150: ; preds = %134
br label %170
151: ; preds = %128
%152 = load i8**, i8*** %5
%153 = getelementptr inbounds i8*, i8** %152, i64 1
%154 = load i8*, i8** %153
%155 = call i64 @strcmp(i8* %154, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.15, i64 0, i64 0))
%156 = icmp eq i64 %155, 0
br i1 %156, label %157, label %169
157: ; preds = %151
%158 = getelementptr inbounds [255 x i8], [255 x i8]* %12, i64 0, i64 0
%159 = load i8**, i8*** %5
%160 = getelementptr inbounds i8*, i8** %159, i64 0
%161 = load i8*, i8** %160
%162 = call i32 @strncpy(i8* %158, i8* %161, i32 255)
%163 = getelementptr inbounds [255 x i8], [255 x i8]* %12, i64 0, i64 0
%164 = call i32 @dirname(i8* %163)
%165 = getelementptr inbounds [255 x i8], [255 x i8]* %12, i64 0, i64 0
%166 = call i32 @strncat(i8* %165, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.16, i64 0, i64 0), i32 255)
%167 = getelementptr inbounds [255 x i8], [255 x i8]* %12, i64 0, i64 0
%168 = call i32 @system(i8* %167)
br label %169
169: ; preds = %157, %151
br label %170
170: ; preds = %169, %150
br label %171
171: ; preds = %170, %116
br label %172
172: ; preds = %171, %98
br label %173
173: ; preds = %172, %84
br label %174
174: ; preds = %173, %57
br label %175
175: ; preds = %174, %40
br label %189
176: ; preds = %2
%177 = call i32 @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.17, i64 0, i64 0))
%178 = call i32 @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.18, i64 0, i64 0))
%179 = call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.19, i64 0, i64 0))
%180 = call i32 @printf(i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str.20, i64 0, i64 0))
%181 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.21, i64 0, i64 0))
%182 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.22, i64 0, i64 0))
%183 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.23, i64 0, i64 0))
%184 = call i32 @printf(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.24, i64 0, i64 0))
%185 = call i32 @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.25, i64 0, i64 0))
%186 = call i32 @printf(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.26, i64 0, i64 0))
%187 = call i32 @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.27, i64 0, i64 0))
%188 = call i32 @printf(i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.28, i64 0, i64 0))
br label %189
189: ; preds = %176, %175
store i32 0, i32* %3
br label %190
190: ; preds = %189, %147
%191 = load i32, i32* %3
ret i32 %191
}

LLVM IR (-O2):
@.str = [5 x i8] c"stop\00"
@.str.1 = [6 x i8] c"start\00"
@.str.2 = [8 x i8] c"restart\00"
@.str.3 = [6 x i8] c"debug\00"
@.str.4 = [22 x i8] c"/etc/init.d/mycodo %s\00"
@.str.5 = [8 x i8] c"restore\00"
@.str.6 = [33 x i8] c"/../restore-mycodo.sh restore %s\00"
@.str.7 = [7 x i8] c"delete\00"
@.str.8 = [10 x i8] c"rm -rf %s\00"
@.str.9 = [7 x i8] c"backup\00"
@.str.10 = [28 x i8] c"/../update-mycodo.sh backup\00"
@.str.11 = [7 x i8] c"update\00"
@.str.12 = [28 x i8] c"/../update-mycodo.sh update\00"
@.str.13 = [12 x i8] c"updatecheck\00"
@.str.14 = [33 x i8] c"/../update-mycodo.sh updatecheck\00"
@.str.15 = [12 x i8] c"fetchorigin\00"
@.str.16 = [33 x i8] c"/../update-mycodo.sh fetchorigin\00"
@str = [60 x i8] c"mycodo-wrapper: A wrapper to allow the mycodo web interface\00"
@str.29 = [60 x i8] c" to stop and start the daemon and update the\00"
@str.30 = [54 x i8] c" mycodo system to the latest version.\0A\00"
@str.31 = [72 x i8] c"Usage: mycodo-wrapper stop|start|restart|debug|update|restore [commit]\0A\00"
@str.32 = [9 x i8] c"Options:\00"
@str.33 = [44 x i8] c" stop: Stop the mycodo daemon\00"
@str.34 = [45 x i8] c" start: Start the mycodo daemon\00"
@str.35 = [62 x i8] c" restart: Restart the mycodo daemon in normal mode\00"
@str.36 = [61 x i8] c" debug: Restart the mycodo daemon in debug mode\00"
@str.37 = [67 x i8] c" update: Update Mycodo to the latest version on github\00"
@str.38 = [59 x i8] c" restore [commit]: Restore Mycodo to a backed up version\00"
@str.39 = [68 x i8] c" updatecheck: Check for a newer version of Mycodo on github\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [255 x i8]
%4 = alloca [255 x i8]
%5 = alloca [255 x i8]
%6 = alloca [255 x i8]
%7 = alloca [255 x i8]
%8 = alloca [255 x i8]
%9 = tail call i32 @setuid(i32 0)
%10 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%11 = icmp sgt i32 %0, 1
br i1 %11, label %12, label %107
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %29, label %17
17: ; preds = %12
%18 = load i8*, i8** %13
%19 = tail call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %29, label %21
21: ; preds = %17
%22 = load i8*, i8** %13
%23 = tail call i64 @strcmp(i8* %22, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %29, label %25
25: ; preds = %21
%26 = load i8*, i8** %13
%27 = tail call i64 @strcmp(i8* %26, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %33
29: ; preds = %25, %21, %17, %12
%30 = load i8*, i8** %13
%31 = call i32 @sprintf(i8* %10, i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i8* %30)
%32 = call i32 @system(i8* %10)
br label %120
33: ; preds = %25
%34 = load i8*, i8** %13
%35 = tail call i64 @strcmp(i8* %34, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
%36 = icmp eq i64 %35, 0
%37 = icmp ugt i32 %0, 2
%38 = and i1 %37, %36
br i1 %38, label %39, label %49
39: ; preds = %33
%40 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%41 = load i8*, i8** %1
%42 = call i32 @strncpy(i8* %40, i8* %41, i32 255)
%43 = call i32 @dirname(i8* %40)
%44 = getelementptr inbounds i8*, i8** %1, i64 2
%45 = load i8*, i8** %44
%46 = call i32 @sprintf(i8* %10, i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0), i8* %45)
%47 = call i32 @strncat(i8* %40, i8* %10, i32 255)
%48 = call i32 @system(i8* %40)
br label %120
49: ; preds = %33
%50 = load i8*, i8** %13
%51 = tail 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
%53 = and i1 %37, %52
br i1 %53, label %54, label %59
54: ; preds = %49
%55 = getelementptr inbounds i8*, i8** %1, i64 2
%56 = load i8*, i8** %55
%57 = call i32 @sprintf(i8* %10, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i8* %56)
%58 = call i32 @system(i8* %10)
br label %120
59: ; preds = %49
%60 = load i8*, i8** %13
%61 = tail call i64 @strcmp(i8* %60, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0))
%62 = icmp eq i64 %61, 0
br i1 %62, label %63, label %70
63: ; preds = %59
%64 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
%65 = load i8*, i8** %1
%66 = call i32 @strncpy(i8* %64, i8* %65, i32 255)
%67 = call i32 @dirname(i8* %64)
%68 = call i32 @strncat(i8* %64, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.10, i64 0, i64 0), i32 255)
%69 = call i32 @system(i8* %64)
br label %120
70: ; preds = %59
%71 = load i8*, i8** %13
%72 = tail call i64 @strcmp(i8* %71, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i64 0, i64 0))
%73 = icmp eq i64 %72, 0
br i1 %73, label %74, label %81
74: ; preds = %70
%75 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%76 = load i8*, i8** %1
%77 = call i32 @strncpy(i8* %75, i8* %76, i32 255)
%78 = call i32 @dirname(i8* %75)
%79 = call i32 @strncat(i8* %75, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.12, i64 0, i64 0), i32 255)
%80 = call i32 @system(i8* %75)
br label %120
81: ; preds = %70
%82 = load i8*, i8** %13
%83 = tail call i64 @strcmp(i8* %82, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.13, i64 0, i64 0))
%84 = icmp eq i64 %83, 0
br i1 %84, label %85, label %96
85: ; preds = %81
%86 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 0
%87 = load i8*, i8** %1
%88 = call i32 @strncpy(i8* %86, i8* %87, i32 255)
%89 = call i32 @dirname(i8* %86)
%90 = call i32 @strncat(i8* %86, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.14, i64 0, i64 0), i32 255)
%91 = call i32 @system(i8* %86)
%92 = icmp eq i32 %91, -1
br i1 %92, label %93, label %94
93: ; preds = %85
br label %120
94: ; preds = %85
%95 = call i32 @WEXITSTATUS(i32 %91)
br label %120
96: ; preds = %81
%97 = load i8*, i8** %13
%98 = tail call i64 @strcmp(i8* %97, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.15, i64 0, i64 0))
%99 = icmp eq i64 %98, 0
br i1 %99, label %100, label %120
100: ; preds = %96
%101 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%102 = load i8*, i8** %1
%103 = call i32 @strncpy(i8* %101, i8* %102, i32 255)
%104 = call i32 @dirname(i8* %101)
%105 = call i32 @strncat(i8* %101, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.16, i64 0, i64 0), i32 255)
%106 = call i32 @system(i8* %101)
br label %120
107: ; preds = %2
%108 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @str, i64 0, i64 0))
%109 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @str.29, i64 0, i64 0))
%110 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @str.30, i64 0, i64 0))
%111 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([72 x i8], [72 x i8]* @str.31, i64 0, i64 0))
%112 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str.32, i64 0, i64 0))
%113 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @str.33, i64 0, i64 0))
%114 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str.34, i64 0, i64 0))
%115 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([62 x i8], [62 x i8]* @str.35, i64 0, i64 0))
%116 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([61 x i8], [61 x i8]* @str.36, i64 0, i64 0))
%117 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([67 x i8], [67 x i8]* @str.37, i64 0, i64 0))
%118 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @str.38, i64 0, i64 0))
%119 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([68 x i8], [68 x i8]* @str.39, i64 0, i64 0))
br label %120
120: ; preds = %107, %39, %63, %100, %96, %74, %54, %29, %93, %94
%121 = phi i32 [ %95, %94 ], [ 0, %93 ], [ 0, %29 ], [ 0, %54 ], [ 0, %74 ], [ 0, %96 ], [ 0, %100 ], [ 0, %63 ], [ 0, %39 ], [ 0, %107 ]
ret i32 %121
}