#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__ get_type_values(int, double *, double *);
int compute_scale(int datatype, double fmin, double fmax, double *scale_factor,
                  double *add_offset) {
  double tmin, tmax;
  double ao = 0.0, sf = 1.0;
  *scale_factor = sf;
  *add_offset = ao;
  if (get_type_values(datatype, &tmin, &tmax))
    return (1);
  if ((fmin < fmax || fmax < fmin)) {
    sf = (fmax - fmin) / (tmax - tmin);
    ao = ((fmax + fmin) - sf * (tmin + tmax)) / 2;
  }
  *scale_factor = sf;
  *add_offset = ao;
  return 0;
}


x86 assembly (clang, -O0):
<compute_scale>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
mov    %rsi,-0x20(%rbp)
mov    %rdx,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  0xec3(%rip),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x40(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x8(%rbp),%edi
lea    -0x30(%rbp),%rsi
lea    -0x38(%rbp),%rdx
call   1030 <get_type_values@plt>
cmp    $0x0,%rax
je     1182 <compute_scale+0x72>
movl   $0x1,-0x4(%rbp)
jmp    1231 <compute_scale+0x121>
movsd  -0x10(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
ja     11aa <compute_scale+0x9a>
movsd  -0x18(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1210 <compute_scale+0x100>
movsd  -0x18(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm1
subsd  -0x30(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x18(%rbp),%xmm1
addsd  -0x10(%rbp),%xmm1
movsd  -0x48(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm2
addsd  -0x38(%rbp),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  0xe01(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x48(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x40(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compute_scale>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
movsd  %xmm1,0x8(%rsp)
movsd  %xmm0,0x10(%rsp)
movabs $0x3ff0000000000000,%rax
mov    %rax,(%rsi)
movq   $0x0,(%rdx)
lea    0x20(%rsp),%rsi
lea    0x18(%rsp),%rdx
call   1030 <get_type_values@plt>
mov    %rax,%rcx
mov    $0x1,%eax
test   %rcx,%rcx
jne    11bc <compute_scale+0xac>
movsd  0x10(%rsp),%xmm4
movsd  0x8(%rsp),%xmm5
ucomisd %xmm5,%xmm4
je     11a5 <compute_scale+0x95>
movapd %xmm5,%xmm0
subsd  %xmm4,%xmm0
movsd  0x18(%rsp),%xmm1
movsd  0x20(%rsp),%xmm2
movapd %xmm1,%xmm3
subsd  %xmm2,%xmm3
divsd  %xmm3,%xmm0
addsd  %xmm5,%xmm4
addsd  %xmm2,%xmm1
mulsd  %xmm0,%xmm1
subsd  %xmm1,%xmm4
mulsd  0xe65(%rip),%xmm4
jmp    11b1 <compute_scale+0xa1>
movsd  0xe53(%rip),%xmm0
xorpd  %xmm4,%xmm4
movsd  %xmm0,(%rbx)
movsd  %xmm4,(%r14)
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @compute_scale(i32 %0, double %1, double %2, double* %3, double* %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca double
%9 = alloca double
%10 = alloca double*
%11 = alloca double*
%12 = alloca double
%13 = alloca double
%14 = alloca double
%15 = 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
store double 0.000000e+00, double* %14
store double 1.000000e+00, double* %15
%16 = load double, double* %15
%17 = load double*, double** %10
store double %16, double* %17
%18 = load double, double* %14
%19 = load double*, double** %11
store double %18, double* %19
%20 = load i32, i32* %7
%21 = call i64 @get_type_values(i32 %20, double* %12, double* %13)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %5
store i32 1, i32* %6
br label %55
24: ; preds = %5
%25 = load double, double* %8
%26 = load double, double* %9
%27 = fcmp olt double %25, %26
br i1 %27, label %32, label %28
28: ; preds = %24
%29 = load double, double* %9
%30 = load double, double* %8
%31 = fcmp olt double %29, %30
br i1 %31, label %32, label %50
32: ; preds = %28, %24
%33 = load double, double* %9
%34 = load double, double* %8
%35 = fsub double %33, %34
%36 = load double, double* %13
%37 = load double, double* %12
%38 = fsub double %36, %37
%39 = fdiv double %35, %38
store double %39, double* %15
%40 = load double, double* %9
%41 = load double, double* %8
%42 = fadd double %40, %41
%43 = load double, double* %15
%44 = load double, double* %12
%45 = load double, double* %13
%46 = fadd double %44, %45
%47 = fneg double %43
%48 = call double @llvm.fmuladd.f64(double %47, double %46, double %42)
%49 = fdiv double %48, 2.000000e+00
store double %49, double* %14
br label %50
50: ; preds = %32, %28
%51 = load double, double* %15
%52 = load double*, double** %10
store double %51, double* %52
%53 = load double, double* %14
%54 = load double*, double** %11
store double %53, double* %54
store i32 0, i32* %6
br label %55
55: ; preds = %50, %23
%56 = load i32, i32* %6
ret i32 %56
}

LLVM IR (-O2):
define i32 @compute_scale(i32 %0, double %1, double %2, double* nocapture writeonly %3, double* nocapture writeonly %4) {
%6 = alloca double
%7 = alloca double
%8 = bitcast double* %6 to i8*
%9 = bitcast double* %7 to i8*
store double 1.000000e+00, double* %3
store double 0.000000e+00, double* %4
%10 = call i64 @get_type_values(i32 %0, double* %6, double* %7)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %28
12: ; preds = %5
%13 = fcmp ueq double %1, %2
br i1 %13, label %25, label %14
14: ; preds = %12
%15 = fsub double %2, %1
%16 = load double, double* %7
%17 = load double, double* %6
%18 = fsub double %16, %17
%19 = fdiv double %15, %18
%20 = fadd double %1, %2
%21 = fadd double %16, %17
%22 = fneg double %19
%23 = call double @llvm.fmuladd.f64(double %22, double %21, double %20)
%24 = fmul double %23, 5.000000e-01
br label %25
25: ; preds = %12, %14
%26 = phi double [ %24, %14 ], [ 0.000000e+00, %12 ]
%27 = phi double [ %19, %14 ], [ 1.000000e+00, %12 ]
store double %27, double* %3
store double %26, double* %4
br label %28
28: ; preds = %5, %25
%29 = phi i32 [ 0, %25 ], [ 1, %5 ]
ret i32 %29
}