#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 crypto_aead_decrypt(unsigned char *, unsigned long long *, unsigned char *,
                        unsigned char *, unsigned long long, unsigned char *,
                        unsigned long long, unsigned char *, unsigned char *);
int /*<<< orphan*/ crypto_aead_encrypt(unsigned char *, unsigned long long *,
                                       unsigned char *, unsigned long long,
                                       unsigned char *, unsigned long long,
                                       unsigned char *, unsigned char *,
                                       unsigned char *);
int /*<<< orphan*/ fill(unsigned char *, unsigned long long);
int /*<<< orphan*/ free(unsigned char *);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ printf(char *, int const, size_t);
int tests_from_supercop() {
  static const size_t MAXTEST_BYTES = 4096;
  unsigned char *c = (unsigned char *)malloc((size_t)MAXTEST_BYTES + 16);
  unsigned char *a = (unsigned char *)malloc((size_t)MAXTEST_BYTES);
  unsigned char *m = (unsigned char *)malloc((size_t)MAXTEST_BYTES);
  unsigned char k[16];
  unsigned char npub[16];
  unsigned char *nsec = 0;
  unsigned long long alen;
  unsigned long long clen;
  unsigned long long mlen;
  int result = 0;
  fill(k, 16);
  fill(npub, 16);
  for (size_t i = 0; i <= MAXTEST_BYTES; ++i) {
    mlen = i;
    alen = i;
    clen = i + 16;
    fill(a, alen);
    fill(m, mlen);
    crypto_aead_encrypt(c, &clen, m, mlen, a, alen, nsec, npub, k);
    const int current_result =
        crypto_aead_decrypt(m, &mlen, nsec, c, clen, a, alen, npub, k);
    result |= current_result;
    if (current_result) {
      printf("crypto_aead_decrypt returned %d at %zu\n", current_result, i);
    }
  }
  free(a);
  free(c);
  free(m);
  return result;
}


