#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__ fabs(double);
int sqrt(int);
void Givens(double a, double b, double *s, double *c) {
  double t;
  if (b == 0.0) {
    *c = 1;
    *s = 0;
  } else if (fabs(b) > fabs(a)) {
    t = -a / b;
    *s = 1 / sqrt(1 + t * t);
    *c = (*s) * t;
  } else {
    t = -b / a;
    *c = 1 / sqrt(1 + t * t);
    *s = (*c) * t;
  }
}


x86 assembly (clang, -O0):
<Givens>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
mov    %rsi,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1172 <Givens+0x52>
jp     1172 <Givens+0x52>
mov    -0x20(%rbp),%rax
movsd  0xea2(%rip),%xmm0
movsd  %xmm0,(%rax)
mov    -0x18(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
jmp    128c <Givens+0x16c>
movsd  -0x10(%rbp),%xmm0
call   1030 <fabs@plt>
mov    %rax,-0x30(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1030 <fabs@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
cmp    %rcx,%rax
jle    1213 <Givens+0xf3>
movsd  -0x8(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
divsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe2a(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1040 <sqrt@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
mulsd  -0x28(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    1287 <Givens+0x167>
movsd  -0x10(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
divsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xdb1(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1040 <sqrt@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x20(%rbp),%rax
movsd  (%rax),%xmm0
mulsd  -0x28(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    128c <Givens+0x16c>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Givens>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
movapd %xmm0,%xmm2
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jne    1158 <Givens+0x38>
jp     1158 <Givens+0x38>
movabs $0x3ff0000000000000,%rax
mov    %rax,(%r14)
movq   $0x0,(%r15)
jmp    1225 <Givens+0x105>
movapd %xmm1,0x10(%rsp)
movapd %xmm1,%xmm0
movapd %xmm2,(%rsp)
call   1030 <fabs@plt>
mov    %rax,%rbx
movaps (%rsp),%xmm0
call   1030 <fabs@plt>
cmp    %rax,%rbx
jle    11d1 <Givens+0xb1>
movapd (%rsp),%xmm0
xorpd  0xe76(%rip),%xmm0
divsd  0x10(%rsp),%xmm0
movapd %xmm0,(%rsp)
mulsd  %xmm0,%xmm0
addsd  0xe6f(%rip),%xmm0
cvttsd2si %xmm0,%edi
call   1040 <sqrt@plt>
lea    0x1(%rax),%ecx
xor    %edx,%edx
cmp    $0x3,%ecx
cmovb  %eax,%edx
xorps  %xmm0,%xmm0
cvtsi2sd %edx,%xmm0
movsd  %xmm0,(%r15)
movapd (%rsp),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,(%r14)
jmp    1225 <Givens+0x105>
movapd 0x10(%rsp),%xmm0
xorpd  0xe21(%rip),%xmm0
divsd  (%rsp),%xmm0
movapd %xmm0,0x10(%rsp)
mulsd  %xmm0,%xmm0
addsd  0xe1a(%rip),%xmm0
cvttsd2si %xmm0,%edi
call   1040 <sqrt@plt>
lea    0x1(%rax),%ecx
xor    %edx,%edx
cmp    $0x3,%ecx
cmovb  %eax,%edx
xorps  %xmm0,%xmm0
cvtsi2sd %edx,%xmm0
movsd  %xmm0,(%r14)
movapd 0x10(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,(%r15)
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @Givens(double %0, double %1, double* %2, double* %3) {
%5 = alloca double
%6 = alloca double
%7 = alloca double*
%8 = alloca double*
%9 = alloca double
store double %0, double* %5
store double %1, double* %6
store double* %2, double** %7
store double* %3, double** %8
%10 = load double, double* %6
%11 = fcmp oeq double %10, 0.000000e+00
br i1 %11, label %12, label %15
12: ; preds = %4
%13 = load double*, double** %8
store double 1.000000e+00, double* %13
%14 = load double*, double** %7
store double 0.000000e+00, double* %14
br label %58
15: ; preds = %4
%16 = load double, double* %6
%17 = call i64 @fabs(double %16)
%18 = load double, double* %5
%19 = call i64 @fabs(double %18)
%20 = icmp sgt i64 %17, %19
br i1 %20, label %21, label %39
21: ; preds = %15
%22 = load double, double* %5
%23 = fneg double %22
%24 = load double, double* %6
%25 = fdiv double %23, %24
store double %25, double* %9
%26 = load double, double* %9
%27 = load double, double* %9
%28 = call double @llvm.fmuladd.f64(double %26, double %27, double 1.000000e+00)
%29 = fptosi double %28 to i32
%30 = call i32 @sqrt(i32 %29)
%31 = sdiv i32 1, %30
%32 = sitofp i32 %31 to double
%33 = load double*, double** %7
store double %32, double* %33
%34 = load double*, double** %7
%35 = load double, double* %34
%36 = load double, double* %9
%37 = fmul double %35, %36
%38 = load double*, double** %8
store double %37, double* %38
br label %57
39: ; preds = %15
%40 = load double, double* %6
%41 = fneg double %40
%42 = load double, double* %5
%43 = fdiv double %41, %42
store double %43, double* %9
%44 = load double, double* %9
%45 = load double, double* %9
%46 = call double @llvm.fmuladd.f64(double %44, double %45, double 1.000000e+00)
%47 = fptosi double %46 to i32
%48 = call i32 @sqrt(i32 %47)
%49 = sdiv i32 1, %48
%50 = sitofp i32 %49 to double
%51 = load double*, double** %8
store double %50, double* %51
%52 = load double*, double** %8
%53 = load double, double* %52
%54 = load double, double* %9
%55 = fmul double %53, %54
%56 = load double*, double** %7
store double %55, double* %56
br label %57
57: ; preds = %39, %21
br label %58
58: ; preds = %57, %12
ret void
}

LLVM IR (-O2):
define void @Givens(double %0, double %1, double* nocapture writeonly %2, double* nocapture writeonly %3) {
%5 = fcmp oeq double %1, 0.000000e+00
br i1 %5, label %6, label %7
6: ; preds = %4
store double 1.000000e+00, double* %3
store double 0.000000e+00, double* %2
br label %33
7: ; preds = %4
%8 = tail call i64 @fabs(double %1)
%9 = tail call i64 @fabs(double %0)
%10 = icmp sgt i64 %8, %9
br i1 %10, label %11, label %22
11: ; preds = %7
%12 = fneg double %0
%13 = fdiv double %12, %1
%14 = tail call double @llvm.fmuladd.f64(double %13, double %13, double 1.000000e+00)
%15 = fptosi double %14 to i32
%16 = tail call i32 @sqrt(i32 %15)
%17 = add i32 %16, 1
%18 = icmp ult i32 %17, 3
%19 = select i1 %18, i32 %16, i32 0
%20 = sitofp i32 %19 to double
store double %20, double* %2
%21 = fmul double %13, %20
store double %21, double* %3
br label %33
22: ; preds = %7
%23 = fneg double %1
%24 = fdiv double %23, %0
%25 = tail call double @llvm.fmuladd.f64(double %24, double %24, double 1.000000e+00)
%26 = fptosi double %25 to i32
%27 = tail call i32 @sqrt(i32 %26)
%28 = add i32 %27, 1
%29 = icmp ult i32 %28, 3
%30 = select i1 %29, i32 %27, i32 0
%31 = sitofp i32 %30 to double
store double %31, double* %3
%32 = fmul double %24, %31
store double %32, double* %2
br label %33
33: ; preds = %11, %22, %6
ret void
}