#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*/ _verbprintf(int, char *, int, int);
scalar_t__ even_parity(int);
unsigned int pocsag_syndrome(uint32_t data) {
  uint32_t shreg = data >> 1;
  uint32_t mask = 1L << (31 - 1), coeff = 03551 << (21 - 1);
  int n = 21;
  for (; n > 0; mask >>= 1, coeff >>= 1, n--)
    if (shreg & mask)
      shreg ^= coeff;
  if (even_parity(data))
    shreg |= (1 << (31 - 21));
  do {
    if (9 <= 0)
      _verbprintf(9, "BCH syndrome: data: %08lx syn: %08lx\n", data, shreg);
  } while (0);
  return shreg;
}


x86 assembly (clang, -O0):
<pocsag_syndrome>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x8(%rbp)
movl   $0x40000000,-0xc(%rbp)
movl   $0x76900000,-0x10(%rbp)
movl   $0x15,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    1180 <pocsag_syndrome+0x70>
mov    -0x8(%rbp),%eax
and    -0xc(%rbp),%eax
cmp    $0x0,%eax
je     115b <pocsag_syndrome+0x4b>
mov    -0x10(%rbp),%eax
xor    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
jmp    1160 <pocsag_syndrome+0x50>
mov    -0xc(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1139 <pocsag_syndrome+0x29>
mov    -0x4(%rbp),%edi
call   1030 <even_parity@plt>
cmp    $0x0,%rax
je     119d <pocsag_syndrome+0x8d>
mov    -0x8(%rbp),%eax
or     $0x400,%eax
mov    %eax,-0x8(%rbp)
jmp    11a2 <pocsag_syndrome+0x92>
jmp    11a7 <pocsag_syndrome+0x97>
mov    -0x8(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pocsag_syndrome>:
push   %rbx
mov    %edi,%eax
sar    %eax
mov    %edi,%ecx
sar    $0x1f,%ecx
and    $0x76900000,%ecx
xor    %eax,%ecx
lea    0x0(,%rcx,4),%eax
sar    $0x1f,%eax
and    $0x3b480000,%eax
xor    %ecx,%eax
lea    0x0(,%rax,8),%ecx
sar    $0x1f,%ecx
and    $0x1da40000,%ecx
xor    %eax,%ecx
mov    %ecx,%eax
shl    $0x4,%eax
sar    $0x1f,%eax
and    $0xed20000,%eax
xor    %ecx,%eax
mov    %eax,%ecx
shl    $0x5,%ecx
sar    $0x1f,%ecx
and    $0x7690000,%ecx
xor    %eax,%ecx
mov    %ecx,%eax
shl    $0x6,%eax
sar    $0x1f,%eax
and    $0x3b48000,%eax
xor    %ecx,%eax
mov    %eax,%ecx
shl    $0x7,%ecx
sar    $0x1f,%ecx
and    $0x1da4000,%ecx
xor    %eax,%ecx
mov    %ecx,%eax
shl    $0x8,%eax
sar    $0x1f,%eax
and    $0xed2000,%eax
xor    %ecx,%eax
mov    %eax,%ecx
shl    $0x9,%ecx
sar    $0x1f,%ecx
and    $0x769000,%ecx
xor    %eax,%ecx
mov    %ecx,%eax
shl    $0xa,%eax
sar    $0x1f,%eax
and    $0x3b4800,%eax
xor    %ecx,%eax
mov    %eax,%ecx
shl    $0xb,%ecx
sar    $0x1f,%ecx
and    $0x1da400,%ecx
xor    %eax,%ecx
mov    %ecx,%eax
shl    $0xc,%eax
sar    $0x1f,%eax
and    $0xed200,%eax
xor    %ecx,%eax
mov    %eax,%ecx
shl    $0xd,%ecx
sar    $0x1f,%ecx
and    $0x76900,%ecx
xor    %eax,%ecx
mov    %ecx,%eax
shl    $0xe,%eax
sar    $0x1f,%eax
and    $0x3b480,%eax
xor    %ecx,%eax
mov    %eax,%ecx
shl    $0xf,%ecx
sar    $0x1f,%ecx
and    $0x1da40,%ecx
xor    %eax,%ecx
movswl %cx,%eax
shr    $0xf,%eax
and    $0xed20,%eax
xor    %ecx,%eax
mov    %eax,%ecx
shl    $0x11,%ecx
sar    $0x1f,%ecx
and    $0x7690,%ecx
xor    %eax,%ecx
mov    %ecx,%eax
shl    $0x12,%eax
sar    $0x1f,%eax
and    $0x3b48,%eax
xor    %ecx,%eax
mov    %eax,%ecx
shl    $0x13,%ecx
sar    $0x1f,%ecx
and    $0x1da4,%ecx
xor    %eax,%ecx
mov    %ecx,%eax
shl    $0x14,%eax
sar    $0x1f,%eax
and    $0xed2,%eax
xor    %ecx,%eax
mov    %eax,%ebx
shl    $0x15,%ebx
sar    $0x1f,%ebx
and    $0x769,%ebx
xor    %eax,%ebx
call   1030 <even_parity@plt>
mov    %ebx,%ecx
or     $0x400,%ecx
test   %rax,%rax
cmove  %ebx,%ecx
mov    %ecx,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @pocsag_syndrome(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %2
%7 = load i32, i32* %2
%8 = ashr i32 %7, 1
store i32 %8, i32* %3
store i32 1073741824, i32* %4
store i32 1989148672, i32* %5
store i32 21, i32* %6
br label %9
9: ; preds = %22, %1
%10 = load i32, i32* %6
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %29
12: ; preds = %9
%13 = load i32, i32* %3
%14 = load i32, i32* %4
%15 = and i32 %13, %14
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %12
%18 = load i32, i32* %5
%19 = load i32, i32* %3
%20 = xor i32 %19, %18
store i32 %20, i32* %3
br label %21
21: ; preds = %17, %12
br label %22
22: ; preds = %21
%23 = load i32, i32* %4
%24 = ashr i32 %23, 1
store i32 %24, i32* %4
%25 = load i32, i32* %5
%26 = ashr i32 %25, 1
store i32 %26, i32* %5
%27 = load i32, i32* %6
%28 = add nsw i32 %27, -1
store i32 %28, i32* %6
br label %9
29: ; preds = %9
%30 = load i32, i32* %2
%31 = call i64 @even_parity(i32 %30)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %29
%34 = load i32, i32* %3
%35 = or i32 %34, 1024
store i32 %35, i32* %3
br label %36
36: ; preds = %33, %29
br label %37
37: ; preds = %36
br label %38
38: ; preds = %37
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
define i32 @pocsag_syndrome(i32 %0) {
%2 = ashr i32 %0, 1
%3 = and i32 %2, 1073741824
%4 = icmp eq i32 %3, 0
%5 = select i1 %4, i32 0, i32 1989148672
%6 = xor i32 %5, %2
%7 = and i32 %6, 536870912
%8 = icmp eq i32 %7, 0
%9 = select i1 %8, i32 0, i32 994574336
%10 = xor i32 %9, %6
%11 = and i32 %10, 268435456
%12 = icmp eq i32 %11, 0
%13 = select i1 %12, i32 0, i32 497287168
%14 = xor i32 %13, %10
%15 = and i32 %14, 134217728
%16 = icmp eq i32 %15, 0
%17 = select i1 %16, i32 0, i32 248643584
%18 = xor i32 %17, %14
%19 = and i32 %18, 67108864
%20 = icmp eq i32 %19, 0
%21 = select i1 %20, i32 0, i32 124321792
%22 = xor i32 %21, %18
%23 = and i32 %22, 33554432
%24 = icmp eq i32 %23, 0
%25 = select i1 %24, i32 0, i32 62160896
%26 = xor i32 %25, %22
%27 = and i32 %26, 16777216
%28 = icmp eq i32 %27, 0
%29 = select i1 %28, i32 0, i32 31080448
%30 = xor i32 %29, %26
%31 = and i32 %30, 8388608
%32 = icmp eq i32 %31, 0
%33 = select i1 %32, i32 0, i32 15540224
%34 = xor i32 %33, %30
%35 = and i32 %34, 4194304
%36 = icmp eq i32 %35, 0
%37 = select i1 %36, i32 0, i32 7770112
%38 = xor i32 %37, %34
%39 = and i32 %38, 2097152
%40 = icmp eq i32 %39, 0
%41 = select i1 %40, i32 0, i32 3885056
%42 = xor i32 %41, %38
%43 = and i32 %42, 1048576
%44 = icmp eq i32 %43, 0
%45 = select i1 %44, i32 0, i32 1942528
%46 = xor i32 %45, %42
%47 = and i32 %46, 524288
%48 = icmp eq i32 %47, 0
%49 = select i1 %48, i32 0, i32 971264
%50 = xor i32 %49, %46
%51 = and i32 %50, 262144
%52 = icmp eq i32 %51, 0
%53 = select i1 %52, i32 0, i32 485632
%54 = xor i32 %53, %50
%55 = and i32 %54, 131072
%56 = icmp eq i32 %55, 0
%57 = select i1 %56, i32 0, i32 242816
%58 = xor i32 %57, %54
%59 = and i32 %58, 65536
%60 = icmp eq i32 %59, 0
%61 = select i1 %60, i32 0, i32 121408
%62 = xor i32 %61, %58
%63 = and i32 %62, 32768
%64 = icmp eq i32 %63, 0
%65 = select i1 %64, i32 0, i32 60704
%66 = xor i32 %65, %62
%67 = and i32 %66, 16384
%68 = icmp eq i32 %67, 0
%69 = select i1 %68, i32 0, i32 30352
%70 = xor i32 %69, %66
%71 = and i32 %70, 8192
%72 = icmp eq i32 %71, 0
%73 = select i1 %72, i32 0, i32 15176
%74 = xor i32 %73, %70
%75 = and i32 %74, 4096
%76 = icmp eq i32 %75, 0
%77 = select i1 %76, i32 0, i32 7588
%78 = xor i32 %77, %74
%79 = and i32 %78, 2048
%80 = icmp eq i32 %79, 0
%81 = select i1 %80, i32 0, i32 3794
%82 = xor i32 %81, %78
%83 = and i32 %82, 1024
%84 = icmp eq i32 %83, 0
%85 = select i1 %84, i32 0, i32 1897
%86 = xor i32 %85, %82
%87 = tail call i64 @even_parity(i32 %0)
%88 = icmp eq i64 %87, 0
%89 = or i32 %86, 1024
%90 = select i1 %88, i32 %86, i32 %89
ret i32 %90
}