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

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


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    $0x4,%rax
shl    $0x2,%rax
add    %rax,%rsi
mov    $0x40,%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    $0x4,%rax
shl    $0x2,%rax
add    %rax,%rsi
mov    $0x40,%edx
call   1030 <blkxor@plt>
mov    -0x18(%rbp),%rdi
call   1040 <salsa20_8@plt>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rax
shl    $0x3,%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    $0x40,%edx
call   1050 <blkcpy@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x28(%rbp),%rax
shl    $0x4,%rax
add    $0x10,%rax
shl    $0x2,%rax
add    %rax,%rsi
mov    $0x40,%edx
call   1030 <blkxor@plt>
mov    -0x18(%rbp),%rdi
call   1040 <salsa20_8@plt>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rax
shl    $0x3,%rax
mov    -0x20(%rbp),%rcx
shl    $0x4,%rcx
add    %rcx,%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    $0x40,%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    $0x7,%rax
lea    (%rax,%rdi,1),%rsi
add    $0xffffffffffffffc0,%rsi
mov    %rdx,%rdi
mov    $0x40,%edx
call   1050 <blkcpy@plt>
test   %r13,%r13
je     11e3 <blockmix_salsa8+0xb3>
shl    $0x6,%r14
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x40,%edx
call   1030 <blkxor@plt>
mov    %r15,%rdi
call   1040 <salsa20_8@plt>
mov    %r12,%rdi
mov    %r15,%rsi
mov    $0x40,%edx
call   1050 <blkcpy@plt>
lea    0x40(%rbx),%rsi
mov    %r15,%rdi
mov    $0x40,%edx
call   1030 <blkxor@plt>
mov    %r15,%rdi
call   1040 <salsa20_8@plt>
lea    (%r12,%r14,1),%rdi
mov    %r15,%rsi
mov    $0x40,%edx
call   1050 <blkcpy@plt>
add    $0x2,%rbp
sub    $0xffffffffffffff80,%rbx
add    $0x40,%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, 16
%16 = getelementptr inbounds i32, i32* %11, i64 %15
%17 = call i32 @blkcpy(i32* %10, i32* %16, i32 64)
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, 16
%28 = getelementptr inbounds i32, i32* %25, i64 %27
%29 = call i32 @blkxor(i32* %24, i32* %28, i32 64)
%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, 8
%35 = getelementptr inbounds i32, i32* %32, i64 %34
%36 = load i32*, i32** %7
%37 = call i32 @blkcpy(i32* %35, i32* %36, i32 64)
%38 = load i32*, i32** %7
%39 = load i32*, i32** %5
%40 = load i64, i64* %9
%41 = mul i64 %40, 16
%42 = add i64 %41, 16
%43 = getelementptr inbounds i32, i32* %39, i64 %42
%44 = call i32 @blkxor(i32* %38, i32* %43, i32 64)
%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, 8
%50 = load i64, i64* %8
%51 = mul i64 %50, 16
%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 64)
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, 5
%7 = add i64 %6, -16
%8 = getelementptr inbounds i32, i32* %0, i64 %7
%9 = tail call i32 @blkcpy(i32* %2, i32* %8, i32 64)
%10 = icmp eq i64 %5, 0
br i1 %10, label %31, label %11
11: ; preds = %4
%12 = shl i64 %3, 4
br label %13
13: ; preds = %11, %13
%14 = phi i64 [ 0, %11 ], [ %29, %13 ]
%15 = shl i64 %14, 4
%16 = getelementptr inbounds i32, i32* %0, i64 %15
%17 = tail call i32 @blkxor(i32* %2, i32* %16, i32 64)
%18 = tail call i32 @salsa20_8(i32* %2)
%19 = shl i64 %14, 3
%20 = getelementptr inbounds i32, i32* %1, i64 %19
%21 = tail call i32 @blkcpy(i32* %20, i32* %2, i32 64)
%22 = or i64 %15, 16
%23 = getelementptr inbounds i32, i32* %0, i64 %22
%24 = tail call i32 @blkxor(i32* %2, i32* %23, i32 64)
%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 64)
%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
}