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

/* Variables and functions */
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ geteuid();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ setresuid(int /*<<< orphan*/, int /*<<< orphan*/,
                             int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(char *, char *);
int main(int argc, char **argv) {
  int score = 0;
  printf("CollageBored (R) Advanced Placement Literature Grader\n");
  if (argc != 2) {
    printf("Usage: %s [essay]\n", argv[0]);
    return 1;
  }
  char buf[700];
  strcpy(buf, argv[1]);
  printf("-------------- YOUR SUBMISSION --------------\n");
  printf("%s\n", buf);
  printf("---------------------------------------------\n");
  printf("According to our analysis, your response received a grade of %d!\n",
         score);
  if (score > 12) {
    uid_t uid = geteuid();
    setresuid(uid, uid, uid);
    FILE *fp;
    fp = fopen("flag.txt", "r");
    char flag[64];
    fgets(flag, 64, (FILE *)fp);
    printf("Wow, you're an HONOR student! Here's a flag: %s\n", flag);
  } else {
    printf("Sorry, you can only view the FLAG if you received a score greater "
           "than 12.\n");
    printf("\n");
    printf("If you didn't do as well as you wanted, be sure to take a look at "
           "our rubric\n");
    printf("to see how we grade your essay!\n");
    printf("********* RUBRIC ************ \n");
    printf("* 0 - your essay sucks      * \n");
    printf("* 1 - impossible to achieve * \n");
    printf("* 2 - impossible to achieve * \n");
    printf("* 3 - impossible to achieve * \n");
    printf("* 4 - impossible to achieve * \n");
    printf("* 5 - impossible to achieve * \n");
    printf("* 6 - impossible to achieve * \n");
    printf("* 7 - impossible to achieve * \n");
    printf("* 8 - impossible to achieve * \n");
    printf("* 9 - impossible to achieve * \n");
    printf("***************************** \n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x320,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpl   $0x2,-0x8(%rbp)
je     11b9 <main+0x59>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1370 <main+0x210>
lea    -0x2d0(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1030 <strcpy@plt>
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x2d0(%rbp),%rsi
lea    0xf39(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%esi
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpl   $0xc,-0x14(%rbp)
jle    1289 <main+0x129>
mov    $0x0,%al
call   1060 <geteuid@plt>
mov    %eax,-0x2d4(%rbp)
mov    -0x2d4(%rbp),%edi
mov    -0x2d4(%rbp),%esi
mov    -0x2d4(%rbp),%edx
call   1040 <setresuid@plt>
lea    0xea6(%rip),%rdi
lea    0xea8(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x2e0(%rbp)
lea    -0x320(%rbp),%rdi
mov    -0x2e0(%rbp),%rdx
mov    $0x40,%esi
call   1070 <fgets@plt>
lea    -0x320(%rbp),%rsi
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1369 <main+0x209>
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xf81(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xec6(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xf06(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xf19(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xf2b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xf3d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xf4f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xf61(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xf73(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xf85(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xf97(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xfa9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xfbb(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xfcd(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xfdf(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x320,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x2c8,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xf00(%rip),%rdi
call   1050 <puts@plt>
cmp    $0x2,%ebp
jne    1264 <main+0x124>
mov    0x8(%rbx),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1040 <strcpy@plt>
lea    0xf12(%rip),%rdi
call   1050 <puts@plt>
mov    %rbx,%rdi
call   1050 <puts@plt>
lea    0xf2c(%rip),%rdi
call   1050 <puts@plt>
lea    0xe7a(%rip),%rdi
xor    %ebx,%ebx
xor    %esi,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xf3c(%rip),%rdi
call   1050 <puts@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xf71(%rip),%rdi
call   1050 <puts@plt>
lea    0xfb2(%rip),%rdi
call   1050 <puts@plt>
lea    0xfc6(%rip),%rdi
call   1050 <puts@plt>
lea    0xfd9(%rip),%rdi
call   1050 <puts@plt>
lea    0xfec(%rip),%rdi
call   1050 <puts@plt>
lea    0xfff(%rip),%rdi
call   1050 <puts@plt>
lea    0x1012(%rip),%rdi
call   1050 <puts@plt>
lea    0x1025(%rip),%rdi
call   1050 <puts@plt>
lea    0x1038(%rip),%rdi
call   1050 <puts@plt>
lea    0x104b(%rip),%rdi
call   1050 <puts@plt>
lea    0x105e(%rip),%rdi
call   1050 <puts@plt>
lea    0x1071(%rip),%rdi
call   1050 <puts@plt>
lea    0x1084(%rip),%rdi
call   1050 <puts@plt>
lea    0x1097(%rip),%rdi
call   1050 <puts@plt>
jmp    127a <main+0x13a>
mov    (%rbx),%rsi
lea    0xd92(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x2c8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [55 x i8] c"CollageBored (R) Advanced Placement Literature Grader\0A\00"
@.str.1 = [19 x i8] c"Usage: %s [essay]\0A\00"
@.str.2 = [47 x i8] c"-------------- YOUR SUBMISSION --------------\0A\00"
@.str.3 = [4 x i8] c"%s\0A\00"
@.str.4 = [47 x i8] c"---------------------------------------------\0A\00"
@.str.5 = [66 x i8] c"According to our analysis, your response received a grade of %d!\0A\00"
@.str.6 = [9 x i8] c"flag.txt\00"
@.str.7 = [2 x i8] c"r\00"
@.str.8 = [49 x i8] c"Wow, you're an HONOR student! Here's a flag: %s\0A\00"
@.str.9 = [76 x i8] c"Sorry, you can only view the FLAG if you received a score greater than 12.\0A\00"
@.str.10 = [2 x i8] c"\0A\00"
@.str.11 = [78 x i8] c"If you didn't do as well as you wanted, be sure to take a look at our rubric\0A\00"
@.str.12 = [33 x i8] c"to see how we grade your essay!\0A\00"
@.str.13 = [32 x i8] c"********* RUBRIC ************ \0A\00"
@.str.14 = [32 x i8] c"* 0 - your essay sucks * \0A\00"
@.str.15 = [32 x i8] c"* 1 - impossible to achieve * \0A\00"
@.str.16 = [32 x i8] c"* 2 - impossible to achieve * \0A\00"
@.str.17 = [32 x i8] c"* 3 - impossible to achieve * \0A\00"
@.str.18 = [32 x i8] c"* 4 - impossible to achieve * \0A\00"
@.str.19 = [32 x i8] c"* 5 - impossible to achieve * \0A\00"
@.str.20 = [32 x i8] c"* 6 - impossible to achieve * \0A\00"
@.str.21 = [32 x i8] c"* 7 - impossible to achieve * \0A\00"
@.str.22 = [32 x i8] c"* 8 - impossible to achieve * \0A\00"
@.str.23 = [32 x i8] c"* 9 - impossible to achieve * \0A\00"
@.str.24 = [32 x i8] c"***************************** \0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [700 x i8]
%8 = alloca i32
%9 = alloca i32*
%10 = alloca [64 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 2
br i1 %13, label %14, label %19
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %17)
store i32 1, i32* %3
br label %63
19: ; preds = %2
%20 = getelementptr inbounds [700 x i8], [700 x i8]* %7, i64 0, i64 0
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32 @strcpy(i8* %20, i8* %23)
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0))
%26 = getelementptr inbounds [700 x i8], [700 x i8]* %7, i64 0, i64 0
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %26)
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.4, i64 0, i64 0))
%29 = load i32, i32* %6
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.5, i64 0, i64 0), i32 %29)
%31 = load i32, i32* %6
%32 = icmp sgt i32 %31, 12
br i1 %32, label %33, label %45
33: ; preds = %19
%34 = call i32 (...) @geteuid()
store i32 %34, i32* %8
%35 = load i32, i32* %8
%36 = load i32, i32* %8
%37 = load i32, i32* %8
%38 = call i32 @setresuid(i32 %35, i32 %36, i32 %37)
%39 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
store i32* %39, i32** %9
%40 = getelementptr inbounds [64 x i8], [64 x i8]* %10, i64 0, i64 0
%41 = load i32*, i32** %9
%42 = call i32 @fgets(i8* %40, i32 64, i32* %41)
%43 = getelementptr inbounds [64 x i8], [64 x i8]* %10, i64 0, i64 0
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.8, i64 0, i64 0), i8* %43)
br label %62
45: ; preds = %19
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str.9, i64 0, i64 0))
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str.11, i64 0, i64 0))
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.12, i64 0, i64 0))
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.13, i64 0, i64 0))
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.14, i64 0, i64 0))
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.15, i64 0, i64 0))
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.16, i64 0, i64 0))
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.17, i64 0, i64 0))
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.18, i64 0, i64 0))
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.19, i64 0, i64 0))
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.20, i64 0, i64 0))
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.21, i64 0, i64 0))
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.22, i64 0, i64 0))
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.23, i64 0, i64 0))
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.24, i64 0, i64 0))
br label %62
62: ; preds = %45, %33
store i32 0, i32* %3
br label %63
63: ; preds = %62, %14
%64 = load i32, i32* %3
ret i32 %64
}

