#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 */

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ gen_rand_str(unsigned char *, size_t);
scalar_t__ getCycles();
int /*<<< orphan*/ joltik_aead_decrypt(unsigned char *, size_t, unsigned char *,
                                       size_t *, unsigned char *,
                                       unsigned char *, unsigned char *,
                                       size_t);
int /*<<< orphan*/ joltik_aead_encrypt(unsigned char *, size_t, unsigned char *,
                                       size_t, unsigned char *, unsigned char *,
                                       unsigned char *, size_t *);
int /*<<< orphan*/ memcmp(unsigned char *, unsigned char *, size_t);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, int);
int /*<<< orphan*/ reset_timer();
int /*<<< orphan*/ start_timer();
int /*<<< orphan*/ stop_timer();
int main(void) {
  unsigned char c[1024 + 8];
  size_t c_len;
  unsigned char m[1024];
  size_t m_len = 1024;
  size_t ad_len = 8;
  unsigned char auth[8];
  unsigned char *key = "ABCDEFCGIJKLMNQU";
  unsigned char *npub = "DDDDDDDD";
  unsigned char msg[1024];
  size_t msg_len;
  int i;
  double num_cycles = 0;
  for (i = 0; i < 1000; i++) {
    gen_rand_str(m, m_len);
    memcpy(auth, m, 8);
    reset_timer();
    start_timer();
    joltik_aead_encrypt(auth, ad_len, m, m_len, key, npub, c, &c_len);
    joltik_aead_decrypt(auth, ad_len, msg, &msg_len, key, npub, c, c_len);
    stop_timer();
    num_cycles += (double)getCycles();
    assert(m_len == msg_len);
    assert(!memcmp(msg, m, m_len));
  }
  num_cycles /= 1000;
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc80,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x400,-0x828(%rbp)
movq   $0x8,-0x830(%rbp)
lea    0xe39(%rip),%rax
mov    %rax,-0x840(%rbp)
lea    0xe3c(%rip),%rax
mov    %rax,-0x848(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0xc68(%rbp)
ff
movl   $0x0,-0xc5c(%rbp)
cmpl   $0x3e8,-0xc5c(%rbp)
jge    134c <main+0x1ac>
lea    -0x820(%rbp),%rdi
mov    -0x828(%rbp),%rsi
call   1040 <gen_rand_str@plt>
lea    -0x838(%rbp),%rdi
lea    -0x820(%rbp),%rsi
mov    $0x8,%edx
call   1080 <memcpy@plt>
mov    $0x0,%al
call   1060 <reset_timer@plt>
mov    $0x0,%al
call   10a0 <start_timer@plt>
lea    -0x838(%rbp),%rdi
mov    -0x830(%rbp),%rsi
lea    -0x820(%rbp),%rdx
mov    -0x828(%rbp),%rcx
mov    -0x840(%rbp),%r8
mov    -0x848(%rbp),%r9
lea    -0x410(%rbp),%r10
lea    -0x418(%rbp),%rax
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   10c0 <joltik_aead_encrypt@plt>
lea    -0x838(%rbp),%rdi
mov    -0x830(%rbp),%rsi
lea    -0xc50(%rbp),%rdx
mov    -0x840(%rbp),%r8
mov    -0x848(%rbp),%r9
lea    -0x410(%rbp),%r10
mov    -0x418(%rbp),%rax
lea    -0xc58(%rbp),%rcx
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1050 <joltik_aead_decrypt@plt>
mov    $0x0,%al
call   10b0 <stop_timer@plt>
mov    $0x0,%al
call   1090 <getCycles@plt>
cvtsi2sd %rax,%xmm0
addsd  -0xc68(%rbp),%xmm0
ff
movsd  %xmm0,-0xc68(%rbp)
ff
mov    -0x828(%rbp),%rax
cmp    -0xc58(%rbp),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
lea    -0xc50(%rbp),%rdi
lea    -0x820(%rbp),%rsi
mov    -0x828(%rbp),%rdx
call   1030 <memcmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0xc5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc5c(%rbp)
jmp    11f9 <main+0x59>
movsd  -0xc68(%rbp),%xmm0
ff
movsd  0xca4(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0xc68(%rbp)
ff
xor    %eax,%eax
add    $0xc80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xc28,%rsp
mov    $0x3e8,%r15d
nopw   0x0(%rax,%rax,1)
mov    $0x400,%esi
lea    0x20(%rsp),%rbp
mov    %rbp,%rdi
call   1030 <gen_rand_str@plt>
lea    0x18(%rsp),%rbx
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    $0x8,%edx
call   1070 <memcpy@plt>
xor    %eax,%eax
call   1050 <reset_timer@plt>
xor    %eax,%eax
call   10a0 <start_timer@plt>
mov    $0x8,%esi
mov    $0x400,%ecx
mov    %rbx,%rdi
mov    %rbp,%rdx
lea    0xdf4(%rip),%r12
mov    %r12,%r8
lea    0xdfb(%rip),%r13
mov    %r13,%r9
lea    0x10(%rsp),%rax
push   %rax
lea    0x828(%rsp),%rbp
push   %rbp
call   10c0 <joltik_aead_encrypt@plt>
add    $0x10,%rsp
mov    $0x8,%esi
mov    %rbx,%rdi
lea    0x420(%rsp),%r14
mov    %r14,%rdx
lea    0x8(%rsp),%rcx
mov    %r12,%r8
mov    %r13,%r9
push   0x10(%rsp)
push   %rbp
call   1040 <joltik_aead_decrypt@plt>
add    $0x10,%rsp
xor    %eax,%eax
call   10b0 <stop_timer@plt>
xor    %eax,%eax
call   1090 <getCycles@plt>
xor    %edi,%edi
cmpq   $0x400,0x8(%rsp)
sete   %dil
call   1060 <assert@plt>
mov    $0x400,%edx
mov    %r14,%rdi
lea    0x20(%rsp),%rsi
call   1080 <bcmp@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1060 <assert@plt>
add    $0xffffffff,%r15d
jne    11c0 <main+0x20>
xor    %eax,%eax
add    $0xc28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"ABCDEFCGIJKLMNQU\00"
@.str.1 = [9 x i8] c"DDDDDDDD\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [1032 x i8]
%3 = alloca i64
%4 = alloca [1024 x i8]
%5 = alloca i64
%6 = alloca i64
%7 = alloca [8 x i8]
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca [1024 x i8]
%11 = alloca i64
%12 = alloca i32
%13 = alloca double
store i32 0, i32* %1
store i64 1024, i64* %5
store i64 8, i64* %6
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8** %8
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8** %9
store double 0.000000e+00, double* %13
store i32 0, i32* %12
br label %14
14: ; preds = %60, %0
%15 = load i32, i32* %12
%16 = icmp slt i32 %15, 1000
br i1 %16, label %17, label %63
17: ; preds = %14
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%19 = load i64, i64* %5
%20 = call i32 @gen_rand_str(i8* %18, i64 %19)
%21 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 0
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%23 = call i32 @memcpy(i8* %21, i8* %22, i32 8)
%24 = call i32 (...) @reset_timer()
%25 = call i32 (...) @start_timer()
%26 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 0
%27 = load i64, i64* %6
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%29 = load i64, i64* %5
%30 = load i8*, i8** %8
%31 = load i8*, i8** %9
%32 = getelementptr inbounds [1032 x i8], [1032 x i8]* %2, i64 0, i64 0
%33 = call i32 @joltik_aead_encrypt(i8* %26, i64 %27, i8* %28, i64 %29, i8* %30, i8* %31, i8* %32, i64* %3)
%34 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 0
%35 = load i64, i64* %6
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%37 = load i8*, i8** %8
%38 = load i8*, i8** %9
%39 = getelementptr inbounds [1032 x i8], [1032 x i8]* %2, i64 0, i64 0
%40 = load i64, i64* %3
%41 = call i32 @joltik_aead_decrypt(i8* %34, i64 %35, i8* %36, i64* %11, i8* %37, i8* %38, i8* %39, i64 %40)
%42 = call i32 (...) @stop_timer()
%43 = call i64 (...) @getCycles()
%44 = sitofp i64 %43 to double
%45 = load double, double* %13
%46 = fadd double %45, %44
store double %46, double* %13
%47 = load i64, i64* %5
%48 = load i64, i64* %11
%49 = icmp eq i64 %47, %48
%50 = zext i1 %49 to i32
%51 = call i32 @assert(i32 %50)
%52 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%53 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%54 = load i64, i64* %5
%55 = call i32 @memcmp(i8* %52, i8* %53, i64 %54)
%56 = icmp ne i32 %55, 0
%57 = xor i1 %56, true
%58 = zext i1 %57 to i32
%59 = call i32 @assert(i32 %58)
br label %60
60: ; preds = %17
%61 = load i32, i32* %12
%62 = add nsw i32 %61, 1
store i32 %62, i32* %12
br label %14
63: ; preds = %14
%64 = load double, double* %13
%65 = fdiv double %64, 1.000000e+03
store double %65, double* %13
ret i32 0
}

LLVM IR (-O2):
@.str = [17 x i8] c"ABCDEFCGIJKLMNQU\00"
@.str.1 = [9 x i8] c"DDDDDDDD\00"
define i32 @main() {
%1 = alloca [1032 x i8]
%2 = alloca i64
%3 = alloca [1024 x i8]
%4 = alloca [8 x i8]
%5 = alloca [1024 x i8]
%6 = alloca i64
%7 = getelementptr inbounds [1032 x i8], [1032 x i8]* %1, i64 0, i64 0
%8 = bitcast i64* %2 to i8*
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%10 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 0
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%12 = bitcast i64* %6 to i8*
br label %13
13: ; preds = %0, %13
%14 = phi i32 [ 0, %0 ], [ %32, %13 ]
%15 = call i32 @gen_rand_str(i8* %9, i64 1024)
%16 = call i32 @memcpy(i8* %10, i8* %9, i32 8)
%17 = call i32 (...) @reset_timer()
%18 = call i32 (...) @start_timer()
%19 = call i32 @joltik_aead_encrypt(i8* %10, i64 8, i8* %9, i64 1024, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %7, i64* %2)
%20 = load i64, i64* %2
%21 = call i32 @joltik_aead_decrypt(i8* %10, i64 8, i8* %11, i64* %6, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %7, i64 %20)
%22 = call i32 (...) @stop_timer()
%23 = call i64 (...) @getCycles()
%24 = load i64, i64* %6
%25 = icmp eq i64 %24, 1024
%26 = zext i1 %25 to i32
%27 = call i32 @assert(i32 %26)
%28 = call i32 @bcmp(i8* dereferenceable(1024) %11, i8* dereferenceable(1024) %9, i64 1024)
%29 = icmp eq i32 %28, 0
%30 = zext i1 %29 to i32
%31 = call i32 @assert(i32 %30)
%32 = add nuw nsw i32 %14, 1
%33 = icmp eq i32 %32, 1000
br i1 %33, label %34, label %13
34: ; preds = %13
ret i32 0
}