#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 __m128i;

/* Variables and functions */
int /*<<< orphan*/ sse2_blkcpy(int /*<<< orphan*/ const *,
                               int /*<<< orphan*/ const *, int);
int /*<<< orphan*/ sse2_blkxor(int /*<<< orphan*/ const *,
                               int /*<<< orphan*/ const *, int);
int /*<<< orphan*/ sse2_salsa20_8(int /*<<< orphan*/ const *);
void sse2_blockmix_salsa8(const __m128i *Bin, __m128i *Bout, __m128i *X,
                          size_t r) {
  size_t i;
  sse2_blkcpy(X, &Bin[8 * r - 4], 64);
  for (i = 0; i < r; i++) {
    sse2_blkxor(X, &Bin[i * 8], 64);
    sse2_salsa20_8(X);
    sse2_blkcpy(&Bout[i * 4], X, 64);
    sse2_blkxor(X, &Bin[i * 8 + 4], 64);
    sse2_salsa20_8(X);
    sse2_blkcpy(&Bout[(r + i) * 4], X, 64);
  }
}


x86 assembly (clang, -O0):
<sse2_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    $0x3,%rax
sub    $0x4,%rax
shl    $0x2,%rax
add    %rax,%rsi
mov    $0x40,%edx
call   1030 <sse2_blkcpy@plt>
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    1232 <sse2_blockmix_salsa8+0x102>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x28(%rbp),%rax
shl    $0x3,%rax
shl    $0x2,%rax
add    %rax,%rsi
mov    $0x40,%edx
call   1050 <sse2_blkxor@plt>
mov    -0x18(%rbp),%rdi
call   1040 <sse2_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    $0x40,%edx
call   1030 <sse2_blkcpy@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x28(%rbp),%rax
shl    $0x3,%rax
add    $0x4,%rax
shl    $0x2,%rax
add    %rax,%rsi
mov    $0x40,%edx
call   1050 <sse2_blkxor@plt>
mov    -0x18(%rbp),%rdi
call   1040 <sse2_salsa20_8@plt>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rax
add    -0x28(%rbp),%rax
shl    $0x2,%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    $0x40,%edx
call   1030 <sse2_blkcpy@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1175 <sse2_blockmix_salsa8+0x45>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sse2_blockmix_salsa8>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rcx,%r15
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%rbx
mov    %rcx,%rax
shl    $0x5,%rax
lea    (%rax,%rdi,1),%rsi
add    $0xfffffffffffffff0,%rsi
mov    %rdx,%rdi
mov    $0x40,%edx
call   1030 <sse2_blkcpy@plt>
test   %r15,%r15
je     11d0 <sse2_blockmix_salsa8+0xa0>
mov    %r15,%r13
shl    $0x4,%r13
nopl   (%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x40,%edx
call   1050 <sse2_blkxor@plt>
mov    %r14,%rdi
call   1040 <sse2_salsa20_8@plt>
mov    %r12,%rdi
mov    %r14,%rsi
mov    $0x40,%edx
call   1030 <sse2_blkcpy@plt>
lea    0x10(%rbx),%rsi
mov    %r14,%rdi
mov    $0x40,%edx
call   1050 <sse2_blkxor@plt>
mov    %r14,%rdi
call   1040 <sse2_salsa20_8@plt>
lea    (%r12,%r13,1),%rdi
mov    %r14,%rsi
mov    $0x40,%edx
call   1030 <sse2_blkcpy@plt>
add    $0x10,%r12
add    $0x20,%rbx
add    $0xffffffffffffffff,%r15
jne    1170 <sse2_blockmix_salsa8+0x40>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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