#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*/ blkcpy(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ blkxor(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ blockmix_salsa8(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                   size_t);
int integerify(int /*<<< orphan*/ *, size_t);
void smix(uint8_t *B, size_t r, uint64_t N, uint8_t *V, uint8_t *XY) {
  uint8_t *X = XY;
  uint8_t *Y = &XY[128 * r];
  uint64_t i;
  uint64_t j;
  blkcpy(X, B, 128 * r);
  for (i = 0; i < N; i++) {
    blkcpy(&V[i * (128 * r)], X, 128 * r);
    blockmix_salsa8(X, Y, r);
  }
  for (i = 0; i < N; i++) {
    j = integerify(X, r) & (N - 1);
    blkxor(X, &V[j * (128 * r)], 128 * r);
    blockmix_salsa8(X, Y, r);
  }
  blkcpy(B, X, 128 * r);
}


x86 assembly (clang, -O0):
<smix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
shl    $0x7,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rax
shl    $0x7,%rax
mov    %eax,%edx
call   1060 <blkcpy@plt>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11f1 <smix+0xb1>
mov    -0x20(%rbp),%rdi
movslq -0x3c(%rbp),%rax
mov    -0x10(%rbp),%rcx
shl    $0x7,%rcx
imul   %rcx,%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x30(%rbp),%rsi
mov    -0x10(%rbp),%rax
shl    $0x7,%rax
mov    %eax,%edx
call   1060 <blkcpy@plt>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1040 <blockmix_salsa8@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1198 <smix+0x58>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1269 <smix+0x129>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <integerify@plt>
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
and    %ecx,%eax
mov    %eax,-0x40(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
movslq -0x40(%rbp),%rax
mov    -0x10(%rbp),%rcx
shl    $0x7,%rcx
imul   %rcx,%rax
shl    $0x2,%rax
add    %rax,%rsi
mov    -0x10(%rbp),%rax
shl    $0x7,%rax
mov    %eax,%edx
call   1050 <blkxor@plt>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1040 <blockmix_salsa8@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11f8 <smix+0xb8>
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x10(%rbp),%rax
shl    $0x7,%rax
mov    %eax,%edx
call   1060 <blkcpy@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<smix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r8,%r12
mov    %rcx,%r14
mov    %edx,%ebx
mov    %rsi,%rbp
mov    %rdi,%rsi
mov    %rbp,%r15
shl    $0x7,%r15
mov    %r8,%rdi
mov    %rsi,0x18(%rsp)
mov    %r15d,%edx
call   1060 <blkcpy@plt>
test   %ebx,%ebx
jle    121f <smix+0xdf>
mov    %rbp,%rax
shl    $0x9,%rax
mov    %rax,0x20(%rsp)
add    %r12,%rax
mov    %rax,0x8(%rsp)
mov    %ebx,%r13d
mov    %r14,0x10(%rsp)
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r12,%rsi
mov    %r15d,%edx
call   1060 <blkcpy@plt>
mov    %r12,%rdi
mov    0x8(%rsp),%rsi
mov    %rbp,%rdx
call   1040 <blockmix_salsa8@plt>
add    0x20(%rsp),%r14
add    $0xffffffffffffffff,%r13
jne    11a0 <smix+0x60>
test   %ebx,%ebx
mov    0x10(%rsp),%r13
jle    121f <smix+0xdf>
lea    -0x1(%rbx),%r14d
cs nopw 0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %rbp,%rsi
call   1030 <integerify@plt>
and    %r14d,%eax
cltq
imul   %r15,%rax
lea    0x0(,%rax,4),%rsi
add    %r13,%rsi
mov    %r12,%rdi
mov    %r15d,%edx
call   1050 <blkxor@plt>
mov    %r12,%rdi
mov    0x8(%rsp),%rsi
mov    %rbp,%rdx
call   1040 <blockmix_salsa8@plt>
add    $0xffffffff,%ebx
jne    11e0 <smix+0xa0>
mov    0x18(%rsp),%rdi
mov    %r12,%rsi
mov    %r15d,%edx
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <blkcpy@plt>

LLVM IR (-O0):
define void @smix(i32* %0, i64 %1, i32 %2, i32* %3, i32* %4) {
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i32
%14 = alloca i32
store i32* %0, i32** %6
store i64 %1, i64* %7
store i32 %2, i32* %8
store i32* %3, i32** %9
store i32* %4, i32** %10
%15 = load i32*, i32** %10
store i32* %15, i32** %11
%16 = load i32*, i32** %10
%17 = load i64, i64* %7
%18 = mul i64 128, %17
%19 = getelementptr inbounds i32, i32* %16, i64 %18
store i32* %19, i32** %12
%20 = load i32*, i32** %11
%21 = load i32*, i32** %6
%22 = load i64, i64* %7
%23 = mul i64 128, %22
%24 = trunc i64 %23 to i32
%25 = call i32 @blkcpy(i32* %20, i32* %21, i32 %24)
store i32 0, i32* %13
br label %26
26: ; preds = %47, %5
%27 = load i32, i32* %13
%28 = load i32, i32* %8
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %50
30: ; preds = %26
%31 = load i32*, i32** %9
%32 = load i32, i32* %13
%33 = sext i32 %32 to i64
%34 = load i64, i64* %7
%35 = mul i64 128, %34
%36 = mul i64 %33, %35
%37 = getelementptr inbounds i32, i32* %31, i64 %36
%38 = load i32*, i32** %11
%39 = load i64, i64* %7
%40 = mul i64 128, %39
%41 = trunc i64 %40 to i32
%42 = call i32 @blkcpy(i32* %37, i32* %38, i32 %41)
%43 = load i32*, i32** %11
%44 = load i32*, i32** %12
%45 = load i64, i64* %7
%46 = call i32 @blockmix_salsa8(i32* %43, i32* %44, i64 %45)
br label %47
47: ; preds = %30
%48 = load i32, i32* %13
%49 = add nsw i32 %48, 1
store i32 %49, i32* %13
br label %26
50: ; preds = %26
store i32 0, i32* %13
br label %51
51: ; preds = %78, %50
%52 = load i32, i32* %13
%53 = load i32, i32* %8
%54 = icmp slt i32 %52, %53
br i1 %54, label %55, label %81
55: ; preds = %51
%56 = load i32*, i32** %11
%57 = load i64, i64* %7
%58 = call i32 @integerify(i32* %56, i64 %57)
%59 = load i32, i32* %8
%60 = sub nsw i32 %59, 1
%61 = and i32 %58, %60
store i32 %61, i32* %14
%62 = load i32*, i32** %11
%63 = load i32*, i32** %9
%64 = load i32, i32* %14
%65 = sext i32 %64 to i64
%66 = load i64, i64* %7
%67 = mul i64 128, %66
%68 = mul i64 %65, %67
%69 = getelementptr inbounds i32, i32* %63, i64 %68
%70 = load i64, i64* %7
%71 = mul i64 128, %70
%72 = trunc i64 %71 to i32
%73 = call i32 @blkxor(i32* %62, i32* %69, i32 %72)
%74 = load i32*, i32** %11
%75 = load i32*, i32** %12
%76 = load i64, i64* %7
%77 = call i32 @blockmix_salsa8(i32* %74, i32* %75, i64 %76)
br label %78
78: ; preds = %55
%79 = load i32, i32* %13
%80 = add nsw i32 %79, 1
store i32 %80, i32* %13
br label %51
81: ; preds = %51
%82 = load i32*, i32** %6
%83 = load i32*, i32** %11
%84 = load i64, i64* %7
%85 = mul i64 128, %84
%86 = trunc i64 %85 to i32
%87 = call i32 @blkcpy(i32* %82, i32* %83, i32 %86)
ret void
}

LLVM IR (-O2):
define void @smix(i32* %0, i64 %1, i32 %2, i32* %3, i32* %4) {
%6 = shl i64 %1, 7
%7 = getelementptr inbounds i32, i32* %4, i64 %6
%8 = trunc i64 %6 to i32
%9 = tail call i32 @blkcpy(i32* %4, i32* %0, i32 %8)
%10 = icmp sgt i32 %2, 0
br i1 %10, label %11, label %35
11: ; preds = %5
%12 = zext i32 %2 to i64
br label %16
13: ; preds = %16
br i1 %10, label %14, label %35
14: ; preds = %13
%15 = add nsw i32 %2, -1
br label %24
16: ; preds = %11, %16
%17 = phi i64 [ 0, %11 ], [ %22, %16 ]
%18 = mul i64 %6, %17
%19 = getelementptr inbounds i32, i32* %3, i64 %18
%20 = tail call i32 @blkcpy(i32* %19, i32* %4, i32 %8)
%21 = tail call i32 @blockmix_salsa8(i32* %4, i32* %7, i64 %1)
%22 = add nuw nsw i64 %17, 1
%23 = icmp eq i64 %22, %12
br i1 %23, label %13, label %16
24: ; preds = %14, %24
%25 = phi i32 [ 0, %14 ], [ %33, %24 ]
%26 = tail call i32 @integerify(i32* %4, i64 %1)
%27 = and i32 %26, %15
%28 = sext i32 %27 to i64
%29 = mul i64 %6, %28
%30 = getelementptr inbounds i32, i32* %3, i64 %29
%31 = tail call i32 @blkxor(i32* %4, i32* %30, i32 %8)
%32 = tail call i32 @blockmix_salsa8(i32* %4, i32* %7, i64 %1)
%33 = add nuw nsw i32 %25, 1
%34 = icmp eq i32 %33, %2
br i1 %34, label %35, label %24
35: ; preds = %24, %5, %13
%36 = tail call i32 @blkcpy(i32* %0, i32* %4, i32 %8)
ret void
}