#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(int /*<<< orphan*/ *, int /*<<< orphan*/);
void blockmix_salsa(uint32_t *B, uint32_t rounds) {
  uint32_t X[16];
  size_t i;
  blkcpy(X, &B[16], 16);
  for (i = 0; i < 2; i++) {
    blkxor(X, &B[i * 16], 16);
    salsa20(X, rounds);
    blkcpy(&B[i * 16], X, 16);
  }
}


x86 assembly (clang, -O0):
<blockmix_salsa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x8(%rbp),%rsi
add    $0x40,%rsi
mov    $0x10,%edx
call   1050 <blkcpy@plt>
movq   $0x0,-0x58(%rbp)
cmpq   $0x2,-0x58(%rbp)
jae    11c7 <blockmix_salsa+0x97>
lea    -0x50(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x58(%rbp),%rax
shl    $0x4,%rax
shl    $0x2,%rax
add    %rax,%rsi
mov    $0x10,%edx
call   1040 <blkxor@plt>
lea    -0x50(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <salsa20@plt>
mov    -0x8(%rbp),%rdi
mov    -0x58(%rbp),%rax
shl    $0x4,%rax
shl    $0x2,%rax
add    %rax,%rdi
lea    -0x50(%rbp),%rsi
mov    $0x10,%edx
call   1050 <blkcpy@plt>
mov    -0x58(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x58(%rbp)
jmp    115d <blockmix_salsa+0x2d>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<blockmix_salsa>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x48,%rsp
mov    %esi,%r15d
mov    %rdi,%rbp
lea    0x40(%rdi),%r14
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x10,%edx
call   1050 <blkcpy@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    $0x10,%edx
call   1040 <blkxor@plt>
mov    %rbx,%rdi
mov    %r15d,%esi
call   1030 <salsa20@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    $0x10,%edx
call   1050 <blkcpy@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x10,%edx
call   1040 <blkxor@plt>
mov    %rbx,%rdi
mov    %r15d,%esi
call   1030 <salsa20@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x10,%edx
call   1050 <blkcpy@plt>
add    $0x48,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @blockmix_salsa(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca [16 x i32]
%6 = alloca i64
store i32* %0, i32** %3
store i32 %1, i32* %4
%7 = getelementptr inbounds [16 x i32], [16 x i32]* %5, i64 0, i64 0
%8 = load i32*, i32** %3
%9 = getelementptr inbounds i32, i32* %8, i64 16
%10 = call i32 @blkcpy(i32* %7, i32* %9, i32 16)
store i64 0, i64* %6
br label %11
11: ; preds = %30, %2
%12 = load i64, i64* %6
%13 = icmp ult i64 %12, 2
br i1 %13, label %14, label %33
14: ; preds = %11
%15 = getelementptr inbounds [16 x i32], [16 x i32]* %5, i64 0, i64 0
%16 = load i32*, i32** %3
%17 = load i64, i64* %6
%18 = mul i64 %17, 16
%19 = getelementptr inbounds i32, i32* %16, i64 %18
%20 = call i32 @blkxor(i32* %15, i32* %19, i32 16)
%21 = getelementptr inbounds [16 x i32], [16 x i32]* %5, i64 0, i64 0
%22 = load i32, i32* %4
%23 = call i32 @salsa20(i32* %21, i32 %22)
%24 = load i32*, i32** %3
%25 = load i64, i64* %6
%26 = mul i64 %25, 16
%27 = getelementptr inbounds i32, i32* %24, i64 %26
%28 = getelementptr inbounds [16 x i32], [16 x i32]* %5, i64 0, i64 0
%29 = call i32 @blkcpy(i32* %27, i32* %28, i32 16)
br label %30
30: ; preds = %14
%31 = load i64, i64* %6
%32 = add i64 %31, 1
store i64 %32, i64* %6
br label %11
33: ; preds = %11
ret void
}

LLVM IR (-O2):
define void @blockmix_salsa(i32* %0, i32 %1) {
%3 = alloca [16 x i32]
%4 = bitcast [16 x i32]* %3 to i8*
%5 = getelementptr inbounds [16 x i32], [16 x i32]* %3, i64 0, i64 0
%6 = getelementptr inbounds i32, i32* %0, i64 16
%7 = call i32 @blkcpy(i32* %5, i32* %6, i32 16)
%8 = call i32 @blkxor(i32* %5, i32* %0, i32 16)
%9 = call i32 @salsa20(i32* %5, i32 %1)
%10 = call i32 @blkcpy(i32* %0, i32* %5, i32 16)
%11 = call i32 @blkxor(i32* %5, i32* %6, i32 16)
%12 = call i32 @salsa20(i32* %5, i32 %1)
%13 = call i32 @blkcpy(i32* %6, i32* %5, i32 16)
ret void
}