#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 double uint32_t;
typedef double int32_t;

/* Variables and functions */
int32_t split_map(uint32_t dim_in, uint32_t dim_out, uint32_t pos,
                  float *rest) {
  double smp;
  int32_t smp_i;
  smp = (pos + 0.5) * ((double)dim_in / dim_out) - 0.5;
  smp_i = smp < 0 ? -1 : smp;
  *rest = smp - smp_i;
  return smp_i;
}


x86 assembly (clang, -O0):
<split_map>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
mov    %rdi,-0x20(%rbp)
movsd  0xee9(%rip),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  -0x8(%rbp),%xmm1
divsd  -0x10(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xec6(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x28(%rbp),%xmm0
jbe    1163 <split_map+0x63>
movsd  0xeb7(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    116d <split_map+0x6d>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
cvtsd2ss %xmm0,%xmm0
mov    -0x20(%rbp),%rax
movss  %xmm0,(%rax)
movsd  -0x30(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<split_map>:
addsd  0xef8(%rip),%xmm2
divsd  %xmm1,%xmm0
mulsd  %xmm2,%xmm0
addsd  0xef0(%rip),%xmm0
xorpd  %xmm1,%xmm1
movapd %xmm0,%xmm2
cmpltsd %xmm1,%xmm2
movsd  0xee3(%rip),%xmm1
andpd  %xmm2,%xmm1
andnpd %xmm0,%xmm2
orpd   %xmm2,%xmm1
subsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,(%rdi)
movapd %xmm1,%xmm0
ret

LLVM IR (-O0):
define double @split_map(double %0, double %1, double %2, float* %3) {
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca float*
%9 = alloca double
%10 = alloca double
store double %0, double* %5
store double %1, double* %6
store double %2, double* %7
store float* %3, float** %8
%11 = load double, double* %7
%12 = fadd double %11, 5.000000e-01
%13 = load double, double* %5
%14 = load double, double* %6
%15 = fdiv double %13, %14
%16 = call double @llvm.fmuladd.f64(double %12, double %15, double -5.000000e-01)
store double %16, double* %9
%17 = load double, double* %9
%18 = fcmp olt double %17, 0.000000e+00
br i1 %18, label %19, label %20
19: ; preds = %4
br label %22
20: ; preds = %4
%21 = load double, double* %9
br label %22
22: ; preds = %20, %19
%23 = phi double [ -1.000000e+00, %19 ], [ %21, %20 ]
store double %23, double* %10
%24 = load double, double* %9
%25 = load double, double* %10
%26 = fsub double %24, %25
%27 = fptrunc double %26 to float
%28 = load float*, float** %8
store float %27, float* %28
%29 = load double, double* %10
ret double %29
}

LLVM IR (-O2):
define double @split_map(double %0, double %1, double %2, float* nocapture writeonly %3) {
%5 = fadd double %2, 5.000000e-01
%6 = fdiv double %0, %1
%7 = tail call double @llvm.fmuladd.f64(double %5, double %6, double -5.000000e-01)
%8 = fcmp olt double %7, 0.000000e+00
%9 = select i1 %8, double -1.000000e+00, double %7
%10 = fsub double %7, %9
%11 = fptrunc double %10 to float
store float %11, float* %3
ret double %9
}