#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) {
  int i;
  uint8_t block[64];
  for (i = 0; i < mlen; i++) {
    if (i % 64 == 0)
      salsa20_block(block, key, nonce, i / 64);
    message[i] ^= block[i % 64];
  }
}


x86 assembly (clang, -O0):
<salsa20>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%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    11ad <salsa20+0x9d>
mov    -0x20(%rbp),%eax
mov    $0x40,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    117c <salsa20+0x6c>
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%eax
mov    %eax,-0x124(%rbp)
mov    -0x20(%rbp),%eax
mov    $0x40,%ecx
cltd
idiv   %ecx
mov    -0x124(%rbp),%edx
mov    %eax,%ecx
call   1030 <salsa20_block@plt>
mov    -0x20(%rbp),%eax
mov    $0x40,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
mov    -0x120(%rbp,%rax,4),%edx
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
xor    (%rax,%rcx,4),%edx
mov    %edx,(%rax,%rcx,4)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1130 <salsa20+0x20>
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<salsa20>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
test   %esi,%esi
jle    1172 <salsa20+0x62>
mov    %ecx,%r14d
mov    %rdx,%r12
mov    %rdi,%r13
mov    %esi,%ebx
xor    %ebp,%ebp
jmp    1154 <salsa20+0x44>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15d,%eax
mov    (%rsp,%rax,4),%eax
xor    %eax,0x0(%r13,%rbp,4)
add    $0x1,%rbp
cmp    %rbp,%rbx
je     1172 <salsa20+0x62>
mov    %ebp,%r15d
and    $0x3f,%r15d
jne    1140 <salsa20+0x30>
mov    %ebp,%ecx
shr    $0x6,%ecx
mov    %rsp,%rdi
mov    %r12,%rsi
mov    %r14d,%edx
call   1030 <salsa20_block@plt>
jmp    1140 <salsa20+0x30>
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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