#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 */
short abs(short);
int /*<<< orphan*/ assert(int);
int ceilf(int);
int log(int);
int logf(short);
int get_dc_difference_category(short val) {
  if (val != 0) {
    val = abs(val);
    int idx = ceilf(logf(val + 1) / log(2));
    assert(idx < 12);
    return idx;
  }
  return 0;
}


x86 assembly (clang, -O0):
<get_dc_difference_category>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %di,%ax
mov    %ax,-0x6(%rbp)
movswl -0x6(%rbp),%eax
cmp    $0x0,%eax
je     11c3 <get_dc_difference_category+0x73>
movswl -0x6(%rbp),%edi
call   1040 <abs@plt>
mov    %ax,-0x6(%rbp)
movswl -0x6(%rbp),%eax
add    $0x1,%eax
movswl %ax,%edi
call   1030 <logf@plt>
mov    %eax,-0x10(%rbp)
mov    $0x2,%edi
call   1070 <log@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,%edi
call   1060 <ceilf@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xc,-0xc(%rbp)
setl   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ca <get_dc_difference_category+0x7a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_dc_difference_category>:
push   %rbx
test   %di,%di
je     1186 <get_dc_difference_category+0x46>
mov    %edi,%eax
neg    %ax
cmovs  %di,%ax
add    $0x1,%eax
movswl %ax,%edi
call   1030 <logf@plt>
mov    %eax,%ebx
mov    $0x2,%edi
call   1060 <log@plt>
mov    %eax,%ecx
mov    %ebx,%eax
cltd
idiv   %ecx
mov    %eax,%edi
call   1050 <ceilf@plt>
mov    %eax,%ebx
xor    %edi,%edi
cmp    $0xc,%eax
setl   %dil
call   1040 <assert@plt>
jmp    1188 <get_dc_difference_category+0x48>
xor    %ebx,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @get_dc_difference_category(i16 signext %0) {
%2 = alloca i32
%3 = alloca i16
%4 = alloca i32
store i16 %0, i16* %3
%5 = load i16, i16* %3
%6 = sext i16 %5 to i32
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %24
8: ; preds = %1
%9 = load i16, i16* %3
%10 = call signext i16 @abs(i16 signext %9)
store i16 %10, i16* %3
%11 = load i16, i16* %3
%12 = sext i16 %11 to i32
%13 = add nsw i32 %12, 1
%14 = trunc i32 %13 to i16
%15 = call i32 @logf(i16 signext %14)
%16 = call i32 @log(i32 2)
%17 = sdiv i32 %15, %16
%18 = call i32 @ceilf(i32 %17)
store i32 %18, i32* %4
%19 = load i32, i32* %4
%20 = icmp slt i32 %19, 12
%21 = zext i1 %20 to i32
%22 = call i32 @assert(i32 %21)
%23 = load i32, i32* %4
store i32 %23, i32* %2
br label %25
24: ; preds = %1
store i32 0, i32* %2
br label %25
25: ; preds = %24, %8
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
define i32 @get_dc_difference_category(i16 signext %0) {
%2 = icmp eq i16 %0, 0
br i1 %2, label %13, label %3
3: ; preds = %1
%4 = tail call i16 @llvm.abs.i16(i16 %0, i1 true)
%5 = add nuw i16 %4, 1
%6 = tail call i32 @logf(i16 signext %5)
%7 = tail call i32 @log(i32 2)
%8 = sdiv i32 %6, %7
%9 = tail call i32 @ceilf(i32 %8)
%10 = icmp slt i32 %9, 12
%11 = zext i1 %10 to i32
%12 = tail call i32 @assert(i32 %11)
br label %13
13: ; preds = %1, %3
%14 = phi i32 [ %9, %3 ], [ 0, %1 ]
ret i32 %14
}