#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 uint8_t;
typedef int uint32_t;
typedef scalar_t__ scratchpad;

/* Variables and functions */
int /*<<< orphan*/ PBKDF2_SHA256(int /*<<< orphan*/ const *, int,
                                 int /*<<< orphan*/ const *, int const, int,
                                 int /*<<< orphan*/ const *, int const);
int /*<<< orphan*/ smix(int /*<<< orphan*/ const *, int const, int const, int *,
                        int *);
void scrypt_1024_1_1_256_sp(const char *input, char *output, char *scratchpad) {
  uint8_t *B;
  uint32_t *V;
  uint32_t *XY;
  uint32_t i;
  const uint32_t N = 1024;
  const uint32_t r = 1;
  const uint32_t p = 1;
  B = (uint8_t *)(((uintptr_t)(scratchpad) + 63) & ~(uintptr_t)(63));
  XY = (uint32_t *)(B + (128 * r * p));
  V = (uint32_t *)(B + (128 * r * p) + (256 * r + 64));
  PBKDF2_SHA256((const uint8_t *)input, 80, (const uint8_t *)input, 80, 1, B,
                p * 128 * r);
  for (i = 0; i < p; i++) {
    smix(&B[i * 128 * r], r, N, V, XY);
  }
  PBKDF2_SHA256((const uint8_t *)input, 80, B, p * 128 * r, 1,
                (uint8_t *)output, 32);
}


x86 assembly (clang, -O0):
<scrypt_1024_1_1_256_sp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x400,-0x38(%rbp)
movl   $0x1,-0x3c(%rbp)
movl   $0x1,-0x40(%rbp)
mov    -0x18(%rbp),%rax
add    $0x3f,%rax
and    $0xffffffffffffffc0,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0x200,%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
add    $0x200,%rax
add    $0x500,%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x20(%rbp),%r9
mov    $0x50,%ecx
mov    $0x1,%r8d
mov    %ecx,%esi
movl   $0x80,(%rsp)
call   1040 <PBKDF2_SHA256@plt>
movl   $0x0,-0x34(%rbp)
cmpl   $0x1,-0x34(%rbp)
jge    11ec <scrypt_1024_1_1_256_sp+0xcc>
mov    -0x20(%rbp),%rdi
mov    -0x34(%rbp),%eax
shl    $0x7,%eax
shl    $0x0,%eax
cltq
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%r8
mov    $0x1,%esi
mov    $0x400,%edx
call   1030 <smix@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11a7 <scrypt_1024_1_1_256_sp+0x87>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x10(%rbp),%r9
mov    $0x50,%esi
mov    $0x80,%ecx
mov    $0x1,%r8d
movl   $0x20,(%rsp)
call   1040 <PBKDF2_SHA256@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scrypt_1024_1_1_256_sp>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
add    $0x3f,%rbx
and    $0xffffffffffffffc0,%rbx
lea    0x200(%rbx),%r12
lea    0x700(%rbx),%r13
movl   $0x80,(%rsp)
mov    $0x50,%esi
mov    %rdi,%rdx
mov    $0x50,%ecx
mov    $0x1,%r8d
mov    %rbx,%r9
call   1040 <PBKDF2_SHA256@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x400,%edx
mov    %r13,%rcx
mov    %r12,%r8
call   1030 <smix@plt>
movl   $0x20,(%rsp)
mov    %r15,%rdi
mov    $0x50,%esi
mov    %rbx,%rdx
mov    $0x80,%ecx
mov    $0x1,%r8d
mov    %r14,%r9
call   1040 <PBKDF2_SHA256@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @scrypt_1024_1_1_256_sp(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
store i32 1024, i32* %11
store i32 1, i32* %12
store i32 1, i32* %13
%14 = load i8*, i8** %6
%15 = ptrtoint i8* %14 to i64
%16 = add i64 %15, 63
%17 = and i64 %16, -64
%18 = inttoptr i64 %17 to i32*
store i32* %18, i32** %7
%19 = load i32*, i32** %7
%20 = getelementptr inbounds i32, i32* %19, i64 128
store i32* %20, i32** %9
%21 = load i32*, i32** %7
%22 = getelementptr inbounds i32, i32* %21, i64 128
%23 = getelementptr inbounds i32, i32* %22, i64 320
store i32* %23, i32** %8
%24 = load i8*, i8** %4
%25 = bitcast i8* %24 to i32*
%26 = load i8*, i8** %4
%27 = bitcast i8* %26 to i32*
%28 = load i32*, i32** %7
%29 = call i32 @PBKDF2_SHA256(i32* %25, i32 80, i32* %27, i32 80, i32 1, i32* %28, i32 128)
store i32 0, i32* %10
br label %30
30: ; preds = %43, %3
%31 = load i32, i32* %10
%32 = icmp slt i32 %31, 1
br i1 %32, label %33, label %46
33: ; preds = %30
%34 = load i32*, i32** %7
%35 = load i32, i32* %10
%36 = mul nsw i32 %35, 128
%37 = mul nsw i32 %36, 1
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i32, i32* %34, i64 %38
%40 = load i32*, i32** %8
%41 = load i32*, i32** %9
%42 = call i32 @smix(i32* %39, i32 1, i32 1024, i32* %40, i32* %41)
br label %43
43: ; preds = %33
%44 = load i32, i32* %10
%45 = add nsw i32 %44, 1
store i32 %45, i32* %10
br label %30
46: ; preds = %30
%47 = load i8*, i8** %4
%48 = bitcast i8* %47 to i32*
%49 = load i32*, i32** %7
%50 = load i8*, i8** %5
%51 = bitcast i8* %50 to i32*
%52 = call i32 @PBKDF2_SHA256(i32* %48, i32 80, i32* %49, i32 128, i32 1, i32* %51, i32 32)
ret void
}

LLVM IR (-O2):
define void @scrypt_1024_1_1_256_sp(i8* %0, i8* %1, i8* %2) {
%4 = ptrtoint i8* %2 to i64
%5 = add i64 %4, 63
%6 = and i64 %5, -64
%7 = inttoptr i64 %6 to i32*
%8 = getelementptr inbounds i32, i32* %7, i64 128
%9 = getelementptr inbounds i32, i32* %7, i64 448
%10 = bitcast i8* %0 to i32*
%11 = tail call i32 @PBKDF2_SHA256(i32* %10, i32 80, i32* %10, i32 80, i32 1, i32* %7, i32 128)
%12 = tail call i32 @smix(i32* %7, i32 1, i32 1024, i32* %9, i32* %8)
%13 = bitcast i8* %1 to i32*
%14 = tail call i32 @PBKDF2_SHA256(i32* %10, i32 80, i32* %7, i32 128, i32 1, i32* %13, i32 32)
ret void
}