#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 */
int BGBDT_SndBTAC1C_EncodeQuantUni3(int, int, int, int, int);
int BGBDT_SndBTAC1C_EncodeQuantUni(int tgt, int pred, int step, int lsbit) {
  int uni, sni, diff;
  diff = tgt - pred;
  if (diff >= 0) {
    sni = (diff * 8 - 1) / (step * 2);
    uni = (sni > 7) ? 7 : sni;
  } else {
    sni = (-diff * 8 - 1) / (step * 2);
    uni = (sni > 7) ? 15 : (8 | sni);
  }
  uni = BGBDT_SndBTAC1C_EncodeQuantUni3(uni, step, pred, tgt, lsbit);
  return (uni);
}


x86 assembly (clang, -O0):
<BGBDT_SndBTAC1C_EncodeQuantUni>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    -0x4(%rbp),%eax
sub    -0x8(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     1174 <BGBDT_SndBTAC1C_EncodeQuantUni+0x64>
mov    -0x1c(%rbp),%eax
shl    $0x3,%eax
sub    $0x1,%eax
mov    -0xc(%rbp),%ecx
shl    $0x1,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
cmpl   $0x7,-0x18(%rbp)
jle    1163 <BGBDT_SndBTAC1C_EncodeQuantUni+0x53>
mov    $0x7,%eax
mov    %eax,-0x20(%rbp)
jmp    1169 <BGBDT_SndBTAC1C_EncodeQuantUni+0x59>
mov    -0x18(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    11b1 <BGBDT_SndBTAC1C_EncodeQuantUni+0xa1>
xor    %eax,%eax
sub    -0x1c(%rbp),%eax
shl    $0x3,%eax
sub    $0x1,%eax
mov    -0xc(%rbp),%ecx
shl    $0x1,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
cmpl   $0x7,-0x18(%rbp)
jle    11a2 <BGBDT_SndBTAC1C_EncodeQuantUni+0x92>
mov    $0xf,%eax
mov    %eax,-0x24(%rbp)
jmp    11ab <BGBDT_SndBTAC1C_EncodeQuantUni+0x9b>
mov    -0x18(%rbp),%eax
or     $0x8,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%edx
mov    -0x4(%rbp),%ecx
mov    -0x10(%rbp),%r8d
call   1030 <BGBDT_SndBTAC1C_EncodeQuantUni3@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BGBDT_SndBTAC1C_EncodeQuantUni>:
mov    %ecx,%r8d
mov    %edx,%r10d
mov    %esi,%r9d
mov    %edi,%ecx
mov    %edi,%eax
sub    %esi,%eax
js     113c <BGBDT_SndBTAC1C_EncodeQuantUni+0x2c>
lea    -0x1(,%rax,8),%eax
lea    (%r10,%r10,1),%esi
cltd
idiv   %esi
cmp    $0x7,%eax
mov    $0x7,%edi
cmovl  %eax,%edi
jmp    1158 <BGBDT_SndBTAC1C_EncodeQuantUni+0x48>
shl    $0x3,%eax
not    %eax
lea    (%r10,%r10,1),%esi
cltd
idiv   %esi
mov    %eax,%edx
or     $0x8,%edx
cmp    $0x8,%eax
mov    $0xf,%edi
cmovl  %edx,%edi
mov    %r10d,%esi
mov    %r9d,%edx
jmp    1030 <BGBDT_SndBTAC1C_EncodeQuantUni3@plt>

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

LLVM IR (-O2):
define i32 @BGBDT_SndBTAC1C_EncodeQuantUni(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = sub nsw i32 %0, %1
%6 = icmp sgt i32 %5, -1
br i1 %6, label %7, label %14
7: ; preds = %4
%8 = shl nsw i32 %5, 3
%9 = add nsw i32 %8, -1
%10 = shl nsw i32 %2, 1
%11 = sdiv i32 %9, %10
%12 = icmp slt i32 %11, 7
%13 = select i1 %12, i32 %11, i32 7
br label %22
14: ; preds = %4
%15 = mul i32 %5, -8
%16 = add nsw i32 %15, -1
%17 = shl nsw i32 %2, 1
%18 = sdiv i32 %16, %17
%19 = icmp sgt i32 %18, 7
%20 = or i32 %18, 8
%21 = select i1 %19, i32 15, i32 %20
br label %22
22: ; preds = %14, %7
%23 = phi i32 [ %13, %7 ], [ %21, %14 ]
%24 = tail call i32 @BGBDT_SndBTAC1C_EncodeQuantUni3(i32 %23, i32 %2, i32 %1, i32 %0, i32 %3)
ret i32 %24
}