#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 */
int log10(double);
int pow(double, int);
double minmax_to_scale(double min, double max) {
  double scale;
  if ((min == 0) || (max == 0))
    return ((double)1);
  scale = 1 / pow(10.0, (log10(min) + log10(max)) / 2);
  return (scale);
}


x86 assembly (clang, -O0):
<minmax_to_scale>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    114f <minmax_to_scale+0x2f>
jp     114f <minmax_to_scale+0x2f>
jmp    1167 <minmax_to_scale+0x47>
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1179 <minmax_to_scale+0x59>
jp     1179 <minmax_to_scale+0x59>
movsd  0xe99(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11cb <minmax_to_scale+0xab>
movsd  -0x10(%rbp),%xmm0
call   1040 <log10@plt>
mov    %eax,-0x24(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1040 <log10@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
add    %ecx,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
movsd  0xe57(%rip),%xmm0
call   1030 <pow@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<minmax_to_scale>:
push   %rbx
sub    $0x10,%rsp
movapd %xmm0,%xmm3
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm0
movsd  0xec7(%rip),%xmm0
jne    113d <minmax_to_scale+0x1d>
jnp    118b <minmax_to_scale+0x6b>
ucomisd %xmm2,%xmm1
jne    1145 <minmax_to_scale+0x25>
jnp    118b <minmax_to_scale+0x6b>
movapd %xmm3,%xmm0
movsd  %xmm1,0x8(%rsp)
call   1040 <log10@plt>
mov    %eax,%ebx
movsd  0x8(%rsp),%xmm0
call   1040 <log10@plt>
add    %eax,%ebx
mov    %ebx,%edi
shr    $0x1f,%edi
add    %ebx,%edi
sar    %edi
movsd  0xe94(%rip),%xmm0
call   1030 <pow@plt>
lea    0x1(%rax),%ecx
xor    %edx,%edx
cmp    $0x3,%ecx
cmovb  %eax,%edx
xorps  %xmm0,%xmm0
cvtsi2sd %edx,%xmm0
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define double @minmax_to_scale(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
store double %0, double* %4
store double %1, double* %5
%7 = load double, double* %4
%8 = fcmp oeq double %7, 0.000000e+00
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = load double, double* %5
%11 = fcmp oeq double %10, 0.000000e+00
br i1 %11, label %12, label %13
12: ; preds = %9, %2
store double 1.000000e+00, double* %3
br label %24
13: ; preds = %9
%14 = load double, double* %4
%15 = call i32 @log10(double %14)
%16 = load double, double* %5
%17 = call i32 @log10(double %16)
%18 = add nsw i32 %15, %17
%19 = sdiv i32 %18, 2
%20 = call i32 @pow(double 1.000000e+01, i32 %19)
%21 = sdiv i32 1, %20
%22 = sitofp i32 %21 to double
store double %22, double* %6
%23 = load double, double* %6
store double %23, double* %3
br label %24
24: ; preds = %13, %12
%25 = load double, double* %3
ret double %25
}

LLVM IR (-O2):
define double @minmax_to_scale(double %0, double %1) {
%3 = fcmp oeq double %0, 0.000000e+00
%4 = fcmp oeq double %1, 0.000000e+00
%5 = or i1 %3, %4
br i1 %5, label %16, label %6
6: ; preds = %2
%7 = tail call i32 @log10(double %0)
%8 = tail call i32 @log10(double %1)
%9 = add nsw i32 %8, %7
%10 = sdiv i32 %9, 2
%11 = tail call i32 @pow(double 1.000000e+01, i32 %10)
%12 = add i32 %11, 1
%13 = icmp ult i32 %12, 3
%14 = select i1 %13, i32 %11, i32 0
%15 = sitofp i32 %14 to double
br label %16
16: ; preds = %2, %6
%17 = phi double [ %15, %6 ], [ 1.000000e+00, %2 ]
ret double %17
}