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

/* Variables and functions */
int /*<<< orphan*/ base_w(int *, int, unsigned char *);
int /*<<< orphan*/ ull_to_bytes(unsigned char *, int, int);
void wots_checksum(int *csum_base_w, const int *msg_base_w) {
  int csum = 0;
  unsigned char csum_bytes[(3 * 4 + 7) / 8];
  unsigned int i;
  for (i = 0; i < (8 * 16 / 4); i++) {
    csum += 16 - 1 - msg_base_w[i];
  }
  csum = csum << (8 - ((3 * 4) % 8));
  ull_to_bytes(csum_bytes, sizeof(csum_bytes), csum);
  base_w(csum_base_w, 3, csum_bytes);
}


x86 assembly (clang, -O0):
<wots_checksum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x20,-0x1c(%rbp)
jae    116d <wots_checksum+0x4d>
mov    -0x10(%rbp),%rcx
mov    -0x1c(%rbp),%eax
mov    %eax,%edx
mov    $0xf,%eax
sub    (%rcx,%rdx,4),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    113e <wots_checksum+0x1e>
mov    -0x14(%rbp),%eax
shl    $0x4,%eax
mov    %eax,-0x14(%rbp)
lea    -0x16(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    $0x2,%esi
call   1030 <ull_to_bytes@plt>
mov    -0x8(%rbp),%rdi
lea    -0x16(%rbp),%rdx
mov    $0x3,%esi
call   1040 <base_w@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wots_checksum>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
movdqu 0x50(%rsi),%xmm0
movdqu 0x70(%rsi),%xmm1
movdqu 0x40(%rsi),%xmm2
movdqu 0x60(%rsi),%xmm3
movdqu (%rsi),%xmm4
paddd  %xmm2,%xmm4
movdqu 0x10(%rsi),%xmm2
paddd  %xmm0,%xmm2
movdqu 0x20(%rsi),%xmm0
paddd  %xmm3,%xmm0
paddd  %xmm4,%xmm0
movdqu 0x30(%rsi),%xmm3
paddd  %xmm1,%xmm3
paddd  %xmm2,%xmm3
paddd  %xmm0,%xmm3
pshufd $0xee,%xmm3,%xmm0
paddd  %xmm3,%xmm0
pshufd $0x55,%xmm0,%xmm1
paddd  %xmm0,%xmm1
movd   %xmm1,%eax
shl    $0x4,%eax
mov    $0x1e00,%edx
sub    %eax,%edx
lea    0x6(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x2,%esi
call   1030 <ull_to_bytes@plt>
mov    %r14,%rdi
mov    $0x3,%esi
mov    %rbx,%rdx
call   1040 <base_w@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @wots_checksum(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca [2 x i8]
%7 = alloca i32
store i32* %0, i32** %3
store i32* %1, i32** %4
store i32 0, i32* %5
store i32 0, i32* %7
br label %8
8: ; preds = %20, %2
%9 = load i32, i32* %7
%10 = icmp ult i32 %9, 32
br i1 %10, label %11, label %23
11: ; preds = %8
%12 = load i32*, i32** %4
%13 = load i32, i32* %7
%14 = zext i32 %13 to i64
%15 = getelementptr inbounds i32, i32* %12, i64 %14
%16 = load i32, i32* %15
%17 = sub nsw i32 15, %16
%18 = load i32, i32* %5
%19 = add nsw i32 %18, %17
store i32 %19, i32* %5
br label %20
20: ; preds = %11
%21 = load i32, i32* %7
%22 = add i32 %21, 1
store i32 %22, i32* %7
br label %8
23: ; preds = %8
%24 = load i32, i32* %5
%25 = shl i32 %24, 4
store i32 %25, i32* %5
%26 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 0
%27 = load i32, i32* %5
%28 = call i32 @ull_to_bytes(i8* %26, i32 2, i32 %27)
%29 = load i32*, i32** %3
%30 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 0
%31 = call i32 @base_w(i32* %29, i32 3, i8* %30)
ret void
}

LLVM IR (-O2):
define void @wots_checksum(i32* %0, i32* nocapture %1) {
%3 = alloca [2 x i8]
%4 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%5 = bitcast i32* %1 to <32 x i32>*
%6 = load <32 x i32>, <32 x i32>* %5
%7 = call i32 @llvm.vector.reduce.add.v32i32(<32 x i32> %6)
%8 = mul i32 %7, -16
%9 = add i32 %8, 7680
%10 = call i32 @ull_to_bytes(i8* %4, i32 2, i32 %9)
%11 = call i32 @base_w(i32* %0, i32 3, i8* %4)
ret void
}