#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 */
scalar_t__ check_password(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ setgid(int /*<<< orphan*/);
int /*<<< orphan*/ setuid(int /*<<< orphan*/);
int /*<<< orphan*/ system(char *);
int main(int argc, char *argv[]) {
  setuid(0);
  setgid(0);
  if (argc < 3) {
    printf("USAGE: %s <password> <command>\n", argv[0]);
    return 1;
  }
  if (check_password(argv[1])) {
    printf("Running command...\n");
    system(argv[2]);
  } else {
    printf("ERROR: invalid password.\n");
    return 1;
  }
  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   1070 <setuid@plt>
xor    %edi,%edi
call   1050 <setgid@plt>
cmpl   $0x3,-0x8(%rbp)
jge    119f <main+0x4f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11f7 <main+0xa7>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <check_password@plt>
cmp    $0x0,%rax
je     11d6 <main+0x86>
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1030 <system@plt>
jmp    11f0 <main+0xa0>
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11f7 <main+0xa7>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%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   1080 <setuid@plt>
xor    %edi,%edi
call   1060 <setgid@plt>
cmp    $0x2,%ebp
jg     118e <main+0x2e>
mov    (%rbx),%rsi
lea    0xe7b(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11c1 <main+0x61>
mov    0x8(%rbx),%rdi
call   1070 <check_password@plt>
test   %rax,%rax
je     11b5 <main+0x55>
lea    0xe96(%rip),%rdi
call   1030 <puts@plt>
mov    0x10(%rbx),%rdi
call   1040 <system@plt>
xor    %eax,%eax
jmp    11c6 <main+0x66>
lea    0xe64(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [32 x i8] c"USAGE: %s <password> <command>\0A\00"
@.str.1 = [20 x i8] c"Running command...\0A\00"
@.str.2 = [26 x i8] c"ERROR: invalid password.\0A\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 i32 @setuid(i32 0)
%7 = call i32 @setgid(i32 0)
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 3
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %13)
store i32 1, i32* %3
br label %30
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i64 @check_password(i8* %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %27
21: ; preds = %15
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 2
%25 = load i8*, i8** %24
%26 = call i32 @system(i8* %25)
br label %29
27: ; preds = %15
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %30
29: ; preds = %21
store i32 0, i32* %3
br label %30
30: ; preds = %29, %27, %10
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
@.str = [32 x i8] c"USAGE: %s <password> <command>\0A\00"
@str = [25 x i8] c"ERROR: invalid password.\00"
@str.3 = [19 x i8] c"Running command...\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i32 @setuid(i32 0)
%4 = tail call i32 @setgid(i32 0)
%5 = icmp slt i32 %0, 3
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %7)
br label %21
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i64 @check_password(i8* %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %19, label %14
14: ; preds = %9
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.3, i64 0, i64 0))
%16 = getelementptr inbounds i8*, i8** %1, i64 2
%17 = load i8*, i8** %16
%18 = tail call i32 @system(i8* %17)
br label %21
19: ; preds = %9
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
br label %21
21: ; preds = %14, %19, %6
%22 = phi i32 [ 1, %6 ], [ 0, %14 ], [ 1, %19 ]
ret i32 %22
}