#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 uint8_t;
typedef int uint32_t;

/* Variables and functions */
uint32_t bech32_polymod_step(uint8_t value, uint32_t chk) {
  size_t i;
  uint8_t b;
  uint32_t gen[5] = {0x3b6a57b2, 0x26508e6d, 0x1ea119fa, 0x3d4233dd,
                     0x2a1462b3};
  b = (chk >> 25);
  chk = (chk & 0x1ffffff) << 5 ^ value;
  for (i = 0; i < 5; ++i) {
    chk ^= ((b >> i) & 1) ? gen[i] : 0;
  }
  return chk;
}


x86 assembly (clang, -O0):
<bech32_polymod_step>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    0xeef(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xeec(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xeea(%rip),%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%eax
sar    $0x19,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
and    $0x1ffffff,%eax
shl    $0x5,%eax
xor    -0x4(%rbp),%eax
mov    %eax,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
cmpq   $0x5,-0x10(%rbp)
jae    119f <bech32_polymod_step+0x9f>
mov    -0x14(%rbp),%eax
mov    -0x10(%rbp),%rcx
sar    %cl,%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     117b <bech32_polymod_step+0x7b>
mov    -0x10(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%eax
mov    %eax,-0x34(%rbp)
jmp    1185 <bech32_polymod_step+0x85>
xor    %eax,%eax
mov    %eax,-0x34(%rbp)
jmp    1185 <bech32_polymod_step+0x85>
mov    -0x34(%rbp),%eax
xor    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    114b <bech32_polymod_step+0x4b>
mov    -0x8(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<bech32_polymod_step>:
mov    %esi,%ecx
shl    $0x6,%ecx
sar    $0x1f,%ecx
and    $0x3b6a57b2,%ecx
movd   %esi,%xmm0
pshufd $0x0,%xmm0,%xmm0
movdqa 0xee1(%rip),%xmm1
pand   %xmm1,%xmm0
pcmpeqd %xmm1,%xmm0
pand   0xee1(%rip),%xmm0
shl    $0x5,%esi
and    $0x3fffffe0,%esi
xor    %edi,%esi
xor    %esi,%ecx
pshufd $0xee,%xmm0,%xmm1
pxor   %xmm0,%xmm1
pshufd $0x55,%xmm1,%xmm0
pxor   %xmm1,%xmm0
movd   %xmm0,%eax
xor    %ecx,%eax
ret

LLVM IR (-O0):
@__const.bech32_polymod_step.gen = [5 x i32] [i32 996825010, i32 642813549, i32 513874426, i32 1027748829, i32 705979059]
define i32 @bech32_polymod_step(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
%6 = alloca i32
%7 = alloca [5 x i32]
store i32 %0, i32* %3
store i32 %1, i32* %4
%8 = bitcast [5 x i32]* %7 to i8*
%9 = load i32, i32* %4
%10 = ashr i32 %9, 25
store i32 %10, i32* %6
%11 = load i32, i32* %4
%12 = and i32 %11, 33554431
%13 = shl i32 %12, 5
%14 = load i32, i32* %3
%15 = xor i32 %13, %14
store i32 %15, i32* %4
store i64 0, i64* %5
br label %16
16: ; preds = %35, %2
%17 = load i64, i64* %5
%18 = icmp ult i64 %17, 5
br i1 %18, label %19, label %38
19: ; preds = %16
%20 = load i32, i32* %6
%21 = load i64, i64* %5
%22 = trunc i64 %21 to i32
%23 = ashr i32 %20, %22
%24 = and i32 %23, 1
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %19
%27 = load i64, i64* %5
%28 = getelementptr inbounds [5 x i32], [5 x i32]* %7, i64 0, i64 %27
%29 = load i32, i32* %28
br label %31
30: ; preds = %19
br label %31
31: ; preds = %30, %26
%32 = phi i32 [ %29, %26 ], [ 0, %30 ]
%33 = load i32, i32* %4
%34 = xor i32 %33, %32
store i32 %34, i32* %4
br label %35
35: ; preds = %31
%36 = load i64, i64* %5
%37 = add i64 %36, 1
store i64 %37, i64* %5
br label %16
38: ; preds = %16
%39 = load i32, i32* %4
ret i32 %39
}

LLVM IR (-O2):
define i32 @bech32_polymod_step(i32 %0, i32 %1) {
%3 = and i32 %1, 33554432
%4 = icmp eq i32 %3, 0
%5 = select i1 %4, i32 0, i32 996825010
%6 = insertelement <4 x i32> poison, i32 %1, i64 0
%7 = shufflevector <4 x i32> %6, <4 x i32> poison, <4 x i32> zeroinitializer
%8 = and <4 x i32> %7, <i32 536870912, i32 268435456, i32 134217728, i32 67108864>
%9 = icmp eq <4 x i32> %8, zeroinitializer
%10 = select <4 x i1> %9, <4 x i32> zeroinitializer, <4 x i32> <i32 705979059, i32 1027748829, i32 513874426, i32 642813549>
%11 = shl i32 %1, 5
%12 = and i32 %11, 1073741792
%13 = xor i32 %12, %0
%14 = call i32 @llvm.vector.reduce.xor.v4i32(<4 x i32> %10)
%15 = xor i32 %14, %5
%16 = xor i32 %15, %13
ret i32 %16
}