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

/* Variables and functions */
int INT16_MIN;
int /*<<< orphan*/ assert(int);
int saturated_abs16(int);
void transform_to_log_area_ratios(int16_t r[8]) {
  int16_t temp;
  int i;
  for (i = 1; i <= 8; i++, r++) {
    temp = saturated_abs16(*r);
    assert(temp >= 0);
    if (temp < 22118) {
      temp >>= 1;
    } else if (temp < 31130) {
      assert(temp >= 11059);
      temp -= 11059;
    } else {
      assert(temp >= 26112);
      temp -= 26112;
      temp <<= 2;
    }
    *r = (*r < 0) ? -temp : temp;
    assert(*r != INT16_MIN);
  }
}


x86 assembly (clang, -O0):
<transform_to_log_area_ratios>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x1,-0x10(%rbp)
cmpl   $0x8,-0x10(%rbp)
jg     1234 <transform_to_log_area_ratios+0x114>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   1040 <saturated_abs16@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
cmpl   $0x5666,-0xc(%rbp)
jge    1177 <transform_to_log_area_ratios+0x57>
mov    -0xc(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11d5 <transform_to_log_area_ratios+0xb5>
cmpl   $0x799a,-0xc(%rbp)
jge    11a8 <transform_to_log_area_ratios+0x88>
cmpl   $0x2b33,-0xc(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0xc(%rbp),%eax
sub    $0x2b33,%eax
mov    %eax,-0xc(%rbp)
jmp    11d0 <transform_to_log_area_ratios+0xb0>
cmpl   $0x6600,-0xc(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0xc(%rbp),%eax
sub    $0x6600,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
shl    $0x2,%eax
mov    %eax,-0xc(%rbp)
jmp    11d5 <transform_to_log_area_ratios+0xb5>
mov    -0x8(%rbp),%rax
cmpl   $0x0,(%rax)
jge    11ef <transform_to_log_area_ratios+0xcf>
xor    %eax,%eax
sub    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    11f5 <transform_to_log_area_ratios+0xd5>
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    0x2dd5(%rip),%rcx
cmp    (%rcx),%eax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x8(%rbp)
jmp    1133 <transform_to_log_area_ratios+0x13>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<transform_to_log_area_ratios>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %r15d,%r15d
mov    0x2eab(%rip),%r12
jmp    116b <transform_to_log_area_ratios+0x4b>
nopw   0x0(%rax,%rax,1)
sar    %ebx
mov    %ebx,%eax
neg    %eax
cmpl   $0x0,(%r14,%r15,4)
cmovns %ebx,%eax
mov    %eax,(%r14,%r15,4)
xor    %edi,%edi
cmp    (%r12),%eax
setne  %dil
call   1030 <assert@plt>
add    $0x1,%r15
cmp    $0x8,%r15d
je     11b9 <transform_to_log_area_ratios+0x99>
mov    (%r14,%r15,4),%edi
call   1040 <saturated_abs16@plt>
mov    %eax,%ebx
mov    %eax,%edi
not    %edi
shr    $0x1f,%edi
call   1030 <assert@plt>
cmp    $0x5665,%ebx
jle    1140 <transform_to_log_area_ratios+0x20>
mov    $0x1,%edi
call   1030 <assert@plt>
cmp    $0x7999,%ebx
ja     11b0 <transform_to_log_area_ratios+0x90>
add    $0xffffd4cd,%ebx
jmp    1142 <transform_to_log_area_ratios+0x22>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    -0x19800(,%rbx,4),%ebx
jmp    1142 <transform_to_log_area_ratios+0x22>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@INT16_MIN = global i32 0
define void @transform_to_log_area_ratios(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
store i32* %0, i32** %2
store i32 1, i32* %4
br label %5
5: ; preds = %59, %1
%6 = load i32, i32* %4
%7 = icmp sle i32 %6, 8
br i1 %7, label %8, label %64
8: ; preds = %5
%9 = load i32*, i32** %2
%10 = load i32, i32* %9
%11 = call i32 @saturated_abs16(i32 %10)
store i32 %11, i32* %3
%12 = load i32, i32* %3
%13 = icmp sge i32 %12, 0
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = load i32, i32* %3
%17 = icmp slt i32 %16, 22118
br i1 %17, label %18, label %21
18: ; preds = %8
%19 = load i32, i32* %3
%20 = ashr i32 %19, 1
store i32 %20, i32* %3
br label %41
21: ; preds = %8
%22 = load i32, i32* %3
%23 = icmp slt i32 %22, 31130
br i1 %23, label %24, label %31
24: ; preds = %21
%25 = load i32, i32* %3
%26 = icmp sge i32 %25, 11059
%27 = zext i1 %26 to i32
%28 = call i32 @assert(i32 %27)
%29 = load i32, i32* %3
%30 = sub nsw i32 %29, 11059
store i32 %30, i32* %3
br label %40
31: ; preds = %21
%32 = load i32, i32* %3
%33 = icmp sge i32 %32, 26112
%34 = zext i1 %33 to i32
%35 = call i32 @assert(i32 %34)
%36 = load i32, i32* %3
%37 = sub nsw i32 %36, 26112
store i32 %37, i32* %3
%38 = load i32, i32* %3
%39 = shl i32 %38, 2
store i32 %39, i32* %3
br label %40
40: ; preds = %31, %24
br label %41
41: ; preds = %40, %18
%42 = load i32*, i32** %2
%43 = load i32, i32* %42
%44 = icmp slt i32 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %41
%46 = load i32, i32* %3
%47 = sub nsw i32 0, %46
br label %50
48: ; preds = %41
%49 = load i32, i32* %3
br label %50
50: ; preds = %48, %45
%51 = phi i32 [ %47, %45 ], [ %49, %48 ]
%52 = load i32*, i32** %2
store i32 %51, i32* %52
%53 = load i32*, i32** %2
%54 = load i32, i32* %53
%55 = load i32, i32* @INT16_MIN
%56 = icmp ne i32 %54, %55
%57 = zext i1 %56 to i32
%58 = call i32 @assert(i32 %57)
br label %59
59: ; preds = %50
%60 = load i32, i32* %4
%61 = add nsw i32 %60, 1
store i32 %61, i32* %4
%62 = load i32*, i32** %2
%63 = getelementptr inbounds i32, i32* %62, i32 1
store i32* %63, i32** %2
br label %5
64: ; preds = %5
ret void
}

LLVM IR (-O2):
@INT16_MIN = global i32 0
define void @transform_to_log_area_ratios(i32* nocapture %0) {
br label %2
2: ; preds = %1, %21
%3 = phi i32 [ 1, %1 ], [ %31, %21 ]
%4 = phi i32* [ %0, %1 ], [ %32, %21 ]
%5 = load i32, i32* %4
%6 = tail call i32 @saturated_abs16(i32 %5)
%7 = xor i32 %6, -1
%8 = lshr i32 %7, 31
%9 = tail call i32 @assert(i32 %8)
%10 = icmp slt i32 %6, 22118
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = ashr i32 %6, 1
br label %21
13: ; preds = %2
%14 = icmp ult i32 %6, 31130
%15 = tail call i32 @assert(i32 1)
br i1 %14, label %16, label %18
16: ; preds = %13
%17 = add nsw i32 %6, -11059
br label %21
18: ; preds = %13
%19 = shl i32 %6, 2
%20 = add i32 %19, -104448
br label %21
21: ; preds = %16, %18, %11
%22 = phi i32 [ %12, %11 ], [ %17, %16 ], [ %20, %18 ]
%23 = load i32, i32* %4
%24 = icmp slt i32 %23, 0
%25 = sub nsw i32 0, %22
%26 = select i1 %24, i32 %25, i32 %22
store i32 %26, i32* %4
%27 = load i32, i32* @INT16_MIN
%28 = icmp ne i32 %26, %27
%29 = zext i1 %28 to i32
%30 = tail call i32 @assert(i32 %29)
%31 = add nuw nsw i32 %3, 1
%32 = getelementptr inbounds i32, i32* %4, i64 1
%33 = icmp eq i32 %31, 9
br i1 %33, label %34, label %2
34: ; preds = %21
ret void
}