#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*/ copy_keypair_addr(int /*<<< orphan*/ *,
                                     int /*<<< orphan*/ *);
int /*<<< orphan*/ copy_subtree_addr(int /*<<< orphan*/ *,
                                     int /*<<< orphan*/ const *);
int /*<<< orphan*/ set_keypair_addr(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ set_type(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ thash(unsigned char *, unsigned char *, int,
                         unsigned char const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ wots_gen_pk(unsigned char *, unsigned char const *,
                               unsigned char const *, int /*<<< orphan*/ *);
void wots_gen_leaf(unsigned char *leaf, const unsigned char *sk_seed,
                   const unsigned char *pub_seed, uint32_t addr_idx,
                   const uint32_t tree_addr[8]) {
  unsigned char pk[(((8 * 16 / 4) + 3) * 16)];
  uint32_t wots_addr[8] = {0};
  uint32_t wots_pk_addr[8] = {0};
  set_type(wots_addr, 0);
  set_type(wots_pk_addr, 1);
  copy_subtree_addr(wots_addr, tree_addr);
  set_keypair_addr(wots_addr, addr_idx);
  wots_gen_pk(pk, sk_seed, pub_seed, wots_addr);
  copy_keypair_addr(wots_pk_addr, wots_addr);
  thash(leaf, pk, ((8 * 16 / 4) + 3), pub_seed, wots_pk_addr);
}


x86 assembly (clang, -O0):
<wots_gen_leaf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2a0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
lea    -0x280(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1080 <memset@plt>
lea    -0x2a0(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1080 <memset@plt>
lea    -0x280(%rbp),%rdi
xor    %esi,%esi
call   1040 <set_type@plt>
lea    -0x2a0(%rbp),%rdi
mov    $0x1,%esi
call   1040 <set_type@plt>
lea    -0x280(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1090 <copy_subtree_addr@plt>
lea    -0x280(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1060 <set_keypair_addr@plt>
lea    -0x260(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    -0x280(%rbp),%rcx
call   1070 <wots_gen_pk@plt>
lea    -0x2a0(%rbp),%rdi
lea    -0x280(%rbp),%rsi
call   1050 <copy_keypair_addr@plt>
mov    -0x8(%rbp),%rdi
lea    -0x260(%rbp),%rsi
mov    -0x18(%rbp),%rcx
lea    -0x2a0(%rbp),%r8
mov    $0x23,%edx
call   1030 <thash@plt>
add    $0x2a0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wots_gen_leaf>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x288,%rsp
mov    %r8,%rbp
mov    %ecx,%r14d
mov    %rdx,%r13
mov    %rsi,%r12
mov    %rdi,0x8(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
lea    0x30(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <set_type@plt>
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    $0x1,%esi
call   1040 <set_type@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1080 <copy_subtree_addr@plt>
mov    %rbx,%rdi
mov    %r14d,%esi
call   1060 <set_keypair_addr@plt>
lea    0x50(%rsp),%rbp
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
mov    %rbx,%rcx
call   1070 <wots_gen_pk@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <copy_keypair_addr@plt>
mov    0x8(%rsp),%rdi
mov    %rbp,%rsi
mov    $0x23,%edx
mov    %r13,%rcx
mov    %r15,%r8
call   1030 <thash@plt>
add    $0x288,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @wots_gen_leaf(i8* %0, i8* %1, i8* %2, i32 %3, i32* %4) {
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32*
%11 = alloca [560 x i8]
%12 = alloca [8 x i32]
%13 = alloca [8 x i32]
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i32 %3, i32* %9
store i32* %4, i32** %10
%14 = bitcast [8 x i32]* %12 to i8*
%15 = bitcast [8 x i32]* %13 to i8*
%16 = getelementptr inbounds [8 x i32], [8 x i32]* %12, i64 0, i64 0
%17 = call i32 @set_type(i32* %16, i32 0)
%18 = getelementptr inbounds [8 x i32], [8 x i32]* %13, i64 0, i64 0
%19 = call i32 @set_type(i32* %18, i32 1)
%20 = getelementptr inbounds [8 x i32], [8 x i32]* %12, i64 0, i64 0
%21 = load i32*, i32** %10
%22 = call i32 @copy_subtree_addr(i32* %20, i32* %21)
%23 = getelementptr inbounds [8 x i32], [8 x i32]* %12, i64 0, i64 0
%24 = load i32, i32* %9
%25 = call i32 @set_keypair_addr(i32* %23, i32 %24)
%26 = getelementptr inbounds [560 x i8], [560 x i8]* %11, i64 0, i64 0
%27 = load i8*, i8** %7
%28 = load i8*, i8** %8
%29 = getelementptr inbounds [8 x i32], [8 x i32]* %12, i64 0, i64 0
%30 = call i32 @wots_gen_pk(i8* %26, i8* %27, i8* %28, i32* %29)
%31 = getelementptr inbounds [8 x i32], [8 x i32]* %13, i64 0, i64 0
%32 = getelementptr inbounds [8 x i32], [8 x i32]* %12, i64 0, i64 0
%33 = call i32 @copy_keypair_addr(i32* %31, i32* %32)
%34 = load i8*, i8** %6
%35 = getelementptr inbounds [560 x i8], [560 x i8]* %11, i64 0, i64 0
%36 = load i8*, i8** %8
%37 = getelementptr inbounds [8 x i32], [8 x i32]* %13, i64 0, i64 0
%38 = call i32 @thash(i8* %34, i8* %35, i32 35, i8* %36, i32* %37)
ret void
}

LLVM IR (-O2):
define void @wots_gen_leaf(i8* %0, i8* %1, i8* %2, i32 %3, i32* %4) {
%6 = alloca [560 x i8]
%7 = alloca [8 x i32]
%8 = alloca [8 x i32]
%9 = getelementptr inbounds [560 x i8], [560 x i8]* %6, i64 0, i64 0
%10 = bitcast [8 x i32]* %7 to i8*
%11 = bitcast [8 x i32]* %8 to i8*
%12 = getelementptr inbounds [8 x i32], [8 x i32]* %7, i64 0, i64 0
%13 = call i32 @set_type(i32* %12, i32 0)
%14 = getelementptr inbounds [8 x i32], [8 x i32]* %8, i64 0, i64 0
%15 = call i32 @set_type(i32* %14, i32 1)
%16 = call i32 @copy_subtree_addr(i32* %12, i32* %4)
%17 = call i32 @set_keypair_addr(i32* %12, i32 %3)
%18 = call i32 @wots_gen_pk(i8* %9, i8* %1, i8* %2, i32* %12)
%19 = call i32 @copy_keypair_addr(i32* %14, i32* %12)
%20 = call i32 @thash(i8* %0, i8* %9, i32 35, i8* %2, i32* %14)
ret void
}