LLVM IR (-O2):
@.str.1 = [19 x i8] c"Usage: %s [essay]\0A\00"
@.str.5 = [66 x i8] c"According to our analysis, your response received a grade of %d!\0A\00"
@str = [54 x i8] c"CollageBored (R) Advanced Placement Literature Grader\00"
@str.25 = [46 x i8] c"-------------- YOUR SUBMISSION --------------\00"
@str.26 = [46 x i8] c"---------------------------------------------\00"
@str.27 = [75 x i8] c"Sorry, you can only view the FLAG if you received a score greater than 12.\00"
@str.28 = [77 x i8] c"If you didn't do as well as you wanted, be sure to take a look at our rubric\00"
@str.29 = [32 x i8] c"to see how we grade your essay!\00"
@str.30 = [31 x i8] c"********* RUBRIC ************ \00"
@str.31 = [31 x i8] c"* 0 - your essay sucks * \00"
@str.32 = [31 x i8] c"* 1 - impossible to achieve * \00"
@str.33 = [31 x i8] c"* 2 - impossible to achieve * \00"
@str.34 = [31 x i8] c"* 3 - impossible to achieve * \00"
@str.35 = [31 x i8] c"* 4 - impossible to achieve * \00"
@str.36 = [31 x i8] c"* 5 - impossible to achieve * \00"
@str.37 = [31 x i8] c"* 6 - impossible to achieve * \00"
@str.38 = [31 x i8] c"* 7 - impossible to achieve * \00"
@str.39 = [31 x i8] c"* 8 - impossible to achieve * \00"
@str.40 = [31 x i8] c"* 9 - impossible to achieve * \00"
@str.41 = [31 x i8] c"***************************** \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [700 x i8]
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @str, i64 0, i64 0))
%5 = icmp eq i32 %0, 2
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %7)
br label %34
9: ; preds = %2
%10 = getelementptr inbounds [700 x i8], [700 x i8]* %3, i64 0, i64 0
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = call i32 @strcpy(i8* %10, i8* %12)
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str.25, i64 0, i64 0))
%15 = call i32 @puts(i8* %10)
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str.26, i64 0, i64 0))
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([66 x i8], [66 x i8]* @.str.5, i64 0, i64 0), i32 0)
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([75 x i8], [75 x i8]* @str.27, i64 0, i64 0))
%19 = call i32 @putchar(i32 10)
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([77 x i8], [77 x i8]* @str.28, i64 0, i64 0))
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.29, i64 0, i64 0))
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.30, i64 0, i64 0))
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.31, i64 0, i64 0))
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.32, i64 0, i64 0))
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.33, i64 0, i64 0))
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.34, i64 0, i64 0))
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.35, i64 0, i64 0))
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.36, i64 0, i64 0))
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.37, i64 0, i64 0))
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.38, i64 0, i64 0))
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.39, i64 0, i64 0))
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.40, i64 0, i64 0))
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.41, i64 0, i64 0))
br label %34
34: ; preds = %9, %6
%35 = phi i32 [ 1, %6 ], [ 0, %9 ]
ret i32 %35
}