#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 /*<<< orphan*/ int32_t;
typedef scalar_t__ int16_t;

/* Variables and functions */
int /*<<< orphan*/ Log2(int /*<<< orphan*/, scalar_t__ *, scalar_t__ *);
scalar_t__ add(scalar_t__, int);
scalar_t__ mult(scalar_t__, int);
int mult_r(scalar_t__, int);
scalar_t__ shl(scalar_t__, int);
scalar_t__ shr(scalar_t__, int);
scalar_t__ sub(scalar_t__, int);
int16_t Quant_Energy(int32_t L_x, int16_t sh, int16_t *enerq) {
  int16_t exp, frac;
  int16_t e_tmp, temp, index;
  Log2(L_x, &exp, &frac);
  temp = sub(exp, sh);
  e_tmp = shl(temp, 10);
  e_tmp = add(e_tmp, mult_r(frac, 1024));
  temp = sub(e_tmp, -2721);
  if (temp <= 0) {
    *enerq = -12;
    return (0);
  }
  temp = sub(e_tmp, 22111);
  if (temp > 0) {
    *enerq = 66;
    return (31);
  }
  temp = sub(e_tmp, 4762);
  if (temp <= 0) {
    e_tmp = add(e_tmp, 3401);
    index = mult(e_tmp, 24);
    if (index < 1)
      index = 1;
    *enerq = sub(shl(index, 2), 8);
    return (index);
  }
  e_tmp = sub(e_tmp, 340);
  index = sub(shr(mult(e_tmp, 193), 2), 1);
  if (index < 6)
    index = 6;
  *enerq = add(shl(index, 1), 4);
  return (index);
}


