#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 uint64_t;
typedef int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ SHA256(unsigned char *, unsigned long long, unsigned char *);
int bytes_to_ull(unsigned char *, int);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char const *, int);
int /*<<< orphan*/ mgf1(unsigned char *, int, unsigned char *, int);
void hash_message(unsigned char *digest, uint64_t *tree, uint32_t *leaf_idx,
                  const unsigned char *R, const unsigned char *pk,
                  unsigned char *m, unsigned long long mlen) {
  unsigned char seed[32];
  unsigned char buf[(((9 * 30 + 7) / 8) + ((((60 / 20) * (20 - 1)) + 7) / 8) +
                     (((60 / 20) + 7) / 8))];
  unsigned char *bufp = buf;
  memcpy(m - 16 - (2 * 16), R, 16);
  memcpy(m - (2 * 16), pk, (2 * 16));
  SHA256(m - 16 - (2 * 16), mlen + 16 + (2 * 16), seed);
  mgf1(bufp,
       (((9 * 30 + 7) / 8) + ((((60 / 20) * (20 - 1)) + 7) / 8) +
        (((60 / 20) + 7) / 8)),
       seed, 32);
  memcpy(digest, bufp, ((9 * 30 + 7) / 8));
  bufp += ((9 * 30 + 7) / 8);
  *tree = bytes_to_ull(bufp, ((((60 / 20) * (20 - 1)) + 7) / 8));
  *tree &= (~(uint64_t)0) >> (64 - ((60 / 20) * (20 - 1)));
  bufp += ((((60 / 20) * (20 - 1)) + 7) / 8);
  *leaf_idx = bytes_to_ull(bufp, (((60 / 20) + 7) / 8));
  *leaf_idx &= (~(uint32_t)0) >> (32 - (60 / 20));
}


