#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 */
scalar_t__ even_parity(unsigned long);
int /*<<< orphan*/ verbprintf(int, char *, unsigned long, unsigned long);
unsigned int pocsag_syndrome(unsigned long data) {
  unsigned long shreg = data >> 1;
  unsigned long 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));
  verbprintf(9, "BCH syndrome: data: %08lx syn: %08lx\n", data, shreg);
  return shreg;
}


x86 assembly (clang, -O0):
<pocsag_syndrome>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
shr    $0x1,%rax
mov    %rax,-0x10(%rbp)
movq   $0x40000000,-0x18(%rbp)
40
movq   $0x76900000,-0x20(%rbp)
76
movl   $0x15,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jle    11a2 <pocsag_syndrome+0x82>
mov    -0x10(%rbp),%rax
and    -0x18(%rbp),%rax
cmp    $0x0,%rax
je     1177 <pocsag_syndrome+0x57>
mov    -0x20(%rbp),%rax
xor    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    117c <pocsag_syndrome+0x5c>
mov    -0x18(%rbp),%rax
shr    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
shr    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
jmp    114f <pocsag_syndrome+0x2f>
mov    -0x8(%rbp),%rdi
call   1040 <even_parity@plt>
cmp    $0x0,%rax
je     11c3 <pocsag_syndrome+0xa3>
mov    -0x10(%rbp),%rax
or     $0x400,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    $0x9,%edi
lea    0xe29(%rip),%rsi
call   1030 <verbprintf@plt>
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pocsag_syndrome>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
mov    %rdi,%rax
shr    %rax
movslq %r14d,%rcx
shr    $0x1f,%rcx
and    $0x76900000,%ecx
xor    %rax,%rcx
mov    %rcx,%rax
shl    $0x22,%rax
sar    $0x3f,%rax
and    $0x3b480000,%eax
xor    %rcx,%rax
mov    %rax,%rcx
shl    $0x23,%rcx
sar    $0x3f,%rcx
and    $0x1da40000,%ecx
xor    %rax,%rcx
mov    %rcx,%rax
shl    $0x24,%rax
sar    $0x3f,%rax
and    $0xed20000,%eax
xor    %rcx,%rax
mov    %rax,%rcx
shl    $0x25,%rcx
sar    $0x3f,%rcx
and    $0x7690000,%ecx
xor    %rax,%rcx
mov    %rcx,%rax
shl    $0x26,%rax
sar    $0x3f,%rax
and    $0x3b48000,%eax
xor    %rcx,%rax
mov    %rax,%rcx
shl    $0x27,%rcx
sar    $0x3f,%rcx
and    $0x1da4000,%ecx
xor    %rax,%rcx
mov    %rcx,%rax
shl    $0x28,%rax
sar    $0x3f,%rax
and    $0xed2000,%eax
xor    %rcx,%rax
mov    %rax,%rcx
shl    $0x29,%rcx
sar    $0x3f,%rcx
and    $0x769000,%ecx
xor    %rax,%rcx
mov    %rcx,%rax
shl    $0x2a,%rax
sar    $0x3f,%rax
and    $0x3b4800,%eax
xor    %rcx,%rax
mov    %rax,%rcx
shl    $0x2b,%rcx
sar    $0x3f,%rcx
and    $0x1da400,%ecx
xor    %rax,%rcx
mov    %rcx,%rax
shl    $0x2c,%rax
sar    $0x3f,%rax
and    $0xed200,%eax
xor    %rcx,%rax
mov    %rax,%rcx
shl    $0x2d,%rcx
sar    $0x3f,%rcx
and    $0x76900,%ecx
xor    %rax,%rcx
mov    %rcx,%rax
shl    $0x2e,%rax
sar    $0x3f,%rax
and    $0x3b480,%eax
xor    %rcx,%rax
mov    %rax,%rcx
shl    $0x2f,%rcx
sar    $0x3f,%rcx
and    $0x1da40,%ecx
xor    %rax,%rcx
movswq %cx,%rax
shr    $0xf,%rax
and    $0xed20,%eax
xor    %rcx,%rax
mov    %rax,%rcx
shl    $0x31,%rcx
sar    $0x3f,%rcx
and    $0x7690,%ecx
xor    %rax,%rcx
mov    %rcx,%rax
shl    $0x32,%rax
sar    $0x3f,%rax
and    $0x3b48,%eax
xor    %rcx,%rax
mov    %rax,%rcx
shl    $0x33,%rcx
sar    $0x3f,%rcx
and    $0x1da4,%ecx
xor    %rax,%rcx
mov    %rcx,%rax
shl    $0x34,%rax
sar    $0x3f,%rax
and    $0xed2,%eax
xor    %rcx,%rax
mov    %rax,%rbx
shl    $0x35,%rbx
sar    $0x3f,%rbx
and    $0x769,%ebx
xor    %rax,%rbx
call   1040 <even_parity@plt>
mov    %rbx,%r15
or     $0x400,%r15
test   %rax,%rax
cmove  %rbx,%r15
lea    0xd22(%rip),%rsi
mov    $0x9,%edi
mov    %r14,%rdx
mov    %r15,%rcx
call   1030 <verbprintf@plt>
mov    %r15d,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [38 x i8] c"BCH syndrome: data: %08lx syn: %08lx\0A\00"
define i32 @pocsag_syndrome(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i32
store i64 %0, i64* %2
%7 = load i64, i64* %2
%8 = lshr i64 %7, 1
store i64 %8, i64* %3
store i64 1073741824, i64* %4
store i64 1989148672, i64* %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 i64, i64* %3
%14 = load i64, i64* %4
%15 = and i64 %13, %14
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %12
%18 = load i64, i64* %5
%19 = load i64, i64* %3
%20 = xor i64 %19, %18
store i64 %20, i64* %3
br label %21
21: ; preds = %17, %12
br label %22
22: ; preds = %21
%23 = load i64, i64* %4
%24 = lshr i64 %23, 1
store i64 %24, i64* %4
%25 = load i64, i64* %5
%26 = lshr i64 %25, 1
store i64 %26, i64* %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 i64, i64* %2
%31 = call i64 @even_parity(i64 %30)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %29
%34 = load i64, i64* %3
%35 = or i64 %34, 1024
store i64 %35, i64* %3
br label %36
36: ; preds = %33, %29
%37 = load i64, i64* %2
%38 = load i64, i64* %3
%39 = call i32 @verbprintf(i32 9, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i64 %37, i64 %38)
%40 = load i64, i64* %3
%41 = trunc i64 %40 to i32
ret i32 %41
}

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