#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 */
unsigned int hue_to_rgb(int);
int mandelbrot(double, double, int const);
unsigned int get_color(int x, int y, int width, int height) {
  double cx = 4 * (x - ((double)width) / 1.5) / width;
  double cy = 4 * (y - ((double)height) / 2.0) / height;
  const int max_iterations = 100;
  int iter = mandelbrot(cx, cy, max_iterations);
  if (iter >= max_iterations)
    return 0x000000;
  else
    return hue_to_rgb(240 + (iter * 360 / max_iterations));
}


x86 assembly (clang, -O0):
<get_color>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
cvtsi2sdl -0x8(%rbp),%xmm1
cvtsi2sdl -0x10(%rbp),%xmm0
movsd  0xeca(%rip),%xmm2
divsd  %xmm2,%xmm0
subsd  %xmm0,%xmm1
movsd  0xeaa(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvtsi2sdl -0x10(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
cvtsi2sdl -0xc(%rbp),%xmm1
cvtsi2sdl -0x14(%rbp),%xmm0
movsd  0xe8e(%rip),%xmm2
divsd  %xmm2,%xmm0
subsd  %xmm0,%xmm1
movsd  0xe76(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvtsi2sdl -0x14(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x64,-0x2c(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
mov    $0x64,%edi
call   1040 <mandelbrot@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x64,-0x30(%rbp)
jl     11d0 <get_color+0xb0>
movl   $0x0,-0x4(%rbp)
jmp    11ef <get_color+0xcf>
imul   $0x168,-0x30(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
add    $0xf0,%edi
call   1030 <hue_to_rgb@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_color>:
push   %rax
cvtsi2sd %edi,%xmm1
cvtsi2sd %edx,%xmm2
movapd %xmm2,%xmm0
divsd  0xecb(%rip),%xmm0
addsd  %xmm1,%xmm0
movsd  0xec7(%rip),%xmm3
mulsd  %xmm3,%xmm0
cvtsi2sd %esi,%xmm4
divsd  %xmm2,%xmm0
xorps  %xmm2,%xmm2
cvtsi2sd %ecx,%xmm2
movsd  0xeb4(%rip),%xmm1
mulsd  %xmm2,%xmm1
addsd  %xmm4,%xmm1
mulsd  %xmm3,%xmm1
divsd  %xmm2,%xmm1
mov    $0x64,%edi
call   1040 <mandelbrot@plt>
cmp    $0x63,%eax
jle    117f <get_color+0x5f>
xor    %eax,%eax
pop    %rcx
ret
imul   $0x168,%eax,%eax
cltq
imul   $0x51eb851f,%rax,%rax
mov    %rax,%rcx
sar    $0x25,%rcx
shr    $0x3f,%rax
lea    (%rcx,%rax,1),%edi
add    $0xf0,%edi
pop    %rax
jmp    1030 <hue_to_rgb@plt>

LLVM IR (-O0):
define i32 @get_color(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 double
%11 = alloca double
%12 = alloca i32
%13 = alloca i32
store i32 %0, i32* %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%14 = load i32, i32* %6
%15 = sitofp i32 %14 to double
%16 = load i32, i32* %8
%17 = sitofp i32 %16 to double
%18 = fdiv double %17, 1.500000e+00
%19 = fsub double %15, %18
%20 = fmul double 4.000000e+00, %19
%21 = load i32, i32* %8
%22 = sitofp i32 %21 to double
%23 = fdiv double %20, %22
store double %23, double* %10
%24 = load i32, i32* %7
%25 = sitofp i32 %24 to double
%26 = load i32, i32* %9
%27 = sitofp i32 %26 to double
%28 = fdiv double %27, 2.000000e+00
%29 = fsub double %25, %28
%30 = fmul double 4.000000e+00, %29
%31 = load i32, i32* %9
%32 = sitofp i32 %31 to double
%33 = fdiv double %30, %32
store double %33, double* %11
store i32 100, i32* %12
%34 = load double, double* %10
%35 = load double, double* %11
%36 = call i32 @mandelbrot(double %34, double %35, i32 100)
store i32 %36, i32* %13
%37 = load i32, i32* %13
%38 = icmp sge i32 %37, 100
br i1 %38, label %39, label %40
39: ; preds = %4
store i32 0, i32* %5
br label %46
40: ; preds = %4
%41 = load i32, i32* %13
%42 = mul nsw i32 %41, 360
%43 = sdiv i32 %42, 100
%44 = add nsw i32 240, %43
%45 = call i32 @hue_to_rgb(i32 %44)
store i32 %45, i32* %5
br label %46
46: ; preds = %40, %39
%47 = load i32, i32* %5
ret i32 %47
}

LLVM IR (-O2):
define i32 @get_color(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = sitofp i32 %0 to double
%6 = sitofp i32 %2 to double
%7 = fdiv double %6, 1.500000e+00
%8 = fsub double %5, %7
%9 = fmul double %8, 4.000000e+00
%10 = fdiv double %9, %6
%11 = sitofp i32 %1 to double
%12 = sitofp i32 %3 to double
%13 = fmul double %12, 5.000000e-01
%14 = fsub double %11, %13
%15 = fmul double %14, 4.000000e+00
%16 = fdiv double %15, %12
%17 = tail call i32 @mandelbrot(double %10, double %16, i32 100)
%18 = icmp sgt i32 %17, 99
br i1 %18, label %24, label %19
19: ; preds = %4
%20 = mul nsw i32 %17, 360
%21 = sdiv i32 %20, 100
%22 = add nsw i32 %21, 240
%23 = tail call i32 @hue_to_rgb(i32 %22)
br label %24
24: ; preds = %4, %19
%25 = phi i32 [ %23, %19 ], [ 0, %4 ]
ret i32 %25
}