#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 radius_from_curvature(double, double, double, double);
double radius_from_volume(double, double, double, double);
double radius_effective(int mode, double radius_equat_core, double x_core,
                        double thick_shell, double x_polar_shell) {
  const double radius_equat_tot = radius_equat_core + thick_shell;
  const double radius_polar_tot =
      radius_equat_core * x_core + thick_shell * x_polar_shell;
  switch (mode) {
  default:
  case 1:
    return radius_from_curvature(radius_equat_core, x_core, thick_shell,
                                 x_polar_shell);
  case 2:
    return radius_from_volume(radius_equat_core, x_core, thick_shell,
                              x_polar_shell);
  case 3:
    return (radius_polar_tot < radius_equat_tot ? radius_polar_tot
                                                : radius_equat_tot);
  case 4:
    return (radius_polar_tot > radius_equat_tot ? radius_polar_tot
                                                : radius_equat_tot);
  }
}


x86 assembly (clang, -O0):
<radius_effective>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  %xmm1,-0x20(%rbp)
movsd  %xmm2,-0x28(%rbp)
movsd  %xmm3,-0x30(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm2
movsd  -0x28(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm3
mulsd  %xmm3,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x48(%rbp)
sub    $0x3,%eax
ja     11a0 <radius_effective+0x80>
mov    -0x48(%rbp),%rax
lea    0xe69(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
jmp    11a5 <radius_effective+0x85>
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm2
movsd  -0x30(%rbp),%xmm3
call   1030 <radius_from_curvature@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    125a <radius_effective+0x13a>
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm2
movsd  -0x30(%rbp),%xmm3
call   1040 <radius_from_volume@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    125a <radius_effective+0x13a>
movsd  -0x40(%rbp),%xmm1
movsd  -0x38(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    120e <radius_effective+0xee>
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
jmp    1218 <radius_effective+0xf8>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    125a <radius_effective+0x13a>
movsd  -0x40(%rbp),%xmm0
ucomisd -0x38(%rbp),%xmm0
jbe    1246 <radius_effective+0x126>
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
jmp    1250 <radius_effective+0x130>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<radius_effective>:
cmp    $0x2,%edi
je     1154 <radius_effective+0x34>
movapd %xmm0,%xmm5
addsd  %xmm2,%xmm5
movapd %xmm2,%xmm6
mulsd  %xmm3,%xmm6
movapd %xmm0,%xmm4
mulsd  %xmm1,%xmm4
addsd  %xmm6,%xmm4
cmp    $0x3,%edi
je     1159 <radius_effective+0x39>
cmp    $0x4,%edi
jne    1162 <radius_effective+0x42>
maxsd  %xmm5,%xmm4
movapd %xmm4,%xmm0
ret
jmp    1040 <radius_from_volume@plt>
minsd  %xmm5,%xmm4
movapd %xmm4,%xmm0
ret
jmp    1030 <radius_from_curvature@plt>

LLVM IR (-O0):
define double @radius_effective(i32 %0, double %1, double %2, double %3, double %4) {
%6 = alloca double
%7 = alloca i32
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
store i32 %0, i32* %7
store double %1, double* %8
store double %2, double* %9
store double %3, double* %10
store double %4, double* %11
%14 = load double, double* %8
%15 = load double, double* %10
%16 = fadd double %14, %15
store double %16, double* %12
%17 = load double, double* %8
%18 = load double, double* %9
%19 = load double, double* %10
%20 = load double, double* %11
%21 = fmul double %19, %20
%22 = call double @llvm.fmuladd.f64(double %17, double %18, double %21)
store double %22, double* %13
%23 = load i32, i32* %7
switch i32 %23, label %24 [
i32 1, label %25
i32 2, label %31
i32 3, label %37
i32 4, label %47
]
24: ; preds = %5
br label %25
25: ; preds = %5, %24
%26 = load double, double* %8
%27 = load double, double* %9
%28 = load double, double* %10
%29 = load double, double* %11
%30 = call double @radius_from_curvature(double %26, double %27, double %28, double %29)
store double %30, double* %6
br label %57
31: ; preds = %5
%32 = load double, double* %8
%33 = load double, double* %9
%34 = load double, double* %10
%35 = load double, double* %11
%36 = call double @radius_from_volume(double %32, double %33, double %34, double %35)
store double %36, double* %6
br label %57
37: ; preds = %5
%38 = load double, double* %13
%39 = load double, double* %12
%40 = fcmp olt double %38, %39
br i1 %40, label %41, label %43
41: ; preds = %37
%42 = load double, double* %13
br label %45
43: ; preds = %37
%44 = load double, double* %12
br label %45
45: ; preds = %43, %41
%46 = phi double [ %42, %41 ], [ %44, %43 ]
store double %46, double* %6
br label %57
47: ; preds = %5
%48 = load double, double* %13
%49 = load double, double* %12
%50 = fcmp ogt double %48, %49
br i1 %50, label %51, label %53
51: ; preds = %47
%52 = load double, double* %13
br label %55
53: ; preds = %47
%54 = load double, double* %12
br label %55
55: ; preds = %53, %51
%56 = phi double [ %52, %51 ], [ %54, %53 ]
store double %56, double* %6
br label %57
57: ; preds = %55, %45, %31, %25
%58 = load double, double* %6
ret double %58
}

LLVM IR (-O2):
define double @radius_effective(i32 %0, double %1, double %2, double %3, double %4) {
%6 = fadd double %1, %3
%7 = fmul double %3, %4
%8 = tail call double @llvm.fmuladd.f64(double %1, double %2, double %7)
switch i32 %0, label %9 [
i32 4, label %16
i32 2, label %11
i32 3, label %13
]
9: ; preds = %5
%10 = tail call double @radius_from_curvature(double %1, double %2, double %3, double %4)
br label %19
11: ; preds = %5
%12 = tail call double @radius_from_volume(double %1, double %2, double %3, double %4)
br label %19
13: ; preds = %5
%14 = fcmp olt double %8, %6
%15 = select i1 %14, double %8, double %6
br label %19
16: ; preds = %5
%17 = fcmp ogt double %8, %6
%18 = select i1 %17, double %8, double %6
br label %19
19: ; preds = %16, %13, %11, %9
%20 = phi double [ %10, %9 ], [ %15, %13 ], [ %12, %11 ], [ %18, %16 ]
ret double %20
}