#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 frexp(double, int *);
double ldexp(double, int);
double sqrt(double);
double pythag(double _a, double _b) {
  double absa;
  double absb;
  double s;
  int sb;
  absa = fabs(_a);
  absb = fabs(_b);
  s = frexp(absa > absb ? absa : absb, &sb);
  if (s > 0 && s <= 1) {
    double a2;
    double b2;
    a2 = ldexp(absa, -sb);
    b2 = ldexp(absb, -sb);
    return ldexp(sqrt(a2 * a2 + b2 * b2), sb);
  } else
    return s;
}


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
movaps 0xeb2(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
movaps 0xe9d(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
ucomisd -0x28(%rbp),%xmm0
jbe    118b <pythag+0x5b>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
jmp    1195 <pythag+0x65>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
lea    -0x34(%rbp),%rdi
call   1040 <frexp@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    1228 <pythag+0xf8>
movsd  0xe4e(%rip),%xmm0
ucomisd -0x30(%rbp),%xmm0
jb     1228 <pythag+0xf8>
movsd  -0x20(%rbp),%xmm0
xor    %edi,%edi
sub    -0x34(%rbp),%edi
call   1030 <ldexp@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  -0x28(%rbp),%xmm0
xor    %edi,%edi
sub    -0x34(%rbp),%edi
call   1030 <ldexp@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm2
movsd  -0x48(%rbp),%xmm1
mulsd  -0x48(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1050 <sqrt@plt>
mov    -0x34(%rbp),%edi
call   1030 <ldexp@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    1232 <pythag+0x102>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pythag>:
push   %rbp
push   %rbx
sub    $0x38,%rsp
movapd 0xec2(%rip),%xmm2
andpd  %xmm2,%xmm0
andpd  %xmm2,%xmm1
movapd %xmm0,0x10(%rsp)
movapd %xmm1,0x20(%rsp)
maxsd  %xmm1,%xmm0
lea    0xc(%rsp),%rdi
call   1040 <frexp@plt>
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11c5 <pythag+0x95>
movsd  0xe9e(%rip),%xmm1
ucomisd %xmm0,%xmm1
jb     11c5 <pythag+0x95>
mov    0xc(%rsp),%ebx
mov    %ebx,%ebp
neg    %ebp
movaps 0x10(%rsp),%xmm0
mov    %ebp,%edi
call   1030 <ldexp@plt>
movsd  %xmm0,0x10(%rsp)
movapd 0x20(%rsp),%xmm0
mov    %ebp,%edi
call   1030 <ldexp@plt>
mulsd  %xmm0,%xmm0
movsd  0x10(%rsp),%xmm1
mulsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
movapd %xmm1,%xmm0
jb     11cc <pythag+0x9c>
sqrtsd %xmm0,%xmm0
jmp    11d1 <pythag+0xa1>
add    $0x38,%rsp
pop    %rbx
pop    %rbp
ret
call   1050 <sqrt@plt>
mov    %ebx,%edi
add    $0x38,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <ldexp@plt>

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
%9 = alloca i32
%10 = alloca double
%11 = alloca double
store double %0, double* %4
store double %1, double* %5
%12 = load double, double* %4
%13 = call double @llvm.fabs.f64(double %12)
store double %13, double* %6
%14 = load double, double* %5
%15 = call double @llvm.fabs.f64(double %14)
store double %15, double* %7
%16 = load double, double* %6
%17 = load double, double* %7
%18 = fcmp ogt double %16, %17
br i1 %18, label %19, label %21
19: ; preds = %2
%20 = load double, double* %6
br label %23
21: ; preds = %2
%22 = load double, double* %7
br label %23
23: ; preds = %21, %19
%24 = phi double [ %20, %19 ], [ %22, %21 ]
%25 = call double @frexp(double %24, i32* %9)
store double %25, double* %8
%26 = load double, double* %8
%27 = fcmp ogt double %26, 0.000000e+00
br i1 %27, label %28, label %49
28: ; preds = %23
%29 = load double, double* %8
%30 = fcmp ole double %29, 1.000000e+00
br i1 %30, label %31, label %49
31: ; preds = %28
%32 = load double, double* %6
%33 = load i32, i32* %9
%34 = sub nsw i32 0, %33
%35 = call double @ldexp(double %32, i32 %34)
store double %35, double* %10
%36 = load double, double* %7
%37 = load i32, i32* %9
%38 = sub nsw i32 0, %37
%39 = call double @ldexp(double %36, i32 %38)
store double %39, double* %11
%40 = load double, double* %10
%41 = load double, double* %10
%42 = load double, double* %11
%43 = load double, double* %11
%44 = fmul double %42, %43
%45 = call double @llvm.fmuladd.f64(double %40, double %41, double %44)
%46 = call double @sqrt(double %45)
%47 = load i32, i32* %9
%48 = call double @ldexp(double %46, i32 %47)
store double %48, double* %3
br label %51
49: ; preds = %28, %23
%50 = load double, double* %8
store double %50, double* %3
br label %51
51: ; preds = %49, %31
%52 = load double, double* %3
ret double %52
}

LLVM IR (-O2):
define double @pythag(double %0, double %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call double @llvm.fabs.f64(double %0)
%6 = tail call double @llvm.fabs.f64(double %1)
%7 = fcmp ogt double %5, %6
%8 = select i1 %7, double %5, double %6
%9 = call double @frexp(double %8, i32* %3)
%10 = fcmp ogt double %9, 0.000000e+00
%11 = fcmp ole double %9, 1.000000e+00
%12 = and i1 %10, %11
br i1 %12, label %13, label %22
13: ; preds = %2
%14 = load i32, i32* %3
%15 = sub nsw i32 0, %14
%16 = tail call double @ldexp(double %5, i32 %15)
%17 = tail call double @ldexp(double %6, i32 %15)
%18 = fmul double %17, %17
%19 = tail call double @llvm.fmuladd.f64(double %16, double %16, double %18)
%20 = tail call double @sqrt(double %19)
%21 = tail call double @ldexp(double %20, i32 %14)
br label %22
22: ; preds = %2, %13
%23 = phi double [ %21, %13 ], [ %9, %2 ]
ret double %23
}