#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 */

/* Variables and functions */
int /*<<< orphan*/ expand_seed(unsigned char *, unsigned char const *);
int /*<<< orphan*/ gen_partialchains(unsigned char *, unsigned char *,
                                     unsigned char const *, int *);
void wots_sign(unsigned char sig[67 * 32], const unsigned char msg[32],
               const unsigned char sk[32],
               const unsigned char masks[((1 << 4) - 1) * 32]) {
  int basew[67], i, c = 0;
  for (i = 0; i < ((256 + 4 - 1) / 4); i += 2) {
    basew[i] = msg[i / 2] & 0xf;
    basew[i + 1] = msg[i / 2] >> 4;
    c += (1 << 4) - 1 - basew[i];
    c += (1 << 4) - 1 - basew[i + 1];
  }
  for (; i < 67; i++) {
    basew[i] = c & 0xf;
    c >>= 4;
  }
  expand_seed(sig, sk);
  gen_partialchains(sig, sig, masks, basew);
}


x86 assembly (clang, -O0):
<wots_sign>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x138(%rbp)
movl   $0x0,-0x134(%rbp)
cmpl   $0x40,-0x134(%rbp)
jge    122b <wots_sign+0x10b>
mov    -0x10(%rbp),%rax
mov    %rax,-0x148(%rbp)
mov    -0x134(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x148(%rbp),%rax
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%ecx
and    $0xf,%ecx
movslq -0x134(%rbp),%rax
mov    %ecx,-0x130(%rbp,%rax,4)
mov    -0x10(%rbp),%rax
mov    %rax,-0x140(%rbp)
mov    -0x134(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x140(%rbp),%rax
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%ecx
sar    $0x4,%ecx
mov    -0x134(%rbp),%eax
add    $0x1,%eax
cltq
mov    %ecx,-0x130(%rbp,%rax,4)
movslq -0x134(%rbp),%rcx
mov    $0xf,%eax
sub    -0x130(%rbp,%rcx,4),%eax
add    -0x138(%rbp),%eax
mov    %eax,-0x138(%rbp)
mov    -0x134(%rbp),%eax
add    $0x1,%eax
movslq %eax,%rcx
mov    $0xf,%eax
sub    -0x130(%rbp,%rcx,4),%eax
add    -0x138(%rbp),%eax
mov    %eax,-0x138(%rbp)
mov    -0x134(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x134(%rbp)
jmp    114f <wots_sign+0x2f>
jmp    1230 <wots_sign+0x110>
cmpl   $0x43,-0x134(%rbp)
jge    1277 <wots_sign+0x157>
mov    -0x138(%rbp),%ecx
and    $0xf,%ecx
movslq -0x134(%rbp),%rax
mov    %ecx,-0x130(%rbp,%rax,4)
mov    -0x138(%rbp),%eax
sar    $0x4,%eax
mov    %eax,-0x138(%rbp)
mov    -0x134(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x134(%rbp)
jmp    1230 <wots_sign+0x110>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <expand_seed@plt>
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    -0x130(%rbp),%rcx
call   1040 <gen_partialchains@plt>
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wots_sign>:
push   %r14
push   %rbx
sub    $0x118,%rsp
mov    %rcx,%r14
mov    %rdi,%rbx
pxor   %xmm0,%xmm0
xor    %eax,%eax
movdqa 0xec2(%rip),%xmm1
movdqa 0xeca(%rip),%xmm2
movdqa 0xed2(%rip),%xmm3
pxor   %xmm4,%xmm4
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzwl (%rsi,%rax,1),%ecx
movd   %ecx,%xmm5
movdqa %xmm5,%xmm6
pand   %xmm1,%xmm6
punpcklbw %xmm0,%xmm6
punpcklwd %xmm0,%xmm6
psrlw  $0x4,%xmm5
pand   %xmm2,%xmm5
punpcklbw %xmm0,%xmm5
punpcklwd %xmm0,%xmm5
movdqa %xmm6,%xmm7
punpckldq %xmm5,%xmm7
movdqa %xmm7,(%rsp,%rax,8)
pxor   %xmm3,%xmm6
paddd  %xmm4,%xmm6
pxor   %xmm3,%xmm5
movdqa %xmm5,%xmm4
paddd  %xmm6,%xmm4
add    $0x2,%rax
cmp    $0x20,%rax
jne    1160 <wots_sign+0x40>
pshufd $0x55,%xmm4,%xmm0
paddd  %xmm4,%xmm0
movd   %xmm0,%eax
mov    %eax,%ecx
and    $0xf,%ecx
mov    %ecx,0x100(%rsp)
mov    %eax,%ecx
shr    $0x4,%ecx
and    $0xf,%ecx
mov    %ecx,0x104(%rsp)
shr    $0x8,%eax
and    $0xf,%eax
mov    %eax,0x108(%rsp)
mov    %rbx,%rdi
mov    %rdx,%rsi
call   1030 <expand_seed@plt>
mov    %rsp,%rcx
mov    %rbx,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1040 <gen_partialchains@plt>
add    $0x118,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @wots_sign(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca [67 x i32]
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i8* %3, i8** %8
store i32 0, i32* %11
store i32 0, i32* %10
br label %12
12: ; preds = %54, %4
%13 = load i32, i32* %10
%14 = icmp slt i32 %13, 64
br i1 %14, label %15, label %57
15: ; preds = %12
%16 = load i8*, i8** %6
%17 = load i32, i32* %10
%18 = sdiv i32 %17, 2
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %16, i64 %19
%21 = load i8, i8* %20
%22 = zext i8 %21 to i32
%23 = and i32 %22, 15
%24 = load i32, i32* %10
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [67 x i32], [67 x i32]* %9, i64 0, i64 %25
store i32 %23, i32* %26
%27 = load i8*, i8** %6
%28 = load i32, i32* %10
%29 = sdiv i32 %28, 2
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %27, i64 %30
%32 = load i8, i8* %31
%33 = zext i8 %32 to i32
%34 = ashr i32 %33, 4
%35 = load i32, i32* %10
%36 = add nsw i32 %35, 1
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [67 x i32], [67 x i32]* %9, i64 0, i64 %37
store i32 %34, i32* %38
%39 = load i32, i32* %10
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [67 x i32], [67 x i32]* %9, i64 0, i64 %40
%42 = load i32, i32* %41
%43 = sub nsw i32 15, %42
%44 = load i32, i32* %11
%45 = add nsw i32 %44, %43
store i32 %45, i32* %11
%46 = load i32, i32* %10
%47 = add nsw i32 %46, 1
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [67 x i32], [67 x i32]* %9, i64 0, i64 %48
%50 = load i32, i32* %49
%51 = sub nsw i32 15, %50
%52 = load i32, i32* %11
%53 = add nsw i32 %52, %51
store i32 %53, i32* %11
br label %54
54: ; preds = %15
%55 = load i32, i32* %10
%56 = add nsw i32 %55, 2
store i32 %56, i32* %10
br label %12
57: ; preds = %12
br label %58
58: ; preds = %69, %57
%59 = load i32, i32* %10
%60 = icmp slt i32 %59, 67
br i1 %60, label %61, label %72
61: ; preds = %58
%62 = load i32, i32* %11
%63 = and i32 %62, 15
%64 = load i32, i32* %10
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds [67 x i32], [67 x i32]* %9, i64 0, i64 %65
store i32 %63, i32* %66
%67 = load i32, i32* %11
%68 = ashr i32 %67, 4
store i32 %68, i32* %11
br label %69
69: ; preds = %61
%70 = load i32, i32* %10
%71 = add nsw i32 %70, 1
store i32 %71, i32* %10
br label %58
72: ; preds = %58
%73 = load i8*, i8** %5
%74 = load i8*, i8** %7
%75 = call i32 @expand_seed(i8* %73, i8* %74)
%76 = load i8*, i8** %5
%77 = load i8*, i8** %5
%78 = load i8*, i8** %8
%79 = getelementptr inbounds [67 x i32], [67 x i32]* %9, i64 0, i64 0
%80 = call i32 @gen_partialchains(i8* %76, i8* %77, i8* %78, i32* %79)
ret void
}

LLVM IR (-O2):
define void @wots_sign(i8* %0, i8* nocapture %1, i8* %2, i8* %3) {
%5 = alloca [67 x i32]
%6 = bitcast [67 x i32]* %5 to i8*
br label %7
7: ; preds = %7, %4
%8 = phi i64 [ 0, %4 ], [ %28, %7 ]
%9 = phi <2 x i32> [ zeroinitializer, %4 ], [ %27, %7 ]
%10 = shl i64 %8, 1
%11 = and i64 %8, 9223372036854775806
%12 = getelementptr inbounds i8, i8* %1, i64 %11
%13 = bitcast i8* %12 to <2 x i8>*
%14 = load <2 x i8>, <2 x i8>* %13
%15 = and <2 x i8> %14, <i8 15, i8 15>
%16 = zext <2 x i8> %15 to <2 x i32>
%17 = lshr <2 x i8> %14, <i8 4, i8 4>
%18 = zext <2 x i8> %17 to <2 x i32>
%19 = or i64 %10, 1
%20 = getelementptr inbounds [67 x i32], [67 x i32]* %5, i64 0, i64 %19
%21 = getelementptr inbounds i32, i32* %20, i64 -1
%22 = bitcast i32* %21 to <4 x i32>*
%23 = shufflevector <2 x i32> %16, <2 x i32> %18, <4 x i32> <i32 0, i32 2, i32 1, i32 3>
store <4 x i32> %23, <4 x i32>* %22
%24 = xor <2 x i32> %16, <i32 15, i32 15>
%25 = add <2 x i32> %24, %9
%26 = xor <2 x i32> %18, <i32 15, i32 15>
%27 = add <2 x i32> %25, %26
%28 = add nuw i64 %8, 2
%29 = icmp eq i64 %28, 32
br i1 %29, label %30, label %7
30: ; preds = %7
%31 = call i32 @llvm.vector.reduce.add.v2i32(<2 x i32> %27)
%32 = and i32 %31, 15
%33 = getelementptr inbounds [67 x i32], [67 x i32]* %5, i64 0, i64 64
store i32 %32, i32* %33
%34 = lshr i32 %31, 4
%35 = and i32 %34, 15
%36 = getelementptr inbounds [67 x i32], [67 x i32]* %5, i64 0, i64 65
store i32 %35, i32* %36
%37 = lshr i32 %31, 8
%38 = and i32 %37, 15
%39 = getelementptr inbounds [67 x i32], [67 x i32]* %5, i64 0, i64 66
store i32 %38, i32* %39
%40 = tail call i32 @expand_seed(i8* %0, i8* %2)
%41 = getelementptr inbounds [67 x i32], [67 x i32]* %5, i64 0, i64 0
%42 = call i32 @gen_partialchains(i8* %0, i8* %0, i8* %3, i32* %41)
ret void
}