#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__ pow(float, int);
int sqrt(scalar_t__);
float circular_io(float step, float max_steps, float max_val) {
  float ratio = step / (max_steps / 2.0);
  if (ratio < 1)
    return -max_val / 2 * (sqrt(1 - pow(ratio, 2)) - 1);
  return max_val / 2 * (sqrt(1 - pow(ratio - 2, 2)) + 1);
}


x86 assembly (clang, -O0):
<circular_io>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movss  %xmm0,-0x8(%rbp)
movss  %xmm1,-0xc(%rbp)
movss  %xmm2,-0x10(%rbp)
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movss  -0xc(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
movsd  0xeb7(%rip),%xmm2
divsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x14(%rbp)
movss  0xe96(%rip),%xmm0
ucomiss -0x14(%rbp),%xmm0
jbe    11cd <circular_io+0xad>
movss  -0x10(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
movss  0xe76(%rip),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x14(%rbp),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
mov    $0x1,%edi
sub    %rax,%rdi
call   1040 <sqrt@plt>
movss  -0x18(%rbp),%xmm0
sub    $0x1,%eax
cvtsi2ss %eax,%xmm1
mulss  %xmm1,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1220 <circular_io+0x100>
movss  -0x10(%rbp),%xmm0
movss  0xe2a(%rip),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x14(%rbp),%xmm0
movss  0xe14(%rip),%xmm1
subss  %xmm1,%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
mov    $0x1,%edi
sub    %rax,%rdi
call   1040 <sqrt@plt>
movss  -0x1c(%rbp),%xmm0
add    $0x1,%eax
cvtsi2ss %eax,%xmm1
mulss  %xmm1,%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<circular_io>:
push   %rbx
sub    $0x10,%rsp
cvtss2sd %xmm0,%xmm0
cvtss2sd %xmm1,%xmm1
mulsd  0xecb(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  0xecb(%rip),%xmm1
xor    %eax,%eax
xor    %ebx,%ebx
ucomiss %xmm0,%xmm1
seta   %cl
setbe  %dl
ja     115c <circular_io+0x3c>
addss  0xeb8(%rip),%xmm0
mov    %dl,%bl
mov    %cl,%al
lea    0xea1(%rip),%rcx
mulss  (%rcx,%rax,4),%xmm2
movss  %xmm2,0xc(%rsp)
mov    $0x2,%edi
call   1030 <pow@plt>
mov    $0x1,%edi
sub    %rax,%rdi
call   1040 <sqrt@plt>
lea    (%rax,%rbx,2),%eax
add    $0xffffffff,%eax
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
mulss  0xc(%rsp),%xmm0
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define float @circular_io(float %0, float %1, float %2) {
%4 = alloca float
%5 = alloca float
%6 = alloca float
%7 = alloca float
%8 = alloca float
store float %0, float* %5
store float %1, float* %6
store float %2, float* %7
%9 = load float, float* %5
%10 = fpext float %9 to double
%11 = load float, float* %6
%12 = fpext float %11 to double
%13 = fdiv double %12, 2.000000e+00
%14 = fdiv double %10, %13
%15 = fptrunc double %14 to float
store float %15, float* %8
%16 = load float, float* %8
%17 = fcmp olt float %16, 1.000000e+00
br i1 %17, label %18, label %29
18: ; preds = %3
%19 = load float, float* %7
%20 = fneg float %19
%21 = fdiv float %20, 2.000000e+00
%22 = load float, float* %8
%23 = call i64 @pow(float %22, i32 2)
%24 = sub nsw i64 1, %23
%25 = call i32 @sqrt(i64 %24)
%26 = sub nsw i32 %25, 1
%27 = sitofp i32 %26 to float
%28 = fmul float %21, %27
store float %28, float* %4
br label %40
29: ; preds = %3
%30 = load float, float* %7
%31 = fdiv float %30, 2.000000e+00
%32 = load float, float* %8
%33 = fsub float %32, 2.000000e+00
%34 = call i64 @pow(float %33, i32 2)
%35 = sub nsw i64 1, %34
%36 = call i32 @sqrt(i64 %35)
%37 = add nsw i32 %36, 1
%38 = sitofp i32 %37 to float
%39 = fmul float %31, %38
store float %39, float* %4
br label %40
40: ; preds = %29, %18
%41 = load float, float* %4
ret float %41
}

LLVM IR (-O2):
define float @circular_io(float %0, float %1, float %2) {
%4 = fpext float %0 to double
%5 = fpext float %1 to double
%6 = fmul double %5, 5.000000e-01
%7 = fdiv double %4, %6
%8 = fptrunc double %7 to float
%9 = fcmp olt float %8, 1.000000e+00
%10 = fadd float %8, -2.000000e+00
%11 = select i1 %9, float %8, float %10
%12 = select i1 %9, i32 -1, i32 1
%13 = select i1 %9, float -5.000000e-01, float 5.000000e-01
%14 = fmul float %13, %2
%15 = tail call i64 @pow(float %11, i32 2)
%16 = sub nsw i64 1, %15
%17 = tail call i32 @sqrt(i64 %16)
%18 = add nsw i32 %17, %12
%19 = sitofp i32 %18 to float
%20 = fmul float %14, %19
ret float %20
}