#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 fabs(double);
double sqrt(int);
double pythag(double a, double b) {
  double absa = fabs(a), absb = fabs(b);
  return (absa > absb) ? absa * sqrt(1 + (absb / absa) * (absb / absa))
         : absb == 0   ? 0
                       : absb * sqrt(1 + (absa / absb) * (absa / absb));
}


x86 assembly (clang, -O0):
<pythag>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm0
movaps 0xed2(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
movaps 0xebd(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    11a9 <pythag+0x99>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
divsd  -0x18(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe8a(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1030 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    1220 <pythag+0x110>
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11ce <pythag+0xbe>
jp     11ce <pythag+0xbe>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    1216 <pythag+0x106>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x18(%rbp),%xmm0
divsd  -0x20(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
divsd  -0x20(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe18(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1030 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pythag>:
sub    $0x18,%rsp
movapd %xmm0,%xmm3
movapd 0xee0(%rip),%xmm2
andpd  %xmm2,%xmm3
andpd  %xmm1,%xmm2
ucomisd %xmm2,%xmm3
jbe    1145 <pythag+0x35>
divsd  %xmm3,%xmm2
mulsd  %xmm2,%xmm2
addsd  0xed2(%rip),%xmm2
movapd %xmm3,(%rsp)
jmp    1173 <pythag+0x63>
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jne    1156 <pythag+0x46>
jp     1156 <pythag+0x46>
add    $0x18,%rsp
ret
movapd %xmm2,%xmm0
divsd  %xmm2,%xmm3
mulsd  %xmm3,%xmm3
addsd  0xea6(%rip),%xmm3
movapd %xmm3,%xmm2
movapd %xmm0,(%rsp)
cvttsd2si %xmm2,%edi
call   1030 <sqrt@plt>
mulsd  (%rsp),%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
store double %0, double* %3
store double %1, double* %4
%7 = load double, double* %3
%8 = call double @llvm.fabs.f64(double %7)
store double %8, double* %5
%9 = load double, double* %4
%10 = call double @llvm.fabs.f64(double %9)
store double %10, double* %6
%11 = load double, double* %5
%12 = load double, double* %6
%13 = fcmp ogt double %11, %12
br i1 %13, label %14, label %26
14: ; preds = %2
%15 = load double, double* %5
%16 = load double, double* %6
%17 = load double, double* %5
%18 = fdiv double %16, %17
%19 = load double, double* %6
%20 = load double, double* %5
%21 = fdiv double %19, %20
%22 = call double @llvm.fmuladd.f64(double %18, double %21, double 1.000000e+00)
%23 = fptosi double %22 to i32
%24 = call double @sqrt(i32 %23)
%25 = fmul double %15, %24
br label %44
26: ; preds = %2
%27 = load double, double* %6
%28 = fcmp oeq double %27, 0.000000e+00
br i1 %28, label %29, label %30
29: ; preds = %26
br label %42
30: ; preds = %26
%31 = load double, double* %6
%32 = load double, double* %5
%33 = load double, double* %6
%34 = fdiv double %32, %33
%35 = load double, double* %5
%36 = load double, double* %6
%37 = fdiv double %35, %36
%38 = call double @llvm.fmuladd.f64(double %34, double %37, double 1.000000e+00)
%39 = fptosi double %38 to i32
%40 = call double @sqrt(i32 %39)
%41 = fmul double %31, %40
br label %42
42: ; preds = %30, %29
%43 = phi double [ 0.000000e+00, %29 ], [ %41, %30 ]
br label %44
44: ; preds = %42, %14
%45 = phi double [ %25, %14 ], [ %43, %42 ]
ret double %45
}

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