x86 assembly (clang, -O0):
<Quant_Energy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x28(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   1060 <Log2@plt>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    %eax,%esi
call   1090 <sub@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    $0xa,%esi
call   1050 <shl@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x30(%rbp),%rdi
mov    $0x400,%esi
call   1080 <mult_r@plt>
mov    -0x50(%rbp),%rdi
mov    %eax,%esi
call   1030 <add@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    $0xfffff55f,%esi
call   1090 <sub@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jg     1212 <Quant_Energy+0xa2>
mov    -0x20(%rbp),%rax
movq   $0xfffffffffffffff4,(%rax)
movq   $0x0,-0x8(%rbp)
jmp    134b <Quant_Energy+0x1db>
mov    -0x38(%rbp),%rdi
mov    $0x565f,%esi
call   1090 <sub@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jle    1247 <Quant_Energy+0xd7>
mov    -0x20(%rbp),%rax
movq   $0x42,(%rax)
movq   $0x1f,-0x8(%rbp)
jmp    134b <Quant_Energy+0x1db>
mov    -0x38(%rbp),%rdi
mov    $0x129a,%esi
call   1090 <sub@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jg     12cd <Quant_Energy+0x15d>
mov    -0x38(%rbp),%rdi
mov    $0xd49,%esi
call   1030 <add@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    $0x18,%esi
call   1070 <mult@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x1,-0x48(%rbp)
jge    129b <Quant_Energy+0x12b>
movq   $0x1,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
mov    $0x2,%esi
call   1050 <shl@plt>
mov    %rax,%rdi
mov    $0x8,%esi
call   1090 <sub@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x48(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    134b <Quant_Energy+0x1db>
mov    -0x38(%rbp),%rdi
mov    $0x154,%esi
call   1090 <sub@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    $0xc1,%esi
call   1070 <mult@plt>
mov    %rax,%rdi
mov    $0x2,%esi
call   1040 <shr@plt>
mov    %rax,%rdi
mov    $0x1,%esi
call   1090 <sub@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x6,-0x48(%rbp)
jge    131e <Quant_Energy+0x1ae>
movq   $0x6,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
mov    $0x1,%esi
call   1050 <shl@plt>
mov    %rax,%rdi
mov    $0x4,%esi
call   1030 <add@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x48(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Quant_Energy>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
call   1060 <Log2@plt>
mov    0x10(%rsp),%rdi
mov    %ebx,%esi
call   1090 <sub@plt>
mov    %rax,%rdi
mov    $0xa,%esi
call   1050 <shl@plt>
mov    %rax,%rbx
mov    0x8(%rsp),%rdi
mov    $0x400,%esi
call   1080 <mult_r@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <add@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0xfffff55f,%esi
call   1090 <sub@plt>
test   %rax,%rax
jle    11f7 <Quant_Energy+0x87>
mov    %rbx,%rdi
mov    $0x565f,%esi
call   1090 <sub@plt>
test   %rax,%rax
jle    1205 <Quant_Energy+0x95>
mov    $0x1f,%ebx
mov    $0x42,%eax
jmp    12b1 <Quant_Energy+0x141>
mov    $0xfffffffffffffff4,%rax
xor    %ebx,%ebx
jmp    12b1 <Quant_Energy+0x141>
mov    %rbx,%rdi
mov    $0x129a,%esi
call   1090 <sub@plt>
mov    %rbx,%rdi
test   %rax,%rax
jle    1274 <Quant_Energy+0x104>
mov    $0x154,%esi
call   1090 <sub@plt>
mov    %rax,%rdi
mov    $0xc1,%esi
call   1070 <mult@plt>
mov    %rax,%rdi
mov    $0x2,%esi
call   1040 <shr@plt>
mov    %rax,%rdi
mov    $0x1,%esi
call   1090 <sub@plt>
cmp    $0x7,%rax
mov    $0x6,%ebx
cmovge %rax,%rbx
mov    %rbx,%rdi
mov    $0x1,%esi
call   1050 <shl@plt>
mov    %rax,%rdi
mov    $0x4,%esi
call   1030 <add@plt>
jmp    12b1 <Quant_Energy+0x141>
mov    $0xd49,%esi
call   1030 <add@plt>
mov    %rax,%rdi
mov    $0x18,%esi
call   1070 <mult@plt>
test   %rax,%rax
mov    $0x1,%ebx
cmovg  %rax,%rbx
mov    %rbx,%rdi
mov    $0x2,%esi
call   1050 <shl@plt>
mov    %rax,%rdi
mov    $0x8,%esi
call   1090 <sub@plt>
mov    %rax,(%r14)
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i64 @Quant_Energy(i32 %0, i64 %1, i64* %2) {
%4 = alloca i64
%5 = alloca i32
%6 = alloca i64
%7 = alloca i64*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca i64
store i32 %0, i32* %5
store i64 %1, i64* %6
store i64* %2, i64** %7
%13 = load i32, i32* %5
%14 = call i32 @Log2(i32 %13, i64* %8, i64* %9)
%15 = load i64, i64* %8
%16 = load i64, i64* %6
%17 = trunc i64 %16 to i32
%18 = call i64 @sub(i64 %15, i32 %17)
store i64 %18, i64* %11
%19 = load i64, i64* %11
%20 = call i64 @shl(i64 %19, i32 10)
store i64 %20, i64* %10
%21 = load i64, i64* %10
%22 = load i64, i64* %9
%23 = call i32 @mult_r(i64 %22, i32 1024)
%24 = call i64 @add(i64 %21, i32 %23)
store i64 %24, i64* %10
%25 = load i64, i64* %10
%26 = call i64 @sub(i64 %25, i32 -2721)
store i64 %26, i64* %11
%27 = load i64, i64* %11
%28 = icmp sle i64 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %3
%30 = load i64*, i64** %7
store i64 -12, i64* %30
store i64 0, i64* %4
br label %73
31: ; preds = %3
%32 = load i64, i64* %10
%33 = call i64 @sub(i64 %32, i32 22111)
store i64 %33, i64* %11
%34 = load i64, i64* %11
%35 = icmp sgt i64 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %31
%37 = load i64*, i64** %7
store i64 66, i64* %37
store i64 31, i64* %4
br label %73
38: ; preds = %31
%39 = load i64, i64* %10
%40 = call i64 @sub(i64 %39, i32 4762)
store i64 %40, i64* %11
%41 = load i64, i64* %11
%42 = icmp sle i64 %41, 0
br i1 %42, label %43, label %57
43: ; preds = %38
%44 = load i64, i64* %10
%45 = call i64 @add(i64 %44, i32 3401)
store i64 %45, i64* %10
%46 = load i64, i64* %10
%47 = call i64 @mult(i64 %46, i32 24)
store i64 %47, i64* %12
%48 = load i64, i64* %12
%49 = icmp slt i64 %48, 1
br i1 %49, label %50, label %51
50: ; preds = %43
store i64 1, i64* %12
br label %51
51: ; preds = %50, %43
%52 = load i64, i64* %12
%53 = call i64 @shl(i64 %52, i32 2)
%54 = call i64 @sub(i64 %53, i32 8)
%55 = load i64*, i64** %7
store i64 %54, i64* %55
%56 = load i64, i64* %12
store i64 %56, i64* %4
br label %73
57: ; preds = %38
%58 = load i64, i64* %10
%59 = call i64 @sub(i64 %58, i32 340)
store i64 %59, i64* %10
%60 = load i64, i64* %10
%61 = call i64 @mult(i64 %60, i32 193)
%62 = call i64 @shr(i64 %61, i32 2)
%63 = call i64 @sub(i64 %62, i32 1)
store i64 %63, i64* %12
%64 = load i64, i64* %12
%65 = icmp slt i64 %64, 6
br i1 %65, label %66, label %67
66: ; preds = %57
store i64 6, i64* %12
br label %67
67: ; preds = %66, %57
%68 = load i64, i64* %12
%69 = call i64 @shl(i64 %68, i32 1)
%70 = call i64 @add(i64 %69, i32 4)
%71 = load i64*, i64** %7
store i64 %70, i64* %71
%72 = load i64, i64* %12
store i64 %72, i64* %4
br label %73
73: ; preds = %67, %51, %36, %29
%74 = load i64, i64* %4
ret i64 %74
}

LLVM IR (-O2):
define i64 @Quant_Energy(i32 %0, i64 %1, i64* nocapture writeonly %2) {
%4 = alloca i64
%5 = alloca i64
%6 = bitcast i64* %4 to i8*
%7 = bitcast i64* %5 to i8*
%8 = call i32 @Log2(i32 %0, i64* %4, i64* %5)
%9 = load i64, i64* %4
%10 = trunc i64 %1 to i32
%11 = call i64 @sub(i64 %9, i32 %10)
%12 = call i64 @shl(i64 %11, i32 10)
%13 = load i64, i64* %5
%14 = call i32 @mult_r(i64 %13, i32 1024)
%15 = call i64 @add(i64 %12, i32 %14)
%16 = call i64 @sub(i64 %15, i32 -2721)
%17 = icmp slt i64 %16, 1
br i1 %17, label %40, label %18
18: ; preds = %3
%19 = call i64 @sub(i64 %15, i32 22111)
%20 = icmp sgt i64 %19, 0
br i1 %20, label %40, label %21
21: ; preds = %18
%22 = call i64 @sub(i64 %15, i32 4762)
%23 = icmp slt i64 %22, 1
br i1 %23, label %24, label %31
24: ; preds = %21
%25 = call i64 @add(i64 %15, i32 3401)
%26 = call i64 @mult(i64 %25, i32 24)
%27 = icmp sgt i64 %26, 1
%28 = select i1 %27, i64 %26, i64 1
%29 = call i64 @shl(i64 %28, i32 2)
%30 = call i64 @sub(i64 %29, i32 8)
br label %40
31: ; preds = %21
%32 = call i64 @sub(i64 %15, i32 340)
%33 = call i64 @mult(i64 %32, i32 193)
%34 = call i64 @shr(i64 %33, i32 2)
%35 = call i64 @sub(i64 %34, i32 1)
%36 = icmp sgt i64 %35, 6
%37 = select i1 %36, i64 %35, i64 6
%38 = call i64 @shl(i64 %37, i32 1)
%39 = call i64 @add(i64 %38, i32 4)
br label %40
40: ; preds = %18, %3, %31, %24
%41 = phi i64 [ %39, %31 ], [ %30, %24 ], [ -12, %3 ], [ 66, %18 ]
%42 = phi i64 [ %37, %31 ], [ %28, %24 ], [ 0, %3 ], [ 31, %18 ]
store i64 %41, i64* %2
ret i64 %42
}