#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 */
struct passwd {
  char *pw_dir;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
char *getmID();
struct passwd *getpwuid(int /*<<< orphan*/);
int /*<<< orphan*/ getuid();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, char const *, char *);
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ xor_decrypt(char *, char *, int);
bool doCRFile(char *rand) {
  char chr[] = {110, 62, 92, 111, 106, 70, 30, 37, 35, 38, 0};
  xor_decrypt(chr, "KMsAO53F", 10);
  printf("%s\n", chr);
  char *mid = getmID();
  if (!mid) {
    printf("9th Checkpoint not working\n");
    return false;
  }
  struct passwd *pw = getpwuid(getuid());
  const char *homedir = pw->pw_dir;
  char out[80];
  sprintf(out, chr, homedir, mid);
  free(mid);
  FILE *fp = fopen(out, "w");
  if (!fp) {
    printf("%s\n", strerror(errno));
    return false;
  }
  fputs(rand, fp);
  fclose(fp);
  return true;
}


x86 assembly (clang, -O0):
<doCRFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x10(%rbp)
mov    0xe3a(%rip),%rax
mov    %rax,-0x1b(%rbp)
mov    0xe37(%rip),%ax
mov    %ax,-0x13(%rbp)
mov    0xe2f(%rip),%al
mov    %al,-0x11(%rbp)
lea    -0x1b(%rbp),%rdi
lea    0xe22(%rip),%rsi
mov    $0xa,%edx
call   10a0 <xor_decrypt@plt>
lea    -0x1b(%rbp),%rsi
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    $0x0,%al
call   1040 <getmID@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1235 <doCRFile+0x85>
lea    0xdf6(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12e9 <doCRFile+0x139>
mov    $0x0,%al
call   1070 <getuid@plt>
mov    %eax,%edi
call   1060 <getpwuid@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
lea    -0x90(%rbp),%rdi
lea    -0x1b(%rbp),%rsi
mov    -0x38(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   10c0 <sprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
lea    -0x90(%rbp),%rdi
lea    0xdb3(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x98(%rbp)
cmpq   $0x0,-0x98(%rbp)
jne    12c6 <doCRFile+0x116>
mov    0x2d3e(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    %rax,%rsi
lea    0xd61(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12e9 <doCRFile+0x139>
mov    -0x10(%rbp),%rdi
mov    -0x98(%rbp),%rsi
call   1090 <fputs@plt>
mov    -0x98(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<doCRFile>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x68,%rsp
mov    %rdi,%r14
movabs $0x251e466a6f5c3e6e,%rax
46 1e 25
mov    %rax,(%rsp)
movl   $0x262325,0x7(%rsp)
lea    0xe31(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0xa,%edx
call   10a0 <xor_decrypt@plt>
mov    %rbx,%rdi
call   1050 <puts@plt>
xor    %ebp,%ebp
xor    %eax,%eax
call   1040 <getmID@plt>
test   %rax,%rax
je     1262 <doCRFile+0xb2>
mov    %rax,%rbx
xor    %ebp,%ebp
xor    %eax,%eax
call   1080 <getuid@plt>
mov    %eax,%edi
call   1070 <getpwuid@plt>
mov    (%rax),%rdx
lea    0x10(%rsp),%r15
mov    %rsp,%rsi
mov    %r15,%rdi
mov    %rbx,%rcx
call   10c0 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xddc(%rip),%rsi
mov    %r15,%rdi
call   10b0 <fopen@plt>
test   %rax,%rax
je     126b <doCRFile+0xbb>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
call   1090 <fputs@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    $0x1,%ebp
jmp    1281 <doCRFile+0xd1>
lea    0xdad(%rip),%rdi
jmp    127c <doCRFile+0xcc>
mov    0x2d6e(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    %rax,%rdi
call   1050 <puts@plt>
mov    %ebp,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.passwd = type { i8* }
@__const.doCRFile.chr = [11 x i8] c"n>\\ojF\1E%#&\00"
@.str = [9 x i8] c"KMsAO53F\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [28 x i8] c"9th Checkpoint not working\0A\00"
@.str.3 = [2 x i8] c"w\00"
@errno = global i32 0
define i32 @doCRFile(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [11 x i8]
%5 = alloca i8*
%6 = alloca %struct.passwd*
%7 = alloca i8*
%8 = alloca [80 x i8]
%9 = alloca i32*
store i8* %0, i8** %3
%10 = bitcast [11 x i8]* %4 to i8*
%11 = getelementptr inbounds [11 x i8], [11 x i8]* %4, i64 0, i64 0
%12 = call i32 @xor_decrypt(i8* %11, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 10)
%13 = getelementptr inbounds [11 x i8], [11 x i8]* %4, i64 0, i64 0
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = call i8* (...) @getmID()
store i8* %15, i8** %5
%16 = load i8*, i8** %5
%17 = icmp ne i8* %16, null
br i1 %17, label %20, label %18
18: ; preds = %1
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %2
br label %47
20: ; preds = %1
%21 = call i32 (...) @getuid()
%22 = call %struct.passwd* @getpwuid(i32 %21)
store %struct.passwd* %22, %struct.passwd** %6
%23 = load %struct.passwd*, %struct.passwd** %6
%24 = getelementptr inbounds %struct.passwd, %struct.passwd* %23, i32 0, i32 0
%25 = load i8*, i8** %24
store i8* %25, i8** %7
%26 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%27 = getelementptr inbounds [11 x i8], [11 x i8]* %4, i64 0, i64 0
%28 = load i8*, i8** %7
%29 = load i8*, i8** %5
%30 = call i32 @sprintf(i8* %26, i8* %27, i8* %28, i8* %29)
%31 = load i8*, i8** %5
%32 = call i32 @free(i8* %31)
%33 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%34 = call i32* @fopen(i8* %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %34, i32** %9
%35 = load i32*, i32** %9
%36 = icmp ne i32* %35, null
br i1 %36, label %41, label %37
37: ; preds = %20
%38 = load i32, i32* @errno
%39 = call i8* @strerror(i32 %38)
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %39)
store i32 0, i32* %2
br label %47
41: ; preds = %20
%42 = load i8*, i8** %3
%43 = load i32*, i32** %9
%44 = call i32 @fputs(i8* %42, i32* %43)
%45 = load i32*, i32** %9
%46 = call i32 @fclose(i32* %45)
store i32 1, i32* %2
br label %47
47: ; preds = %41, %37, %18
%48 = load i32, i32* %2
ret i32 %48
}

LLVM IR (-O2):
%struct.passwd = type { i8* }
@__const.doCRFile.chr = [11 x i8] c"n>\\ojF\1E%#&\00"
@.str = [9 x i8] c"KMsAO53F\00"
@.str.3 = [2 x i8] c"w\00"
@errno = global i32 0
@str = [27 x i8] c"9th Checkpoint not working\00"
define i32 @doCRFile(i8* nocapture %0) {
%2 = alloca [11 x i8]
%3 = alloca [80 x i8]
%4 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 0
%5 = call i32 @xor_decrypt(i8* %4, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 10)
%6 = call i32 @puts(i8* %4)
%7 = call i8* (...) @getmID()
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
br label %30
11: ; preds = %1
%12 = call i32 (...) @getuid()
%13 = call %struct.passwd* @getpwuid(i32 %12)
%14 = getelementptr inbounds %struct.passwd, %struct.passwd* %13, i64 0, i32 0
%15 = load i8*, i8** %14
%16 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%17 = call i32 @sprintf(i8* %16, i8* %4, i8* %15, i8* %7)
%18 = call i32 @free(i8* %7)
%19 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %25
21: ; preds = %11
%22 = load i32, i32* @errno
%23 = call i8* @strerror(i32 %22)
%24 = call i32 @puts(i8* dereferenceable(1) %23)
br label %28
25: ; preds = %11
%26 = call i32 @fputs(i8* %0, i32* %19)
%27 = call i32 @fclose(i32* %19)
br label %28
28: ; preds = %25, %21
%29 = phi i32 [ 1, %25 ], [ 0, %21 ]
br label %30
30: ; preds = %28, %9
%31 = phi i32 [ %29, %28 ], [ 0, %9 ]
ret i32 %31
}