#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 */
double log(long double);
long double sqrt(long double);
int smooth_color(int total, int n, int imax, long double zr, long double zi,
                 long double logr) {
  int c = total;
  long double mu;
  if (n < imax) {
    mu = n - log(log(sqrt(zr * zr + zi * zi)) / logr) /
                 0.69314718055994530941723212145817;
    c = mu * total / imax;
    if (c < 0)
      c = 0;
    else if (c >= total)
      c = total - 1;
  }
  return c;
}


x86 assembly (clang, -O0):
<smooth_color>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
fldt   0x30(%rbp)
fldt   0x20(%rbp)
fldt   0x10(%rbp)
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
fstpt  -0x20(%rbp)
fstpt  -0x30(%rbp)
fstpt  -0x40(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1240 <smooth_color+0x120>
cvtsi2sdl -0x8(%rbp),%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
fldt   -0x20(%rbp)
fldt   -0x30(%rbp)
fmul   %st,%st(0)
fxch   %st(1)
fmul   %st,%st(0)
faddp  %st,%st(1)
mov    %rsp,%rax
fstpt  (%rax)
call   1040 <sqrt@plt>
mov    %rsp,%rax
fstpt  (%rax)
call   1030 <log@plt>
movsd  %xmm0,-0x78(%rbp)
fldl   -0x78(%rbp)
fldt   -0x40(%rbp)
fdivrp %st,%st(1)
mov    %rsp,%rax
fstpt  (%rax)
call   1030 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x90(%rbp),%xmm0
ff
movsd  0xe4f(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x80(%rbp)
fldl   -0x80(%rbp)
fstpt  -0x60(%rbp)
fldt   -0x60(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x68(%rbp)
fildl  -0x68(%rbp)
fmulp  %st,%st(1)
mov    -0xc(%rbp),%eax
mov    %eax,-0x6c(%rbp)
fildl  -0x6c(%rbp)
fdivrp %st,%st(1)
fnstcw -0x82(%rbp)
movzwl -0x82(%rbp),%eax
or     $0xc00,%eax
mov    %ax,-0x84(%rbp)
fldcw  -0x84(%rbp)
fistpl -0x64(%rbp)
fldcw  -0x82(%rbp)
mov    -0x64(%rbp),%eax
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jge    1221 <smooth_color+0x101>
movl   $0x0,-0x44(%rbp)
jmp    123b <smooth_color+0x11b>
mov    -0x44(%rbp),%eax
cmp    -0x4(%rbp),%eax
jl     1236 <smooth_color+0x116>
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    123b <smooth_color+0x11b>
jmp    1240 <smooth_color+0x120>
mov    -0x44(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<smooth_color>:
push   %rbp
push   %rbx
sub    $0x48,%rsp
mov    %edi,%ebx
fldt   0x80(%rsp)
fldt   0x70(%rsp)
fldt   0x60(%rsp)
cmp    %edx,%esi
jge    11f4 <smooth_color+0xd4>
mov    %edx,%ebp
fxch   %st(2)
fstpt  0x3c(%rsp)
cvtsi2sd %esi,%xmm0
movsd  %xmm0,0x20(%rsp)
fmul   %st,%st(0)
fxch   %st(1)
fmul   %st,%st(0)
faddp  %st,%st(1)
fld    %st(0)
fsqrt
fldz
fxch   %st(2)
fucomi %st(2),%st
fstp   %st(2)
jae    1175 <smooth_color+0x55>
fstp   %st(0)
fstpt  (%rsp)
call   1040 <sqrt@plt>
fldz
fxch   %st(1)
fstp   %st(1)
fstpt  (%rsp)
call   1030 <log@plt>
movsd  %xmm0,0x30(%rsp)
fldt   0x3c(%rsp)
fdivrl 0x30(%rsp)
fstpt  (%rsp)
call   1030 <log@plt>
divsd  0xe63(%rip),%xmm0
movsd  0x20(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x28(%rsp)
mov    %ebx,0x14(%rsp)
fildl  0x14(%rsp)
fmull  0x28(%rsp)
mov    %ebp,0x18(%rsp)
fidivl 0x18(%rsp)
fnstcw 0x10(%rsp)
movzwl 0x10(%rsp),%eax
or     $0xc00,%eax
mov    %ax,0x12(%rsp)
fldcw  0x12(%rsp)
fistpl 0x1c(%rsp)
fldcw  0x10(%rsp)
mov    0x1c(%rsp),%eax
test   %eax,%eax
js     11fc <smooth_color+0xdc>
cmp    %ebx,%eax
lea    -0x1(%rbx),%ecx
cmovl  %eax,%ecx
mov    %ecx,%ebx
jmp    11fe <smooth_color+0xde>
fstp   %st(0)
fstp   %st(0)
fstp   %st(0)
jmp    11fe <smooth_color+0xde>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x48,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @smooth_color(i32 %0, i32 %1, i32 %2, x86_fp80 %3, x86_fp80 %4, x86_fp80 %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca x86_fp80
%11 = alloca x86_fp80
%12 = alloca x86_fp80
%13 = alloca i32
%14 = alloca x86_fp80
store i32 %0, i32* %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store x86_fp80 %3, x86_fp80* %10
store x86_fp80 %4, x86_fp80* %11
store x86_fp80 %5, x86_fp80* %12
%15 = load i32, i32* %7
store i32 %15, i32* %13
%16 = load i32, i32* %8
%17 = load i32, i32* %9
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %57
19: ; preds = %6
%20 = load i32, i32* %8
%21 = sitofp i32 %20 to double
%22 = load x86_fp80, x86_fp80* %10
%23 = load x86_fp80, x86_fp80* %10
%24 = load x86_fp80, x86_fp80* %11
%25 = load x86_fp80, x86_fp80* %11
%26 = fmul x86_fp80 %24, %25
%27 = call x86_fp80 @llvm.fmuladd.f80(x86_fp80 %22, x86_fp80 %23, x86_fp80 %26)
%28 = call x86_fp80 @sqrt(x86_fp80 %27)
%29 = call double @log(x86_fp80 %28)
%30 = fpext double %29 to x86_fp80
%31 = load x86_fp80, x86_fp80* %12
%32 = fdiv x86_fp80 %30, %31
%33 = call double @log(x86_fp80 %32)
%34 = fdiv double %33, 0x3FE62E42FEFA39EF
%35 = fsub double %21, %34
%36 = fpext double %35 to x86_fp80
store x86_fp80 %36, x86_fp80* %14
%37 = load x86_fp80, x86_fp80* %14
%38 = load i32, i32* %7
%39 = sitofp i32 %38 to x86_fp80
%40 = fmul x86_fp80 %37, %39
%41 = load i32, i32* %9
%42 = sitofp i32 %41 to x86_fp80
%43 = fdiv x86_fp80 %40, %42
%44 = fptosi x86_fp80 %43 to i32
store i32 %44, i32* %13
%45 = load i32, i32* %13
%46 = icmp slt i32 %45, 0
br i1 %46, label %47, label %48
47: ; preds = %19
store i32 0, i32* %13
br label %56
48: ; preds = %19
%49 = load i32, i32* %13
%50 = load i32, i32* %7
%51 = icmp sge i32 %49, %50
br i1 %51, label %52, label %55
52: ; preds = %48
%53 = load i32, i32* %7
%54 = sub nsw i32 %53, 1
store i32 %54, i32* %13
br label %55
55: ; preds = %52, %48
br label %56
56: ; preds = %55, %47
br label %57
57: ; preds = %56, %6
%58 = load i32, i32* %13
ret i32 %58
}

LLVM IR (-O2):
define i32 @smooth_color(i32 %0, i32 %1, i32 %2, x86_fp80 %3, x86_fp80 %4, x86_fp80 %5) {
%7 = icmp slt i32 %1, %2
br i1 %7, label %8, label %30
8: ; preds = %6
%9 = sitofp i32 %1 to double
%10 = fmul x86_fp80 %4, %4
%11 = tail call x86_fp80 @llvm.fmuladd.f80(x86_fp80 %3, x86_fp80 %3, x86_fp80 %10)
%12 = tail call x86_fp80 @sqrt(x86_fp80 %11)
%13 = tail call double @log(x86_fp80 %12)
%14 = fpext double %13 to x86_fp80
%15 = fdiv x86_fp80 %14, %5
%16 = tail call double @log(x86_fp80 %15)
%17 = fdiv double %16, 0x3FE62E42FEFA39EF
%18 = fsub double %9, %17
%19 = fpext double %18 to x86_fp80
%20 = sitofp i32 %0 to x86_fp80
%21 = fmul x86_fp80 %20, %19
%22 = sitofp i32 %2 to x86_fp80
%23 = fdiv x86_fp80 %21, %22
%24 = fptosi x86_fp80 %23 to i32
%25 = icmp slt i32 %24, 0
br i1 %25, label %30, label %26
26: ; preds = %8
%27 = icmp slt i32 %24, %0
%28 = add nsw i32 %0, -1
%29 = select i1 %27, i32 %24, i32 %28
br label %30
30: ; preds = %26, %8, %6
%31 = phi i32 [ %0, %6 ], [ 0, %8 ], [ %29, %26 ]
ret i32 %31
}