#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 uint32_t;

/* Variables and functions */
int /*<<< orphan*/ chain_lengths(int *, unsigned char const *);
int /*<<< orphan*/ gen_chain(unsigned char *, unsigned char const *, int, int,
                             unsigned char const *, int *);
int /*<<< orphan*/ set_chain_addr(int *, int);
void wots_pk_from_sig(unsigned char *pk, const unsigned char *sig,
                      const unsigned char *msg, const unsigned char *pub_seed,
                      uint32_t addr[8]) {
  int lengths[((8 * 16 / 4) + 3)];
  uint32_t i;
  chain_lengths(lengths, msg);
  for (i = 0; i < ((8 * 16 / 4) + 3); i++) {
    set_chain_addr(addr, i);
    gen_chain(pk + i * 16, sig + i * 16, lengths[i], 16 - 1 - lengths[i],
              pub_seed, addr);
  }
}


x86 assembly (clang, -O0):
<wots_pk_from_sig>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
lea    -0xc0(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <chain_lengths@plt>
movl   $0x0,-0xc4(%rbp)
cmpl   $0x23,-0xc4(%rbp)
jge    11eb <wots_pk_from_sig+0xbb>
mov    -0x28(%rbp),%rdi
mov    -0xc4(%rbp),%esi
call   1050 <set_chain_addr@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc4(%rbp),%eax
shl    $0x4,%eax
cltq
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
mov    -0xc4(%rbp),%eax
shl    $0x4,%eax
cltq
add    %rax,%rsi
movslq -0xc4(%rbp),%rax
mov    -0xc0(%rbp,%rax,4),%edx
movslq -0xc4(%rbp),%rax
mov    $0xf,%ecx
sub    -0xc0(%rbp,%rax,4),%ecx
mov    -0x20(%rbp),%r8
mov    -0x28(%rbp),%r9
call   1040 <gen_chain@plt>
mov    -0xc4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc4(%rbp)
jmp    1169 <wots_pk_from_sig+0x39>
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wots_pk_from_sig>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x90,%rsp
mov    %r8,%r15
mov    %rcx,%r14
mov    %rsi,%r12
mov    %rdi,%r13
mov    %rsp,%rdi
mov    %rdx,%rsi
call   1030 <chain_lengths@plt>
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %ebx,%esi
call   1050 <set_chain_addr@plt>
mov    (%rsp,%rbx,4),%edx
mov    $0xf,%ecx
sub    %edx,%ecx
mov    %r13,%rdi
mov    %r12,%rsi
mov    %r14,%r8
mov    %r15,%r9
call   1040 <gen_chain@plt>
add    $0x1,%rbx
add    $0x10,%r12
add    $0x10,%r13
cmp    $0x23,%rbx
jne    1160 <wots_pk_from_sig+0x30>
add    $0x90,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @wots_pk_from_sig(i8* %0, i8* %1, i8* %2, i8* %3, i32* %4) {
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32*
%11 = alloca [35 x i32]
%12 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
store i32* %4, i32** %10
%13 = getelementptr inbounds [35 x i32], [35 x i32]* %11, i64 0, i64 0
%14 = load i8*, i8** %8
%15 = call i32 @chain_lengths(i32* %13, i8* %14)
store i32 0, i32* %12
br label %16
16: ; preds = %45, %5
%17 = load i32, i32* %12
%18 = icmp slt i32 %17, 35
br i1 %18, label %19, label %48
19: ; preds = %16
%20 = load i32*, i32** %10
%21 = load i32, i32* %12
%22 = call i32 @set_chain_addr(i32* %20, i32 %21)
%23 = load i8*, i8** %6
%24 = load i32, i32* %12
%25 = mul nsw i32 %24, 16
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %23, i64 %26
%28 = load i8*, i8** %7
%29 = load i32, i32* %12
%30 = mul nsw i32 %29, 16
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %28, i64 %31
%33 = load i32, i32* %12
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [35 x i32], [35 x i32]* %11, i64 0, i64 %34
%36 = load i32, i32* %35
%37 = load i32, i32* %12
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [35 x i32], [35 x i32]* %11, i64 0, i64 %38
%40 = load i32, i32* %39
%41 = sub nsw i32 15, %40
%42 = load i8*, i8** %9
%43 = load i32*, i32** %10
%44 = call i32 @gen_chain(i8* %27, i8* %32, i32 %36, i32 %41, i8* %42, i32* %43)
br label %45
45: ; preds = %19
%46 = load i32, i32* %12
%47 = add nsw i32 %46, 1
store i32 %47, i32* %12
br label %16
48: ; preds = %16
ret void
}

LLVM IR (-O2):
define void @wots_pk_from_sig(i8* %0, i8* %1, i8* %2, i8* %3, i32* %4) {
%6 = alloca [35 x i32]
%7 = bitcast [35 x i32]* %6 to i8*
%8 = getelementptr inbounds [35 x i32], [35 x i32]* %6, i64 0, i64 0
%9 = call i32 @chain_lengths(i32* %8, i8* %2)
br label %10
10: ; preds = %5, %10
%11 = phi i64 [ 0, %5 ], [ %21, %10 ]
%12 = trunc i64 %11 to i32
%13 = call i32 @set_chain_addr(i32* %4, i32 %12)
%14 = shl nuw nsw i64 %11, 4
%15 = getelementptr inbounds i8, i8* %0, i64 %14
%16 = getelementptr inbounds i8, i8* %1, i64 %14
%17 = getelementptr inbounds [35 x i32], [35 x i32]* %6, i64 0, i64 %11
%18 = load i32, i32* %17
%19 = sub nsw i32 15, %18
%20 = call i32 @gen_chain(i8* %15, i8* %16, i32 %18, i32 %19, i8* %3, i32* %4)
%21 = add nuw nsw i64 %11, 1
%22 = icmp eq i64 %21, 35
br i1 %22, label %23, label %10
23: ; preds = %10
ret void
}