#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;

/* Variables and functions */
int /*<<< orphan*/ bzero(int *, int);
int /*<<< orphan*/ cf_norx32_decrypt(int const *, int const *,
                                     int /*<<< orphan*/ *, int /*<<< orphan*/,
                                     int *, size_t const, int /*<<< orphan*/ *,
                                     int /*<<< orphan*/, int *, int *);
int /*<<< orphan*/ cf_norx32_encrypt(int const *, int const *,
                                     int /*<<< orphan*/ *, int /*<<< orphan*/,
                                     int *, size_t const, int /*<<< orphan*/ *,
                                     int /*<<< orphan*/, int *, int *);
int /*<<< orphan*/ free(int *);
int *malloc(size_t const);
int memcmp(int *, int *, size_t const);
int /*<<< orphan*/ printf(char *, int);
int main() {
  static const uint8_t key[16] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05,
                                  0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B,
                                  0x0C, 0x0D, 0x0E, 0x0F};
  static const uint8_t nonce[8] = {0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7};
  static const size_t DATA_SIZE = 32 * 1024 * 1024;
  uint8_t tag[16];
  uint8_t *pt1 = malloc(DATA_SIZE);
  uint8_t *ct = malloc(DATA_SIZE);
  uint8_t *pt2 = malloc(DATA_SIZE);
  char c = 0x01;
  for (size_t j = 0; j < DATA_SIZE; j += sizeof(int)) {
    pt1[j] = (c ^= c * 7);
  }
  bzero(tag, sizeof tag);
  cf_norx32_encrypt(key, nonce, NULL, 0, pt1, DATA_SIZE, NULL, 0, ct, tag);
  bzero(tag, sizeof tag);
  cf_norx32_decrypt(key, nonce, NULL, 0, ct, DATA_SIZE, NULL, 0, tag, pt2);
  printf("%d\n", memcmp(pt1, pt2, DATA_SIZE));
  free(pt1);
  free(ct);
  free(pt2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x2000000,%edi
call   1080 <malloc@plt>
mov    %rax,-0x58(%rbp)
mov    $0x2000000,%edi
call   1080 <malloc@plt>
mov    %rax,-0x60(%rbp)
mov    $0x2000000,%edi
call   1080 <malloc@plt>
mov    %rax,-0x68(%rbp)
movb   $0x1,-0x69(%rbp)
movq   $0x0,-0x78(%rbp)
cmpq   $0x2000000,-0x78(%rbp)
02
jae    11f5 <main+0x85>
movsbl -0x69(%rbp),%eax
imul   $0x7,%eax,%ecx
movsbl -0x69(%rbp),%eax
xor    %ecx,%eax
mov    %al,-0x69(%rbp)
movsbl %al,%edx
mov    -0x58(%rbp),%rax
mov    -0x78(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x78(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x78(%rbp)
jmp    11b8 <main+0x48>
lea    -0x50(%rbp),%rdi
mov    $0x40,%esi
call   1090 <bzero@plt>
mov    -0x58(%rbp),%r8
mov    -0x60(%rbp),%r10
lea    -0x50(%rbp),%rax
lea    0xdea(%rip),%rdi
lea    0xe23(%rip),%rsi
xor    %ecx,%ecx
mov    %ecx,%edx
xor    %ecx,%ecx
mov    $0x2000000,%r9d
movq   $0x0,(%rsp)
movl   $0x0,0x8(%rsp)
mov    %r10,0x10(%rsp)
mov    %rax,0x18(%rsp)
call   1060 <cf_norx32_encrypt@plt>
lea    -0x50(%rbp),%rdi
mov    $0x40,%esi
call   1090 <bzero@plt>
mov    -0x60(%rbp),%r8
lea    -0x50(%rbp),%r10
mov    -0x68(%rbp),%rax
lea    0xd97(%rip),%rdi
lea    0xdd0(%rip),%rsi
xor    %ecx,%ecx
mov    %ecx,%edx
xor    %ecx,%ecx
mov    $0x2000000,%r9d
movq   $0x0,(%rsp)
movl   $0x0,0x8(%rsp)
mov    %r10,0x10(%rsp)
mov    %rax,0x18(%rsp)
call   1050 <cf_norx32_decrypt@plt>
mov    -0x58(%rbp),%rdi
mov    -0x68(%rbp),%rsi
mov    $0x2000000,%edx
call   1070 <memcmp@plt>
mov    %eax,%esi
lea    0xdb2(%rip),%rdi
call   1040 <printf@plt>
mov    -0x58(%rbp),%rdi
call   1030 <free@plt>
mov    -0x60(%rbp),%rdi
call   1030 <free@plt>
mov    -0x68(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    $0x2000000,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
mov    $0x2000000,%edi
call   1080 <malloc@plt>
mov    %rax,%r14
mov    $0x2000000,%edi
call   1080 <malloc@plt>
mov    %rax,%r15
mov    $0x1,%ecx
mov    $0xfffffffffffffffc,%rax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0x0(,%rcx,8),%edx
sub    %ecx,%edx
xor    %ecx,%edx
movsbl %dl,%edx
mov    %edx,0x10(%rbx,%rax,4)
lea    0x0(,%rdx,8),%ecx
sub    %edx,%ecx
xor    %edx,%ecx
movsbl %cl,%edx
mov    %edx,0x20(%rbx,%rax,4)
add    $0x8,%rax
cmp    $0x1fffffc,%rax
jb     11c0 <main+0x50>
mov    %rsp,%r12
mov    %r12,%rdi
mov    $0x40,%esi
call   1090 <bzero@plt>
lea    0xdf9(%rip),%r13
lea    0xe32(%rip),%rbp
mov    $0x2000000,%r9d
mov    %r13,%rdi
mov    %rbp,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %rbx,%r8
push   %r12
push   %r14
push   $0x0
push   $0x0
call   1060 <cf_norx32_encrypt@plt>
add    $0x20,%rsp
mov    %r12,%rdi
mov    $0x40,%esi
call   1090 <bzero@plt>
mov    $0x2000000,%r9d
mov    %r13,%rdi
mov    %rbp,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %r14,%r8
push   %r15
push   %r12
push   $0x0
push   $0x0
call   1050 <cf_norx32_decrypt@plt>
add    $0x20,%rsp
mov    $0x2000000,%edx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <memcmp@plt>
lea    0xde6(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@main.key = internal constant [16 x i32] [i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15]
@main.nonce = internal constant [8 x i32] [i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7]
@main.DATA_SIZE = internal constant i64 33554432
@.str = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [16 x i32]
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i8
%7 = alloca i64
store i32 0, i32* %1
%8 = call i32* @malloc(i64 33554432)
store i32* %8, i32** %3
%9 = call i32* @malloc(i64 33554432)
store i32* %9, i32** %4
%10 = call i32* @malloc(i64 33554432)
store i32* %10, i32** %5
store i8 1, i8* %6
store i64 0, i64* %7
br label %11
11: ; preds = %26, %0
%12 = load i64, i64* %7
%13 = icmp ult i64 %12, 33554432
br i1 %13, label %14, label %29
14: ; preds = %11
%15 = load i8, i8* %6
%16 = sext i8 %15 to i32
%17 = mul nsw i32 %16, 7
%18 = load i8, i8* %6
%19 = sext i8 %18 to i32
%20 = xor i32 %19, %17
%21 = trunc i32 %20 to i8
store i8 %21, i8* %6
%22 = sext i8 %21 to i32
%23 = load i32*, i32** %3
%24 = load i64, i64* %7
%25 = getelementptr inbounds i32, i32* %23, i64 %24
store i32 %22, i32* %25
br label %26
26: ; preds = %14
%27 = load i64, i64* %7
%28 = add i64 %27, 4
store i64 %28, i64* %7
br label %11
29: ; preds = %11
%30 = getelementptr inbounds [16 x i32], [16 x i32]* %2, i64 0, i64 0
%31 = call i32 @bzero(i32* %30, i32 64)
%32 = load i32*, i32** %3
%33 = load i32*, i32** %4
%34 = getelementptr inbounds [16 x i32], [16 x i32]* %2, i64 0, i64 0
%35 = call i32 @cf_norx32_encrypt(i32* getelementptr inbounds ([16 x i32], [16 x i32]* @main.key, i64 0, i64 0), i32* getelementptr inbounds ([8 x i32], [8 x i32]* @main.nonce, i64 0, i64 0), i32* null, i32 0, i32* %32, i64 33554432, i32* null, i32 0, i32* %33, i32* %34)
%36 = getelementptr inbounds [16 x i32], [16 x i32]* %2, i64 0, i64 0
%37 = call i32 @bzero(i32* %36, i32 64)
%38 = load i32*, i32** %4
%39 = getelementptr inbounds [16 x i32], [16 x i32]* %2, i64 0, i64 0
%40 = load i32*, i32** %5
%41 = call i32 @cf_norx32_decrypt(i32* getelementptr inbounds ([16 x i32], [16 x i32]* @main.key, i64 0, i64 0), i32* getelementptr inbounds ([8 x i32], [8 x i32]* @main.nonce, i64 0, i64 0), i32* null, i32 0, i32* %38, i64 33554432, i32* null, i32 0, i32* %39, i32* %40)
%42 = load i32*, i32** %3
%43 = load i32*, i32** %5
%44 = call i32 @memcmp(i32* %42, i32* %43, i64 33554432)
%45 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %44)
%46 = load i32*, i32** %3
%47 = call i32 @free(i32* %46)
%48 = load i32*, i32** %4
%49 = call i32 @free(i32* %48)
%50 = load i32*, i32** %5
%51 = call i32 @free(i32* %50)
ret i32 0
}

LLVM IR (-O2):
@main.key = internal constant [16 x i32] [i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15]
@main.nonce = internal constant [8 x i32] [i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7]
@.str = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca [16 x i32]
%2 = bitcast [16 x i32]* %1 to i8*
%3 = tail call i32* @malloc(i64 33554432)
%4 = tail call i32* @malloc(i64 33554432)
%5 = tail call i32* @malloc(i64 33554432)
br label %17
6: ; preds = %17
%7 = getelementptr inbounds [16 x i32], [16 x i32]* %1, i64 0, i64 0
%8 = call i32 @bzero(i32* %7, i32 64)
%9 = call i32 @cf_norx32_encrypt(i32* getelementptr inbounds ([16 x i32], [16 x i32]* @main.key, i64 0, i64 0), i32* getelementptr inbounds ([8 x i32], [8 x i32]* @main.nonce, i64 0, i64 0), i32* null, i32 0, i32* %3, i64 33554432, i32* null, i32 0, i32* %4, i32* %7)
%10 = call i32 @bzero(i32* %7, i32 64)
%11 = call i32 @cf_norx32_decrypt(i32* getelementptr inbounds ([16 x i32], [16 x i32]* @main.key, i64 0, i64 0), i32* getelementptr inbounds ([8 x i32], [8 x i32]* @main.nonce, i64 0, i64 0), i32* null, i32 0, i32* %4, i64 33554432, i32* null, i32 0, i32* %7, i32* %5)
%12 = call i32 @memcmp(i32* dereferenceable(33554432) %3, i32* dereferenceable(33554432) %5, i64 33554432)
%13 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = call i32 @free(i32* %3)
%15 = call i32 @free(i32* %4)
%16 = call i32 @free(i32* %5)
ret i32 0
17: ; preds = %17, %0
%18 = phi i64 [ 0, %0 ], [ %35, %17 ]
%19 = phi i32 [ 1, %0 ], [ %31, %17 ]
%20 = shl i32 %19, 24
%21 = ashr exact i32 %20, 24
%22 = mul nsw i32 %21, 7
%23 = xor i32 %22, %21
%24 = shl i32 %23, 24
%25 = ashr exact i32 %24, 24
%26 = getelementptr inbounds i32, i32* %3, i64 %18
store i32 %25, i32* %26
%27 = or i64 %18, 4
%28 = shl i32 %23, 24
%29 = ashr exact i32 %28, 24
%30 = mul nsw i32 %29, 7
%31 = xor i32 %30, %29
%32 = shl i32 %31, 24
%33 = ashr exact i32 %32, 24
%34 = getelementptr inbounds i32, i32* %3, i64 %27
store i32 %33, i32* %34
%35 = add nuw nsw i64 %18, 8
%36 = icmp ult i64 %27, 33554428
br i1 %36, label %17, label %6
}