#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 */
typedef int /*<<< orphan*/ line;

/* Variables and functions */
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ system(char *);
int main(void) {
  printf("Welcome to the Flag Charity. Do you want a shell? [Y/n]\n");
  char line[10];
  if (!fgets(line, sizeof(line), stdin) || line[0] == 'n' || line[0] == 'N') {
    printf("Hmm, guess you don't want a free flag...\n");
  } else {
    printf("Thought so. Here's your free shell!\n");
    system("/bin/sh");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
call   1040 <printf@plt>
lea    -0xe(%rbp),%rdi
mov    0x2e92(%rip),%rax
mov    (%rax),%edx
mov    $0xa,%esi
call   1050 <fgets@plt>
cmp    $0x0,%eax
je     1185 <main+0x55>
movsbl -0xe(%rbp),%eax
cmp    $0x6e,%eax
je     1185 <main+0x55>
movsbl -0xe(%rbp),%eax
cmp    $0x4e,%eax
jne    1196 <main+0x66>
lea    0xead(%rip),%rdi
call   1040 <printf@plt>
jmp    11ae <main+0x7e>
lea    0xec6(%rip),%rdi
call   1040 <printf@plt>
lea    0xedf(%rip),%rdi
call   1030 <system@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
lea    0xecd(%rip),%rdi
call   1030 <puts@plt>
mov    0x2ea1(%rip),%rax
mov    (%rax),%edx
lea    0xe(%rsp),%rdi
mov    $0xa,%esi
call   1050 <fgets@plt>
test   %eax,%eax
je     1182 <main+0x52>
mov    0xe(%rsp),%al
cmp    $0x6e,%al
je     1182 <main+0x52>
cmp    $0x4e,%al
je     1182 <main+0x52>
lea    0xed1(%rip),%rdi
call   1030 <puts@plt>
lea    0xe85(%rip),%rdi
call   1040 <system@plt>
jmp    118e <main+0x5e>
lea    0xedb(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [57 x i8] c"Welcome to the Flag Charity. Do you want a shell? [Y/n]\0A\00"
@stdin = global i32 0
@.str.1 = [42 x i8] c"Hmm, guess you don't want a free flag...\0A\00"
@.str.2 = [37 x i8] c"Thought so. Here's your free shell!\0A\00"
@.str.3 = [8 x i8] c"/bin/sh\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10 x i8]
store i32 0, i32* %1
%3 = call i32 @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0))
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%5 = load i32, i32* @stdin
%6 = call i32 @fgets(i8* %4, i32 10, i32 %5)
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %18
8: ; preds = %0
%9 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp eq i32 %11, 110
br i1 %12, label %18, label %13
13: ; preds = %8
%14 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 78
br i1 %17, label %18, label %20
18: ; preds = %13, %8, %0
%19 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
br label %23
20: ; preds = %13
%21 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
%22 = call i32 @system(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %23
23: ; preds = %20, %18
ret i32 0
}

LLVM IR (-O2):
@stdin = global i32 0
@.str.3 = [8 x i8] c"/bin/sh\00"
@str = [56 x i8] c"Welcome to the Flag Charity. Do you want a shell? [Y/n]\00"
@str.4 = [36 x i8] c"Thought so. Here's your free shell!\00"
@str.5 = [41 x i8] c"Hmm, guess you don't want a free flag...\00"
define i32 @main() {
%1 = alloca [10 x i8]
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @str, i64 0, i64 0))
%3 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%4 = load i32, i32* @stdin
%5 = call i32 @fgets(i8* %3, i32 10, i32 %4)
%6 = icmp eq i32 %5, 0
%7 = load i8, i8* %3
%8 = icmp eq i8 %7, 110
%9 = select i1 %6, i1 true, i1 %8
%10 = icmp eq i8 %7, 78
%11 = select i1 %9, i1 true, i1 %10
br i1 %11, label %12, label %14
12: ; preds = %0
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str.5, i64 0, i64 0))
br label %17
14: ; preds = %0
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.4, i64 0, i64 0))
%16 = call i32 @system(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %17
17: ; preds = %14, %12
ret i32 0
}