#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 *,
                             int /*<<< orphan*/, int, unsigned char const *,
                             int *);
int /*<<< orphan*/ set_chain_addr(int *, int);
int /*<<< orphan*/ wots_gen_sk(unsigned char *, unsigned char const *, int *);
void wots_sign(unsigned char *sig, const unsigned char *msg,
               const unsigned char *sk_seed, 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);
    wots_gen_sk(sig + i * 16, sk_seed, addr);
    gen_chain(sig + i * 16, sig + i * 16, 0, lengths[i], pub_seed, addr);
  }
}


x86 assembly (clang, -O0):
<wots_sign>:
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    -0x10(%rbp),%rsi
call   1030 <chain_lengths@plt>
movl   $0x0,-0xc4(%rbp)
cmpl   $0x23,-0xc4(%rbp)
jge    1209 <wots_sign+0xc9>
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    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1060 <wots_gen_sk@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc4(%rbp),%eax
shl    $0x4,%eax
cltq
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
mov    -0xc4(%rbp),%eax
shl    $0x4,%eax
cltq
add    %rax,%rsi
movslq -0xc4(%rbp),%rax
mov    -0xc0(%rbp,%rax,4),%ecx
mov    -0x20(%rbp),%r8
mov    -0x28(%rbp),%r9
xor    %edx,%edx
call   1040 <gen_chain@plt>
mov    -0xc4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc4(%rbp)
jmp    1179 <wots_sign+0x39>
add    $0xd0,%rsp
pop    %rbp
ret

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

LLVM IR (-O0):
define void @wots_sign(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** %7
%15 = call i32 @chain_lengths(i32* %13, i8* %14)
store i32 0, i32* %12
br label %16
16: ; preds = %48, %5
%17 = load i32, i32* %12
%18 = icmp slt i32 %17, 35
br i1 %18, label %19, label %51
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** %8
%29 = load i32*, i32** %10
%30 = call i32 @wots_gen_sk(i8* %27, i8* %28, i32* %29)
%31 = load i8*, i8** %6
%32 = load i32, i32* %12
%33 = mul nsw i32 %32, 16
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %31, i64 %34
%36 = load i8*, i8** %6
%37 = load i32, i32* %12
%38 = mul nsw i32 %37, 16
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %36, i64 %39
%41 = load i32, i32* %12
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [35 x i32], [35 x i32]* %11, i64 0, i64 %42
%44 = load i32, i32* %43
%45 = load i8*, i8** %9
%46 = load i32*, i32** %10
%47 = call i32 @gen_chain(i8* %35, i8* %40, i32 0, i32 %44, i8* %45, i32* %46)
br label %48
48: ; preds = %19
%49 = load i32, i32* %12
%50 = add nsw i32 %49, 1
store i32 %50, i32* %12
br label %16
51: ; preds = %16
ret void
}

LLVM IR (-O2):
define void @wots_sign(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* %1)
br label %10
10: ; preds = %5, %10
%11 = phi i64 [ 0, %5 ], [ %20, %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 = call i32 @wots_gen_sk(i8* %15, i8* %2, i32* %4)
%17 = getelementptr inbounds [35 x i32], [35 x i32]* %6, i64 0, i64 %11
%18 = load i32, i32* %17
%19 = call i32 @gen_chain(i8* %15, i8* %15, i32 0, i32 %18, i8* %3, i32* %4)
%20 = add nuw nsw i64 %11, 1
%21 = icmp eq i64 %20, 35
br i1 %21, label %22, label %10
22: ; preds = %10
ret void
}