#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 */
short *foveon_make_curve(double, double, float);
void foveon_make_curves(short **curvep, float dq[3], float div[3], float filt) {
  double mul[3], max = 0;
  int c;
  for (c = 0; c < 3; c++)
    mul[c] = dq[c] / div[c];
  for (c = 0; c < 3; c++)
    if (max < mul[c])
      max = mul[c];
  for (c = 0; c < 3; c++)
    curvep[c] = foveon_make_curve(max, mul[c], filt);
}


x86 assembly (clang, -O0):
<foveon_make_curves>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movss  %xmm0,-0x1c(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
movl   $0x0,-0x4c(%rbp)
cmpl   $0x3,-0x4c(%rbp)
jge    1178 <foveon_make_curves+0x68>
mov    -0x10(%rbp),%rax
movslq -0x4c(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x4c(%rbp),%rcx
divss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
movslq -0x4c(%rbp),%rax
movsd  %xmm0,-0x40(%rbp,%rax,8)
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    1138 <foveon_make_curves+0x28>
movl   $0x0,-0x4c(%rbp)
cmpl   $0x3,-0x4c(%rbp)
jge    11c4 <foveon_make_curves+0xb4>
movsd  -0x48(%rbp),%xmm1
movslq -0x4c(%rbp),%rax
movsd  -0x40(%rbp,%rax,8),%xmm0
ucomisd %xmm1,%xmm0
jbe    11b1 <foveon_make_curves+0xa1>
movslq -0x4c(%rbp),%rax
movsd  -0x40(%rbp,%rax,8),%xmm0
movsd  %xmm0,-0x48(%rbp)
jmp    11b6 <foveon_make_curves+0xa6>
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    117f <foveon_make_curves+0x6f>
movl   $0x0,-0x4c(%rbp)
cmpl   $0x3,-0x4c(%rbp)
jge    120b <foveon_make_curves+0xfb>
movsd  -0x48(%rbp),%xmm0
movslq -0x4c(%rbp),%rax
movsd  -0x40(%rbp,%rax,8),%xmm1
movss  -0x1c(%rbp),%xmm2
call   1030 <foveon_make_curve@plt>
mov    %rax,%rdx
mov    -0x8(%rbp),%rax
movslq -0x4c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    11cb <foveon_make_curves+0xbb>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<foveon_make_curves>:
push   %rbx
sub    $0x20,%rsp
movaps %xmm0,%xmm3
movss  %xmm0,0x4(%rsp)
mov    %rdi,%rbx
movss  (%rsi),%xmm0
movss  0x4(%rsi),%xmm2
divss  (%rdx),%xmm0
cvtss2sd %xmm0,%xmm1
divss  0x4(%rdx),%xmm2
cvtss2sd %xmm2,%xmm5
movsd  %xmm5,0x10(%rsp)
movss  0x8(%rsi),%xmm0
divss  0x8(%rdx),%xmm0
cvtss2sd %xmm0,%xmm4
movsd  %xmm4,0x18(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm1,%xmm2
maxsd  %xmm0,%xmm2
movaps %xmm5,%xmm0
maxsd  %xmm2,%xmm0
maxsd  %xmm0,%xmm4
movsd  %xmm4,0x8(%rsp)
movapd %xmm4,%xmm0
movaps %xmm3,%xmm2
call   1030 <foveon_make_curve@plt>
mov    %rax,(%rbx)
movsd  0x8(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
movss  0x4(%rsp),%xmm2
call   1030 <foveon_make_curve@plt>
mov    %rax,0x8(%rbx)
movsd  0x8(%rsp),%xmm0
movsd  0x18(%rsp),%xmm1
movss  0x4(%rsp),%xmm2
call   1030 <foveon_make_curve@plt>
mov    %rax,0x10(%rbx)
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define void @foveon_make_curves(i16** %0, float* %1, float* %2, float %3) {
%5 = alloca i16**
%6 = alloca float*
%7 = alloca float*
%8 = alloca float
%9 = alloca [3 x double]
%10 = alloca double
%11 = alloca i32
store i16** %0, i16*** %5
store float* %1, float** %6
store float* %2, float** %7
store float %3, float* %8
store double 0.000000e+00, double* %10
store i32 0, i32* %11
br label %12
12: ; preds = %31, %4
%13 = load i32, i32* %11
%14 = icmp slt i32 %13, 3
br i1 %14, label %15, label %34
15: ; preds = %12
%16 = load float*, float** %6
%17 = load i32, i32* %11
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds float, float* %16, i64 %18
%20 = load float, float* %19
%21 = load float*, float** %7
%22 = load i32, i32* %11
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds float, float* %21, i64 %23
%25 = load float, float* %24
%26 = fdiv float %20, %25
%27 = fpext float %26 to double
%28 = load i32, i32* %11
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [3 x double], [3 x double]* %9, i64 0, i64 %29
store double %27, double* %30
br label %31
31: ; preds = %15
%32 = load i32, i32* %11
%33 = add nsw i32 %32, 1
store i32 %33, i32* %11
br label %12
34: ; preds = %12
store i32 0, i32* %11
br label %35
35: ; preds = %51, %34
%36 = load i32, i32* %11
%37 = icmp slt i32 %36, 3
br i1 %37, label %38, label %54
38: ; preds = %35
%39 = load double, double* %10
%40 = load i32, i32* %11
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [3 x double], [3 x double]* %9, i64 0, i64 %41
%43 = load double, double* %42
%44 = fcmp olt double %39, %43
br i1 %44, label %45, label %50
45: ; preds = %38
%46 = load i32, i32* %11
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [3 x double], [3 x double]* %9, i64 0, i64 %47
%49 = load double, double* %48
store double %49, double* %10
br label %50
50: ; preds = %45, %38
br label %51
51: ; preds = %50
%52 = load i32, i32* %11
%53 = add nsw i32 %52, 1
store i32 %53, i32* %11
br label %35
54: ; preds = %35
store i32 0, i32* %11
br label %55
55: ; preds = %70, %54
%56 = load i32, i32* %11
%57 = icmp slt i32 %56, 3
br i1 %57, label %58, label %73
58: ; preds = %55
%59 = load double, double* %10
%60 = load i32, i32* %11
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds [3 x double], [3 x double]* %9, i64 0, i64 %61
%63 = load double, double* %62
%64 = load float, float* %8
%65 = call i16* @foveon_make_curve(double %59, double %63, float %64)
%66 = load i16**, i16*** %5
%67 = load i32, i32* %11
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i16*, i16** %66, i64 %68
store i16* %65, i16** %69
br label %70
70: ; preds = %58
%71 = load i32, i32* %11
%72 = add nsw i32 %71, 1
store i32 %72, i32* %11
br label %55
73: ; preds = %55
ret void
}

LLVM IR (-O2):
define void @foveon_make_curves(i16** nocapture writeonly %0, float* nocapture %1, float* nocapture %2, float %3) {
%5 = load float, float* %1
%6 = load float, float* %2
%7 = fdiv float %5, %6
%8 = fpext float %7 to double
%9 = getelementptr inbounds float, float* %1, i64 1
%10 = load float, float* %9
%11 = getelementptr inbounds float, float* %2, i64 1
%12 = load float, float* %11
%13 = fdiv float %10, %12
%14 = fpext float %13 to double
%15 = getelementptr inbounds float, float* %1, i64 2
%16 = load float, float* %15
%17 = getelementptr inbounds float, float* %2, i64 2
%18 = load float, float* %17
%19 = fdiv float %16, %18
%20 = fpext float %19 to double
%21 = fcmp ogt double %8, 0.000000e+00
%22 = select i1 %21, double %8, double 0.000000e+00
%23 = fcmp olt double %22, %14
%24 = select i1 %23, double %14, double %22
%25 = fcmp olt double %24, %20
%26 = select i1 %25, double %20, double %24
%27 = tail call i16* @foveon_make_curve(double %26, double %8, float %3)
store i16* %27, i16** %0
%28 = tail call i16* @foveon_make_curve(double %26, double %14, float %3)
%29 = getelementptr inbounds i16*, i16** %0, i64 1
store i16* %28, i16** %29
%30 = tail call i16* @foveon_make_curve(double %26, double %20, float %3)
%31 = getelementptr inbounds i16*, i16** %0, i64 2
store i16* %30, i16** %31
ret void
}