x86 assembly (clang, -O0):
<hash_message>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
lea    -0x80(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    -0x30(%rbp),%rdi
add    $0xfffffffffffffff0,%rdi
add    $0xffffffffffffffe0,%rdi
mov    -0x20(%rbp),%rsi
mov    $0x10,%edx
call   1040 <memcpy@plt>
mov    -0x30(%rbp),%rdi
add    $0xffffffffffffffe0,%rdi
mov    -0x28(%rbp),%rsi
mov    $0x20,%edx
call   1040 <memcpy@plt>
mov    -0x30(%rbp),%rdi
add    $0xfffffffffffffff0,%rdi
add    $0xffffffffffffffe0,%rdi
mov    0x10(%rbp),%rsi
add    $0x10,%rsi
add    $0x20,%rsi
lea    -0x50(%rbp),%rdx
call   1030 <SHA256@plt>
mov    -0x88(%rbp),%rdi
lea    -0x50(%rbp),%rdx
mov    $0x2b,%esi
mov    $0x20,%ecx
call   1060 <mgf1@plt>
mov    -0x8(%rbp),%rdi
mov    -0x88(%rbp),%rsi
mov    $0x22,%edx
call   1040 <memcpy@plt>
mov    -0x88(%rbp),%rax
add    $0x22,%rax
mov    %rax,-0x88(%rbp)
mov    -0x88(%rbp),%rdi
mov    $0x8,%esi
call   1050 <bytes_to_ull@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
and    $0xffffffff,%ecx
mov    %ecx,(%rax)
mov    -0x88(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x88(%rbp)
mov    -0x88(%rbp),%rdi
mov    $0x1,%esi
call   1050 <bytes_to_ull@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
and    $0xffffffff,%ecx
mov    %ecx,(%rax)
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hash_message>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %r9,%rbx
mov    %r8,%r13
mov    %rdx,0x8(%rsp)
mov    %rsi,%r15
mov    %rdi,%r12
mov    0xa0(%rsp),%rbp
lea    -0x30(%r9),%r14
mov    %r14,%rdi
mov    %rcx,%rsi
mov    $0x10,%edx
call   1040 <memcpy@plt>
add    $0xffffffffffffffe0,%rbx
mov    %rbx,%rdi
mov    %r13,%rsi
mov    $0x20,%edx
call   1040 <memcpy@plt>
add    $0x30,%rbp
lea    0x40(%rsp),%rbx
mov    %r14,%rdi
mov    %rbp,%rsi
mov    %rbx,%rdx
call   1030 <SHA256@plt>
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x2b,%esi
mov    %rbx,%rdx
mov    $0x20,%ecx
call   1060 <mgf1@plt>
mov    %r12,%rdi
mov    %rbp,%rsi
mov    $0x22,%edx
call   1040 <memcpy@plt>
lea    0x32(%rsp),%rdi
mov    $0x8,%esi
call   1050 <bytes_to_ull@plt>
mov    %eax,(%r15)
lea    0x3a(%rsp),%rdi
mov    $0x1,%esi
call   1050 <bytes_to_ull@plt>
mov    0x8(%rsp),%rcx
mov    %eax,(%rcx)
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @hash_message(i8* %0, i32* %1, i32* %2, i8* %3, i8* %4, i8* %5, i64 %6) {
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i64
%15 = alloca [32 x i8]
%16 = alloca [43 x i8]
%17 = alloca i8*
store i8* %0, i8** %8
store i32* %1, i32** %9
store i32* %2, i32** %10
store i8* %3, i8** %11
store i8* %4, i8** %12
store i8* %5, i8** %13
store i64 %6, i64* %14
%18 = getelementptr inbounds [43 x i8], [43 x i8]* %16, i64 0, i64 0
store i8* %18, i8** %17
%19 = load i8*, i8** %13
%20 = getelementptr inbounds i8, i8* %19, i64 -16
%21 = getelementptr inbounds i8, i8* %20, i64 -32
%22 = load i8*, i8** %11
%23 = call i32 @memcpy(i8* %21, i8* %22, i32 16)
%24 = load i8*, i8** %13
%25 = getelementptr inbounds i8, i8* %24, i64 -32
%26 = load i8*, i8** %12
%27 = call i32 @memcpy(i8* %25, i8* %26, i32 32)
%28 = load i8*, i8** %13
%29 = getelementptr inbounds i8, i8* %28, i64 -16
%30 = getelementptr inbounds i8, i8* %29, i64 -32
%31 = load i64, i64* %14
%32 = add i64 %31, 16
%33 = add i64 %32, 32
%34 = getelementptr inbounds [32 x i8], [32 x i8]* %15, i64 0, i64 0
%35 = call i32 @SHA256(i8* %30, i64 %33, i8* %34)
%36 = load i8*, i8** %17
%37 = getelementptr inbounds [32 x i8], [32 x i8]* %15, i64 0, i64 0
%38 = call i32 @mgf1(i8* %36, i32 43, i8* %37, i32 32)
%39 = load i8*, i8** %8
%40 = load i8*, i8** %17
%41 = call i32 @memcpy(i8* %39, i8* %40, i32 34)
%42 = load i8*, i8** %17
%43 = getelementptr inbounds i8, i8* %42, i64 34
store i8* %43, i8** %17
%44 = load i8*, i8** %17
%45 = call i32 @bytes_to_ull(i8* %44, i32 8)
%46 = load i32*, i32** %9
store i32 %45, i32* %46
%47 = load i32*, i32** %9
%48 = load i32, i32* %47
%49 = and i32 %48, -1
store i32 %49, i32* %47
%50 = load i8*, i8** %17
%51 = getelementptr inbounds i8, i8* %50, i64 8
store i8* %51, i8** %17
%52 = load i8*, i8** %17
%53 = call i32 @bytes_to_ull(i8* %52, i32 1)
%54 = load i32*, i32** %10
store i32 %53, i32* %54
%55 = load i32*, i32** %10
%56 = load i32, i32* %55
%57 = and i32 %56, -1
store i32 %57, i32* %55
ret void
}

LLVM IR (-O2):
define void @hash_message(i8* %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2, i8* %3, i8* %4, i8* %5, i64 %6) {
%8 = alloca [32 x i8]
%9 = alloca [43 x i8]
%10 = getelementptr inbounds [32 x i8], [32 x i8]* %8, i64 0, i64 0
%11 = getelementptr inbounds [43 x i8], [43 x i8]* %9, i64 0, i64 0
%12 = getelementptr inbounds i8, i8* %5, i64 -48
%13 = tail call i32 @memcpy(i8* %12, i8* %3, i32 16)
%14 = getelementptr inbounds i8, i8* %5, i64 -32
%15 = tail call i32 @memcpy(i8* %14, i8* %4, i32 32)
%16 = add i64 %6, 48
%17 = call i32 @SHA256(i8* %12, i64 %16, i8* %10)
%18 = call i32 @mgf1(i8* %11, i32 43, i8* %10, i32 32)
%19 = call i32 @memcpy(i8* %0, i8* %11, i32 34)
%20 = getelementptr inbounds [43 x i8], [43 x i8]* %9, i64 0, i64 34
%21 = call i32 @bytes_to_ull(i8* %20, i32 8)
store i32 %21, i32* %1
%22 = getelementptr inbounds [43 x i8], [43 x i8]* %9, i64 0, i64 42
%23 = call i32 @bytes_to_ull(i8* %22, i32 1)
store i32 %23, i32* %2
ret void
}