#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_stream_chacha20_tinynacl_xor(unsigned char *, unsigned char *,
                                        unsigned long long, unsigned char *,
                                        unsigned char *);
int crypto_stream_chacha20_tinynacl(unsigned char *c, unsigned long long l,
                                    const unsigned char *n,
                                    const unsigned char *k) {
  long long j;
  unsigned char ncopy[8], kcopy[32];
  for (j = 0; j < 32; ++j)
    kcopy[j] = k[j];
  for (j = 0; j < 8; ++j)
    ncopy[j] = n[j];
  for (j = 0; j < l; ++j)
    c[j] = 0;
  return crypto_stream_chacha20_tinynacl_xor(c, c, l, ncopy, kcopy);
}


x86 assembly (clang, -O0):
<crypto_stream_chacha20_tinynacl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
cmpq   $0x20,-0x28(%rbp)
jge    115f <crypto_stream_chacha20_tinynacl+0x4f>
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
mov    -0x28(%rbp),%rax
mov    %cl,-0x50(%rbp,%rax,1)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1130 <crypto_stream_chacha20_tinynacl+0x20>
movq   $0x0,-0x28(%rbp)
cmpq   $0x8,-0x28(%rbp)
jge    1196 <crypto_stream_chacha20_tinynacl+0x86>
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
mov    -0x28(%rbp),%rax
mov    %cl,-0x30(%rbp,%rax,1)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1167 <crypto_stream_chacha20_tinynacl+0x57>
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11c9 <crypto_stream_chacha20_tinynacl+0xb9>
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    119e <crypto_stream_chacha20_tinynacl+0x8e>
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    -0x30(%rbp),%rcx
lea    -0x50(%rbp),%r8
call   1030 <crypto_stream_chacha20_tinynacl_xor@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<crypto_stream_chacha20_tinynacl>:
push   %r14
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
movups (%rcx),%xmm0
movups 0x10(%rcx),%xmm1
movaps %xmm1,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
mov    (%rdx),%rax
mov    %rax,0x8(%rsp)
test   %rsi,%rsi
je     1158 <crypto_stream_chacha20_tinynacl+0x38>
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r14,%rdx
call   1030 <memset@plt>
lea    0x8(%rsp),%rcx
lea    0x10(%rsp),%r8
mov    %rbx,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1040 <crypto_stream_chacha20_tinynacl_xor@plt>
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @crypto_stream_chacha20_tinynacl(i8* %0, i64 %1, i8* %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca [8 x i8]
%11 = alloca [32 x i8]
store i8* %0, i8** %5
store i64 %1, i64* %6
store i8* %2, i8** %7
store i8* %3, i8** %8
store i64 0, i64* %9
br label %12
12: ; preds = %22, %4
%13 = load i64, i64* %9
%14 = icmp slt i64 %13, 32
br i1 %14, label %15, label %25
15: ; preds = %12
%16 = load i8*, i8** %8
%17 = load i64, i64* %9
%18 = getelementptr inbounds i8, i8* %16, i64 %17
%19 = load i8, i8* %18
%20 = load i64, i64* %9
%21 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 %20
store i8 %19, i8* %21
br label %22
22: ; preds = %15
%23 = load i64, i64* %9
%24 = add nsw i64 %23, 1
store i64 %24, i64* %9
br label %12
25: ; preds = %12
store i64 0, i64* %9
br label %26
26: ; preds = %36, %25
%27 = load i64, i64* %9
%28 = icmp slt i64 %27, 8
br i1 %28, label %29, label %39
29: ; preds = %26
%30 = load i8*, i8** %7
%31 = load i64, i64* %9
%32 = getelementptr inbounds i8, i8* %30, i64 %31
%33 = load i8, i8* %32
%34 = load i64, i64* %9
%35 = getelementptr inbounds [8 x i8], [8 x i8]* %10, i64 0, i64 %34
store i8 %33, i8* %35
br label %36
36: ; preds = %29
%37 = load i64, i64* %9
%38 = add nsw i64 %37, 1
store i64 %38, i64* %9
br label %26
39: ; preds = %26
store i64 0, i64* %9
br label %40
40: ; preds = %48, %39
%41 = load i64, i64* %9
%42 = load i64, i64* %6
%43 = icmp ult i64 %41, %42
br i1 %43, label %44, label %51
44: ; preds = %40
%45 = load i8*, i8** %5
%46 = load i64, i64* %9
%47 = getelementptr inbounds i8, i8* %45, i64 %46
store i8 0, i8* %47
br label %48
48: ; preds = %44
%49 = load i64, i64* %9
%50 = add nsw i64 %49, 1
store i64 %50, i64* %9
br label %40
51: ; preds = %40
%52 = load i8*, i8** %5
%53 = load i8*, i8** %5
%54 = load i64, i64* %6
%55 = getelementptr inbounds [8 x i8], [8 x i8]* %10, i64 0, i64 0
%56 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
%57 = call i32 @crypto_stream_chacha20_tinynacl_xor(i8* %52, i8* %53, i64 %54, i8* %55, i8* %56)
ret i32 %57
}

LLVM IR (-O2):
define i32 @crypto_stream_chacha20_tinynacl(i8* %0, i64 %1, i8* nocapture %2, i8* nocapture %3) {
%5 = alloca i64
%6 = alloca [32 x i8]
%7 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%8 = bitcast i64* %5 to i8*
%9 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%10 = bitcast i8* %2 to i64*
%11 = load i64, i64* %10
store i64 %11, i64* %5
%12 = icmp eq i64 %1, 0
br i1 %12, label %14, label %13
13: ; preds = %4
br label %14
14: ; preds = %13, %4
%15 = call i32 @crypto_stream_chacha20_tinynacl_xor(i8* %0, i8* %0, i64 %1, i8* %8, i8* %9)
ret i32 %15
}