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

/* Variables and functions */
int /*<<< orphan*/ CLOCK_MONOTONIC;
double EXIT_FAILURE;
int /*<<< orphan*/ RAND_bytes(unsigned char *, int);
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
unsigned long fread(unsigned char *, int, unsigned long, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(unsigned char *);
unsigned long fwrite(unsigned char *, int, unsigned long, int /*<<< orphan*/ *);
unsigned char *malloc(unsigned long);
scalar_t__ memcmp(unsigned char *, unsigned char *, unsigned long);
int /*<<< orphan*/ printf(char *, unsigned long);
int /*<<< orphan*/ t_mixdecrypt_oaep(unsigned int, unsigned char *,
                                     unsigned char *, unsigned long,
                                     unsigned char *, unsigned char *);
int /*<<< orphan*/ t_mixencrypt_oaep(unsigned int, unsigned char *,
                                     unsigned char *, unsigned long,
                                     unsigned char *, unsigned char *);
double test(char *filename, char *output, unsigned long size,
            unsigned int threads, unsigned int times) {
  unsigned char key[16];
  unsigned char iv[16];
  unsigned char *in;
  unsigned char *dec;
  unsigned char *out;
  unsigned long bytes;
  unsigned int i;
  struct timespec start, finish;
  double elapsed = 0;
  FILE *fp;
  in = malloc(size);
  dec = malloc(size);
  out = malloc(size);
  fp = fopen(filename, "rb");
  bytes = fread(in, 1, size, fp);
  fclose(fp);
  if (bytes != size) {
    printf("Can read only %lu Bytes from file\n", bytes);
    return EXIT_FAILURE;
  }
  RAND_bytes(key, 16);
  RAND_bytes(iv, 16);
  for (i = 0; i < times; ++i) {
    clock_gettime(CLOCK_MONOTONIC, &start);
    if (0)
      printf("ENCRYPTION (size %lu)\n", size);
    t_mixencrypt_oaep(threads, in, out, size, key, iv);
    if (0)
      printf("DECRYPTION (size %lu)\n", size);
    if (0)
      t_mixdecrypt_oaep(threads, out, dec, size, key, iv);
    clock_gettime(CLOCK_MONOTONIC, &finish);
    elapsed += (finish.tv_sec - start.tv_sec);
    elapsed += (finish.tv_nsec - start.tv_nsec) / 1000000000.0;
    if (0)
      assert(0 == memcmp(in, dec, size));
  }
  fp = fopen(output, "wb");
  bytes = fwrite(dec, 1, size, fp);
  fclose(fp);
  if (bytes != size) {
    printf("Can write only %lu Bytes from file\n", bytes);
    return EXIT_FAILURE;
  }
  free(in);
  free(out);
  free(dec);
  return elapsed;
}


x86 assembly (clang, -O0):
<test>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8d,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0xa0(%rbp)
ff
mov    -0x20(%rbp),%rdi
call   1090 <malloc@plt>
mov    %rax,-0x58(%rbp)
mov    -0x20(%rbp),%rdi
call   1090 <malloc@plt>
mov    %rax,-0x60(%rbp)
mov    -0x20(%rbp),%rdi
call   1090 <malloc@plt>
mov    %rax,-0x68(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe0d(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0xa8(%rbp)
mov    -0x58(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0xa8(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    %rax,-0x70(%rbp)
mov    -0xa8(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x70(%rbp),%rax
cmp    -0x20(%rbp),%rax
je     1263 <test+0xc3>
mov    -0x70(%rbp),%rsi
lea    0xdc2(%rip),%rdi
call   1080 <printf@plt>
mov    0x2d83(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    13cd <test+0x22d>
lea    -0x40(%rbp),%rdi
mov    $0x10,%esi
call   1070 <RAND_bytes@plt>
lea    -0x50(%rbp),%rdi
mov    $0x10,%esi
call   1070 <RAND_bytes@plt>
movl   $0x0,-0x74(%rbp)
mov    -0x74(%rbp),%eax
cmp    -0x28(%rbp),%eax
jae    1332 <test+0x192>
mov    0x2d4f(%rip),%rax
mov    (%rax),%edi
lea    -0x88(%rbp),%rsi
call   1050 <clock_gettime@plt>
mov    -0x24(%rbp),%edi
mov    -0x58(%rbp),%rsi
mov    -0x68(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    -0x40(%rbp),%r8
lea    -0x50(%rbp),%r9
call   10a0 <t_mixencrypt_oaep@plt>
mov    0x2d1e(%rip),%rax
mov    (%rax),%edi
lea    -0x98(%rbp),%rsi
call   1050 <clock_gettime@plt>
mov    -0x90(%rbp),%rax
sub    -0x80(%rbp),%rax
cvtsi2sd %rax,%xmm0
addsd  -0xa0(%rbp),%xmm0
ff
movsd  %xmm0,-0xa0(%rbp)
ff
movsd  -0x98(%rbp),%xmm0
ff
subsd  -0x88(%rbp),%xmm0
ff
movsd  0xcf0(%rip),%xmm1
divsd  %xmm1,%xmm0
addsd  -0xa0(%rbp),%xmm0
ff
movsd  %xmm0,-0xa0(%rbp)
ff
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
jmp    1286 <test+0xe6>
mov    -0x18(%rbp),%rdi
lea    0xcf1(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0xa8(%rbp)
mov    -0x60(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0xa8(%rbp),%rcx
mov    $0x1,%esi
call   10c0 <fwrite@plt>
mov    %rax,-0x70(%rbp)
mov    -0xa8(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x70(%rbp),%rax
cmp    -0x20(%rbp),%rax
je     13a5 <test+0x205>
mov    -0x70(%rbp),%rsi
lea    0xca6(%rip),%rdi
call   1080 <printf@plt>
mov    0x2c41(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    13cd <test+0x22d>
mov    -0x58(%rbp),%rdi
call   1030 <free@plt>
mov    -0x68(%rbp),%rdi
call   1030 <free@plt>
mov    -0x60(%rbp),%rdi
call   1030 <free@plt>
movsd  -0xa0(%rbp),%xmm0
ff
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %r8d,%ebp
mov    %ecx,%r13d
mov    %rdx,%rbx
mov    %rsi,0x10(%rsp)
mov    %rdi,%r14
mov    %rdx,%rdi
call   1090 <malloc@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1090 <malloc@plt>
mov    %rax,0x18(%rsp)
mov    %rbx,%rdi
call   1090 <malloc@plt>
mov    %rax,%r12
lea    0xe1f(%rip),%rsi
mov    %r14,%rdi
call   10b0 <fopen@plt>
mov    %rax,%r14
mov    %r15,%rdi
mov    $0x1,%esi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1040 <fread@plt>
mov    %rax,0x8(%rsp)
mov    %r14,%rdi
call   1060 <fclose@plt>
mov    0x8(%rsp),%rsi
cmp    %rbx,%rsi
jne    1322 <test+0x182>
lea    0x50(%rsp),%rdi
mov    $0x10,%esi
call   1070 <RAND_bytes@plt>
lea    0x40(%rsp),%rdi
mov    $0x10,%esi
call   1070 <RAND_bytes@plt>
xorpd  %xmm1,%xmm1
test   %ebp,%ebp
je     12c0 <test+0x120>
mov    0x2d99(%rip),%r14
nop
movsd  %xmm1,0x8(%rsp)
mov    (%r14),%edi
lea    0x30(%rsp),%rsi
call   1050 <clock_gettime@plt>
mov    %r13d,%edi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %rbx,%rcx
lea    0x50(%rsp),%r8
lea    0x40(%rsp),%r9
call   10a0 <t_mixencrypt_oaep@plt>
mov    (%r14),%edi
lea    0x20(%rsp),%rsi
call   1050 <clock_gettime@plt>
mov    0x28(%rsp),%rax
sub    0x38(%rsp),%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  0x8(%rsp),%xmm0
movsd  0x20(%rsp),%xmm1
subsd  0x30(%rsp),%xmm1
divsd  0xd49(%rip),%xmm1
addsd  %xmm0,%xmm1
add    $0xffffffff,%ebp
jne    1250 <test+0xb0>
movsd  %xmm1,0x8(%rsp)
lea    0xd61(%rip),%rsi
mov    0x10(%rsp),%rdi
call   10b0 <fopen@plt>
mov    %rax,%rbp
mov    0x18(%rsp),%r13
mov    %r13,%rdi
mov    $0x1,%esi
mov    %rbx,%rdx
mov    %rax,%rcx
call   10c0 <fwrite@plt>
mov    %rax,%r14
mov    %rbp,%rdi
call   1060 <fclose@plt>
cmp    %rbx,%r14
jne    132b <test+0x18b>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r13,%rdi
call   1030 <free@plt>
movsd  0x8(%rsp),%xmm0
jmp    1345 <test+0x1a5>
lea    0xce2(%rip),%rdi
jmp    1335 <test+0x195>
lea    0xcff(%rip),%rdi
mov    %r14,%rsi
call   1080 <printf@plt>
mov    0x2c97(%rip),%rax
movsd  (%rax),%xmm0
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timespec = type { double, i64 }
@.str = [3 x i8] c"rb\00"
@.str.1 = [35 x i8] c"Can read only %lu Bytes from file\0A\00"
@EXIT_FAILURE = global double 0.000000e+00
@CLOCK_MONOTONIC = global i32 0
@.str.2 = [3 x i8] c"wb\00"
@.str.3 = [36 x i8] c"Can write only %lu Bytes from file\0A\00"
define double @test(i8* %0, i8* %1, i64 %2, i32 %3, i32 %4) {
%6 = alloca double
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
%12 = alloca [16 x i8]
%13 = alloca [16 x i8]
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca i8*
%17 = alloca i64
%18 = alloca i32
%19 = alloca %struct.timespec
%20 = alloca %struct.timespec
%21 = alloca double
%22 = alloca i32*
store i8* %0, i8** %7
store i8* %1, i8** %8
store i64 %2, i64* %9
store i32 %3, i32* %10
store i32 %4, i32* %11
store double 0.000000e+00, double* %21
%23 = load i64, i64* %9
%24 = call i8* @malloc(i64 %23)
store i8* %24, i8** %14
%25 = load i64, i64* %9
%26 = call i8* @malloc(i64 %25)
store i8* %26, i8** %15
%27 = load i64, i64* %9
%28 = call i8* @malloc(i64 %27)
store i8* %28, i8** %16
%29 = load i8*, i8** %7
%30 = call i32* @fopen(i8* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %30, i32** %22
%31 = load i8*, i8** %14
%32 = load i64, i64* %9
%33 = load i32*, i32** %22
%34 = call i64 @fread(i8* %31, i32 1, i64 %32, i32* %33)
store i64 %34, i64* %17
%35 = load i32*, i32** %22
%36 = call i32 @fclose(i32* %35)
%37 = load i64, i64* %17
%38 = load i64, i64* %9
%39 = icmp ne i64 %37, %38
br i1 %39, label %40, label %44
40: ; preds = %5
%41 = load i64, i64* %17
%42 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i64 %41)
%43 = load double, double* @EXIT_FAILURE
store double %43, double* %6
br label %108
44: ; preds = %5
%45 = getelementptr inbounds [16 x i8], [16 x i8]* %12, i64 0, i64 0
%46 = call i32 @RAND_bytes(i8* %45, i32 16)
%47 = getelementptr inbounds [16 x i8], [16 x i8]* %13, i64 0, i64 0
%48 = call i32 @RAND_bytes(i8* %47, i32 16)
store i32 0, i32* %18
br label %49
49: ; preds = %81, %44
%50 = load i32, i32* %18
%51 = load i32, i32* %11
%52 = icmp ult i32 %50, %51
br i1 %52, label %53, label %84
53: ; preds = %49
%54 = load i32, i32* @CLOCK_MONOTONIC
%55 = call i32 @clock_gettime(i32 %54, %struct.timespec* %19)
%56 = load i32, i32* %10
%57 = load i8*, i8** %14
%58 = load i8*, i8** %16
%59 = load i64, i64* %9
%60 = getelementptr inbounds [16 x i8], [16 x i8]* %12, i64 0, i64 0
%61 = getelementptr inbounds [16 x i8], [16 x i8]* %13, i64 0, i64 0
%62 = call i32 @t_mixencrypt_oaep(i32 %56, i8* %57, i8* %58, i64 %59, i8* %60, i8* %61)
%63 = load i32, i32* @CLOCK_MONOTONIC
%64 = call i32 @clock_gettime(i32 %63, %struct.timespec* %20)
%65 = getelementptr inbounds %struct.timespec, %struct.timespec* %20, i32 0, i32 1
%66 = load i64, i64* %65
%67 = getelementptr inbounds %struct.timespec, %struct.timespec* %19, i32 0, i32 1
%68 = load i64, i64* %67
%69 = sub nsw i64 %66, %68
%70 = sitofp i64 %69 to double
%71 = load double, double* %21
%72 = fadd double %71, %70
store double %72, double* %21
%73 = getelementptr inbounds %struct.timespec, %struct.timespec* %20, i32 0, i32 0
%74 = load double, double* %73
%75 = getelementptr inbounds %struct.timespec, %struct.timespec* %19, i32 0, i32 0
%76 = load double, double* %75
%77 = fsub double %74, %76
%78 = fdiv double %77, 1.000000e+09
%79 = load double, double* %21
%80 = fadd double %79, %78
store double %80, double* %21
br label %81
81: ; preds = %53
%82 = load i32, i32* %18
%83 = add i32 %82, 1
store i32 %83, i32* %18
br label %49
84: ; preds = %49
%85 = load i8*, i8** %8
%86 = call i32* @fopen(i8* %85, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %86, i32** %22
%87 = load i8*, i8** %15
%88 = load i64, i64* %9
%89 = load i32*, i32** %22
%90 = call i64 @fwrite(i8* %87, i32 1, i64 %88, i32* %89)
store i64 %90, i64* %17
%91 = load i32*, i32** %22
%92 = call i32 @fclose(i32* %91)
%93 = load i64, i64* %17
%94 = load i64, i64* %9
%95 = icmp ne i64 %93, %94
br i1 %95, label %96, label %100
96: ; preds = %84
%97 = load i64, i64* %17
%98 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i64 %97)
%99 = load double, double* @EXIT_FAILURE
store double %99, double* %6
br label %108
100: ; preds = %84
%101 = load i8*, i8** %14
%102 = call i32 @free(i8* %101)
%103 = load i8*, i8** %16
%104 = call i32 @free(i8* %103)
%105 = load i8*, i8** %15
%106 = call i32 @free(i8* %105)
%107 = load double, double* %21
store double %107, double* %6
br label %108
108: ; preds = %100, %96, %40
%109 = load double, double* %6
ret double %109
}

LLVM IR (-O2):
%struct.timespec = type { double, i64 }
@.str = [3 x i8] c"rb\00"
@.str.1 = [35 x i8] c"Can read only %lu Bytes from file\0A\00"
@EXIT_FAILURE = global double 0.000000e+00
@CLOCK_MONOTONIC = global i32 0
@.str.2 = [3 x i8] c"wb\00"
@.str.3 = [36 x i8] c"Can write only %lu Bytes from file\0A\00"
define double @test(i8* nocapture %0, i8* nocapture %1, i64 %2, i32 %3, i32 %4) {
%6 = alloca [16 x i8]
%7 = alloca [16 x i8]
%8 = alloca %struct.timespec
%9 = alloca %struct.timespec
%10 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%11 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%12 = bitcast %struct.timespec* %8 to i8*
%13 = bitcast %struct.timespec* %9 to i8*
%14 = tail call i8* @malloc(i64 %2)
%15 = tail call i8* @malloc(i64 %2)
%16 = tail call i8* @malloc(i64 %2)
%17 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%18 = tail call i64 @fread(i8* %14, i32 1, i64 %2, i32* %17)
%19 = tail call i32 @fclose(i32* %17)
%20 = icmp eq i64 %18, %2
br i1 %20, label %24, label %21
21: ; preds = %5
%22 = tail call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i64 %18)
%23 = load double, double* @EXIT_FAILURE
br label %66
24: ; preds = %5
%25 = call i32 @RAND_bytes(i8* %10, i32 16)
%26 = call i32 @RAND_bytes(i8* %11, i32 16)
%27 = icmp eq i32 %4, 0
br i1 %27, label %53, label %28
28: ; preds = %24
%29 = getelementptr inbounds %struct.timespec, %struct.timespec* %9, i64 0, i32 1
%30 = getelementptr inbounds %struct.timespec, %struct.timespec* %8, i64 0, i32 1
%31 = getelementptr inbounds %struct.timespec, %struct.timespec* %9, i64 0, i32 0
%32 = getelementptr inbounds %struct.timespec, %struct.timespec* %8, i64 0, i32 0
br label %33
33: ; preds = %28, %33
%34 = phi double [ 0.000000e+00, %28 ], [ %50, %33 ]
%35 = phi i32 [ 0, %28 ], [ %51, %33 ]
%36 = load i32, i32* @CLOCK_MONOTONIC
%37 = call i32 @clock_gettime(i32 %36, %struct.timespec* %8)
%38 = call i32 @t_mixencrypt_oaep(i32 %3, i8* %14, i8* %16, i64 %2, i8* %10, i8* %11)
%39 = load i32, i32* @CLOCK_MONOTONIC
%40 = call i32 @clock_gettime(i32 %39, %struct.timespec* %9)
%41 = load i64, i64* %29
%42 = load i64, i64* %30
%43 = sub nsw i64 %41, %42
%44 = sitofp i64 %43 to double
%45 = fadd double %34, %44
%46 = load double, double* %31
%47 = load double, double* %32
%48 = fsub double %46, %47
%49 = fdiv double %48, 1.000000e+09
%50 = fadd double %45, %49
%51 = add nuw i32 %35, 1
%52 = icmp eq i32 %51, %4
br i1 %52, label %53, label %33
53: ; preds = %33, %24
%54 = phi double [ 0.000000e+00, %24 ], [ %50, %33 ]
%55 = call i32* @fopen(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%56 = call i64 @fwrite(i8* %15, i32 1, i64 %2, i32* %55)
%57 = call i32 @fclose(i32* %55)
%58 = icmp eq i64 %56, %2
br i1 %58, label %62, label %59
59: ; preds = %53
%60 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i64 %56)
%61 = load double, double* @EXIT_FAILURE
br label %66
62: ; preds = %53
%63 = call i32 @free(i8* %14)
%64 = call i32 @free(i8* %16)
%65 = call i32 @free(i8* %15)
br label %66
66: ; preds = %62, %59, %21
%67 = phi double [ %23, %21 ], [ %61, %59 ], [ %54, %62 ]
ret double %67
}