x86 assembly (clang, -O0):
<tests_from_supercop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    $0x1010,%edi
call   1080 <malloc@plt>
mov    %rax,-0x8(%rbp)
mov    $0x1000,%edi
call   1080 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    $0x1000,%edi
call   1080 <malloc@plt>
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x48(%rbp)
movl   $0x0,-0x64(%rbp)
lea    -0x30(%rbp),%rdi
mov    $0x10,%esi
call   1060 <fill@plt>
lea    -0x40(%rbp),%rdi
mov    $0x10,%esi
call   1060 <fill@plt>
movq   $0x0,-0x70(%rbp)
cmpq   $0x1000,-0x70(%rbp)
ja     12b9 <tests_from_supercop+0x159>
mov    -0x70(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x70(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x70(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x58(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x50(%rbp),%rsi
call   1060 <fill@plt>
mov    -0x18(%rbp),%rdi
mov    -0x60(%rbp),%rsi
call   1060 <fill@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x60(%rbp),%rcx
mov    -0x10(%rbp),%r8
mov    -0x50(%rbp),%r9
mov    -0x48(%rbp),%r11
lea    -0x40(%rbp),%r10
lea    -0x30(%rbp),%rax
lea    -0x58(%rbp),%rsi
mov    %r11,(%rsp)
mov    %r10,0x8(%rsp)
mov    %rax,0x10(%rsp)
call   1070 <crypto_aead_encrypt@plt>
mov    -0x18(%rbp),%rdi
mov    -0x48(%rbp),%rdx
mov    -0x8(%rbp),%rcx
mov    -0x58(%rbp),%r8
mov    -0x10(%rbp),%r9
mov    -0x50(%rbp),%r11
lea    -0x40(%rbp),%r10
lea    -0x30(%rbp),%rax
lea    -0x60(%rbp),%rsi
mov    %r11,(%rsp)
mov    %r10,0x8(%rsp)
mov    %rax,0x10(%rsp)
call   1040 <crypto_aead_decrypt@plt>
mov    %eax,-0x74(%rbp)
mov    -0x74(%rbp),%eax
or     -0x64(%rbp),%eax
mov    %eax,-0x64(%rbp)
cmpl   $0x0,-0x74(%rbp)
je     12a3 <tests_from_supercop+0x143>
mov    -0x74(%rbp),%esi
mov    -0x70(%rbp),%rdx
lea    0xd6a(%rip),%rdi
call   1050 <printf@plt>
jmp    12a8 <tests_from_supercop+0x148>
mov    -0x70(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x70(%rbp)
jmp    11c8 <tests_from_supercop+0x68>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x64(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tests_from_supercop>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    $0x1010,%edi
call   1080 <malloc@plt>
mov    %rax,0x20(%rsp)
mov    $0x1000,%edi
call   1080 <malloc@plt>
mov    %rax,0x10(%rsp)
mov    $0x1000,%edi
call   1080 <malloc@plt>
mov    %rax,0x18(%rsp)
lea    0x40(%rsp),%rdi
mov    $0x10,%r14d
mov    $0x10,%esi
call   1060 <fill@plt>
lea    0x30(%rsp),%rdi
mov    $0x10,%esi
call   1060 <fill@plt>
xor    %ebx,%ebx
mov    0x10(%rsp),%r15
mov    0x18(%rsp),%r12
jmp    11e3 <tests_from_supercop+0x83>
nopl   (%rax)
or     %ebp,%ebx
add    $0x1,%r14
cmp    $0x1011,%r14
je     128f <tests_from_supercop+0x12f>
lea    -0x10(%r14),%r13
mov    %r13,0x8(%rsp)
mov    %r14,0x28(%rsp)
mov    %r15,%rdi
mov    %r13,%rsi
call   1060 <fill@plt>
mov    0x8(%rsp),%rsi
mov    %r12,%rdi
call   1060 <fill@plt>
mov    0x8(%rsp),%rcx
sub    $0x8,%rsp
mov    0x28(%rsp),%rbp
mov    %rbp,%rdi
lea    0x30(%rsp),%rsi
mov    %r12,%rdx
mov    %r15,%r8
mov    %r13,%r9
lea    0x48(%rsp),%rax
push   %rax
lea    0x40(%rsp),%rax
push   %rax
push   $0x0
call   1070 <crypto_aead_encrypt@plt>
add    $0x20,%rsp
mov    0x28(%rsp),%r8
sub    $0x8,%rsp
mov    %r12,%rdi
lea    0x10(%rsp),%rsi
xor    %edx,%edx
mov    %rbp,%rcx
mov    %r15,%r9
lea    0x48(%rsp),%rax
push   %rax
lea    0x40(%rsp),%rax
push   %rax
push   %r13
call   1040 <crypto_aead_decrypt@plt>
add    $0x20,%rsp
mov    %eax,%ebp
test   %eax,%eax
je     11d0 <tests_from_supercop+0x70>
lea    0xd80(%rip),%rdi
mov    %ebp,%esi
mov    %r13,%rdx
call   1050 <printf@plt>
jmp    11d0 <tests_from_supercop+0x70>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
mov    0x20(%rsp),%rdi
call   1030 <free@plt>
mov    0x18(%rsp),%rdi
call   1030 <free@plt>
mov    %ebx,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@tests_from_supercop.MAXTEST_BYTES = internal constant i64 4096
@.str = [40 x i8] c"crypto_aead_decrypt returned %d at %zu\0A\00"
define i32 @tests_from_supercop() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca [16 x i8]
%5 = alloca [16 x i8]
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i32
%11 = alloca i64
%12 = alloca i32
%13 = call i64 @malloc(i64 4112)
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %1
%15 = call i64 @malloc(i64 4096)
%16 = inttoptr i64 %15 to i8*
store i8* %16, i8** %2
%17 = call i64 @malloc(i64 4096)
%18 = inttoptr i64 %17 to i8*
store i8* %18, i8** %3
store i8* null, i8** %6
store i32 0, i32* %10
%19 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%20 = call i32 @fill(i8* %19, i64 16)
%21 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%22 = call i32 @fill(i8* %21, i64 16)
store i64 0, i64* %11
br label %23
23: ; preds = %65, %0
%24 = load i64, i64* %11
%25 = icmp ule i64 %24, 4096
br i1 %25, label %26, label %68
26: ; preds = %23
%27 = load i64, i64* %11
store i64 %27, i64* %9
%28 = load i64, i64* %11
store i64 %28, i64* %7
%29 = load i64, i64* %11
%30 = add i64 %29, 16
store i64 %30, i64* %8
%31 = load i8*, i8** %2
%32 = load i64, i64* %7
%33 = call i32 @fill(i8* %31, i64 %32)
%34 = load i8*, i8** %3
%35 = load i64, i64* %9
%36 = call i32 @fill(i8* %34, i64 %35)
%37 = load i8*, i8** %1
%38 = load i8*, i8** %3
%39 = load i64, i64* %9
%40 = load i8*, i8** %2
%41 = load i64, i64* %7
%42 = load i8*, i8** %6
%43 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%44 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%45 = call i32 @crypto_aead_encrypt(i8* %37, i64* %8, i8* %38, i64 %39, i8* %40, i64 %41, i8* %42, i8* %43, i8* %44)
%46 = load i8*, i8** %3
%47 = load i8*, i8** %6
%48 = load i8*, i8** %1
%49 = load i64, i64* %8
%50 = load i8*, i8** %2
%51 = load i64, i64* %7
%52 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%53 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%54 = call i32 @crypto_aead_decrypt(i8* %46, i64* %9, i8* %47, i8* %48, i64 %49, i8* %50, i64 %51, i8* %52, i8* %53)
store i32 %54, i32* %12
%55 = load i32, i32* %12
%56 = load i32, i32* %10
%57 = or i32 %56, %55
store i32 %57, i32* %10
%58 = load i32, i32* %12
%59 = icmp ne i32 %58, 0
br i1 %59, label %60, label %64
60: ; preds = %26
%61 = load i32, i32* %12
%62 = load i64, i64* %11
%63 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %61, i64 %62)
br label %64
64: ; preds = %60, %26
br label %65
65: ; preds = %64
%66 = load i64, i64* %11
%67 = add i64 %66, 1
store i64 %67, i64* %11
br label %23
68: ; preds = %23
%69 = load i8*, i8** %2
%70 = call i32 @free(i8* %69)
%71 = load i8*, i8** %1
%72 = call i32 @free(i8* %71)
%73 = load i8*, i8** %3
%74 = call i32 @free(i8* %73)
%75 = load i32, i32* %10
ret i32 %75
}

LLVM IR (-O2):
@.str = [40 x i8] c"crypto_aead_decrypt returned %d at %zu\0A\00"
define i32 @tests_from_supercop() {
%1 = alloca [16 x i8]
%2 = alloca [16 x i8]
%3 = alloca i64
%4 = alloca i64
%5 = tail call i64 @malloc(i64 4112)
%6 = inttoptr i64 %5 to i8*
%7 = tail call i64 @malloc(i64 4096)
%8 = inttoptr i64 %7 to i8*
%9 = tail call i64 @malloc(i64 4096)
%10 = inttoptr i64 %9 to i8*
%11 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 0
%12 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%13 = bitcast i64* %3 to i8*
%14 = bitcast i64* %4 to i8*
%15 = call i32 @fill(i8* %11, i64 16)
%16 = call i32 @fill(i8* %12, i64 16)
br label %21
17: ; preds = %36
%18 = call i32 @free(i8* %8)
%19 = call i32 @free(i8* %6)
%20 = call i32 @free(i8* %10)
ret i32 %32
21: ; preds = %0, %36
%22 = phi i32 [ 0, %0 ], [ %32, %36 ]
%23 = phi i64 [ 0, %0 ], [ %37, %36 ]
store i64 %23, i64* %4
%24 = add nuw nsw i64 %23, 16
store i64 %24, i64* %3
%25 = call i32 @fill(i8* %8, i64 %23)
%26 = load i64, i64* %4
%27 = call i32 @fill(i8* %10, i64 %26)
%28 = load i64, i64* %4
%29 = call i32 @crypto_aead_encrypt(i8* %6, i64* %3, i8* %10, i64 %28, i8* %8, i64 %23, i8* null, i8* %12, i8* %11)
%30 = load i64, i64* %3
%31 = call i32 @crypto_aead_decrypt(i8* %10, i64* %4, i8* null, i8* %6, i64 %30, i8* %8, i64 %23, i8* %12, i8* %11)
%32 = or i32 %31, %22
%33 = icmp eq i32 %31, 0
br i1 %33, label %36, label %34
34: ; preds = %21
%35 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %31, i64 %23)
br label %36
36: ; preds = %34, %21
%37 = add nuw nsw i64 %23, 1
%38 = icmp eq i64 %37, 4097
br i1 %38, label %17, label %21
}