#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 uint16_t;

/* Variables and functions */
uint16_t bcdadd_cf_16(uint16_t a, uint16_t b) {
  int carry = 0;
  int i, j = 0;
  int nib_a, nib_b;
  for (i = 0; i < 16; i += 4) {
    nib_a = (a >> i) & (0xF);
    nib_b = (b >> i) & (0xF);
    j = (carry + nib_a + nib_b);
    if (j >= 10) {
      carry = 1;
      j -= 10;
      j &= 0xf;
    } else {
      carry = 0;
    }
  }
  return carry;
}


x86 assembly (clang, -O0):
<bcdadd_cf_16>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x10,-0x10(%rbp)
jge    1193 <bcdadd_cf_16+0x93>
mov    -0x4(%rbp),%eax
mov    -0x10(%rbp),%ecx
sar    %cl,%eax
and    $0xf,%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%eax
mov    -0x10(%rbp),%ecx
sar    %cl,%eax
and    $0xf,%eax
mov    %eax,-0x1c(%rbp)
mov    -0xc(%rbp),%eax
add    -0x18(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0xa,-0x14(%rbp)
jl     1179 <bcdadd_cf_16+0x79>
movl   $0x1,-0xc(%rbp)
mov    -0x14(%rbp),%eax
sub    $0xa,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
and    $0xf,%eax
mov    %eax,-0x14(%rbp)
jmp    1180 <bcdadd_cf_16+0x80>
movl   $0x0,-0xc(%rbp)
jmp    1185 <bcdadd_cf_16+0x85>
mov    -0x10(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x10(%rbp)
jmp    111f <bcdadd_cf_16+0x1f>
mov    -0xc(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<bcdadd_cf_16>:
mov    %edi,%eax
and    $0xf,%eax
mov    %esi,%ecx
and    $0xf,%ecx
add    %eax,%ecx
mov    %edi,%eax
shr    $0x4,%eax
and    $0xf,%eax
mov    %esi,%edx
shr    $0x4,%edx
and    $0xf,%edx
cmp    $0xa,%ecx
sbb    $0xffffffff,%eax
add    %edx,%eax
mov    %edi,%ecx
shr    $0x8,%ecx
and    $0xf,%ecx
mov    %esi,%edx
shr    $0x8,%edx
and    $0xf,%edx
cmp    $0xa,%eax
sbb    $0xffffffff,%ecx
add    %edx,%ecx
shr    $0xc,%edi
and    $0xf,%edi
shr    $0xc,%esi
and    $0xf,%esi
cmp    $0xa,%ecx
sbb    $0xffffffff,%edi
add    %esi,%edi
xor    %eax,%eax
cmp    $0xa,%edi
setae  %al
ret

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

LLVM IR (-O2):
define i32 @bcdadd_cf_16(i32 %0, i32 %1) {
%3 = and i32 %0, 15
%4 = and i32 %1, 15
%5 = add nuw nsw i32 %3, %4
%6 = icmp ugt i32 %5, 9
%7 = zext i1 %6 to i32
%8 = lshr i32 %0, 4
%9 = and i32 %8, 15
%10 = lshr i32 %1, 4
%11 = and i32 %10, 15
%12 = add nuw nsw i32 %9, %7
%13 = add nuw nsw i32 %12, %11
%14 = icmp ugt i32 %13, 9
%15 = zext i1 %14 to i32
%16 = lshr i32 %0, 8
%17 = and i32 %16, 15
%18 = lshr i32 %1, 8
%19 = and i32 %18, 15
%20 = add nuw nsw i32 %17, %15
%21 = add nuw nsw i32 %20, %19
%22 = icmp ugt i32 %21, 9
%23 = zext i1 %22 to i32
%24 = lshr i32 %0, 12
%25 = and i32 %24, 15
%26 = lshr i32 %1, 12
%27 = and i32 %26, 15
%28 = add nuw nsw i32 %25, %23
%29 = add nuw nsw i32 %28, %27
%30 = icmp ugt i32 %29, 9
%31 = zext i1 %30 to i32
ret i32 %31
}