#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*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int read(int, char *, int);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ setbuf(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ system(char *);
int main(int argc) {
  char buf[32] = {0x00};
  int key = 0x00;
  setbuf(stdout, NULL);
  printf("Key? ");
  scanf("%d", &key);
  int fd = key - 0x31337;
  int len = read(fd, buf, 32);
  if (!strcmp("GIMMEDAFLAG\n", buf)) {
    system("/bin/cat flag.txt");
    exit(0);
  }
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1060 <memset@plt>
movl   $0x0,-0x34(%rbp)
mov    0x2e30(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <setbuf@plt>
lea    0xe3e(%rip),%rdi
call   1050 <printf@plt>
lea    0xe38(%rip),%rdi
lea    -0x34(%rbp),%rsi
call   1090 <scanf@plt>
mov    -0x34(%rbp),%eax
sub    $0x31337,%eax
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x20,%edx
call   1070 <read@plt>
mov    %eax,-0x3c(%rbp)
lea    -0x30(%rbp),%rsi
lea    0xe08(%rip),%rdi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
jne    1222 <main+0xa2>
lea    0xe00(%rip),%rdi
call   1040 <system@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
mov    $0x1,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x38,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movl   $0x0,0xc(%rsp)
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1030 <setbuf@plt>
lea    0xe70(%rip),%rdi
call   1050 <printf@plt>
lea    0xe6a(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1070 <scanf@plt>
mov    $0xfffcecc9,%edi
add    0xc(%rsp),%edi
lea    0x10(%rsp),%rsi
mov    $0x20,%edx
call   1060 <read@plt>
movabs $0x464144454d4d4947,%rax
44 41 46
xor    0x10(%rsp),%rax
movabs $0xa47414c464144,%rcx
xor    0x15(%rsp),%rcx
or     %rax,%rcx
je     11eb <main+0x8b>
mov    $0x1,%eax
add    $0x38,%rsp
ret
lea    0xe24(%rip),%rdi
call   1040 <system@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stdout = global i32 0
@.str = [6 x i8] c"Key? \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [13 x i8] c"GIMMEDAFLAG\0A\00"
@.str.3 = [18 x i8] c"/bin/cat flag.txt\00"
define i32 @main(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [32 x i8]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %2
store i32 %0, i32* %3
%8 = bitcast [32 x i8]* %4 to i8*
store i32 0, i32* %5
%9 = load i32, i32* @stdout
%10 = call i32 @setbuf(i32 %9, i32* null)
%11 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %5)
%13 = load i32, i32* %5
%14 = sub nsw i32 %13, 201527
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%17 = call i32 @read(i32 %15, i8* %16, i32 32)
store i32 %17, i32* %7
%18 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%19 = call i32 @strcmp(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %18)
%20 = icmp ne i32 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %1
%22 = call i32 @system(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%23 = call i32 @exit(i32 0)
unreachable
24: ; preds = %1
ret i32 1
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [6 x i8] c"Key? \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [13 x i8] c"GIMMEDAFLAG\0A\00"
@.str.3 = [18 x i8] c"/bin/cat flag.txt\00"
define i32 @main(i32 %0) {
%2 = alloca [32 x i8]
%3 = alloca i32
%4 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%5 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%6 = load i32, i32* @stdout
%7 = tail call i32 @setbuf(i32 %6, i32* null)
%8 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%10 = load i32, i32* %3
%11 = add nsw i32 %10, -201527
%12 = call i32 @read(i32 %11, i8* %4, i32 32)
%13 = call i32 @bcmp(i8* dereferenceable(13) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* dereferenceable(13) %4, i64 13)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %1
%16 = call i32 @system(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%17 = call i32 @exit(i32 0)
unreachable
18: ; preds = %1
ret i32 1
}