#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 */
scalar_t__ floor(float);
void stbir__calculate_sample_range_downsample(
    int n, float in_pixels_radius, float scale_ratio, float out_shift,
    int *out_first_pixel, int *out_last_pixel, float *out_center_of_in) {
  float in_pixel_center = (float)n + 0.5f;
  float in_pixel_influence_lowerbound = in_pixel_center - in_pixels_radius;
  float in_pixel_influence_upperbound = in_pixel_center + in_pixels_radius;
  float out_pixel_influence_lowerbound =
      in_pixel_influence_lowerbound * scale_ratio - out_shift;
  float out_pixel_influence_upperbound =
      in_pixel_influence_upperbound * scale_ratio - out_shift;
  *out_center_of_in = in_pixel_center * scale_ratio - out_shift;
  *out_first_pixel = (int)(floor(out_pixel_influence_lowerbound + 0.5));
  *out_last_pixel = (int)(floor(out_pixel_influence_upperbound - 0.5));
}


x86 assembly (clang, -O0):
<stbir__calculate_sample_range_downsample>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
movss  %xmm0,-0x8(%rbp)
movss  %xmm1,-0xc(%rbp)
movss  %xmm2,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
cvtsi2ssl -0x4(%rbp),%xmm0
movss  0xec5(%rip),%xmm1
addss  %xmm1,%xmm0
movss  %xmm0,-0x2c(%rbp)
movss  -0x2c(%rbp),%xmm0
subss  -0x8(%rbp),%xmm0
movss  %xmm0,-0x30(%rbp)
movss  -0x2c(%rbp),%xmm0
addss  -0x8(%rbp),%xmm0
movss  %xmm0,-0x34(%rbp)
movss  -0x30(%rbp),%xmm0
movss  -0xc(%rbp),%xmm2
movss  -0x10(%rbp),%xmm1
movd   %xmm1,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x38(%rbp)
movss  -0x34(%rbp),%xmm0
movss  -0xc(%rbp),%xmm2
movss  -0x10(%rbp),%xmm1
movd   %xmm1,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x3c(%rbp)
movss  -0x2c(%rbp),%xmm0
movss  -0xc(%rbp),%xmm2
movss  -0x10(%rbp),%xmm1
movd   %xmm1,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
mov    -0x28(%rbp),%rax
movss  %xmm0,(%rax)
movss  -0x38(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe07(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
call   1030 <floor@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movss  -0x3c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xde1(%rip),%xmm1
subsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
call   1030 <floor@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stbir__calculate_sample_range_downsample>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
movaps %xmm0,%xmm5
cvtsi2ss %edi,%xmm3
movss  0xed7(%rip),%xmm4
addss  %xmm4,%xmm3
movaps %xmm3,%xmm0
subss  %xmm5,%xmm0
addss  %xmm3,%xmm5
mulss  %xmm1,%xmm0
subss  %xmm2,%xmm0
mulss  %xmm1,%xmm5
subss  %xmm2,%xmm5
movss  %xmm5,0x4(%rsp)
mulss  %xmm1,%xmm3
subss  %xmm2,%xmm3
movss  %xmm3,(%rcx)
addss  %xmm4,%xmm0
call   1030 <floor@plt>
mov    %eax,(%rbx)
movss  0x4(%rsp),%xmm0
addss  0xe91(%rip),%xmm0
call   1030 <floor@plt>
mov    %eax,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @stbir__calculate_sample_range_downsample(i32 %0, float %1, float %2, float %3, i32* %4, i32* %5, float* %6) {
%8 = alloca i32
%9 = alloca float
%10 = alloca float
%11 = alloca float
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca float*
%15 = alloca float
%16 = alloca float
%17 = alloca float
%18 = alloca float
%19 = alloca float
store i32 %0, i32* %8
store float %1, float* %9
store float %2, float* %10
store float %3, float* %11
store i32* %4, i32** %12
store i32* %5, i32** %13
store float* %6, float** %14
%20 = load i32, i32* %8
%21 = sitofp i32 %20 to float
%22 = fadd float %21, 5.000000e-01
store float %22, float* %15
%23 = load float, float* %15
%24 = load float, float* %9
%25 = fsub float %23, %24
store float %25, float* %16
%26 = load float, float* %15
%27 = load float, float* %9
%28 = fadd float %26, %27
store float %28, float* %17
%29 = load float, float* %16
%30 = load float, float* %10
%31 = load float, float* %11
%32 = fneg float %31
%33 = call float @llvm.fmuladd.f32(float %29, float %30, float %32)
store float %33, float* %18
%34 = load float, float* %17
%35 = load float, float* %10
%36 = load float, float* %11
%37 = fneg float %36
%38 = call float @llvm.fmuladd.f32(float %34, float %35, float %37)
store float %38, float* %19
%39 = load float, float* %15
%40 = load float, float* %10
%41 = load float, float* %11
%42 = fneg float %41
%43 = call float @llvm.fmuladd.f32(float %39, float %40, float %42)
%44 = load float*, float** %14
store float %43, float* %44
%45 = load float, float* %18
%46 = fpext float %45 to double
%47 = fadd double %46, 5.000000e-01
%48 = fptrunc double %47 to float
%49 = call i64 @floor(float %48)
%50 = trunc i64 %49 to i32
%51 = load i32*, i32** %12
store i32 %50, i32* %51
%52 = load float, float* %19
%53 = fpext float %52 to double
%54 = fsub double %53, 5.000000e-01
%55 = fptrunc double %54 to float
%56 = call i64 @floor(float %55)
%57 = trunc i64 %56 to i32
%58 = load i32*, i32** %13
store i32 %57, i32* %58
ret void
}

LLVM IR (-O2):
define void @stbir__calculate_sample_range_downsample(i32 %0, float %1, float %2, float %3, i32* nocapture writeonly %4, i32* nocapture writeonly %5, float* nocapture writeonly %6) {
%8 = sitofp i32 %0 to float
%9 = fadd float %8, 5.000000e-01
%10 = fsub float %9, %1
%11 = fadd float %9, %1
%12 = fneg float %3
%13 = tail call float @llvm.fmuladd.f32(float %10, float %2, float %12)
%14 = tail call float @llvm.fmuladd.f32(float %11, float %2, float %12)
%15 = tail call float @llvm.fmuladd.f32(float %9, float %2, float %12)
store float %15, float* %6
%16 = fadd float %13, 5.000000e-01
%17 = tail call i64 @floor(float %16)
%18 = trunc i64 %17 to i32
store i32 %18, i32* %4
%19 = fadd float %14, -5.000000e-01
%20 = tail call i64 @floor(float %19)
%21 = trunc i64 %20 to i32
store i32 %21, i32* %5
ret void
}