#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 log10(double);
void psycho_1_smr(double ltmin[32], double spike[32], double scale[32],
                  int sblimit) {
  int i;
  double max;
  for (i = 0; i < sblimit; i++) {
    max = 20 * log10(scale[i] * 32768) - 10;
    if (spike[i] > max)
      max = spike[i];
    max -= ltmin[i];
    ltmin[i] = max;
  }
}


x86 assembly (clang, -O0):
<psycho_1_smr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11c8 <psycho_1_smr+0xb8>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsd  0xeb6(%rip),%xmm0
mulsd  (%rax,%rcx,8),%xmm0
call   1030 <log10@plt>
imul   $0x14,%eax,%eax
sub    $0xa,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
ucomisd -0x28(%rbp),%xmm0
jbe    118d <psycho_1_smr+0x7d>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
movsd  -0x28(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    112e <psycho_1_smr+0x1e>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<psycho_1_smr>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %ecx,%ecx
jle    1175 <psycho_1_smr+0x65>
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r13
mov    %ecx,%r12d
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
movsd  (%r14,%rbx,8),%xmm0
mulsd  0xec2(%rip),%xmm0
call   1030 <log10@plt>
lea    (%rax,%rax,4),%eax
lea    -0xa(,%rax,4),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  (%r15,%rbx,8),%xmm1
maxsd  %xmm0,%xmm1
subsd  0x0(%r13,%rbx,8),%xmm1
movsd  %xmm1,0x0(%r13,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1130 <psycho_1_smr+0x20>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @psycho_1_smr(double* %0, double* %1, double* %2, i32 %3) {
%5 = alloca double*
%6 = alloca double*
%7 = alloca double*
%8 = alloca i32
%9 = alloca i32
%10 = alloca double
store double* %0, double** %5
store double* %1, double** %6
store double* %2, double** %7
store i32 %3, i32* %8
store i32 0, i32* %9
br label %11
11: ; preds = %52, %4
%12 = load i32, i32* %9
%13 = load i32, i32* %8
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %55
15: ; preds = %11
%16 = load double*, double** %7
%17 = load i32, i32* %9
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds double, double* %16, i64 %18
%20 = load double, double* %19
%21 = fmul double %20, 3.276800e+04
%22 = call i32 @log10(double %21)
%23 = mul nsw i32 20, %22
%24 = sub nsw i32 %23, 10
%25 = sitofp i32 %24 to double
store double %25, double* %10
%26 = load double*, double** %6
%27 = load i32, i32* %9
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds double, double* %26, i64 %28
%30 = load double, double* %29
%31 = load double, double* %10
%32 = fcmp ogt double %30, %31
br i1 %32, label %33, label %39
33: ; preds = %15
%34 = load double*, double** %6
%35 = load i32, i32* %9
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds double, double* %34, i64 %36
%38 = load double, double* %37
store double %38, double* %10
br label %39
39: ; preds = %33, %15
%40 = load double*, double** %5
%41 = load i32, i32* %9
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds double, double* %40, i64 %42
%44 = load double, double* %43
%45 = load double, double* %10
%46 = fsub double %45, %44
store double %46, double* %10
%47 = load double, double* %10
%48 = load double*, double** %5
%49 = load i32, i32* %9
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds double, double* %48, i64 %50
store double %47, double* %51
br label %52
52: ; preds = %39
%53 = load i32, i32* %9
%54 = add nsw i32 %53, 1
store i32 %54, i32* %9
br label %11
55: ; preds = %11
ret void
}

LLVM IR (-O2):
define void @psycho_1_smr(double* nocapture %0, double* nocapture %1, double* nocapture %2, i32 %3) {
%5 = icmp sgt i32 %3, 0
br i1 %5, label %6, label %26
6: ; preds = %4
%7 = zext i32 %3 to i64
br label %8
8: ; preds = %6, %8
%9 = phi i64 [ 0, %6 ], [ %24, %8 ]
%10 = getelementptr inbounds double, double* %2, i64 %9
%11 = load double, double* %10
%12 = fmul double %11, 3.276800e+04
%13 = tail call i32 @log10(double %12)
%14 = mul nsw i32 %13, 20
%15 = add nsw i32 %14, -10
%16 = sitofp i32 %15 to double
%17 = getelementptr inbounds double, double* %1, i64 %9
%18 = load double, double* %17
%19 = fcmp ogt double %18, %16
%20 = select i1 %19, double %18, double %16
%21 = getelementptr inbounds double, double* %0, i64 %9
%22 = load double, double* %21
%23 = fsub double %20, %22
store double %23, double* %21
%24 = add nuw nsw i64 %9, 1
%25 = icmp eq i64 %24, %7
br i1 %25, label %26, label %8
26: ; preds = %8, %4
ret void
}