#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*/ geteuid();
char *hexdecode(char *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ setreuid(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcmp(char *, char *);
int system(char *);
int main(int argc, char **argv) {
  char *cmd;
  setreuid(geteuid(), geteuid());
  if (argc == 2) {
    cmd = hexdecode(argv[1]);
    if (!strcmp(cmd, "hostname")) {
      puts("too-many-secrets.playtronics.int\n");
      return 0;
    }
    return system(cmd);
  }
  return -1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1050 <geteuid@plt>
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   1050 <geteuid@plt>
mov    -0x1c(%rbp),%edi
mov    %eax,%esi
call   1080 <setreuid@plt>
cmpl   $0x2,-0x8(%rbp)
jne    11ee <main+0x8e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <hexdecode@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe49(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    11dd <main+0x7d>
lea    0xe3d(%rip),%rdi
call   1030 <puts@plt>
movl   $0x0,-0x4(%rbp)
jmp    11f5 <main+0x95>
mov    -0x18(%rbp),%rdi
call   1040 <system@plt>
mov    %eax,-0x4(%rbp)
jmp    11f5 <main+0x95>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebp
xor    %eax,%eax
call   1050 <geteuid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1050 <geteuid@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1080 <setreuid@plt>
mov    $0xffffffff,%eax
cmp    $0x2,%ebp
jne    11c5 <main+0x65>
mov    0x8(%r14),%rdi
call   1070 <hexdecode@plt>
mov    %rax,%rbx
lea    0xe61(%rip),%rsi
mov    %rax,%rdi
call   1060 <strcmp@plt>
test   %eax,%eax
je     11b7 <main+0x57>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <system@plt>
lea    0xe4b(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"hostname\00"
@.str.1 = [34 x i8] c"too-many-secrets.playtronics.int\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = call i32 (...) @geteuid()
%8 = call i32 (...) @geteuid()
%9 = call i32 @setreuid(i32 %7, i32 %8)
%10 = load i32, i32* %4
%11 = icmp eq i32 %10, 2
br i1 %11, label %12, label %25
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i8* @hexdecode(i8* %15)
store i8* %16, i8** %6
%17 = load i8*, i8** %6
%18 = call i32 @strcmp(i8* %17, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%19 = icmp ne i32 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %12
%21 = call i32 @puts(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %26
22: ; preds = %12
%23 = load i8*, i8** %6
%24 = call i32 @system(i8* %23)
store i32 %24, i32* %3
br label %26
25: ; preds = %2
store i32 -1, i32* %3
br label %26
26: ; preds = %25, %22, %20
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
@.str = [9 x i8] c"hostname\00"
@.str.1 = [34 x i8] c"too-many-secrets.playtronics.int\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i32 (...) @geteuid()
%4 = tail call i32 (...) @geteuid()
%5 = tail call i32 @setreuid(i32 %3, i32 %4)
%6 = icmp eq i32 %0, 2
br i1 %6, label %7, label %17
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i8* @hexdecode(i8* %9)
%11 = tail call i32 @strcmp(i8* dereferenceable(1) %10, i8* dereferenceable(9) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %7
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
br label %17
15: ; preds = %7
%16 = tail call i32 @system(i8* %10)
br label %17
17: ; preds = %2, %15, %13
%18 = phi i32 [ %16, %15 ], [ 0, %13 ], [ -1, %2 ]
ret i32 %18
}