#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);
void v_u_param_sphere(int i, double u, double *pv) {
  double t = 1.0 - u * u;
  double v = 0.0;
  if (t > 1e-14)
    t = sqrt(t);
  else if (t < -1e-14)
    t = -sqrt(-t);
  else
    t = 0.0;
  if (i == 1)
    v = t;
  else if (i == 2)
    v = -t;
  *pv = v;
}


x86 assembly (clang, -O0):
<v_u_param_sphere>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
movsd  %xmm0,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm1,%xmm0
movsd  0xeb7(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  0xe91(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    118d <v_u_param_sphere+0x7d>
movsd  -0x20(%rbp),%xmm0
call   1030 <sqrt@plt>
movsd  %xmm0,-0x20(%rbp)
jmp    11ef <v_u_param_sphere+0xdf>
movsd  0xe7b(%rip),%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    11e2 <v_u_param_sphere+0xd2>
movsd  -0x20(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
call   1030 <sqrt@plt>
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    11ea <v_u_param_sphere+0xda>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    11ef <v_u_param_sphere+0xdf>
cmpl   $0x1,-0x4(%rbp)
jne    1208 <v_u_param_sphere+0xf8>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    1238 <v_u_param_sphere+0x128>
cmpl   $0x2,-0x4(%rbp)
jne    1233 <v_u_param_sphere+0x123>
movsd  -0x20(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    1238 <v_u_param_sphere+0x128>
movsd  -0x28(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<v_u_param_sphere>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
mulsd  %xmm0,%xmm0
movsd  0xedc(%rip),%xmm1
subsd  %xmm0,%xmm1
xorpd  %xmm0,%xmm0
ucomisd 0xed4(%rip),%xmm1
jbe    114a <v_u_param_sphere+0x3a>
ucomisd %xmm0,%xmm1
jb     1178 <v_u_param_sphere+0x68>
xorps  %xmm0,%xmm0
sqrtsd %xmm1,%xmm0
cmp    $0x1,%ebp
jne    1186 <v_u_param_sphere+0x76>
jmp    1199 <v_u_param_sphere+0x89>
movsd  0xebe(%rip),%xmm2
ucomisd %xmm1,%xmm2
jbe    1181 <v_u_param_sphere+0x71>
movapd 0xec0(%rip),%xmm0
xorpd  %xmm1,%xmm0
movsd  0xeac(%rip),%xmm2
ucomisd %xmm1,%xmm2
jb     11a4 <v_u_param_sphere+0x94>
sqrtsd %xmm0,%xmm0
jmp    11a9 <v_u_param_sphere+0x99>
movapd %xmm1,%xmm0
call   1030 <sqrt@plt>
cmp    $0x1,%ebp
je     1199 <v_u_param_sphere+0x89>
cmp    $0x2,%ebp
jne    1195 <v_u_param_sphere+0x85>
xorpd  0xe8d(%rip),%xmm0
jmp    1199 <v_u_param_sphere+0x89>
xorpd  %xmm0,%xmm0
movsd  %xmm0,(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
call   1030 <sqrt@plt>
xorpd  0xe6f(%rip),%xmm0
cmp    $0x1,%ebp
jne    1186 <v_u_param_sphere+0x76>
jmp    1199 <v_u_param_sphere+0x89>

LLVM IR (-O0):
define void @v_u_param_sphere(i32 %0, double %1, double* %2) {
%4 = alloca i32
%5 = alloca double
%6 = alloca double*
%7 = alloca double
%8 = alloca double
store i32 %0, i32* %4
store double %1, double* %5
store double* %2, double** %6
%9 = load double, double* %5
%10 = load double, double* %5
%11 = fneg double %9
%12 = call double @llvm.fmuladd.f64(double %11, double %10, double 1.000000e+00)
store double %12, double* %7
store double 0.000000e+00, double* %8
%13 = load double, double* %7
%14 = fcmp ogt double %13, 0x3D06849B86A12B9B
br i1 %14, label %15, label %18
15: ; preds = %3
%16 = load double, double* %7
%17 = call double @sqrt(double %16)
store double %17, double* %7
br label %28
18: ; preds = %3
%19 = load double, double* %7
%20 = fcmp olt double %19, 0xBD06849B86A12B9B
br i1 %20, label %21, label %26
21: ; preds = %18
%22 = load double, double* %7
%23 = fneg double %22
%24 = call double @sqrt(double %23)
%25 = fneg double %24
store double %25, double* %7
br label %27
26: ; preds = %18
store double 0.000000e+00, double* %7
br label %27
27: ; preds = %26, %21
br label %28
28: ; preds = %27, %15
%29 = load i32, i32* %4
%30 = icmp eq i32 %29, 1
br i1 %30, label %31, label %33
31: ; preds = %28
%32 = load double, double* %7
store double %32, double* %8
br label %40
33: ; preds = %28
%34 = load i32, i32* %4
%35 = icmp eq i32 %34, 2
br i1 %35, label %36, label %39
36: ; preds = %33
%37 = load double, double* %7
%38 = fneg double %37
store double %38, double* %8
br label %39
39: ; preds = %36, %33
br label %40
40: ; preds = %39, %31
%41 = load double, double* %8
%42 = load double*, double** %6
store double %41, double* %42
ret void
}

LLVM IR (-O2):
define void @v_u_param_sphere(i32 %0, double %1, double* nocapture writeonly %2) {
%4 = fneg double %1
%5 = tail call double @llvm.fmuladd.f64(double %4, double %1, double 1.000000e+00)
%6 = fcmp ogt double %5, 0x3D06849B86A12B9B
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call double @sqrt(double %5)
br label %15
9: ; preds = %3
%10 = fcmp olt double %5, 0xBD06849B86A12B9B
br i1 %10, label %11, label %15
11: ; preds = %9
%12 = fneg double %5
%13 = tail call double @sqrt(double %12)
%14 = fneg double %13
br label %15
15: ; preds = %9, %11, %7
%16 = phi double [ %8, %7 ], [ %14, %11 ], [ 0.000000e+00, %9 ]
switch i32 %0, label %19 [
i32 1, label %20
i32 2, label %17
]
17: ; preds = %15
%18 = fneg double %16
br label %20
19: ; preds = %15
br label %20
20: ; preds = %15, %19, %17
%21 = phi double [ %18, %17 ], [ %16, %15 ], [ 0.000000e+00, %19 ]
store double %21, double* %2
ret void
}