#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 scalar_t__ int64_t;

/* Variables and functions */
int64_t mlt_audio_calculate_samples_to_position(float fps, int frequency,
                                                int64_t position) {
  int64_t samples = 0;
  if (fps) {
    samples = (int64_t)((double)position * (double)frequency / (double)fps +
                        (position < 0 ? -0.5 : 0.5));
  }
  return samples;
}


x86 assembly (clang, -O0):
<mlt_audio_calculate_samples_to_position>:
push   %rbp
mov    %rsp,%rbp
movss  %xmm0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movss  -0x4(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    1134 <mlt_audio_calculate_samples_to_position+0x34>
jp     1134 <mlt_audio_calculate_samples_to_position+0x34>
jmp    119e <mlt_audio_calculate_samples_to_position+0x9e>
cvtsi2sdq -0x10(%rbp),%xmm0
cvtsi2sdl -0x8(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movss  -0x4(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x10(%rbp),%rax
movsd  0xe9f(%rip),%xmm0
movsd  0xe9f(%rip),%xmm1
movsd  %xmm1,-0x28(%rbp)
cmp    $0x0,%rax
movsd  %xmm0,-0x20(%rbp)
jl     1187 <mlt_audio_calculate_samples_to_position+0x87>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<mlt_audio_calculate_samples_to_position>:
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    110a <mlt_audio_calculate_samples_to_position+0xa>
jnp    1138 <mlt_audio_calculate_samples_to_position+0x38>
xorps  %xmm1,%xmm1
cvtsi2sd %rsi,%xmm1
cvtsi2sd %edi,%xmm2
mulsd  %xmm1,%xmm2
cvtss2sd %xmm0,%xmm0
divsd  %xmm0,%xmm2
shr    $0x3f,%rsi
lea    0xed3(%rip),%rax
addsd  (%rax,%rsi,8),%xmm2
cvttsd2si %xmm2,%rax
ret
xor    %eax,%eax
ret

LLVM IR (-O0):
define i64 @mlt_audio_calculate_samples_to_position(float %0, i32 %1, i64 %2) {
%4 = alloca float
%5 = alloca i32
%6 = alloca i64
%7 = alloca i64
store float %0, float* %4
store i32 %1, i32* %5
store i64 %2, i64* %6
store i64 0, i64* %7
%8 = load float, float* %4
%9 = fcmp une float %8, 0.000000e+00
br i1 %9, label %10, label %25
10: ; preds = %3
%11 = load i64, i64* %6
%12 = sitofp i64 %11 to double
%13 = load i32, i32* %5
%14 = sitofp i32 %13 to double
%15 = fmul double %12, %14
%16 = load float, float* %4
%17 = fpext float %16 to double
%18 = fdiv double %15, %17
%19 = load i64, i64* %6
%20 = icmp slt i64 %19, 0
%21 = zext i1 %20 to i64
%22 = select i1 %20, double -5.000000e-01, double 5.000000e-01
%23 = fadd double %18, %22
%24 = fptosi double %23 to i64
store i64 %24, i64* %7
br label %25
25: ; preds = %10, %3
%26 = load i64, i64* %7
ret i64 %26
}

LLVM IR (-O2):
define i64 @mlt_audio_calculate_samples_to_position(float %0, i32 %1, i64 %2) {
%4 = fcmp une float %0, 0.000000e+00
br i1 %4, label %5, label %15
5: ; preds = %3
%6 = sitofp i64 %2 to double
%7 = sitofp i32 %1 to double
%8 = fmul double %7, %6
%9 = fpext float %0 to double
%10 = fdiv double %8, %9
%11 = icmp slt i64 %2, 0
%12 = select i1 %11, double -5.000000e-01, double 5.000000e-01
%13 = fadd double %12, %10
%14 = fptosi double %13 to i64
br label %15
15: ; preds = %5, %3
%16 = phi i64 [ %14, %5 ], [ 0, %3 ]
ret i64 %16
}