#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 uint8_t;
typedef int /*<<< orphan*/ data;
typedef int /*<<< orphan*/ RSA;

/* Variables and functions */
int /*<<< orphan*/ ERR_error_string(unsigned long, char *);
unsigned long ERR_get_error();
int /*<<< orphan*/ RSA_NO_PADDING;
int RSA_private_decrypt(int, int *, int *, int /*<<< orphan*/ *,
                        int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ *read_RSA_key_from_file(char *, int /*<<< orphan*/);
int read_file(char *, int *, int);
int main() {
  int i;
  uint8_t data[1024 * 5] = {0}, out[1024 * 5] = {0};
  RSA *rsa_pkey = read_RSA_key_from_file("test.key", 0);
  int ret = read_file("data.bin", data, sizeof(data));
  printf("ret = %d\n", ret);
  ret = RSA_private_decrypt(256, data, out, rsa_pkey, RSA_NO_PADDING);
  printf("ret = %d\n", ret);
  char err_buf[1024];
  unsigned long err = ERR_get_error();
  ERR_error_string(err, err_buf);
  printf("error = %s\n", err_buf);
  for (i = 0; i < 256; i++) {
    printf("%02x ", (uint8_t)out[i]);
    if (i % 15 == 0)
      printf("\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa430,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x5010(%rbp),%rdi
xor    %esi,%esi
mov    $0x5000,%edx
call   1040 <memset@plt>
lea    -0xa010(%rbp),%rdi
xor    %esi,%esi
mov    $0x5000,%edx
call   1040 <memset@plt>
lea    0xe51(%rip),%rdi
xor    %esi,%esi
call   1070 <read_RSA_key_from_file@plt>
mov    %rax,-0xa018(%rbp)
lea    -0x5010(%rbp),%rsi
lea    0xe3e(%rip),%rdi
mov    $0x5000,%edx
call   1050 <read_file@plt>
mov    %eax,-0xa01c(%rbp)
mov    -0xa01c(%rbp),%esi
lea    0xe2a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x5010(%rbp),%rsi
lea    -0xa010(%rbp),%rdx
mov    -0xa018(%rbp),%rcx
mov    0x2ddd(%rip),%rax
mov    (%rax),%r8d
mov    $0x100,%edi
call   1090 <RSA_private_decrypt@plt>
mov    %eax,-0xa01c(%rbp)
mov    -0xa01c(%rbp),%esi
lea    0xde7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1080 <ERR_get_error@plt>
mov    %rax,-0xa428(%rbp)
mov    -0xa428(%rbp),%rdi
lea    -0xa420(%rbp),%rsi
call   1060 <ERR_error_string@plt>
lea    -0xa420(%rbp),%rsi
lea    0xdbb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x100,-0x8(%rbp)
jge    12ca <main+0x15a>
movslq -0x8(%rbp),%rax
mov    -0xa010(%rbp,%rax,4),%esi
lea    0xd9a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
mov    $0xf,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    12b7 <main+0x147>
lea    0xd6a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12bc <main+0x14c>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    126f <main+0xff>
xor    %eax,%eax
add    $0xa430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xa400,%rsp
lea    0x5400(%rsp),%r15
mov    $0x5000,%edx
mov    %r15,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
lea    0x400(%rsp),%r14
mov    $0x5000,%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
lea    0xe3c(%rip),%rdi
xor    %esi,%esi
call   1080 <read_RSA_key_from_file@plt>
mov    %rax,%rbx
lea    0xe34(%rip),%rdi
mov    %r15,%rsi
mov    $0x5000,%edx
call   1060 <read_file@plt>
lea    0xe29(%rip),%r12
mov    %r12,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2dec(%rip),%rax
mov    (%rax),%r8d
mov    $0x100,%edi
mov    %r15,%rsi
mov    %r14,%rdx
mov    %rbx,%rcx
call   10a0 <RSA_private_decrypt@plt>
mov    %r12,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1090 <ERR_get_error@plt>
mov    %rsp,%rbx
mov    %rax,%rdi
mov    %rbx,%rsi
call   1070 <ERR_error_string@plt>
lea    0xde2(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xddd(%rip),%r14
xor    %r15d,%r15d
xor    %ebx,%ebx
jmp    1271 <main+0xf1>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%rbx
add    $0xff,%r15b
cmp    $0x100,%rbx
je     12a5 <main+0x125>
movzbl %bl,%eax
imul   $0x89,%eax,%eax
shr    $0xb,%eax
lea    (%rax,%rax,4),%eax
lea    (%rax,%rax,2),%ebp
mov    0x400(%rsp,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    %r15b,%bpl
jne    1260 <main+0xe0>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1260 <main+0xe0>
xor    %eax,%eax
add    $0xa400,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"test.key\00"
@.str.1 = [9 x i8] c"data.bin\00"
@.str.2 = [10 x i8] c"ret = %d\0A\00"
@RSA_NO_PADDING = global i32 0
@.str.3 = [12 x i8] c"error = %s\0A\00"
@.str.4 = [6 x i8] c"%02x \00"
@.str.5 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [5120 x i32]
%4 = alloca [5120 x i32]
%5 = alloca i32*
%6 = alloca i32
%7 = alloca [1024 x i8]
%8 = alloca i64
store i32 0, i32* %1
%9 = bitcast [5120 x i32]* %3 to i8*
%10 = bitcast [5120 x i32]* %4 to i8*
%11 = call i32* @read_RSA_key_from_file(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 0)
store i32* %11, i32** %5
%12 = getelementptr inbounds [5120 x i32], [5120 x i32]* %3, i64 0, i64 0
%13 = call i32 @read_file(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32* %12, i32 20480)
store i32 %13, i32* %6
%14 = load i32, i32* %6
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%16 = getelementptr inbounds [5120 x i32], [5120 x i32]* %3, i64 0, i64 0
%17 = getelementptr inbounds [5120 x i32], [5120 x i32]* %4, i64 0, i64 0
%18 = load i32*, i32** %5
%19 = load i32, i32* @RSA_NO_PADDING
%20 = call i32 @RSA_private_decrypt(i32 256, i32* %16, i32* %17, i32* %18, i32 %19)
store i32 %20, i32* %6
%21 = load i32, i32* %6
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %21)
%23 = call i64 (...) @ERR_get_error()
store i64 %23, i64* %8
%24 = load i64, i64* %8
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%26 = call i32 @ERR_error_string(i64 %24, i8* %25)
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %27)
store i32 0, i32* %2
br label %29
29: ; preds = %44, %0
%30 = load i32, i32* %2
%31 = icmp slt i32 %30, 256
br i1 %31, label %32, label %47
32: ; preds = %29
%33 = load i32, i32* %2
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [5120 x i32], [5120 x i32]* %4, i64 0, i64 %34
%36 = load i32, i32* %35
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %36)
%38 = load i32, i32* %2
%39 = srem i32 %38, 15
%40 = icmp eq i32 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %32
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %43
43: ; preds = %41, %32
br label %44
44: ; preds = %43
%45 = load i32, i32* %2
%46 = add nsw i32 %45, 1
store i32 %46, i32* %2
br label %29
47: ; preds = %29
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"test.key\00"
@.str.1 = [9 x i8] c"data.bin\00"
@.str.2 = [10 x i8] c"ret = %d\0A\00"
@RSA_NO_PADDING = global i32 0
@.str.3 = [12 x i8] c"error = %s\0A\00"
@.str.4 = [6 x i8] c"%02x \00"
define i32 @main() {
%1 = alloca [5120 x i32]
%2 = alloca [5120 x i32]
%3 = alloca [1024 x i8]
%4 = bitcast [5120 x i32]* %1 to i8*
%5 = bitcast [5120 x i32]* %2 to i8*
%6 = tail call i32* @read_RSA_key_from_file(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 0)
%7 = getelementptr inbounds [5120 x i32], [5120 x i32]* %1, i64 0, i64 0
%8 = call i32 @read_file(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32* %7, i32 20480)
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %8)
%10 = getelementptr inbounds [5120 x i32], [5120 x i32]* %2, i64 0, i64 0
%11 = load i32, i32* @RSA_NO_PADDING
%12 = call i32 @RSA_private_decrypt(i32 256, i32* %7, i32* %10, i32* %6, i32 %11)
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %12)
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%15 = call i64 (...) @ERR_get_error()
%16 = call i32 @ERR_error_string(i64 %15, i8* %14)
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %14)
br label %18
18: ; preds = %0, %28
%19 = phi i64 [ 0, %0 ], [ %29, %28 ]
%20 = getelementptr inbounds [5120 x i32], [5120 x i32]* %2, i64 0, i64 %19
%21 = load i32, i32* %20
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %21)
%23 = trunc i64 %19 to i8
%24 = urem i8 %23, 15
%25 = icmp eq i8 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %18
%27 = call i32 @putchar(i32 10)
br label %28
28: ; preds = %18, %26
%29 = add nuw nsw i64 %19, 1
%30 = icmp eq i64 %29, 256
br i1 %30, label %31, label %18
31: ; preds = %28
ret i32 0
}