#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 */
double sqrt(double);
float tb_project_to_sphere(float r, float x, float y) {
  float d;
  float t;
  float z;
  double tmp;
  double tmp___0;
  {
    tmp = sqrt((double)(x * x + y * y));
    d = (float)tmp;
    if ((double)d < (double)r * 0.70710678118654752440) {
      tmp___0 = sqrt((double)(r * r - d * d));
      z = (float)tmp___0;
    } else {
      t = (float)((double)r / 1.41421356237309504880);
      z = (t * t) / d;
    }
    return (z);
  }
}


x86 assembly (clang, -O0):
<tb_project_to_sphere>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movss  %xmm0,-0x4(%rbp)
movss  %xmm1,-0x8(%rbp)
movss  %xmm2,-0xc(%rbp)
movss  -0x8(%rbp),%xmm0
movss  -0x8(%rbp),%xmm2
movss  -0xc(%rbp),%xmm1
mulss  -0xc(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
call   1030 <sqrt@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movss  -0x4(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe87(%rip),%xmm2
mulsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
jbe    11d1 <tb_project_to_sphere+0xc1>
movss  -0x4(%rbp),%xmm0
movss  -0x4(%rbp),%xmm2
movss  -0x10(%rbp),%xmm1
mulss  -0x10(%rbp),%xmm1
movd   %xmm1,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
call   1030 <sqrt@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x18(%rbp)
jmp    1203 <tb_project_to_sphere+0xf3>
movss  -0x4(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe26(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x14(%rbp),%xmm0
mulss  -0x14(%rbp),%xmm0
divss  -0x10(%rbp),%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x18(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tb_project_to_sphere>:
push   %rax
movaps %xmm0,%xmm4
mulss  %xmm2,%xmm2
mulss  %xmm1,%xmm1
addss  %xmm2,%xmm1
xorps  %xmm0,%xmm0
ucomiss %xmm0,%xmm1
jb     1131 <tb_project_to_sphere+0x21>
xorps  %xmm0,%xmm0
sqrtss %xmm1,%xmm0
jmp    1145 <tb_project_to_sphere+0x35>
movaps %xmm1,%xmm0
movss  %xmm4,0x4(%rsp)
call   1030 <sqrtf@plt>
movss  0x4(%rsp),%xmm4
xorps  %xmm2,%xmm2
cvtss2sd %xmm0,%xmm2
xorps  %xmm1,%xmm1
cvtss2sd %xmm4,%xmm1
movsd  0xea5(%rip),%xmm3
mulsd  %xmm1,%xmm3
ucomisd %xmm2,%xmm3
jbe    1182 <tb_project_to_sphere+0x72>
mulss  %xmm0,%xmm0
mulss  %xmm4,%xmm4
subss  %xmm0,%xmm4
xorps  %xmm0,%xmm0
ucomiss %xmm0,%xmm4
jb     119b <tb_project_to_sphere+0x8b>
xorps  %xmm1,%xmm1
sqrtss %xmm4,%xmm1
jmp    1196 <tb_project_to_sphere+0x86>
divsd  0xe7e(%rip),%xmm1
cvtsd2ss %xmm1,%xmm1
mulss  %xmm1,%xmm1
divss  %xmm0,%xmm1
movaps %xmm1,%xmm0
pop    %rax
ret
movaps %xmm4,%xmm0
pop    %rax
jmp    1030 <sqrtf@plt>

LLVM IR (-O0):
define float @tb_project_to_sphere(float %0, float %1, float %2) {
%4 = alloca float
%5 = alloca float
%6 = alloca float
%7 = alloca float
%8 = alloca float
%9 = alloca float
%10 = alloca double
%11 = alloca double
store float %0, float* %4
store float %1, float* %5
store float %2, float* %6
%12 = load float, float* %5
%13 = load float, float* %5
%14 = load float, float* %6
%15 = load float, float* %6
%16 = fmul float %14, %15
%17 = call float @llvm.fmuladd.f32(float %12, float %13, float %16)
%18 = fpext float %17 to double
%19 = call double @sqrt(double %18)
store double %19, double* %10
%20 = load double, double* %10
%21 = fptrunc double %20 to float
store float %21, float* %7
%22 = load float, float* %7
%23 = fpext float %22 to double
%24 = load float, float* %4
%25 = fpext float %24 to double
%26 = fmul double %25, 0x3FE6A09E667F3BCD
%27 = fcmp olt double %23, %26
br i1 %27, label %28, label %40
28: ; preds = %3
%29 = load float, float* %4
%30 = load float, float* %4
%31 = load float, float* %7
%32 = load float, float* %7
%33 = fmul float %31, %32
%34 = fneg float %33
%35 = call float @llvm.fmuladd.f32(float %29, float %30, float %34)
%36 = fpext float %35 to double
%37 = call double @sqrt(double %36)
store double %37, double* %11
%38 = load double, double* %11
%39 = fptrunc double %38 to float
store float %39, float* %9
br label %50
40: ; preds = %3
%41 = load float, float* %4
%42 = fpext float %41 to double
%43 = fdiv double %42, 0x3FF6A09E667F3BCD
%44 = fptrunc double %43 to float
store float %44, float* %8
%45 = load float, float* %8
%46 = load float, float* %8
%47 = fmul float %45, %46
%48 = load float, float* %7
%49 = fdiv float %47, %48
store float %49, float* %9
br label %50
50: ; preds = %40, %28
%51 = load float, float* %9
ret float %51
}

LLVM IR (-O2):
define float @tb_project_to_sphere(float %0, float %1, float %2) {
%4 = fmul float %2, %2
%5 = tail call float @llvm.fmuladd.f32(float %1, float %1, float %4)
%6 = tail call float @sqrtf(float %5)
%7 = fpext float %6 to double
%8 = fpext float %0 to double
%9 = fmul double %8, 0x3FE6A09E667F3BCD
%10 = fcmp ogt double %9, %7
br i1 %10, label %11, label %16
11: ; preds = %3
%12 = fneg float %6
%13 = fmul float %6, %12
%14 = tail call float @llvm.fmuladd.f32(float %0, float %0, float %13)
%15 = tail call float @sqrtf(float %14)
br label %21
16: ; preds = %3
%17 = fdiv double %8, 0x3FF6A09E667F3BCD
%18 = fptrunc double %17 to float
%19 = fmul float %18, %18
%20 = fdiv float %19, %6
br label %21
21: ; preds = %16, %11
%22 = phi float [ %15, %11 ], [ %20, %16 ]
ret float %22
}