#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 /*<<< orphan*/ uint8_t;
typedef int uint64_t;

/* Variables and functions */
int /*<<< orphan*/ salsa20_block(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                 int, int);
void salsa20(uint8_t *message, uint64_t mlen, uint8_t key[32], uint64_t nonce) {
  static int i;
  static uint8_t block[64];
  int k;
  for (k = 0; k < mlen; k++) {
    if (i % 64 == 0)
      salsa20_block(block, key, nonce, i / 64);
    message[k] ^= block[i % 64];
    i++;
  }
}


x86 assembly (clang, -O0):
<salsa20>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11bf <salsa20+0xaf>
mov    0x2f01(%rip),%eax
mov    $0x40,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1179 <salsa20+0x69>
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    0x2ee0(%rip),%eax
mov    $0x40,%ecx
cltd
idiv   %ecx
mov    -0x24(%rbp),%edx
mov    %eax,%ecx
lea    0x2edc(%rip),%rdi
call   1030 <salsa20_block@plt>
mov    0x2ec1(%rip),%eax
mov    $0x40,%ecx
cltd
idiv   %ecx
movslq %edx,%rcx
lea    0x2ebf(%rip),%rax
mov    (%rax,%rcx,4),%edx
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
xor    (%rax,%rcx,4),%edx
mov    %edx,(%rax,%rcx,4)
mov    0x2e98(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2e8f(%rip)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    112d <salsa20+0x1d>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<salsa20>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    1192 <salsa20+0x82>
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %rdi,%r13
mov    %esi,%ebx
mov    0x2f10(%rip),%eax
xor    %ebp,%ebp
lea    0x2f17(%rip),%r12
jmp    116d <salsa20+0x5d>
nopl   0x0(%rax,%rax,1)
lea    0x3f(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0xffffffc0,%ecx
mov    %eax,%edx
sub    %ecx,%edx
movslq %edx,%rcx
mov    (%r12,%rcx,4),%ecx
xor    %ecx,0x0(%r13,%rbp,4)
add    $0x1,%eax
mov    %eax,0x2edc(%rip)
add    $0x1,%rbp
cmp    %rbp,%rbx
je     1192 <salsa20+0x82>
test   $0x3f,%al
jne    1140 <salsa20+0x30>
lea    0x3f(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
sar    $0x6,%ecx
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
call   1030 <salsa20_block@plt>
mov    0x2eb0(%rip),%eax
jmp    1140 <salsa20+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@salsa20.i = internal global i32 0
@salsa20.block = internal global [64 x i32] zeroinitializer
define void @salsa20(i32* %0, i32 %1, i32* %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32* %2, i32** %7
store i32 %3, i32* %8
store i32 0, i32* %9
br label %10
10: ; preds = %38, %4
%11 = load i32, i32* %9
%12 = load i32, i32* %6
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %41
14: ; preds = %10
%15 = load i32, i32* @salsa20.i
%16 = srem i32 %15, 64
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %24
18: ; preds = %14
%19 = load i32*, i32** %7
%20 = load i32, i32* %8
%21 = load i32, i32* @salsa20.i
%22 = sdiv i32 %21, 64
%23 = call i32 @salsa20_block(i32* getelementptr inbounds ([64 x i32], [64 x i32]* @salsa20.block, i64 0, i64 0), i32* %19, i32 %20, i32 %22)
br label %24
24: ; preds = %18, %14
%25 = load i32, i32* @salsa20.i
%26 = srem i32 %25, 64
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [64 x i32], [64 x i32]* @salsa20.block, i64 0, i64 %27
%29 = load i32, i32* %28
%30 = load i32*, i32** %5
%31 = load i32, i32* %9
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i32, i32* %30, i64 %32
%34 = load i32, i32* %33
%35 = xor i32 %34, %29
store i32 %35, i32* %33
%36 = load i32, i32* @salsa20.i
%37 = add nsw i32 %36, 1
store i32 %37, i32* @salsa20.i
br label %38
38: ; preds = %24
%39 = load i32, i32* %9
%40 = add nsw i32 %39, 1
store i32 %40, i32* %9
br label %10
41: ; preds = %10
ret void
}

LLVM IR (-O2):
@salsa20.i = internal unnamed_addr global i32 0
@salsa20.block = internal global [64 x i32] zeroinitializer
define void @salsa20(i32* nocapture %0, i32 %1, i32* %2, i32 %3) {
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %30
6: ; preds = %4
%7 = zext i32 %1 to i64
%8 = load i32, i32* @salsa20.i
br label %9
9: ; preds = %6, %18
%10 = phi i32 [ %8, %6 ], [ %27, %18 ]
%11 = phi i64 [ 0, %6 ], [ %28, %18 ]
%12 = and i32 %10, 63
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %9
%15 = sdiv i32 %10, 64
%16 = tail call i32 @salsa20_block(i32* getelementptr inbounds ([64 x i32], [64 x i32]* @salsa20.block, i64 0, i64 0), i32* %2, i32 %3, i32 %15)
%17 = load i32, i32* @salsa20.i
br label %18
18: ; preds = %14, %9
%19 = phi i32 [ %17, %14 ], [ %10, %9 ]
%20 = srem i32 %19, 64
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [64 x i32], [64 x i32]* @salsa20.block, i64 0, i64 %21
%23 = load i32, i32* %22
%24 = getelementptr inbounds i32, i32* %0, i64 %11
%25 = load i32, i32* %24
%26 = xor i32 %25, %23
store i32 %26, i32* %24
%27 = add nsw i32 %19, 1
store i32 %27, i32* @salsa20.i
%28 = add nuw nsw i64 %11, 1
%29 = icmp eq i64 %28, %7
br i1 %29, label %30, label %9
30: ; preds = %18, %4
ret void
}