#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 */
struct stat {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ alarm(int);
scalar_t__ chdir(char *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ randop();
int /*<<< orphan*/ sleep(int);
scalar_t__ stat(char *, struct stat *);
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  struct stat st;
  if (argc != 2 || chdir(argv[1]) != 0 || stat("./flag", &st) != 0) {
    puts("oops, problem set up wrong D:");
    fflush(stdout);
    return 1;
  } else {
    puts("yo, what's up?");
    alarm(30);
    sleep(1);
    randop();
    fflush(stdout);
    return 0;
  }
}


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)
cmpl   $0x2,-0x8(%rbp)
jne    11c1 <main+0x51>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <chdir@plt>
cmp    $0x0,%rax
jne    11c1 <main+0x51>
lea    0xe52(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1070 <stat@plt>
cmp    $0x0,%rax
je     11e7 <main+0x77>
lea    0xe3f(%rip),%rdi
call   1040 <puts@plt>
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
call   1080 <fflush@plt>
movl   $0x1,-0x4(%rbp)
jmp    1223 <main+0xb3>
lea    0xe37(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1e,%edi
call   1060 <alarm@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
mov    $0x0,%al
call   1030 <randop@plt>
mov    0x2dcb(%rip),%rax
mov    (%rax),%edi
call   1080 <fflush@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
cmp    $0x2,%edi
jne    119e <main+0x2e>
mov    0x8(%rsi),%rdi
call   1050 <chdir@plt>
test   %rax,%rax
jne    119e <main+0x2e>
lea    0xe71(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1070 <stat@plt>
test   %rax,%rax
je     11c5 <main+0x55>
lea    0xe62(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%ebx
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
call   1080 <fflush@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe59(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1e,%edi
call   1060 <alarm@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <randop@plt>
jmp    11af <main+0x3f>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [7 x i8] c"./flag\00"
@.str.1 = [30 x i8] c"oops, problem set up wrong D:\00"
@stdout = global i32 0
@.str.2 = [15 x i8] c"yo, what's up?\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.stat
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 2
br i1 %8, label %18, label %9
9: ; preds = %2
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
%13 = call i64 @chdir(i8* %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %9
%16 = call i64 @stat(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), %struct.stat* %6)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %15, %9, %2
%19 = call i32 @puts(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
%20 = load i32, i32* @stdout
%21 = call i32 @fflush(i32 %20)
store i32 1, i32* %3
br label %29
22: ; preds = %15
%23 = call i32 @puts(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%24 = call i32 @alarm(i32 30)
%25 = call i32 @sleep(i32 1)
%26 = call i32 (...) @randop()
%27 = load i32, i32* @stdout
%28 = call i32 @fflush(i32 %27)
store i32 0, i32* %3
br label %29
29: ; preds = %22, %18
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [7 x i8] c"./flag\00"
@.str.1 = [30 x i8] c"oops, problem set up wrong D:\00"
@stdout = global i32 0
@.str.2 = [15 x i8] c"yo, what's up?\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %6, label %14
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i64 @chdir(i8* %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %6
%12 = call i64 @stat(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), %struct.stat* %3)
%13 = icmp eq i64 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %11, %6, %2
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
br label %21
16: ; preds = %11
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%18 = call i32 @alarm(i32 30)
%19 = call i32 @sleep(i32 1)
%20 = call i32 (...) @randop()
br label %21
21: ; preds = %16, %14
%22 = phi i32 [ 1, %14 ], [ 0, %16 ]
%23 = load i32, i32* @stdout
%24 = call i32 @fflush(i32 %23)
ret i32 %22
}