#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*/ bch_syndrome(int);
uint32_t bch_fix(uint32_t data) {
  uint32_t t;
  int i, j;
  for (i = 0; i < 32; i++) {
    t = data ^ (1 << i);
    if (!bch_syndrome(t))
      return t;
  }
  for (i = 0; i < 32; i++) {
    for (j = i + 1; j < 32; j++) {
      t = data ^ ((1 << i) | (1 << j));
      if (!bch_syndrome(t))
        return t;
    }
  }
  return data;
}


x86 assembly (clang, -O0):
<bch_fix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x20,-0x10(%rbp)
jge    116f <bch_fix+0x5f>
mov    -0x8(%rbp),%eax
mov    -0x10(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
xor    %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <bch_syndrome@plt>
cmp    $0x0,%eax
jne    115c <bch_fix+0x4c>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ff <bch_fix+0xef>
jmp    1161 <bch_fix+0x51>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1122 <bch_fix+0x12>
movl   $0x0,-0x10(%rbp)
cmpl   $0x20,-0x10(%rbp)
jge    11f9 <bch_fix+0xe9>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x20,-0x14(%rbp)
jge    11e6 <bch_fix+0xd6>
mov    -0x8(%rbp),%eax
mov    -0x10(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,-0x18(%rbp)
mov    -0x14(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    -0x18(%rbp),%ecx
or     %edx,%ecx
xor    %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <bch_syndrome@plt>
cmp    $0x0,%eax
jne    11d3 <bch_fix+0xc3>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ff <bch_fix+0xef>
jmp    11d8 <bch_fix+0xc8>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1189 <bch_fix+0x79>
jmp    11eb <bch_fix+0xdb>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1176 <bch_fix+0x66>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bch_fix>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edi,%r15d
xor    %ebx,%ebx
nopl   (%rax)
mov    %r15d,%ebp
btc    %ebx,%ebp
mov    %ebp,%edi
call   1030 <bch_syndrome@plt>
test   %eax,%eax
je     1181 <bch_fix+0x71>
add    $0x1,%ebx
cmp    $0x20,%ebx
jne    1120 <bch_fix+0x10>
xor    %r14d,%r14d
jmp    1146 <bch_fix+0x36>
xchg   %ax,%ax
cmp    $0x20,%r14d
je     117e <bch_fix+0x6e>
mov    %r14d,%ecx
lea    0x1(%rcx),%r14d
cmp    $0x1e,%ecx
ja     1140 <bch_fix+0x30>
mov    $0x1,%r12d
shl    %cl,%r12d
mov    %r14d,%ebx
xchg   %ax,%ax
mov    %r12d,%ebp
bts    %ebx,%ebp
xor    %r15d,%ebp
mov    %ebp,%edi
call   1030 <bch_syndrome@plt>
test   %eax,%eax
je     1181 <bch_fix+0x71>
add    $0x1,%ebx
cmp    $0x20,%ebx
jne    1160 <bch_fix+0x50>
jmp    1140 <bch_fix+0x30>
mov    %r15d,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @bch_fix(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i32 0, i32* %5
br label %7
7: ; preds = %21, %1
%8 = load i32, i32* %5
%9 = icmp slt i32 %8, 32
br i1 %9, label %10, label %24
10: ; preds = %7
%11 = load i32, i32* %3
%12 = load i32, i32* %5
%13 = shl i32 1, %12
%14 = xor i32 %11, %13
store i32 %14, i32* %4
%15 = load i32, i32* %4
%16 = call i32 @bch_syndrome(i32 %15)
%17 = icmp ne i32 %16, 0
br i1 %17, label %20, label %18
18: ; preds = %10
%19 = load i32, i32* %4
store i32 %19, i32* %2
br label %57
20: ; preds = %10
br label %21
21: ; preds = %20
%22 = load i32, i32* %5
%23 = add nsw i32 %22, 1
store i32 %23, i32* %5
br label %7
24: ; preds = %7
store i32 0, i32* %5
br label %25
25: ; preds = %52, %24
%26 = load i32, i32* %5
%27 = icmp slt i32 %26, 32
br i1 %27, label %28, label %55
28: ; preds = %25
%29 = load i32, i32* %5
%30 = add nsw i32 %29, 1
store i32 %30, i32* %6
br label %31
31: ; preds = %48, %28
%32 = load i32, i32* %6
%33 = icmp slt i32 %32, 32
br i1 %33, label %34, label %51
34: ; preds = %31
%35 = load i32, i32* %3
%36 = load i32, i32* %5
%37 = shl i32 1, %36
%38 = load i32, i32* %6
%39 = shl i32 1, %38
%40 = or i32 %37, %39
%41 = xor i32 %35, %40
store i32 %41, i32* %4
%42 = load i32, i32* %4
%43 = call i32 @bch_syndrome(i32 %42)
%44 = icmp ne i32 %43, 0
br i1 %44, label %47, label %45
45: ; preds = %34
%46 = load i32, i32* %4
store i32 %46, i32* %2
br label %57
47: ; preds = %34
br label %48
48: ; preds = %47
%49 = load i32, i32* %6
%50 = add nsw i32 %49, 1
store i32 %50, i32* %6
br label %31
51: ; preds = %31
br label %52
52: ; preds = %51
%53 = load i32, i32* %5
%54 = add nsw i32 %53, 1
store i32 %54, i32* %5
br label %25
55: ; preds = %25
%56 = load i32, i32* %3
store i32 %56, i32* %2
br label %57
57: ; preds = %55, %45, %18
%58 = load i32, i32* %2
ret i32 %58
}

LLVM IR (-O2):
define i32 @bch_fix(i32 %0) {
br label %5
2: ; preds = %5
%3 = add nuw nsw i32 %6, 1
%4 = icmp eq i32 %3, 32
br i1 %4, label %13, label %5
5: ; preds = %1, %2
%6 = phi i32 [ 0, %1 ], [ %3, %2 ]
%7 = shl nuw i32 1, %6
%8 = xor i32 %7, %0
%9 = tail call i32 @bch_syndrome(i32 %8)
%10 = icmp eq i32 %9, 0
br i1 %10, label %29, label %2
11: ; preds = %19, %13
%12 = icmp eq i32 %15, 32
br i1 %12, label %29, label %13
13: ; preds = %2, %11
%14 = phi i32 [ %15, %11 ], [ 0, %2 ]
%15 = add nuw nsw i32 %14, 1
%16 = icmp ult i32 %14, 31
br i1 %16, label %17, label %11
17: ; preds = %13
%18 = shl nuw nsw i32 1, %14
br label %22
19: ; preds = %22
%20 = add nuw nsw i32 %23, 1
%21 = icmp eq i32 %20, 32
br i1 %21, label %11, label %22
22: ; preds = %17, %19
%23 = phi i32 [ %15, %17 ], [ %20, %19 ]
%24 = shl nuw i32 1, %23
%25 = or i32 %24, %18
%26 = xor i32 %25, %0
%27 = tail call i32 @bch_syndrome(i32 %26)
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %19
29: ; preds = %5, %11, %22
%30 = phi i32 [ %26, %22 ], [ %0, %11 ], [ %8, %5 ]
ret i32 %30
}