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

/* Variables and functions */
uint64_t u32_to_bcd(uint32_t n) {
  uint64_t bcd;
  uint32_t bit_mask;
  bcd = 0;
  bit_mask = 0x80000000L;
  do {
    uint64_t digit_mask;
    uint64_t digit_compare;
    uint64_t digit_add;
    digit_mask = 0xF000000000L;
    digit_compare = 0x4000000000L;
    digit_add = 0x3000000000L;
    do {
      if ((bcd & digit_mask) > digit_compare) {
        bcd += digit_add;
      }
      digit_mask >>= 4;
      digit_compare >>= 4;
      digit_add >>= 4;
    } while (digit_mask != 0);
    bcd <<= 1;
    if (n & bit_mask) {
      bcd |= 1;
    }
    bit_mask >>= 1;
  } while (bit_mask != 0);
  return (bcd);
}


x86 assembly (clang, -O0):
<u32_to_bcd>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x80000000,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%eax
and    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jle    1142 <u32_to_bcd+0x42>
mov    -0x18(%rbp),%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%eax
sar    $0x4,%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
sar    $0x4,%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
sar    $0x4,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    112a <u32_to_bcd+0x2a>
mov    -0x8(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
and    -0xc(%rbp),%eax
cmp    $0x0,%eax
je     1188 <u32_to_bcd+0x88>
mov    -0x8(%rbp),%eax
or     $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1115 <u32_to_bcd+0x15>
mov    -0x8(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<u32_to_bcd>:
jmp    1100 <u32_to_bcd>

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

LLVM IR (-O2):
define i32 @u32_to_bcd(i32 %0) {
br label %2
2: ; preds = %2, %1
br label %2
}