#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*/ controlProcess(char *, char *, char *);
int /*<<< orphan*/ exit(int);
int getuid();
int /*<<< orphan*/ killProcess(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int main(int argc, char *argv[]) {
  char daemon_str[512];
  char usuario_str[512];
  int id = getuid();
  if (id != 0) {
    printf("Debe ejecutar como root.\n");
    exit(1);
  }
  if (argc == 4 && strcmp(argv[1], "stop") == 0 && strcmp(argv[2], "-d") == 0) {
    printf("Terminando programa.\n");
    strcpy(daemon_str, "");
    strcat(daemon_str, argv[3]);
    killProcess(daemon_str);
  } else {
    if (argc < 2) {
      printf("No ingreso la cantidad de argumento permitidos\n");
      exit(1);
    } else {
      if (argc == 7 && strcmp(argv[1], "start") == 0 &&
          strcmp(argv[2], "-d") == 0 && strcmp(argv[4], "-u") == 0) {
        strcpy(daemon_str, "");
        strcat(daemon_str, argv[3]);
        strcpy(usuario_str, "");
        strcat(usuario_str, argv[5]);
        controlProcess(argv[6], daemon_str, usuario_str);
      } else {
        printf("Solo se permiten como parametros start | stop y el path del "
               "demonio -d /var/run/daemon.pid -u www-data\n");
        exit(1);
      }
    }
  }
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1040 <getuid@plt>
mov    %eax,-0x414(%rbp)
cmpl   $0x0,-0x414(%rbp)
je     11c9 <main+0x49>
lea    0xe46(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
cmpl   $0x4,-0x8(%rbp)
jne    1253 <main+0xd3>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe38(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1253 <main+0xd3>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe1f(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1253 <main+0xd3>
lea    0xe0c(%rip),%rdi
call   1050 <printf@plt>
lea    -0x210(%rbp),%rdi
lea    0xe0e(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x210(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rsi
call   1080 <strcat@plt>
lea    -0x210(%rbp),%rdi
call   1070 <killProcess@plt>
jmp    1365 <main+0x1e5>
cmpl   $0x2,-0x8(%rbp)
jge    1273 <main+0xf3>
lea    0xdd4(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
cmpl   $0x7,-0x8(%rbp)
jne    1345 <main+0x1c5>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xddc(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1345 <main+0x1c5>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xd75(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1345 <main+0x1c5>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
lea    0xda6(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1345 <main+0x1c5>
lea    -0x210(%rbp),%rdi
lea    0xd52(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x210(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rsi
call   1080 <strcat@plt>
lea    -0x410(%rbp),%rdi
lea    0xd2b(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x28(%rax),%rsi
call   1080 <strcat@plt>
mov    -0x10(%rbp),%rax
mov    0x30(%rax),%rdi
lea    -0x210(%rbp),%rsi
lea    -0x410(%rbp),%rdx
call   10a0 <controlProcess@plt>
jmp    135b <main+0x1db>
lea    0xd25(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    1360 <main+0x1e0>
jmp    1365 <main+0x1e5>
lea    0xcca(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %eax,%eax
call   1060 <getuid@plt>
test   %eax,%eax
jne    12e6 <main+0x156>
cmp    $0x4,%ebp
jne    121f <main+0x8f>
mov    0x8(%rbx),%rdi
lea    0xe3f(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
jne    12dd <main+0x14d>
mov    0x10(%rbx),%rdi
lea    0xe2b(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
jne    12dd <main+0x14d>
lea    0xeb8(%rip),%rdi
call   1050 <puts@plt>
lea    0xec0(%rip),%rsi
mov    %rsp,%rbp
mov    %rbp,%rdi
call   1040 <strcpy@plt>
mov    0x18(%rbx),%rsi
mov    %rbp,%rdi
call   1090 <strcat@plt>
mov    %rbp,%rdi
call   1080 <killProcess@plt>
jmp    12c3 <main+0x133>
cmp    $0x1,%ebp
jle    12ef <main+0x15f>
cmp    $0x7,%ebp
jne    12dd <main+0x14d>
mov    0x8(%rbx),%rdi
lea    0xdcc(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
jne    12dd <main+0x14d>
mov    0x10(%rbx),%rdi
lea    0xdb0(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
jne    12dd <main+0x14d>
mov    0x20(%rbx),%rdi
lea    0xda4(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
jne    12dd <main+0x14d>
lea    0xe40(%rip),%r14
mov    %rsp,%r15
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
mov    0x18(%rbx),%rsi
mov    %r15,%rdi
call   1090 <strcat@plt>
lea    0x200(%rsp),%rbp
mov    %rbp,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
mov    0x28(%rbx),%rsi
mov    %rbp,%rdi
call   1090 <strcat@plt>
mov    0x30(%rbx),%rdi
mov    %r15,%rsi
mov    %rbp,%rdx
call   10b0 <controlProcess@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd2d(%rip),%rdi
jmp    12f6 <main+0x166>
lea    0xdcf(%rip),%rdi
jmp    12f6 <main+0x166>
lea    0xd82(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [26 x i8] c"Debe ejecutar como root.\0A\00"
@.str.1 = [5 x i8] c"stop\00"
@.str.2 = [3 x i8] c"-d\00"
@.str.3 = [22 x i8] c"Terminando programa.\0A\00"
@.str.4 = [1 x i8] zeroinitializer
@.str.5 = [48 x i8] c"No ingreso la cantidad de argumento permitidos\0A\00"
@.str.6 = [6 x i8] c"start\00"
@.str.7 = [3 x i8] c"-u\00"
@.str.8 = [104 x i8] c"Solo se permiten como parametros start | stop y el path del demonio -d /var/run/daemon.pid -u www-data\0A\00"
@.str.9 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [512 x i8]
%7 = alloca [512 x i8]
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32 (...) @getuid()
store i32 %9, i32* %8
%10 = load i32, i32* %8
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = load i32, i32* %4
%17 = icmp eq i32 %16, 4
br i1 %17, label %18, label %41
18: ; preds = %15
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i64 @strcmp(i8* %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %41
24: ; preds = %18
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 2
%27 = load i8*, i8** %26
%28 = call i64 @strcmp(i8* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %41
30: ; preds = %24
%31 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%32 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%33 = call i32 @strcpy(i8* %32, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0))
%34 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 3
%37 = load i8*, i8** %36
%38 = call i32 @strcat(i8* %34, i8* %37)
%39 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%40 = call i32 @killProcess(i8* %39)
br label %94
41: ; preds = %24, %18, %15
%42 = load i32, i32* %4
%43 = icmp slt i32 %42, 2
br i1 %43, label %44, label %47
44: ; preds = %41
%45 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.5, i64 0, i64 0))
%46 = call i32 @exit(i32 1)
unreachable
47: ; preds = %41
%48 = load i32, i32* %4
%49 = icmp eq i32 %48, 7
br i1 %49, label %50, label %89
50: ; preds = %47
%51 = load i8**, i8*** %5
%52 = getelementptr inbounds i8*, i8** %51, i64 1
%53 = load i8*, i8** %52
%54 = call i64 @strcmp(i8* %53, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%55 = icmp eq i64 %54, 0
br i1 %55, label %56, label %89
56: ; preds = %50
%57 = load i8**, i8*** %5
%58 = getelementptr inbounds i8*, i8** %57, i64 2
%59 = load i8*, i8** %58
%60 = call i64 @strcmp(i8* %59, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%61 = icmp eq i64 %60, 0
br i1 %61, label %62, label %89
62: ; preds = %56
%63 = load i8**, i8*** %5
%64 = getelementptr inbounds i8*, i8** %63, i64 4
%65 = load i8*, i8** %64
%66 = call i64 @strcmp(i8* %65, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%67 = icmp eq i64 %66, 0
br i1 %67, label %68, label %89
68: ; preds = %62
%69 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%70 = call i32 @strcpy(i8* %69, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0))
%71 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%72 = load i8**, i8*** %5
%73 = getelementptr inbounds i8*, i8** %72, i64 3
%74 = load i8*, i8** %73
%75 = call i32 @strcat(i8* %71, i8* %74)
%76 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%77 = call i32 @strcpy(i8* %76, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0))
%78 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%79 = load i8**, i8*** %5
%80 = getelementptr inbounds i8*, i8** %79, i64 5
%81 = load i8*, i8** %80
%82 = call i32 @strcat(i8* %78, i8* %81)
%83 = load i8**, i8*** %5
%84 = getelementptr inbounds i8*, i8** %83, i64 6
%85 = load i8*, i8** %84
%86 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%87 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%88 = call i32 @controlProcess(i8* %85, i8* %86, i8* %87)
br label %92
89: ; preds = %62, %56, %50, %47
%90 = call i32 @printf(i8* getelementptr inbounds ([104 x i8], [104 x i8]* @.str.8, i64 0, i64 0))
%91 = call i32 @exit(i32 1)
unreachable
92: ; preds = %68
br label %93
93: ; preds = %92
br label %94
94: ; preds = %93, %30
%95 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [5 x i8] c"stop\00"
@.str.2 = [3 x i8] c"-d\00"
@.str.4 = [1 x i8] zeroinitializer
@.str.6 = [6 x i8] c"start\00"
@.str.7 = [3 x i8] c"-u\00"
@str = [103 x i8] c"Solo se permiten como parametros start | stop y el path del demonio -d /var/run/daemon.pid -u www-data\00"
@str.10 = [47 x i8] c"No ingreso la cantidad de argumento permitidos\00"
@str.11 = [21 x i8] c"Terminando programa.\00"
@str.12 = [25 x i8] c"Debe ejecutar como root.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [512 x i8]
%4 = alloca [512 x i8]
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%7 = tail call i32 (...) @getuid()
%8 = icmp eq i32 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.12, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %2
%13 = icmp eq i32 %0, 4
br i1 %13, label %14, label %31
14: ; preds = %12
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = tail call i64 @strcmp(i8* %16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %65
19: ; preds = %14
%20 = getelementptr inbounds i8*, i8** %1, i64 2
%21 = load i8*, i8** %20
%22 = tail call i64 @strcmp(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %65
24: ; preds = %19
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.11, i64 0, i64 0))
%26 = call i32 @strcpy(i8* %5, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0))
%27 = getelementptr inbounds i8*, i8** %1, i64 3
%28 = load i8*, i8** %27
%29 = call i32 @strcat(i8* %5, i8* %28)
%30 = call i32 @killProcess(i8* %5)
br label %68
31: ; preds = %12
%32 = icmp slt i32 %0, 2
br i1 %32, label %33, label %36
33: ; preds = %31
%34 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str.10, i64 0, i64 0))
%35 = tail call i32 @exit(i32 1)
unreachable
36: ; preds = %31
%37 = icmp eq i32 %0, 7
br i1 %37, label %38, label %65
38: ; preds = %36
%39 = getelementptr inbounds i8*, i8** %1, i64 1
%40 = load i8*, i8** %39
%41 = tail call i64 @strcmp(i8* %40, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%42 = icmp eq i64 %41, 0
br i1 %42, label %43, label %65
43: ; preds = %38
%44 = getelementptr inbounds i8*, i8** %1, i64 2
%45 = load i8*, i8** %44
%46 = tail call i64 @strcmp(i8* %45, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%47 = icmp eq i64 %46, 0
br i1 %47, label %48, label %65
48: ; preds = %43
%49 = getelementptr inbounds i8*, i8** %1, i64 4
%50 = load i8*, i8** %49
%51 = tail call i64 @strcmp(i8* %50, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%52 = icmp eq i64 %51, 0
br i1 %52, label %53, label %65
53: ; preds = %48
%54 = call i32 @strcpy(i8* %5, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0))
%55 = getelementptr inbounds i8*, i8** %1, i64 3
%56 = load i8*, i8** %55
%57 = call i32 @strcat(i8* %5, i8* %56)
%58 = call i32 @strcpy(i8* %6, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0))
%59 = getelementptr inbounds i8*, i8** %1, i64 5
%60 = load i8*, i8** %59
%61 = call i32 @strcat(i8* %6, i8* %60)
%62 = getelementptr inbounds i8*, i8** %1, i64 6
%63 = load i8*, i8** %62
%64 = call i32 @controlProcess(i8* %63, i8* %5, i8* %6)
br label %68
65: ; preds = %19, %14, %48, %43, %38, %36
%66 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([103 x i8], [103 x i8]* @str, i64 0, i64 0))
%67 = tail call i32 @exit(i32 1)
unreachable
68: ; preds = %53, %24
%69 = call i32 @putchar(i32 10)
ret i32 0
}