#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 timeval {
  double tv_sec;
  scalar_t__ tv_usec;
};
typedef int /*<<< orphan*/ RSA;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ ERR_print_errors_fp(int /*<<< orphan*/);
int /*<<< orphan*/ RSA_PKCS1_PADDING;
int RSA_private_decrypt(int, unsigned char *, unsigned char *,
                        int /*<<< orphan*/ *, int /*<<< orphan*/);
int RSA_public_encrypt(int, unsigned char *, unsigned char *,
                       int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, double);
int /*<<< orphan*/ fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(unsigned char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int RsaEncDec(const char *rf, const char *wf, RSA **key, int ed) {
  struct timeval st, ft;
  gettimeofday(&st, NULL);
  int r = 0, v = 0, len = 0, rps = 0;
  unsigned char *rb;
  unsigned char *wb;
  FILE *i = fopen(rf, "rb"), *o = fopen(wf, "wb"), *t = 0;
  if (i && o) {
    fseek(i, 0, SEEK_END);
    len = ftell(i);
    fseek(i, 0, SEEK_SET);
    rb = (unsigned char *)malloc(len);
    fread(rb, 1, len, i);
    fclose(i);
    wb = (unsigned char *)malloc(256);
    if (ed == 0)
      printf("RSA decrypting in file %s to out file %s\n", rf, wf);
    else
      printf("RSA encrypting in file %s to out file %s\n", rf, wf);
    while (rps < len) {
      memset(wb, 0, 256);
      if (ed == 0) {
        v = RSA_private_decrypt(256, rb + rps, wb, *key, RSA_PKCS1_PADDING);
        rps += 256;
      } else {
        v = RSA_public_encrypt(128, rb + rps, wb, *key, RSA_PKCS1_PADDING);
        rps += 128;
      }
      if (v != -1)
        fwrite(wb, 1, v, o);
      else if (r + rps < len) {
        ERR_print_errors_fp(stderr);
        r = 2;
      }
    }
    free(rb);
    free(wb);
    fclose(o);
    gettimeofday(&ft, NULL);
    double us = ((ft.tv_sec - st.tv_sec) * 1000000.0) +
                ((double)(ft.tv_usec - st.tv_usec));
    t = fopen("../doc/rsa_us.txt", "a");
    if (ed)
      fprintf(t, "encode: %f us\n", us);
    else
      fprintf(t, "decode: %f us\n", us);
    fclose(t);
  } else {
    printf("I/O error\n");
    if (!i && rf)
      printf("open %s failed\n", rf);
    if (!o && wf)
      printf("open %s failed\n", wf);
    r = 1;
  }
  return r;
}


x86 assembly (clang, -O0):
<RsaEncDec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
lea    -0x30(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1080 <gettimeofday@plt>
movl   $0x0,-0x44(%rbp)
movl   $0x0,-0x48(%rbp)
movl   $0x0,-0x4c(%rbp)
movl   $0x0,-0x50(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xdca(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x68(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xdb9(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x70(%rbp)
movq   $0x0,-0x78(%rbp)
cmpq   $0x0,-0x68(%rbp)
je     14c4 <RsaEncDec+0x2d4>
cmpq   $0x0,-0x70(%rbp)
je     14c4 <RsaEncDec+0x2d4>
mov    -0x68(%rbp),%rdi
mov    0x2d64(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10d0 <fseek@plt>
mov    -0x68(%rbp),%rdi
call   10b0 <ftell@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x68(%rbp),%rdi
mov    0x2d2c(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10d0 <fseek@plt>
mov    -0x4c(%rbp),%edi
call   10c0 <malloc@plt>
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rdi
mov    -0x4c(%rbp),%edx
mov    -0x68(%rbp),%rcx
mov    $0x1,%esi
call   1050 <fread@plt>
mov    -0x68(%rbp),%rdi
call   1060 <fclose@plt>
mov    $0x100,%edi
call   10c0 <malloc@plt>
mov    %rax,-0x60(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    130a <RsaEncDec+0x11a>
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    0xd10(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1320 <RsaEncDec+0x130>
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    0xd1f(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1325 <RsaEncDec+0x135>
mov    -0x50(%rbp),%eax
cmp    -0x4c(%rbp),%eax
jge    1412 <RsaEncDec+0x222>
mov    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1090 <memset@plt>
cmpl   $0x0,-0x1c(%rbp)
jne    1388 <RsaEncDec+0x198>
mov    -0x58(%rbp),%rsi
movslq -0x50(%rbp),%rax
add    %rax,%rsi
mov    -0x60(%rbp),%rdx
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
mov    0x2c58(%rip),%rax
mov    (%rax),%r8d
mov    $0x100,%edi
call   1110 <RSA_private_decrypt@plt>
mov    %eax,-0x48(%rbp)
mov    -0x50(%rbp),%eax
add    $0x100,%eax
mov    %eax,-0x50(%rbp)
jmp    13c0 <RsaEncDec+0x1d0>
mov    -0x58(%rbp),%rsi
movslq -0x50(%rbp),%rax
add    %rax,%rsi
mov    -0x60(%rbp),%rdx
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
mov    0x2c1b(%rip),%rax
mov    (%rax),%r8d
mov    $0x80,%edi
call   1040 <RSA_public_encrypt@plt>
mov    %eax,-0x48(%rbp)
mov    -0x50(%rbp),%eax
add    $0x80,%eax
mov    %eax,-0x50(%rbp)
cmpl   $0xffffffff,-0x48(%rbp)
je     13e4 <RsaEncDec+0x1f4>
mov    -0x60(%rbp),%rdi
mov    -0x48(%rbp),%edx
mov    -0x70(%rbp),%rcx
mov    $0x1,%esi
call   10f0 <fwrite@plt>
jmp    140d <RsaEncDec+0x21d>
mov    -0x44(%rbp),%eax
add    -0x50(%rbp),%eax
cmp    -0x4c(%rbp),%eax
jge    1408 <RsaEncDec+0x218>
mov    0x2bde(%rip),%rax
mov    (%rax),%edi
call   1100 <ERR_print_errors_fp@plt>
movl   $0x2,-0x44(%rbp)
jmp    140d <RsaEncDec+0x21d>
jmp    1325 <RsaEncDec+0x135>
mov    -0x58(%rbp),%rdi
call   1030 <free@plt>
mov    -0x60(%rbp),%rdi
call   1030 <free@plt>
mov    -0x70(%rbp),%rdi
call   1060 <fclose@plt>
lea    -0x40(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1080 <gettimeofday@plt>
movsd  -0x40(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
mov    -0x38(%rbp),%rax
sub    -0x28(%rbp),%rax
cvtsi2sd %rax,%xmm1
movsd  0xba7(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x80(%rbp)
lea    0xbf5(%rip),%rdi
lea    0xc00(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x78(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     14a1 <RsaEncDec+0x2b1>
mov    -0x78(%rbp),%rdi
movsd  -0x80(%rbp),%xmm0
lea    0xbdf(%rip),%rsi
call   10a0 <fprintf@plt>
jmp    14b6 <RsaEncDec+0x2c6>
mov    -0x78(%rbp),%rdi
movsd  -0x80(%rbp),%xmm0
lea    0xbd4(%rip),%rsi
call   10a0 <fprintf@plt>
mov    -0x78(%rbp),%rdi
call   1060 <fclose@plt>
jmp    1529 <RsaEncDec+0x339>
lea    0xbc9(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
cmpq   $0x0,-0x68(%rbp)
jne    14fa <RsaEncDec+0x30a>
cmpq   $0x0,-0x8(%rbp)
je     14fa <RsaEncDec+0x30a>
mov    -0x8(%rbp),%rsi
lea    0xbac(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
cmpq   $0x0,-0x70(%rbp)
jne    1522 <RsaEncDec+0x332>
cmpq   $0x0,-0x10(%rbp)
je     1522 <RsaEncDec+0x332>
mov    -0x10(%rbp),%rsi
lea    0xb84(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x1,-0x44(%rbp)
mov    -0x44(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<RsaEncDec>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %ecx,0x4(%rsp)
mov    %rdx,%r13
mov    %rsi,%r15
mov    %rdi,%r12
lea    0x28(%rsp),%rdi
xor    %esi,%esi
call   1090 <gettimeofday@plt>
lea    0xdda(%rip),%rsi
mov    %r12,%rdi
call   10f0 <fopen@plt>
mov    %rax,%r14
lea    0xdcb(%rip),%rsi
mov    %r15,%rdi
call   10f0 <fopen@plt>
mov    %rax,%rbx
test   %r14,%r14
je     13b4 <RsaEncDec+0x1b4>
test   %rbx,%rbx
je     13b4 <RsaEncDec+0x1b4>
mov    %rbx,0x10(%rsp)
mov    0x2d7f(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %rax,0x8(%rsp)
mov    %r14,%rdi
xor    %esi,%esi
call   10e0 <fseek@plt>
mov    %r14,%rdi
call   10c0 <ftell@plt>
mov    %eax,%ebp
mov    0x2d43(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   10e0 <fseek@plt>
mov    %ebp,%edi
call   10d0 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x1,%esi
mov    %ebp,%edx
mov    %r14,%rcx
call   1060 <fread@plt>
mov    %r14,%rdi
call   1070 <fclose@plt>
mov    $0x100,%edi
call   10d0 <malloc@plt>
mov    %rax,%r14
cmpl   $0x0,0x4(%rsp)
lea    0xd38(%rip),%rax
lea    0xd5b(%rip),%rdi
cmove  %rax,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1080 <printf@plt>
test   %ebp,%ebp
jle    140d <RsaEncDec+0x20d>
xor    %eax,%eax
mov    %rax,0x8(%rsp)
xor    %r15d,%r15d
jmp    132d <RsaEncDec+0x12d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    0x10(%rsp),%rcx
call   1100 <fwrite@plt>
cmp    %ebp,%r15d
jge    140d <RsaEncDec+0x20d>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   10a0 <memset@plt>
mov    %r15d,%esi
add    %rbx,%rsi
mov    0x0(%r13),%rcx
mov    0x2c73(%rip),%rax
mov    (%rax),%r8d
cmpl   $0x0,0x4(%rsp)
je     1370 <RsaEncDec+0x170>
mov    $0x80,%r12d
mov    $0x80,%edi
mov    %r14,%rdx
call   1040 <RSA_public_encrypt@plt>
jmp    1383 <RsaEncDec+0x183>
nopl   0x0(%rax)
mov    $0x100,%r12d
mov    $0x100,%edi
mov    %r14,%rdx
call   1120 <RSA_private_decrypt@plt>
add    %r12d,%r15d
cmp    $0xffffffff,%eax
jne    1310 <RsaEncDec+0x110>
mov    0x8(%rsp),%rax
add    %r15d,%eax
cmp    %ebp,%eax
jge    1324 <RsaEncDec+0x124>
mov    0x2c3a(%rip),%rax
mov    (%rax),%edi
call   1110 <ERR_print_errors_fp@plt>
mov    $0x2,%eax
mov    %rax,0x8(%rsp)
jmp    1324 <RsaEncDec+0x124>
lea    0xce9(%rip),%rdi
call   1050 <puts@plt>
test   %r12,%r12
je     13db <RsaEncDec+0x1db>
test   %r14,%r14
jne    13db <RsaEncDec+0x1db>
lea    0xcc3(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    $0x1,%eax
mov    %rax,0x8(%rsp)
test   %r15,%r15
je     14aa <RsaEncDec+0x2aa>
test   %rbx,%rbx
jne    14aa <RsaEncDec+0x2aa>
lea    0xc96(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
jmp    14aa <RsaEncDec+0x2aa>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    0x10(%rsp),%rdi
call   1070 <fclose@plt>
lea    0x18(%rsp),%rdi
xor    %esi,%esi
call   1090 <gettimeofday@plt>
movsd  0x18(%rsp),%xmm0
subsd  0x28(%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
mov    0x20(%rsp),%rbp
sub    0x30(%rsp),%rbp
lea    0xc0c(%rip),%rdi
lea    0xc17(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,%rbx
xorps  %xmm0,%xmm0
cvtsi2sd %rbp,%xmm0
cmpl   $0x0,0x4(%rsp)
movsd  0x10(%rsp),%xmm1
mulsd  0xb80(%rip),%xmm1
addsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
lea    0xbf6(%rip),%rax
lea    0xbe0(%rip),%rsi
cmove  %rax,%rsi
mov    %rbx,%rdi
call   10b0 <fprintf@plt>
mov    %rbx,%rdi
call   1070 <fclose@plt>
mov    0x8(%rsp),%rax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { double, i64 }
@.str = [3 x i8] c"rb\00"
@.str.1 = [3 x i8] c"wb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.2 = [42 x i8] c"RSA decrypting in file %s to out file %s\0A\00"
@.str.3 = [42 x i8] c"RSA encrypting in file %s to out file %s\0A\00"
@RSA_PKCS1_PADDING = global i32 0
@stderr = global i32 0
@.str.4 = [18 x i8] c"../doc/rsa_us.txt\00"
@.str.5 = [2 x i8] c"a\00"
@.str.6 = [15 x i8] c"encode: %f us\0A\00"
@.str.7 = [15 x i8] c"decode: %f us\0A\00"
@.str.8 = [11 x i8] c"I/O error\0A\00"
@.str.9 = [16 x i8] c"open %s failed\0A\00"
define i32 @RsaEncDec(i8* %0, i8* %1, i32** %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32**
%8 = alloca i32
%9 = alloca %struct.timeval
%10 = alloca %struct.timeval
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i8*
%16 = alloca i8*
%17 = alloca i32*
%18 = alloca i32*
%19 = alloca i32*
%20 = alloca double
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32** %2, i32*** %7
store i32 %3, i32* %8
%21 = call i32 @gettimeofday(%struct.timeval* %9, i32* null)
store i32 0, i32* %11
store i32 0, i32* %12
store i32 0, i32* %13
store i32 0, i32* %14
%22 = load i8*, i8** %5
%23 = call i32* @fopen(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %23, i32** %17
%24 = load i8*, i8** %6
%25 = call i32* @fopen(i8* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %25, i32** %18
store i32* null, i32** %19
%26 = load i32*, i32** %17
%27 = icmp ne i32* %26, null
br i1 %27, label %28, label %148
28: ; preds = %4
%29 = load i32*, i32** %18
%30 = icmp ne i32* %29, null
br i1 %30, label %31, label %148
31: ; preds = %28
%32 = load i32*, i32** %17
%33 = load i32, i32* @SEEK_END
%34 = call i32 @fseek(i32* %32, i32 0, i32 %33)
%35 = load i32*, i32** %17
%36 = call i32 @ftell(i32* %35)
store i32 %36, i32* %13
%37 = load i32*, i32** %17
%38 = load i32, i32* @SEEK_SET
%39 = call i32 @fseek(i32* %37, i32 0, i32 %38)
%40 = load i32, i32* %13
%41 = call i64 @malloc(i32 %40)
%42 = inttoptr i64 %41 to i8*
store i8* %42, i8** %15
%43 = load i8*, i8** %15
%44 = load i32, i32* %13
%45 = load i32*, i32** %17
%46 = call i32 @fread(i8* %43, i32 1, i32 %44, i32* %45)
%47 = load i32*, i32** %17
%48 = call i32 @fclose(i32* %47)
%49 = call i64 @malloc(i32 256)
%50 = inttoptr i64 %49 to i8*
store i8* %50, i8** %16
%51 = load i32, i32* %8
%52 = icmp eq i32 %51, 0
br i1 %52, label %53, label %57
53: ; preds = %31
%54 = load i8*, i8** %5
%55 = load i8*, i8** %6
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i8* %54, i8* %55)
br label %61
57: ; preds = %31
%58 = load i8*, i8** %5
%59 = load i8*, i8** %6
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i8* %58, i8* %59)
br label %61
61: ; preds = %57, %53
br label %62
62: ; preds = %113, %61
%63 = load i32, i32* %14
%64 = load i32, i32* %13
%65 = icmp slt i32 %63, %64
br i1 %65, label %66, label %114
66: ; preds = %62
%67 = load i8*, i8** %16
%68 = call i32 @memset(i8* %67, i32 0, i32 256)
%69 = load i32, i32* %8
%70 = icmp eq i32 %69, 0
br i1 %70, label %71, label %83
71: ; preds = %66
%72 = load i8*, i8** %15
%73 = load i32, i32* %14
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds i8, i8* %72, i64 %74
%76 = load i8*, i8** %16
%77 = load i32**, i32*** %7
%78 = load i32*, i32** %77
%79 = load i32, i32* @RSA_PKCS1_PADDING
%80 = call i32 @RSA_private_decrypt(i32 256, i8* %75, i8* %76, i32* %78, i32 %79)
store i32 %80, i32* %12
%81 = load i32, i32* %14
%82 = add nsw i32 %81, 256
store i32 %82, i32* %14
br label %95
83: ; preds = %66
%84 = load i8*, i8** %15
%85 = load i32, i32* %14
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds i8, i8* %84, i64 %86
%88 = load i8*, i8** %16
%89 = load i32**, i32*** %7
%90 = load i32*, i32** %89
%91 = load i32, i32* @RSA_PKCS1_PADDING
%92 = call i32 @RSA_public_encrypt(i32 128, i8* %87, i8* %88, i32* %90, i32 %91)
store i32 %92, i32* %12
%93 = load i32, i32* %14
%94 = add nsw i32 %93, 128
store i32 %94, i32* %14
br label %95
95: ; preds = %83, %71
%96 = load i32, i32* %12
%97 = icmp ne i32 %96, -1
br i1 %97, label %98, label %103
98: ; preds = %95
%99 = load i8*, i8** %16
%100 = load i32, i32* %12
%101 = load i32*, i32** %18
%102 = call i32 @fwrite(i8* %99, i32 1, i32 %100, i32* %101)
br label %113
103: ; preds = %95
%104 = load i32, i32* %11
%105 = load i32, i32* %14
%106 = add nsw i32 %104, %105
%107 = load i32, i32* %13
%108 = icmp slt i32 %106, %107
br i1 %108, label %109, label %112
109: ; preds = %103
%110 = load i32, i32* @stderr
%111 = call i32 @ERR_print_errors_fp(i32 %110)
store i32 2, i32* %11
br label %112
112: ; preds = %109, %103
br label %113
113: ; preds = %112, %98
br label %62
114: ; preds = %62
%115 = load i8*, i8** %15
%116 = call i32 @free(i8* %115)
%117 = load i8*, i8** %16
%118 = call i32 @free(i8* %117)
%119 = load i32*, i32** %18
%120 = call i32 @fclose(i32* %119)
%121 = call i32 @gettimeofday(%struct.timeval* %10, i32* null)
%122 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i32 0, i32 0
%123 = load double, double* %122
%124 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 0
%125 = load double, double* %124
%126 = fsub double %123, %125
%127 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i32 0, i32 1
%128 = load i64, i64* %127
%129 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 1
%130 = load i64, i64* %129
%131 = sub nsw i64 %128, %130
%132 = sitofp i64 %131 to double
%133 = call double @llvm.fmuladd.f64(double %126, double 1.000000e+06, double %132)
store double %133, double* %20
%134 = call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %134, i32** %19
%135 = load i32, i32* %8
%136 = icmp ne i32 %135, 0
br i1 %136, label %137, label %141
137: ; preds = %114
%138 = load i32*, i32** %19
%139 = load double, double* %20
%140 = call i32 @fprintf(i32* %138, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), double %139)
br label %145
141: ; preds = %114
%142 = load i32*, i32** %19
%143 = load double, double* %20
%144 = call i32 @fprintf(i32* %142, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0), double %143)
br label %145
145: ; preds = %141, %137
%146 = load i32*, i32** %19
%147 = call i32 @fclose(i32* %146)
br label %168
148: ; preds = %28, %4
%149 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0))
%150 = load i32*, i32** %17
%151 = icmp ne i32* %150, null
br i1 %151, label %158, label %152
152: ; preds = %148
%153 = load i8*, i8** %5
%154 = icmp ne i8* %153, null
br i1 %154, label %155, label %158
155: ; preds = %152
%156 = load i8*, i8** %5
%157 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0), i8* %156)
br label %158
158: ; preds = %155, %152, %148
%159 = load i32*, i32** %18
%160 = icmp ne i32* %159, null
br i1 %160, label %167, label %161
161: ; preds = %158
%162 = load i8*, i8** %6
%163 = icmp ne i8* %162, null
br i1 %163, label %164, label %167
164: ; preds = %161
%165 = load i8*, i8** %6
%166 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0), i8* %165)
br label %167
167: ; preds = %164, %161, %158
store i32 1, i32* %11
br label %168
168: ; preds = %167, %145
%169 = load i32, i32* %11
ret i32 %169
}

LLVM IR (-O2):
%struct.timeval = type { double, i64 }
@.str = [3 x i8] c"rb\00"
@.str.1 = [3 x i8] c"wb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.2 = [42 x i8] c"RSA decrypting in file %s to out file %s\0A\00"
@.str.3 = [42 x i8] c"RSA encrypting in file %s to out file %s\0A\00"
@RSA_PKCS1_PADDING = global i32 0
@stderr = global i32 0
@.str.4 = [18 x i8] c"../doc/rsa_us.txt\00"
@.str.5 = [2 x i8] c"a\00"
@.str.6 = [15 x i8] c"encode: %f us\0A\00"
@.str.7 = [15 x i8] c"decode: %f us\0A\00"
@.str.9 = [16 x i8] c"open %s failed\0A\00"
@str = [10 x i8] c"I/O error\00"
define i32 @RsaEncDec(i8* %0, i8* %1, i32** nocapture %2, i32 %3) {
%5 = alloca %struct.timeval
%6 = alloca %struct.timeval
%7 = bitcast %struct.timeval* %5 to i8*
%8 = bitcast %struct.timeval* %6 to i8*
%9 = call i32 @gettimeofday(%struct.timeval* %5, i32* null)
%10 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp ne i32* %10, null
%13 = icmp ne i32* %11, null
%14 = and i1 %12, %13
br i1 %14, label %15, label %81
15: ; preds = %4
%16 = load i32, i32* @SEEK_END
%17 = tail call i32 @fseek(i32* %10, i32 0, i32 %16)
%18 = tail call i32 @ftell(i32* %10)
%19 = load i32, i32* @SEEK_SET
%20 = tail call i32 @fseek(i32* %10, i32 0, i32 %19)
%21 = tail call i64 @malloc(i32 %18)
%22 = inttoptr i64 %21 to i8*
%23 = tail call i32 @fread(i8* %22, i32 1, i32 %18, i32* %10)
%24 = tail call i32 @fclose(i32* %10)
%25 = tail call i64 @malloc(i32 256)
%26 = inttoptr i64 %25 to i8*
%27 = icmp eq i32 %3, 0
%28 = select i1 %27, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0)
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %28, i8* %0, i8* %1)
%30 = icmp sgt i32 %18, 0
br i1 %30, label %31, label %59
31: ; preds = %15, %56
%32 = phi i32 [ %57, %56 ], [ 0, %15 ]
%33 = phi i32 [ %46, %56 ], [ 0, %15 ]
%34 = tail call i32 @memset(i8* %26, i32 0, i32 256)
%35 = zext i32 %33 to i64
%36 = getelementptr inbounds i8, i8* %22, i64 %35
%37 = load i32*, i32** %2
%38 = load i32, i32* @RSA_PKCS1_PADDING
br i1 %27, label %39, label %41
39: ; preds = %31
%40 = tail call i32 @RSA_private_decrypt(i32 256, i8* %36, i8* %26, i32* %37, i32 %38)
br label %43
41: ; preds = %31
%42 = tail call i32 @RSA_public_encrypt(i32 128, i8* %36, i8* %26, i32* %37, i32 %38)
br label %43
43: ; preds = %41, %39
%44 = phi i32 [ 128, %41 ], [ 256, %39 ]
%45 = phi i32 [ %42, %41 ], [ %40, %39 ]
%46 = add nuw nsw i32 %33, %44
%47 = icmp eq i32 %45, -1
br i1 %47, label %50, label %48
48: ; preds = %43
%49 = tail call i32 @fwrite(i8* %26, i32 1, i32 %45, i32* %11)
br label %56
50: ; preds = %43
%51 = add nsw i32 %46, %32
%52 = icmp slt i32 %51, %18
br i1 %52, label %53, label %56
53: ; preds = %50
%54 = load i32, i32* @stderr
%55 = tail call i32 @ERR_print_errors_fp(i32 %54)
br label %56
56: ; preds = %50, %53, %48
%57 = phi i32 [ %32, %48 ], [ 2, %53 ], [ %32, %50 ]
%58 = icmp slt i32 %46, %18
br i1 %58, label %31, label %59
59: ; preds = %56, %15
%60 = phi i32 [ 0, %15 ], [ %57, %56 ]
%61 = tail call i32 @free(i8* %22)
%62 = tail call i32 @free(i8* %26)
%63 = tail call i32 @fclose(i32* %11)
%64 = call i32 @gettimeofday(%struct.timeval* %6, i32* null)
%65 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i64 0, i32 0
%66 = load double, double* %65
%67 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 0
%68 = load double, double* %67
%69 = fsub double %66, %68
%70 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i64 0, i32 1
%71 = load i64, i64* %70
%72 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 1
%73 = load i64, i64* %72
%74 = sub nsw i64 %71, %73
%75 = sitofp i64 %74 to double
%76 = tail call double @llvm.fmuladd.f64(double %69, double 1.000000e+06, double %75)
%77 = tail call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%78 = select i1 %27, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0)
%79 = tail call i32 @fprintf(i32* %77, i8* %78, double %76)
%80 = tail call i32 @fclose(i32* %77)
br label %94
81: ; preds = %4
%82 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
%83 = icmp eq i32* %10, null
%84 = icmp ne i8* %0, null
%85 = and i1 %84, %83
br i1 %85, label %86, label %88
86: ; preds = %81
%87 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0), i8* %0)
br label %88
88: ; preds = %86, %81
%89 = icmp eq i32* %11, null
%90 = icmp ne i8* %1, null
%91 = and i1 %90, %89
br i1 %91, label %92, label %94
92: ; preds = %88
%93 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0), i8* %1)
br label %94
94: ; preds = %88, %92, %59
%95 = phi i32 [ %60, %59 ], [ 1, %92 ], [ 1, %88 ]
ret i32 %95
}