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

/* Variables and functions */
int /*<<< orphan*/ *PEM_read_PrivateKey(int /*<<< orphan*/ *,
                                        int /*<<< orphan*/ *,
                                        int /*<<< orphan*/ *, void *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, char *);
char *strerror(int /*<<< orphan*/);
void gpw_run(void *run_data) {
  if (run_data == NULL) {
    goto DONE;
  }
  {
    FILE *fp;
    fp = fopen("./hackme", "r");
    if (fp == NULL) {
      printf("fopen() failed: %s\n", strerror(errno));
      exit(1);
    }
    EVP_PKEY *key = PEM_read_PrivateKey(fp, NULL, NULL, run_data);
    if (key == NULL) {
      fclose(fp);
      goto DONE;
    }
    fclose(fp);
    printf("success! > %s <\n", (char *)run_data);
    exit(1);
  }
DONE:
  return;
}


x86 assembly (clang, -O0):
<gpw_run>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    117c <gpw_run+0x1c>
jmp    1219 <gpw_run+0xb9>
lea    0xe7d(%rip),%rdi
lea    0xe7f(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11c5 <gpw_run+0x65>
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    %rax,%rsi
lea    0xe55(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rsi
call   1060 <PEM_read_PrivateKey@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11f6 <gpw_run+0x96>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
jmp    1219 <gpw_run+0xb9>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x8(%rbp),%rsi
lea    0xe15(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gpw_run>:
push   %r15
push   %r14
push   %rbx
test   %rdi,%rdi
je     11a7 <gpw_run+0x47>
mov    %rdi,%r14
lea    0xe8c(%rip),%rdi
lea    0xe8e(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     11ad <gpw_run+0x4d>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
xor    %edx,%edx
mov    %r14,%rcx
call   1060 <PEM_read_PrivateKey@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1030 <fclose@plt>
test   %r15,%r15
jne    11c7 <gpw_run+0x67>
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe49(%rip),%rdi
mov    %rax,%rsi
jmp    11d1 <gpw_run+0x71>
lea    0xe51(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"./hackme\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [20 x i8] c"fopen() failed: %s\0A\00"
@errno = global i32 0
@.str.3 = [17 x i8] c"success! > %s <\0A\00"
define void @gpw_run(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %8
7: ; preds = %1
br label %32
8: ; preds = %1
%9 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %3
%10 = load i32*, i32** %3
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %17
12: ; preds = %8
%13 = load i32, i32* @errno
%14 = call i8* @strerror(i32 %13)
%15 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %14)
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %8
%18 = load i32*, i32** %3
%19 = load i8*, i8** %2
%20 = call i32* @PEM_read_PrivateKey(i32* %18, i32* null, i32* null, i8* %19)
store i32* %20, i32** %4
%21 = load i32*, i32** %4
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %26
23: ; preds = %17
%24 = load i32*, i32** %3
%25 = call i32 @fclose(i32* %24)
br label %32
26: ; preds = %17
%27 = load i32*, i32** %3
%28 = call i32 @fclose(i32* %27)
%29 = load i8*, i8** %2
%30 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* %29)
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %23, %7
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"./hackme\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [20 x i8] c"fopen() failed: %s\0A\00"
@errno = global i32 0
@.str.3 = [17 x i8] c"success! > %s <\0A\00"
define void @gpw_run(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %18, label %3
3: ; preds = %1
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %11
6: ; preds = %3
%7 = load i32, i32* @errno
%8 = tail call i8* @strerror(i32 %7)
%9 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %8)
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %3
%12 = tail call i32* @PEM_read_PrivateKey(i32* %4, i32* null, i32* null, i8* %0)
%13 = icmp eq i32* %12, null
%14 = tail call i32 @fclose(i32* %4)
br i1 %13, label %18, label %15
15: ; preds = %11
%16 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* %0)
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %11, %1
ret void
}