#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*/ const uint64_t;

/* Variables and functions */
int /*<<< orphan*/ blkcpy(int /*<<< orphan*/ const *,
                          int /*<<< orphan*/ const *, int);
int /*<<< orphan*/ blkxor(int /*<<< orphan*/ const *,
                          int /*<<< orphan*/ const *, int);
int /*<<< orphan*/ salsa20_8(int /*<<< orphan*/ const *);
void blockmix_salsa8(const uint64_t *Bin, uint64_t *Bout, uint64_t *X,
                     size_t r) {
  size_t i;
  blkcpy(X, &Bin[(2 * r - 1) * 8], 8);
  for (i = 0; i < 2 * r; i += 2) {
    blkxor(X, &Bin[i * 8], 8);
    salsa20_8(X);
    blkcpy(&Bout[i * 4], X, 8);
    blkxor(X, &Bin[i * 8 + 8], 8);
    salsa20_8(X);
    blkcpy(&Bout[i * 4 + r * 8], X, 8);
  }
}


x86 assembly (clang, -O0):
<blockmix_salsa8>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x20(%rbp),%rax
shl    $0x1,%rax
sub    $0x1,%rax
shl    $0x3,%rax
shl    $0x2,%rax
add    %rax,%rsi
mov    $0x8,%edx
call   1050 <blkcpy@plt>
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
shl    $0x1,%rcx
cmp    %rcx,%rax
jae    1244 <blockmix_salsa8+0x114>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x28(%rbp),%rax
shl    $0x3,%rax
shl    $0x2,%rax
add    %rax,%rsi
mov    $0x8,%edx
call   1030 <blkxor@plt>
mov    -0x18(%rbp),%rdi
call   1040 <salsa20_8@plt>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rax
shl    $0x2,%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    $0x8,%edx
call   1050 <blkcpy@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x28(%rbp),%rax
shl    $0x3,%rax
add    $0x8,%rax
shl    $0x2,%rax
add    %rax,%rsi
mov    $0x8,%edx
call   1030 <blkxor@plt>
mov    -0x18(%rbp),%rdi
call   1040 <salsa20_8@plt>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rax
shl    $0x2,%rax
mov    -0x20(%rbp),%rcx
shl    $0x3,%rcx
add    %rcx,%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    $0x8,%edx
call   1050 <blkcpy@plt>
mov    -0x28(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x28(%rbp)
jmp    1179 <blockmix_salsa8+0x49>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<blockmix_salsa8>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%rbx
lea    (%rcx,%rcx,1),%r13
mov    %rcx,%rax
shl    $0x6,%rax
lea    (%rax,%rdi,1),%rsi
add    $0xffffffffffffffe0,%rsi
mov    %rdx,%rdi
mov    $0x8,%edx
call   1050 <blkcpy@plt>
test   %r13,%r13
je     11e3 <blockmix_salsa8+0xb3>
shl    $0x5,%r14
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x8,%edx
call   1030 <blkxor@plt>
mov    %r15,%rdi
call   1040 <salsa20_8@plt>
mov    %r12,%rdi
mov    %r15,%rsi
mov    $0x8,%edx
call   1050 <blkcpy@plt>
lea    0x20(%rbx),%rsi
mov    %r15,%rdi
mov    $0x8,%edx
call   1030 <blkxor@plt>
mov    %r15,%rdi
call   1040 <salsa20_8@plt>
lea    (%r12,%r14,1),%rdi
mov    %r15,%rsi
mov    $0x8,%edx
call   1050 <blkcpy@plt>
add    $0x2,%rbp
add    $0x40,%rbx
add    $0x20,%r12
cmp    %r13,%rbp
jb     1180 <blockmix_salsa8+0x50>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @blockmix_salsa8(i32* %0, i32* %1, i32* %2, i64 %3) {
%5 = shl i64 %3, 1
%6 = shl i64 %3, 4
%7 = add i64 %6, -8
%8 = getelementptr inbounds i32, i32* %0, i64 %7
%9 = tail call i32 @blkcpy(i32* %2, i32* %8, i32 8)
%10 = icmp eq i64 %5, 0
br i1 %10, label %31, label %11
11: ; preds = %4
%12 = shl i64 %3, 3
br label %13
13: ; preds = %11, %13
%14 = phi i64 [ 0, %11 ], [ %29, %13 ]
%15 = shl i64 %14, 3
%16 = getelementptr inbounds i32, i32* %0, i64 %15
%17 = tail call i32 @blkxor(i32* %2, i32* %16, i32 8)
%18 = tail call i32 @salsa20_8(i32* %2)
%19 = shl i64 %14, 2
%20 = getelementptr inbounds i32, i32* %1, i64 %19
%21 = tail call i32 @blkcpy(i32* %20, i32* %2, i32 8)
%22 = or i64 %15, 8
%23 = getelementptr inbounds i32, i32* %0, i64 %22
%24 = tail call i32 @blkxor(i32* %2, i32* %23, i32 8)
%25 = tail call i32 @salsa20_8(i32* %2)
%26 = add i64 %19, %12
%27 = getelementptr inbounds i32, i32* %1, i64 %26
%28 = tail call i32 @blkcpy(i32* %27, i32* %2, i32 8)
%29 = add nuw i64 %14, 2
%30 = icmp ult i64 %29, %5
br i1 %30, label %13, label %31
31: ; preds = %13, %4
ret void
}