#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 bcd_add_16(int, int, int *);
uint32_t bcd_sub_16(uint32_t a, uint32_t b, uint32_t *carry) {
  uint32_t t1, t2;
  if (*carry) {
    b++;
  }
  *carry = 0;
  t1 = 0x9999 - b;
  t2 = bcd_add_16(t1, 1, carry);
  t2 = bcd_add_16(a, t2, carry);
  *carry = 1 - *carry;
  return t2;
}


x86 assembly (clang, -O0):
<bcd_sub_16>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpl   $0x0,(%rax)
je     1138 <bcd_sub_16+0x28>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
mov    $0x9999,%eax
sub    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rdx
mov    $0x1,%esi
call   1030 <bcd_add_16@plt>
mov    %eax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x10(%rbp),%rdx
call   1030 <bcd_add_16@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    $0x1,%ecx
sub    (%rax),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bcd_sub_16>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%rbx
xor    %eax,%eax
cmp    (%rdx),%eax
sbb    %eax,%eax
mov    %edi,%r14d
movl   $0x0,(%rdx)
sub    %esi,%eax
add    $0x9999,%eax
mov    $0x1,%ebp
mov    %eax,%edi
mov    $0x1,%esi
call   1030 <bcd_add_16@plt>
mov    %r14d,%edi
mov    %eax,%esi
mov    %rbx,%rdx
call   1030 <bcd_add_16@plt>
sub    (%rbx),%ebp
mov    %ebp,(%rbx)
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @bcd_sub_16(i32 %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32* %2, i32** %6
%9 = load i32*, i32** %6
%10 = load i32, i32* %9
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %3
%13 = load i32, i32* %5
%14 = add nsw i32 %13, 1
store i32 %14, i32* %5
br label %15
15: ; preds = %12, %3
%16 = load i32*, i32** %6
store i32 0, i32* %16
%17 = load i32, i32* %5
%18 = sub nsw i32 39321, %17
store i32 %18, i32* %7
%19 = load i32, i32* %7
%20 = load i32*, i32** %6
%21 = call i32 @bcd_add_16(i32 %19, i32 1, i32* %20)
store i32 %21, i32* %8
%22 = load i32, i32* %4
%23 = load i32, i32* %8
%24 = load i32*, i32** %6
%25 = call i32 @bcd_add_16(i32 %22, i32 %23, i32* %24)
store i32 %25, i32* %8
%26 = load i32*, i32** %6
%27 = load i32, i32* %26
%28 = sub nsw i32 1, %27
%29 = load i32*, i32** %6
store i32 %28, i32* %29
%30 = load i32, i32* %8
ret i32 %30
}

LLVM IR (-O2):
define i32 @bcd_sub_16(i32 %0, i32 %1, i32* %2) {
%4 = load i32, i32* %2
%5 = icmp ne i32 %4, 0
%6 = sext i1 %5 to i32
store i32 0, i32* %2
%7 = sub i32 39321, %1
%8 = add i32 %7, %6
%9 = tail call i32 @bcd_add_16(i32 %8, i32 1, i32* %2)
%10 = tail call i32 @bcd_add_16(i32 %0, i32 %9, i32* %2)
%11 = load i32, i32* %2
%12 = sub nsw i32 1, %11
store i32 %12, i32* %2
ret i32 %10
}