#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*/ execlp(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int geteuid();
scalar_t__ guess(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ seedrand(char *);
int /*<<< orphan*/ setresuid(int, int, int);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char **argv) {
  char seed[16];
  int i;
  seedrand(seed);
  for (i = 0; i < 10; i++) {
    if (guess(seed)) {
      i = geteuid();
      setresuid(i, i, i);
      write(1, "YAY!\n", 5);
      execlp("/bin/sh", "sh", 0);
      exit(0);
    }
  }
  printf("sorry.\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
call   1080 <seedrand@plt>
movl   $0x0,-0x24(%rbp)
cmpl   $0xa,-0x24(%rbp)
jge    1220 <main+0xa0>
lea    -0x20(%rbp),%rdi
call   1070 <guess@plt>
cmp    $0x0,%rax
je     120d <main+0x8d>
mov    $0x0,%al
call   1060 <geteuid@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x24(%rbp),%esi
mov    -0x24(%rbp),%edx
call   1040 <setresuid@plt>
mov    $0x1,%edi
lea    0xe19(%rip),%rsi
mov    $0x5,%edx
call   1030 <write@plt>
lea    0xe0e(%rip),%rdi
lea    0xe0c(%rip),%rsi
xor    %edx,%edx
call   10a0 <execlp@plt>
xor    %edi,%edi
call   1090 <exit@plt>
jmp    1212 <main+0x92>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11a6 <main+0x26>
lea    0xde7(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1080 <seedrand@plt>
mov    %rbx,%rdi
call   1070 <guess@plt>
test   %rax,%rax
jne    122a <main+0xaa>
mov    %rsp,%rdi
call   1070 <guess@plt>
test   %rax,%rax
jne    122a <main+0xaa>
mov    %rsp,%rdi
call   1070 <guess@plt>
test   %rax,%rax
jne    122a <main+0xaa>
mov    %rsp,%rdi
call   1070 <guess@plt>
test   %rax,%rax
jne    122a <main+0xaa>
mov    %rsp,%rdi
call   1070 <guess@plt>
test   %rax,%rax
jne    122a <main+0xaa>
mov    %rsp,%rdi
call   1070 <guess@plt>
test   %rax,%rax
jne    122a <main+0xaa>
mov    %rsp,%rdi
call   1070 <guess@plt>
test   %rax,%rax
jne    122a <main+0xaa>
mov    %rsp,%rdi
call   1070 <guess@plt>
test   %rax,%rax
jne    122a <main+0xaa>
mov    %rsp,%rdi
call   1070 <guess@plt>
test   %rax,%rax
jne    122a <main+0xaa>
mov    %rsp,%rdi
call   1070 <guess@plt>
test   %rax,%rax
jne    122a <main+0xaa>
lea    0xdf1(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
xor    %eax,%eax
call   1060 <geteuid@plt>
mov    %eax,%edi
mov    %eax,%esi
mov    %eax,%edx
call   1050 <setresuid@plt>
lea    0xdbd(%rip),%rsi
mov    $0x1,%edi
mov    $0x5,%edx
call   1040 <write@plt>
lea    0xdad(%rip),%rdi
lea    0xdab(%rip),%rsi
xor    %edx,%edx
call   10a0 <execlp@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"YAY!\0A\00"
@.str.1 = [8 x i8] c"/bin/sh\00"
@.str.2 = [3 x i8] c"sh\00"
@.str.3 = [8 x i8] c"sorry.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [16 x i8]
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%9 = call i32 @seedrand(i8* %8)
store i32 0, i32* %7
br label %10
10: ; preds = %27, %2
%11 = load i32, i32* %7
%12 = icmp slt i32 %11, 10
br i1 %12, label %13, label %30
13: ; preds = %10
%14 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%15 = call i64 @guess(i8* %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %26
17: ; preds = %13
%18 = call i32 (...) @geteuid()
store i32 %18, i32* %7
%19 = load i32, i32* %7
%20 = load i32, i32* %7
%21 = load i32, i32* %7
%22 = call i32 @setresuid(i32 %19, i32 %20, i32 %21)
%23 = call i32 @write(i32 1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 5)
%24 = call i32 @execlp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 0)
%25 = call i32 @exit(i32 0)
unreachable
26: ; preds = %13
br label %27
27: ; preds = %26
%28 = load i32, i32* %7
%29 = add nsw i32 %28, 1
store i32 %29, i32* %7
br label %10
30: ; preds = %10
%31 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"YAY!\0A\00"
@.str.1 = [8 x i8] c"/bin/sh\00"
@.str.2 = [3 x i8] c"sh\00"
@str = [7 x i8] c"sorry.\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [16 x i8]
%4 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%5 = call i32 @seedrand(i8* %4)
%6 = call i64 @guess(i8* %4)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %37
8: ; preds = %2
%9 = call i64 @guess(i8* %4)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %37
11: ; preds = %8
%12 = call i64 @guess(i8* %4)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %37
14: ; preds = %11
%15 = call i64 @guess(i8* %4)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %37
17: ; preds = %14
%18 = call i64 @guess(i8* %4)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %37
20: ; preds = %17
%21 = call i64 @guess(i8* %4)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %37
23: ; preds = %20
%24 = call i64 @guess(i8* %4)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %37
26: ; preds = %23
%27 = call i64 @guess(i8* %4)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %37
29: ; preds = %26
%30 = call i64 @guess(i8* %4)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %37
32: ; preds = %29
%33 = call i64 @guess(i8* %4)
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %32
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
ret i32 0
37: ; preds = %32, %29, %26, %23, %20, %17, %14, %11, %8, %2
%38 = call i32 (...) @geteuid()
%39 = call i32 @setresuid(i32 %38, i32 %38, i32 %38)
%40 = call i32 @write(i32 1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 5)
%41 = call i32 @execlp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 0)
%42 = call i32 @exit(i32 0)
unreachable
}