#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);
double sqrt(double);
double pythag(double a, double b) {
  double absa, absb, val;
  absa = (double)fabs(a);
  absb = (double)fabs(b);
  if (absa > absb) {
    val = (double)absa * sqrt(1.0 + (absb / absa) * (absb / absa));
    return val;
  } else {
    val = (double)(absb == 0.0
                       ? 0.0
                       : absb * sqrt(1.0 + (absa / absb) * (absa / absb)));
    return val;
  }
}


x86 assembly (clang, -O0):
<pythag>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <fabs@plt>
cvtsi2sd %rax,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1030 <fabs@plt>
cvtsi2sd %rax,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
ucomisd -0x28(%rbp),%xmm0
jbe    11bd <pythag+0x9d>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x28(%rbp),%xmm0
divsd  -0x20(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
divsd  -0x20(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe6c(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1040 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    123a <pythag+0x11a>
movsd  -0x28(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11e2 <pythag+0xc2>
jp     11e2 <pythag+0xc2>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
jmp    1226 <pythag+0x106>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x20(%rbp),%xmm0
divsd  -0x28(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
divsd  -0x28(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xdf4(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1040 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x48(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pythag>:
sub    $0x18,%rsp
movsd  %xmm1,0x10(%rsp)
call   1030 <fabs@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x10(%rsp),%xmm0
call   1030 <fabs@plt>
movsd  0x8(%rsp),%xmm2
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
ucomisd %xmm1,%xmm2
jbe    1172 <pythag+0x52>
divsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm1
addsd  0xe94(%rip),%xmm1
movapd %xmm1,%xmm0
jmp    118f <pythag+0x6f>
test   %rax,%rax
je     11b9 <pythag+0x99>
divsd  %xmm1,%xmm2
mulsd  %xmm2,%xmm2
addsd  0xe79(%rip),%xmm2
movapd %xmm2,%xmm0
movapd %xmm1,%xmm2
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     119f <pythag+0x7f>
sqrtsd %xmm0,%xmm0
jmp    11b0 <pythag+0x90>
movsd  %xmm2,0x8(%rsp)
call   1040 <sqrt@plt>
movsd  0x8(%rsp),%xmm2
mulsd  %xmm2,%xmm0
add    $0x18,%rsp
ret
xorps  %xmm0,%xmm0
add    $0x18,%rsp
ret

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

LLVM IR (-O2):
define double @pythag(double %0, double %1) {
%3 = tail call i64 @fabs(double %0)
%4 = sitofp i64 %3 to double
%5 = tail call i64 @fabs(double %1)
%6 = sitofp i64 %5 to double
%7 = fcmp ogt double %4, %6
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = fdiv double %6, %4
%10 = tail call double @llvm.fmuladd.f64(double %9, double %9, double 1.000000e+00)
br label %16
11: ; preds = %2
%12 = icmp eq i64 %5, 0
br i1 %12, label %21, label %13
13: ; preds = %11
%14 = fdiv double %4, %6
%15 = tail call double @llvm.fmuladd.f64(double %14, double %14, double 1.000000e+00)
br label %16
16: ; preds = %8, %13
%17 = phi double [ %15, %13 ], [ %10, %8 ]
%18 = phi double [ %6, %13 ], [ %4, %8 ]
%19 = tail call double @sqrt(double %17)
%20 = fmul double %19, %18
br label %21
21: ; preds = %16, %11
%22 = phi double [ 0.000000e+00, %11 ], [ %20, %16 ]
ret double %22
}