#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 /*<<< orphan*/ assert(int);
int gsm_asl(int, int);
int gsm_asr(int, int);
int gsm_mult_r(int, int);
int saturated_add16(int, int);
int saturated_sub16(int, int);
void apcm_inverse_quantization(int16_t xMc[13], int16_t mant, int16_t exp,
                               int16_t xMp[13]) {
  static const int16_t gsm_FAC[8] = {18431, 20479, 22527, 24575,
                                     26623, 28671, 30719, 32767};
  int i;
  int16_t temp;
  int16_t temp1;
  int16_t temp2;
  int16_t temp3;
  temp1 = gsm_FAC[mant];
  temp2 = saturated_sub16(6, exp);
  temp3 = gsm_asl(1, saturated_sub16(temp2, 1));
  for (i = 0; i < 13; i++) {
    assert(xMc[i] >= 0 && xMc[i] <= 7);
    temp = (int16_t)((xMc[i] << 1) - 7);
    assert(temp <= 7 && temp >= -7);
    temp <<= 12;
    temp = gsm_mult_r(temp1, temp);
    temp = saturated_add16(temp, temp3);
    xMp[i] = gsm_asr(temp, temp2);
  }
}


x86 assembly (clang, -O0):
<apcm_inverse_quantization>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
movslq -0xc(%rbp),%rcx
lea    0xe7f(%rip),%rax
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%esi
mov    $0x6,%edi
call   1080 <saturated_sub16@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%edi
mov    $0x1,%esi
call   1080 <saturated_sub16@plt>
mov    %eax,%esi
mov    $0x1,%edi
call   1060 <gsm_asl@plt>
mov    %eax,-0x2c(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0xd,-0x1c(%rbp)
jge    127f <apcm_inverse_quantization+0x11f>
mov    -0x8(%rbp),%rcx
movslq -0x1c(%rbp),%rdx
xor    %eax,%eax
cmpl   $0x0,(%rcx,%rdx,4)
mov    %al,-0x2d(%rbp)
jl     11ed <apcm_inverse_quantization+0x8d>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
cmpl   $0x7,(%rax,%rcx,4)
setle  %al
mov    %al,-0x2d(%rbp)
mov    -0x2d(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
shl    $0x1,%eax
sub    $0x7,%eax
mov    %eax,-0x20(%rbp)
xor    %eax,%eax
cmpl   $0x7,-0x20(%rbp)
mov    %al,-0x2e(%rbp)
jg     1227 <apcm_inverse_quantization+0xc7>
cmpl   $0xfffffff9,-0x20(%rbp)
setge  %al
mov    %al,-0x2e(%rbp)
mov    -0x2e(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x20(%rbp),%eax
shl    $0xc,%eax
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%esi
call   1050 <gsm_mult_r@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x2c(%rbp),%esi
call   1030 <saturated_add16@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x28(%rbp),%esi
call   1070 <gsm_asr@plt>
mov    %eax,%edx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11ba <apcm_inverse_quantization+0x5a>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<apcm_inverse_quantization>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,(%rsp)
mov    %rdi,%rbx
movslq %esi,%rax
lea    0xe84(%rip),%rcx
mov    (%rcx,%rax,4),%r15d
mov    $0x6,%edi
mov    %edx,%esi
call   1080 <saturated_sub16@plt>
mov    %eax,%r12d
mov    %eax,%edi
mov    $0x1,%esi
call   1080 <saturated_sub16@plt>
mov    $0x1,%edi
mov    %eax,%esi
call   1060 <gsm_asl@plt>
mov    %eax,%r13d
xor    %r14d,%r14d
nopl   (%rax)
xor    %edi,%edi
cmpl   $0x8,(%rbx,%r14,4)
setb   %dil
call   1040 <assert@plt>
mov    (%rbx,%r14,4),%ebp
lea    0x0(%rbp,%rbp,1),%eax
xor    %edi,%edi
cmp    $0xf,%eax
setb   %dil
call   1040 <assert@plt>
shl    $0xd,%ebp
add    $0xffff9000,%ebp
mov    %r15d,%edi
mov    %ebp,%esi
call   1050 <gsm_mult_r@plt>
mov    %eax,%edi
mov    %r13d,%esi
call   1030 <saturated_add16@plt>
mov    %eax,%edi
mov    %r12d,%esi
call   1070 <gsm_asr@plt>
mov    (%rsp),%rcx
mov    %eax,(%rcx,%r14,4)
add    $0x1,%r14
cmp    $0xd,%r14
jne    11b0 <apcm_inverse_quantization+0x50>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@apcm_inverse_quantization.gsm_FAC = internal constant [8 x i32] [i32 18431, i32 20479, i32 22527, i32 24575, i32 26623, i32 28671, i32 30719, i32 32767]
define void @apcm_inverse_quantization(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
%12 = alloca i32
%13 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32* %3, i32** %8
%14 = load i32, i32* %6
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [8 x i32], [8 x i32]* @apcm_inverse_quantization.gsm_FAC, i64 0, i64 %15
%17 = load i32, i32* %16
store i32 %17, i32* %11
%18 = load i32, i32* %7
%19 = call i32 @saturated_sub16(i32 6, i32 %18)
store i32 %19, i32* %12
%20 = load i32, i32* %12
%21 = call i32 @saturated_sub16(i32 %20, i32 1)
%22 = call i32 @gsm_asl(i32 1, i32 %21)
store i32 %22, i32* %13
store i32 0, i32* %9
br label %23
23: ; preds = %75, %4
%24 = load i32, i32* %9
%25 = icmp slt i32 %24, 13
br i1 %25, label %26, label %78
26: ; preds = %23
%27 = load i32*, i32** %5
%28 = load i32, i32* %9
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i32, i32* %27, i64 %29
%31 = load i32, i32* %30
%32 = icmp sge i32 %31, 0
br i1 %32, label %33, label %40
33: ; preds = %26
%34 = load i32*, i32** %5
%35 = load i32, i32* %9
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i32, i32* %34, i64 %36
%38 = load i32, i32* %37
%39 = icmp sle i32 %38, 7
br label %40
40: ; preds = %33, %26
%41 = phi i1 [ false, %26 ], [ %39, %33 ]
%42 = zext i1 %41 to i32
%43 = call i32 @assert(i32 %42)
%44 = load i32*, i32** %5
%45 = load i32, i32* %9
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i32, i32* %44, i64 %46
%48 = load i32, i32* %47
%49 = shl i32 %48, 1
%50 = sub nsw i32 %49, 7
store i32 %50, i32* %10
%51 = load i32, i32* %10
%52 = icmp sle i32 %51, 7
br i1 %52, label %53, label %56
53: ; preds = %40
%54 = load i32, i32* %10
%55 = icmp sge i32 %54, -7
br label %56
56: ; preds = %53, %40
%57 = phi i1 [ false, %40 ], [ %55, %53 ]
%58 = zext i1 %57 to i32
%59 = call i32 @assert(i32 %58)
%60 = load i32, i32* %10
%61 = shl i32 %60, 12
store i32 %61, i32* %10
%62 = load i32, i32* %11
%63 = load i32, i32* %10
%64 = call i32 @gsm_mult_r(i32 %62, i32 %63)
store i32 %64, i32* %10
%65 = load i32, i32* %10
%66 = load i32, i32* %13
%67 = call i32 @saturated_add16(i32 %65, i32 %66)
store i32 %67, i32* %10
%68 = load i32, i32* %10
%69 = load i32, i32* %12
%70 = call i32 @gsm_asr(i32 %68, i32 %69)
%71 = load i32*, i32** %8
%72 = load i32, i32* %9
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds i32, i32* %71, i64 %73
store i32 %70, i32* %74
br label %75
75: ; preds = %56
%76 = load i32, i32* %9
%77 = add nsw i32 %76, 1
store i32 %77, i32* %9
br label %23
78: ; preds = %23
ret void
}

LLVM IR (-O2):
@apcm_inverse_quantization.gsm_FAC = internal unnamed_addr constant [8 x i32] [i32 18431, i32 20479, i32 22527, i32 24575, i32 26623, i32 28671, i32 30719, i32 32767]
define void @apcm_inverse_quantization(i32* nocapture %0, i32 %1, i32 %2, i32* nocapture writeonly %3) {
%5 = sext i32 %1 to i64
%6 = getelementptr inbounds [8 x i32], [8 x i32]* @apcm_inverse_quantization.gsm_FAC, i64 0, i64 %5
%7 = load i32, i32* %6
%8 = tail call i32 @saturated_sub16(i32 6, i32 %2)
%9 = tail call i32 @saturated_sub16(i32 %8, i32 1)
%10 = tail call i32 @gsm_asl(i32 1, i32 %9)
br label %11
11: ; preds = %4, %11
%12 = phi i64 [ 0, %4 ], [ %29, %11 ]
%13 = getelementptr inbounds i32, i32* %0, i64 %12
%14 = load i32, i32* %13
%15 = icmp ult i32 %14, 8
%16 = zext i1 %15 to i32
%17 = tail call i32 @assert(i32 %16)
%18 = load i32, i32* %13
%19 = shl i32 %18, 1
%20 = icmp ult i32 %19, 15
%21 = zext i1 %20 to i32
%22 = tail call i32 @assert(i32 %21)
%23 = shl i32 %18, 13
%24 = add i32 %23, -28672
%25 = tail call i32 @gsm_mult_r(i32 %7, i32 %24)
%26 = tail call i32 @saturated_add16(i32 %25, i32 %10)
%27 = tail call i32 @gsm_asr(i32 %26, i32 %8)
%28 = getelementptr inbounds i32, i32* %3, i64 %12
store i32 %27, i32* %28
%29 = add nuw nsw i64 %12, 1
%30 = icmp eq i64 %29, 13
br i1 %30, label %31, label %11
31: ; preds = %11
ret void
}