#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 */
scalar_t__ EOF;
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
scalar_t__ scanf(char *, char *);
int /*<<< orphan*/ strcmp(char *, char *);
int main() {
  char inp[128], *pass = "APACTF{Ok4y_u_know_r3v3r53_bas!cs}";
  int i = 0;
  printf("Please provide the serial number:");
  while (i < 128) {
    if (scanf("%c", &inp[i]) == EOF)
      break;
    if (inp[i] == '\n' || inp[i] == '\r' || inp[i] == 0)
      break;
    i++;
  }
  inp[i] = 0;
  if (!strcmp(inp, pass))
    printf("Flag is %s\n", pass);
  else
    puts("Sorry... Serial number is invalid.");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xea7(%rip),%rax
mov    %rax,-0x98(%rbp)
movl   $0x0,-0x9c(%rbp)
lea    0xeb2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x80,-0x9c(%rbp)
jge    121b <main+0xdb>
movslq -0x9c(%rbp),%rax
lea    -0x90(%rbp),%rsi
add    %rax,%rsi
lea    0xea5(%rip),%rdi
call   1060 <scanf@plt>
mov    0x2e3c(%rip),%rcx
cmp    (%rcx),%rax
jne    11ba <main+0x7a>
jmp    121b <main+0xdb>
movslq -0x9c(%rbp),%rax
movsbl -0x90(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
je     1202 <main+0xc2>
movslq -0x9c(%rbp),%rax
movsbl -0x90(%rbp,%rax,1),%eax
ff
cmp    $0xd,%eax
je     1202 <main+0xc2>
movslq -0x9c(%rbp),%rax
movsbl -0x90(%rbp,%rax,1),%eax
ff
cmp    $0x0,%eax
jne    1207 <main+0xc7>
jmp    121b <main+0xdb>
mov    -0x9c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x9c(%rbp)
jmp    1178 <main+0x38>
movslq -0x9c(%rbp),%rax
movb   $0x0,-0x90(%rbp,%rax,1)
lea    -0x90(%rbp),%rdi
mov    -0x98(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    1260 <main+0x120>
mov    -0x98(%rbp),%rsi
lea    0xdf4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    126c <main+0x12c>
lea    0xded(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x80,%rsp
lea    0xecc(%rip),%rdi
xor    %r15d,%r15d
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xedd(%rip),%r14
mov    0x2e79(%rip),%r12
mov    $0x2401,%r13d
jmp    118d <main+0x4d>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r15
cmp    $0x80,%r15
je     11b3 <main+0x73>
lea    (%rsp,%r15,1),%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <scanf@plt>
cmp    (%r12),%rax
je     11b9 <main+0x79>
movzbl (%rbx),%eax
cmp    $0xd,%rax
ja     1180 <main+0x40>
bt     %rax,%r13
jae    1180 <main+0x40>
jmp    11b9 <main+0x79>
mov    $0x80,%r15d
mov    %r15d,%eax
movb   $0x0,(%rsp,%rax,1)
lea    0xe39(%rip),%rsi
mov    %rsp,%rdi
mov    $0x23,%edx
call   1050 <bcmp@plt>
test   %eax,%eax
je     11e6 <main+0xa6>
lea    0xe75(%rip),%rdi
call   1030 <puts@plt>
jmp    11fb <main+0xbb>
lea    0xe5b(%rip),%rdi
lea    0xe0c(%rip),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [35 x i8] c"APACTF{Ok4y_u_know_r3v3r53_bas!cs}\00"
@.str.1 = [34 x i8] c"Please provide the serial number:\00"
@.str.2 = [3 x i8] c"%c\00"
@EOF = global i64 0
@.str.3 = [12 x i8] c"Flag is %s\0A\00"
@.str.4 = [35 x i8] c"Sorry... Serial number is invalid.\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [128 x i8]
%3 = alloca i8*
%4 = alloca i32
store i32 0, i32* %1
store i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8** %3
store i32 0, i32* %4
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
br label %6
6: ; preds = %39, %0
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 128
br i1 %8, label %9, label %42
9: ; preds = %6
%10 = load i32, i32* %4
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 %11
%13 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %12)
%14 = load i64, i64* @EOF
%15 = icmp eq i64 %13, %14
br i1 %15, label %16, label %17
16: ; preds = %9
br label %42
17: ; preds = %9
%18 = load i32, i32* %4
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 %19
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 10
br i1 %23, label %38, label %24
24: ; preds = %17
%25 = load i32, i32* %4
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 %26
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 13
br i1 %30, label %38, label %31
31: ; preds = %24
%32 = load i32, i32* %4
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 %33
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %31, %24, %17
br label %42
39: ; preds = %31
%40 = load i32, i32* %4
%41 = add nsw i32 %40, 1
store i32 %41, i32* %4
br label %6
42: ; preds = %38, %16, %6
%43 = load i32, i32* %4
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 %44
store i8 0, i8* %45
%46 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%47 = load i8*, i8** %3
%48 = call i32 @strcmp(i8* %46, i8* %47)
%49 = icmp ne i32 %48, 0
br i1 %49, label %53, label %50
50: ; preds = %42
%51 = load i8*, i8** %3
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %51)
br label %55
53: ; preds = %42
%54 = call i32 @puts(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0))
br label %55
55: ; preds = %53, %50
ret i32 0
}

LLVM IR (-O2):
@.str = [35 x i8] c"APACTF{Ok4y_u_know_r3v3r53_bas!cs}\00"
@.str.1 = [34 x i8] c"Please provide the serial number:\00"
@.str.2 = [3 x i8] c"%c\00"
@EOF = global i64 0
@.str.3 = [12 x i8] c"Flag is %s\0A\00"
@.str.4 = [35 x i8] c"Sorry... Serial number is invalid.\00"
define i32 @main() {
%1 = alloca [128 x i8]
%2 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
br label %4
4: ; preds = %0, %12
%5 = phi i64 [ 0, %0 ], [ %13, %12 ]
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 %5
%7 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %6)
%8 = load i64, i64* @EOF
%9 = icmp eq i64 %7, %8
br i1 %9, label %15, label %10
10: ; preds = %4
%11 = load i8, i8* %6
switch i8 %11, label %12 [
i8 10, label %15
i8 13, label %15
i8 0, label %15
]
12: ; preds = %10
%13 = add nuw nsw i64 %5, 1
%14 = icmp eq i64 %13, 128
br i1 %14, label %15, label %4
15: ; preds = %10, %10, %10, %4, %12
%16 = phi i64 [ %5, %10 ], [ %5, %10 ], [ %5, %10 ], [ %5, %4 ], [ 128, %12 ]
%17 = and i64 %16, 4294967295
%18 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 %17
store i8 0, i8* %18
%19 = call i32 @bcmp(i8* dereferenceable(35) %2, i8* dereferenceable(35) getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i64 35)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %15
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
br label %25
23: ; preds = %15
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0))
br label %25
25: ; preds = %23, %21
ret i32 0
}