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


x86 assembly (clang, -O0):
<v_u_param>:
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  0xeaf(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     1188 <v_u_param+0x78>
movsd  -0x20(%rbp),%xmm0
call   1030 <sqrt@plt>
movsd  %xmm0,-0x20(%rbp)
jmp    11c5 <v_u_param+0xb5>
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)
cmpl   $0x1,-0x4(%rbp)
jne    11de <v_u_param+0xce>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    120e <v_u_param+0xfe>
cmpl   $0x2,-0x4(%rbp)
jne    1209 <v_u_param+0xf9>
movsd  -0x20(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    120e <v_u_param+0xfe>
movsd  -0x28(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<v_u_param>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
movapd %xmm0,%xmm1
mov    %edi,%ebp
mulsd  %xmm0,%xmm1
movsd  0xed8(%rip),%xmm0
subsd  %xmm1,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jae    1159 <v_u_param+0x49>
movapd 0xed2(%rip),%xmm1
xorpd  %xmm0,%xmm1
movsd  0xebe(%rip),%xmm2
ucomisd %xmm0,%xmm2
jb     1166 <v_u_param+0x56>
xorps  %xmm0,%xmm0
sqrtsd %xmm1,%xmm0
jmp    116f <v_u_param+0x5f>
jb     117e <v_u_param+0x6e>
sqrtsd %xmm0,%xmm0
cmp    $0x1,%ebp
jne    1188 <v_u_param+0x78>
jmp    119b <v_u_param+0x8b>
movapd %xmm1,%xmm0
call   1030 <sqrt@plt>
xorpd  0xe99(%rip),%xmm0
cmp    $0x1,%ebp
jne    1188 <v_u_param+0x78>
jmp    119b <v_u_param+0x8b>
call   1030 <sqrt@plt>
cmp    $0x1,%ebp
je     119b <v_u_param+0x8b>
cmp    $0x2,%ebp
jne    1197 <v_u_param+0x87>
xorpd  0xe7b(%rip),%xmm0
jmp    119b <v_u_param+0x8b>
xorpd  %xmm0,%xmm0
movsd  %xmm0,(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define void @v_u_param(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 oge double %13, 0.000000e+00
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 %23
18: ; preds = %3
%19 = load double, double* %7
%20 = fneg double %19
%21 = call double @sqrt(double %20)
%22 = fneg double %21
store double %22, double* %7
br label %23
23: ; preds = %18, %15
%24 = load i32, i32* %4
%25 = icmp eq i32 %24, 1
br i1 %25, label %26, label %28
26: ; preds = %23
%27 = load double, double* %7
store double %27, double* %8
br label %35
28: ; preds = %23
%29 = load i32, i32* %4
%30 = icmp eq i32 %29, 2
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = load double, double* %7
%33 = fneg double %32
store double %33, double* %8
br label %34
34: ; preds = %31, %28
br label %35
35: ; preds = %34, %26
%36 = load double, double* %8
%37 = load double*, double** %6
store double %36, double* %37
ret void
}

LLVM IR (-O2):
define void @v_u_param(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 ult double %5, 0.000000e+00
br i1 %6, label %9, label %7
7: ; preds = %3
%8 = tail call double @sqrt(double %5)
br label %13
9: ; preds = %3
%10 = fneg double %5
%11 = tail call double @sqrt(double %10)
%12 = fneg double %11
br label %13
13: ; preds = %9, %7
%14 = phi double [ %8, %7 ], [ %12, %9 ]
switch i32 %0, label %17 [
i32 1, label %18
i32 2, label %15
]
15: ; preds = %13
%16 = fneg double %14
br label %18
17: ; preds = %13
br label %18
18: ; preds = %13, %17, %15
%19 = phi double [ %16, %15 ], [ %14, %13 ], [ 0.000000e+00, %17 ]
store double %19, double* %2
ret void
}