#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 strlen(char *);
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 (strlen(argv[1]) > 10) {
    printf("ERROR: password is too long.\n");
    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   1080 <setuid@plt>
xor    %edi,%edi
call   1060 <setgid@plt>
cmpl   $0x3,-0x8(%rbp)
jge    11af <main+0x4f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1237 <main+0xd7>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <strlen@plt>
cmp    $0xa,%eax
jle    11df <main+0x7f>
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1237 <main+0xd7>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <check_password@plt>
cmp    $0x0,%rax
je     1216 <main+0xb6>
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1040 <system@plt>
jmp    1230 <main+0xd0>
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1237 <main+0xd7>
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   1090 <setuid@plt>
xor    %edi,%edi
call   1070 <setgid@plt>
cmp    $0x2,%ebp
jg     119e <main+0x2e>
mov    (%rbx),%rsi
lea    0xe6b(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    11e8 <main+0x78>
mov    0x8(%rbx),%rdi
call   1040 <strlen@plt>
cmp    $0xb,%eax
jl     11b5 <main+0x45>
lea    0xe99(%rip),%rdi
jmp    11e3 <main+0x73>
mov    0x8(%rbx),%rdi
call   1080 <check_password@plt>
test   %rax,%rax
je     11dc <main+0x6c>
lea    0xe6f(%rip),%rdi
call   1030 <puts@plt>
mov    0x10(%rbx),%rdi
call   1050 <system@plt>
xor    %eax,%eax
jmp    11ed <main+0x7d>
lea    0xe3d(%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 = [30 x i8] c"ERROR: password is too long.\0A\00"
@.str.2 = [20 x i8] c"Running command...\0A\00"
@.str.3 = [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 %38
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32 @strlen(i8* %18)
%20 = icmp sgt i32 %19, 10
br i1 %20, label %21, label %23
21: ; preds = %15
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %38
23: ; preds = %15
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i64 @check_password(i8* %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %35
29: ; preds = %23
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 2
%33 = load i8*, i8** %32
%34 = call i32 @system(i8* %33)
br label %37
35: ; preds = %23
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %38
37: ; preds = %29
store i32 0, i32* %3
br label %38
38: ; preds = %37, %35, %21, %10
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
@.str = [32 x i8] c"USAGE: %s <password> <command>\0A\00"
@str = [25 x i8] c"ERROR: invalid password.\00"
@str.4 = [19 x i8] c"Running command...\00"
@str.5 = [29 x i8] c"ERROR: password is too long.\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 %27
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @strlen(i8* %11)
%13 = icmp sgt i32 %12, 10
br i1 %13, label %14, label %16
14: ; preds = %9
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.5, i64 0, i64 0))
br label %27
16: ; preds = %9
%17 = load i8*, i8** %10
%18 = tail call i64 @check_password(i8* %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %25, label %20
20: ; preds = %16
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.4, i64 0, i64 0))
%22 = getelementptr inbounds i8*, i8** %1, i64 2
%23 = load i8*, i8** %22
%24 = tail call i32 @system(i8* %23)
br label %27
25: ; preds = %16
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
br label %27
27: ; preds = %20, %25, %14, %6
%28 = phi i32 [ 1, %6 ], [ 1, %14 ], [ 0, %20 ], [ 1, %25 ]
ret i32 %28
}