#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*/ const *);
int /*<<< orphan*/ fors_gen_sk(unsigned char *, unsigned char const *,
                               int /*<<< orphan*/ *);
int /*<<< orphan*/ fors_sk_to_leaf(unsigned char *, unsigned char *,
                                   unsigned char const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ set_tree_index(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ set_type(int /*<<< orphan*/ *, int);
void fors_gen_leaf(unsigned char *leaf, const unsigned char *sk_seed,
                   const unsigned char *pub_seed, uint32_t addr_idx,
                   const uint32_t fors_tree_addr[8]) {
  uint32_t fors_leaf_adr[8] = {0};
  copy_keypair_addr(fors_leaf_adr, fors_tree_addr);
  set_type(fors_leaf_adr, 3);
  set_tree_index(fors_leaf_adr, addr_idx);
  fors_gen_sk(leaf, sk_seed, fors_leaf_adr);
  fors_sk_to_leaf(leaf, leaf, pub_seed, fors_leaf_adr);
}


x86 assembly (clang, -O0):
<fors_gen_leaf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1060 <memset@plt>
lea    -0x50(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <copy_keypair_addr@plt>
lea    -0x50(%rbp),%rdi
mov    $0x3,%esi
call   1030 <set_type@plt>
lea    -0x50(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1070 <set_tree_index@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    -0x50(%rbp),%rdx
call   1050 <fors_gen_sk@plt>
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    -0x50(%rbp),%rcx
call   1080 <fors_sk_to_leaf@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fors_gen_leaf>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %ecx,%r12d
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    %r8,%rsi
call   1040 <copy_keypair_addr@plt>
mov    %rbp,%rdi
mov    $0x3,%esi
call   1030 <set_type@plt>
mov    %rbp,%rdi
mov    %r12d,%esi
call   1060 <set_tree_index@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %rbp,%rdx
call   1050 <fors_gen_sk@plt>
mov    %rbx,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
mov    %rbp,%rcx
call   1070 <fors_sk_to_leaf@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @fors_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 [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
%12 = bitcast [8 x i32]* %11 to i8*
%13 = getelementptr inbounds [8 x i32], [8 x i32]* %11, i64 0, i64 0
%14 = load i32*, i32** %10
%15 = call i32 @copy_keypair_addr(i32* %13, i32* %14)
%16 = getelementptr inbounds [8 x i32], [8 x i32]* %11, i64 0, i64 0
%17 = call i32 @set_type(i32* %16, i32 3)
%18 = getelementptr inbounds [8 x i32], [8 x i32]* %11, i64 0, i64 0
%19 = load i32, i32* %9
%20 = call i32 @set_tree_index(i32* %18, i32 %19)
%21 = load i8*, i8** %6
%22 = load i8*, i8** %7
%23 = getelementptr inbounds [8 x i32], [8 x i32]* %11, i64 0, i64 0
%24 = call i32 @fors_gen_sk(i8* %21, i8* %22, i32* %23)
%25 = load i8*, i8** %6
%26 = load i8*, i8** %6
%27 = load i8*, i8** %8
%28 = getelementptr inbounds [8 x i32], [8 x i32]* %11, i64 0, i64 0
%29 = call i32 @fors_sk_to_leaf(i8* %25, i8* %26, i8* %27, i32* %28)
ret void
}

LLVM IR (-O2):
define void @fors_gen_leaf(i8* %0, i8* %1, i8* %2, i32 %3, i32* %4) {
%6 = alloca [8 x i32]
%7 = bitcast [8 x i32]* %6 to i8*
%8 = getelementptr inbounds [8 x i32], [8 x i32]* %6, i64 0, i64 0
%9 = call i32 @copy_keypair_addr(i32* %8, i32* %4)
%10 = call i32 @set_type(i32* %8, i32 3)
%11 = call i32 @set_tree_index(i32* %8, i32 %3)
%12 = call i32 @fors_gen_sk(i8* %0, i8* %1, i32* %8)
%13 = call i32 @fors_sk_to_leaf(i8* %0, i8* %0, i8* %2, i32* %8)
ret void
}