#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*/ *, char *);
int /*<<< orphan*/ SSL_library_init();
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
char *strchr(char *, char);
int main(int argc, char *argv[]) {
  FILE *fp = fopen(argv[1], "r");
  EVP_PKEY *pk;
  char *ptr;
  char pwd[1024];
  SSL_library_init();
  pwd[0] = '\0';
  while (1) {
    if (!fgets(pwd, sizeof pwd, stdin)) {
      printf("Password not found.\n");
      exit(0);
    }
    ptr = strchr(pwd, '\n');
    if (ptr)
      *ptr = '\0';
    pk = PEM_read_PrivateKey(fp, NULL, NULL, (char *)pwd);
    if (pk) {
      printf("THC THC THC THC THC THC THC THC THC\n");
      printf("----> pwd is '%s' <-----\n", pwd);
      printf("THC THC THC THC THC THC THC THC THC\n");
      exit(0);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe68(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1050 <SSL_library_init@plt>
movb   $0x0,-0x430(%rbp)
lea    -0x430(%rbp),%rdi
mov    0x2e2b(%rip),%rax
mov    (%rax),%edx
mov    $0x400,%esi
call   1060 <fgets@plt>
cmp    $0x0,%eax
jne    11e7 <main+0x77>
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
lea    -0x430(%rbp),%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     120e <main+0x9e>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
lea    -0x430(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rsi
call   1080 <PEM_read_PrivateKey@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     126c <main+0xfc>
lea    0xddc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x430(%rbp),%rsi
lea    0xdec(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdb9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
jmp    11af <main+0x3f>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    0x8(%rsi),%rdi
lea    0xe69(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1060 <SSL_library_init@plt>
movb   $0x0,(%rsp)
mov    0x2e37(%rip),%r15
mov    %rsp,%rbx
jmp    11d4 <main+0x54>
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
xor    %esi,%esi
xor    %edx,%edx
mov    %rbx,%rcx
call   1090 <PEM_read_PrivateKey@plt>
test   %rax,%rax
jne    11ff <main+0x7f>
mov    (%r15),%edx
mov    %rbx,%rdi
mov    $0x400,%esi
call   1070 <fgets@plt>
test   %eax,%eax
je     1224 <main+0xa4>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11c0 <main+0x40>
movb   $0x0,(%rax)
jmp    11c0 <main+0x40>
lea    0xe2a(%rip),%rbx
mov    %rbx,%rdi
call   1030 <puts@plt>
lea    0xded(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
jmp    122b <main+0xab>
lea    0xdf1(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stdin = global i32 0
@.str.1 = [21 x i8] c"Password not found.\0A\00"
@.str.2 = [37 x i8] c"THC THC THC THC THC THC THC THC THC\0A\00"
@.str.3 = [26 x i8] c"----> pwd is '%s' <-----\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca [1024 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %6
%14 = call i32 (...) @SSL_library_init()
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
store i8 0, i8* %15
br label %16
16: ; preds = %2, %43
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%18 = load i32, i32* @stdin
%19 = call i32 @fgets(i8* %17, i32 1024, i32 %18)
%20 = icmp ne i32 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %16
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%23 = call i32 @exit(i32 0)
unreachable
24: ; preds = %16
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%26 = call i8* @strchr(i8* %25, i8 signext 10)
store i8* %26, i8** %8
%27 = load i8*, i8** %8
%28 = icmp ne i8* %27, null
br i1 %28, label %29, label %31
29: ; preds = %24
%30 = load i8*, i8** %8
store i8 0, i8* %30
br label %31
31: ; preds = %29, %24
%32 = load i32*, i32** %6
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%34 = call i32* @PEM_read_PrivateKey(i32* %32, i32* null, i32* null, i8* %33)
store i32* %34, i32** %7
%35 = load i32*, i32** %7
%36 = icmp ne i32* %35, null
br i1 %36, label %37, label %43
37: ; preds = %31
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %39)
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
%42 = call i32 @exit(i32 0)
unreachable
43: ; preds = %31
br label %16
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stdin = global i32 0
@.str.3 = [26 x i8] c"----> pwd is '%s' <-----\0A\00"
@str = [20 x i8] c"Password not found.\00"
@str.5 = [36 x i8] c"THC THC THC THC THC THC THC THC THC\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds i8*, i8** %1, i64 1
%5 = load i8*, i8** %4
%6 = tail call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%8 = tail call i32 (...) @SSL_library_init()
store i8 0, i8* %7
br label %9
9: ; preds = %20, %2
%10 = load i32, i32* @stdin
%11 = call i32 @fgets(i8* %7, i32 1024, i32 %10)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %9
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%15 = call i32 @exit(i32 0)
unreachable
16: ; preds = %9
%17 = call i8* @strchr(i8* %7, i8 signext 10)
%18 = icmp eq i8* %17, null
br i1 %18, label %20, label %19
19: ; preds = %16
store i8 0, i8* %17
br label %20
20: ; preds = %19, %16
%21 = call i32* @PEM_read_PrivateKey(i32* %6, i32* null, i32* null, i8* %7)
%22 = icmp eq i32* %21, null
br i1 %22, label %9, label %23
23: ; preds = %20
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.5, i64 0, i64 0))
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %7)
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.5, i64 0, i64 0))
%27 = call i32 @exit(i32 0)
unreachable
}