#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(int);
int /*<<< orphan*/ execvp(char const *, char const **);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ geteuid();
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ wait(int *);
int runCmd(const char *args[]) {
  if (geteuid() == 0) {
    int pid = fork();
    int status;
    if (pid == 0) {
      execvp(args[0], args);
      _exit(1);
      return 1;
    } else if (pid < 0) {
      fprintf(stderr, "Failed to execute command\n");
      return 0;
    } else {
      wait(&status);
      return 1;
    }
  } else {
    fprintf(stderr,
            "You need to run this command as root (try using 'sudo')\n");
    return 0;
  }
}


x86 assembly (clang, -O0):
<runCmd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   1040 <geteuid@plt>
cmp    $0x0,%rax
jne    11eb <runCmd+0x8b>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    11ab <runCmd+0x4b>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <execvp@plt>
mov    $0x1,%edi
call   1030 <_exit@plt>
cmpl   $0x0,-0x14(%rbp)
jge    11d6 <runCmd+0x76>
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
lea    0xe3b(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1207 <runCmd+0xa7>
lea    -0x18(%rbp),%rdi
call   1070 <wait@plt>
movl   $0x1,-0x4(%rbp)
jmp    1207 <runCmd+0xa7>
mov    0x2dee(%rip),%rax
mov    (%rax),%edi
lea    0xe20(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<runCmd>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <geteuid@plt>
test   %rax,%rax
je     118c <runCmd+0x2c>
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
lea    0xe96(%rip),%rsi
call   1050 <fprintf@plt>
jmp    11c1 <runCmd+0x61>
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     11cb <runCmd+0x6b>
js     11aa <runCmd+0x4a>
lea    0x4(%rsp),%rdi
call   1070 <wait@plt>
mov    $0x1,%ebx
jmp    11c1 <runCmd+0x61>
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
lea    0xe46(%rip),%rsi
call   1050 <fprintf@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    (%r14),%rdi
mov    %r14,%rsi
call   1060 <execvp@plt>
mov    $0x1,%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [27 x i8] c"Failed to execute command\0A\00"
@.str.1 = [57 x i8] c"You need to run this command as root (try using 'sudo')\0A\00"
define i32 @runCmd(i8** %0) {
%2 = alloca i32
%3 = alloca i8**
%4 = alloca i32
%5 = alloca i32
store i8** %0, i8*** %3
%6 = call i64 (...) @geteuid()
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %27
8: ; preds = %1
%9 = call i32 (...) @fork()
store i32 %9, i32* %4
%10 = load i32, i32* %4
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %19
12: ; preds = %8
%13 = load i8**, i8*** %3
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = load i8**, i8*** %3
%17 = call i32 @execvp(i8* %15, i8** %16)
%18 = call i32 @_exit(i32 1)
unreachable
19: ; preds = %8
%20 = load i32, i32* %4
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %2
br label %30
25: ; preds = %19
%26 = call i32 @wait(i32* %5)
store i32 1, i32* %2
br label %30
27: ; preds = %1
%28 = load i32, i32* @stderr
%29 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %2
br label %30
30: ; preds = %27, %25, %22
%31 = load i32, i32* %2
ret i32 %31
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [27 x i8] c"Failed to execute command\0A\00"
@.str.1 = [57 x i8] c"You need to run this command as root (try using 'sudo')\0A\00"
define i32 @runCmd(i8** %0) {
%2 = alloca i32
%3 = tail call i64 (...) @geteuid()
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %22
5: ; preds = %1
%6 = tail call i32 (...) @fork()
%7 = bitcast i32* %2 to i8*
%8 = icmp eq i32 %6, 0
br i1 %8, label %9, label %13
9: ; preds = %5
%10 = load i8*, i8** %0
%11 = tail call i32 @execvp(i8* %10, i8** %0)
%12 = tail call i32 @_exit(i32 1)
unreachable
13: ; preds = %5
%14 = icmp slt i32 %6, 0
br i1 %14, label %15, label %18
15: ; preds = %13
%16 = load i32, i32* @stderr
%17 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %20
18: ; preds = %13
%19 = call i32 @wait(i32* %2)
br label %20
20: ; preds = %18, %15
%21 = phi i32 [ 0, %15 ], [ 1, %18 ]
br label %25
22: ; preds = %1
%23 = load i32, i32* @stderr
%24 = tail call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.1, i64 0, i64 0))
br label %25
25: ; preds = %22, %20
%26 = phi i32 [ %21, %20 ], [ 0, %22 ]
ret i32 %26
}