#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*/ buf;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
scalar_t__ check_pw(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ print_flag(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdin;
size_t strcspn(char *, char *);
int main(void) {
  char buf[256] = {0};
  printf("You are fantastic\n");
  printf("Password please: ");
  if (!fgets(buf, sizeof(buf), stdin)) {
    perror("fgets()");
    exit(EXIT_FAILURE);
  }
  buf[strcspn(buf, "\n")] = '\0';
  if (check_pw(buf)) {
    printf("yay\n");
    print_flag(buf);
  } else {
    printf("nope :(\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1040 <memset@plt>
lea    0xe54(%rip),%rdi
call   1030 <printf@plt>
lea    0xe5b(%rip),%rdi
call   1030 <printf@plt>
lea    -0x110(%rbp),%rdi
mov    0x2e1d(%rip),%rax
mov    (%rax),%edx
mov    $0x100,%esi
call   1060 <fgets@plt>
cmp    $0x0,%eax
jne    11fa <main+0x7a>
lea    0xe3e(%rip),%rdi
call   1080 <perror@plt>
mov    0x2de5(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
lea    -0x110(%rbp),%rdi
lea    0xe31(%rip),%rsi
call   1050 <strcspn@plt>
movb   $0x0,-0x110(%rbp,%rax,1)
lea    -0x110(%rbp),%rdi
call   1070 <check_pw@plt>
cmp    $0x0,%rax
je     1248 <main+0xc8>
lea    0xdfb(%rip),%rdi
call   1030 <printf@plt>
lea    -0x110(%rbp),%rdi
call   1090 <print_flag@plt>
jmp    1254 <main+0xd4>
lea    0xde3(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x100,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
lea    0xe23(%rip),%rdi
call   1030 <puts@plt>
lea    0xdfb(%rip),%rdi
call   1040 <printf@plt>
mov    0x2dd7(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rdi
mov    $0x100,%esi
call   1060 <fgets@plt>
test   %eax,%eax
je     1274 <main+0xf4>
lea    0xdef(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1050 <strcspn@plt>
movb   $0x0,(%rsp,%rax,1)
mov    %rbx,%rdi
call   1070 <check_pw@plt>
test   %rax,%rax
je     125d <main+0xdd>
lea    0xde8(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rdi
call   1090 <print_flag@plt>
jmp    1269 <main+0xe9>
lea    0xdca(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x100,%rsp
pop    %rbx
ret
lea    0xd97(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d51(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [19 x i8] c"You are fantastic\0A\00"
@.str.1 = [18 x i8] c"Password please: \00"
@stdin = global i32 0
@.str.2 = [8 x i8] c"fgets()\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [5 x i8] c"yay\0A\00"
@.str.5 = [9 x i8] c"nope :(\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [256 x i8]
store i32 0, i32* %1
%3 = bitcast [256 x i8]* %2 to i8*
%4 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%7 = load i32, i32* @stdin
%8 = call i32 @fgets(i8* %6, i32 256, i32 %7)
%9 = icmp ne i32 %8, 0
br i1 %9, label %14, label %10
10: ; preds = %0
%11 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%12 = load i32, i32* @EXIT_FAILURE
%13 = call i32 @exit(i32 %12)
unreachable
14: ; preds = %0
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%16 = call i64 @strcspn(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 %16
store i8 0, i8* %17
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%19 = call i64 @check_pw(i8* %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %14
%22 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%24 = call i32 @print_flag(i8* %23)
br label %27
25: ; preds = %14
%26 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
br label %27
27: ; preds = %25, %21
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [18 x i8] c"Password please: \00"
@stdin = global i32 0
@.str.2 = [8 x i8] c"fgets()\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [2 x i8] c"\0A\00"
@str = [18 x i8] c"You are fantastic\00"
@str.6 = [8 x i8] c"nope :(\00"
@str.7 = [4 x i8] c"yay\00"
define i32 @main() {
%1 = alloca [256 x i8]
%2 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%5 = load i32, i32* @stdin
%6 = call i32 @fgets(i8* %2, i32 256, i32 %5)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %0
%9 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%10 = load i32, i32* @EXIT_FAILURE
%11 = call i32 @exit(i32 %10)
unreachable
12: ; preds = %0
%13 = call i64 @strcspn(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 %13
store i8 0, i8* %14
%15 = call i64 @check_pw(i8* %2)
%16 = icmp eq i64 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %12
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str.7, i64 0, i64 0))
%19 = call i32 @print_flag(i8* %2)
br label %22
20: ; preds = %12
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.6, i64 0, i64 0))
br label %22
22: ; preds = %20, %17
ret i32 0
}