#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 CSPL_Array_min(double *, long const);
double CSPL_Array_range(double *, long const);
void CSPL_Array_scale(double *inval, const double min, const double max,
                      const long n) {
  double _range = CSPL_Array_range(inval, n);
  double _min = CSPL_Array_min(inval, n);
  long i;
  for (i = 0; i < n; i++) {
    inval[i] -= _min;
    inval[i] /= _range;
    inval[i] *= (max - min);
    inval[i] += min;
  }
}


x86 assembly (clang, -O0):
<CSPL_Array_scale>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
mov    %rsi,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <CSPL_Array_range@plt>
movsd  %xmm0,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <CSPL_Array_min@plt>
movsd  %xmm0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x20(%rbp),%rax
jge    11ee <CSPL_Array_scale+0xce>
movsd  -0x30(%rbp),%xmm1
mov    -0x8(%rbp),%rax
mov    -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x28(%rbp),%xmm1
mov    -0x8(%rbp),%rax
mov    -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x18(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
mov    -0x8(%rbp),%rax
mov    -0x38(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x10(%rbp),%xmm0
mov    -0x8(%rbp),%rax
mov    -0x38(%rbp),%rcx
addsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    1166 <CSPL_Array_scale+0x46>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CSPL_Array_scale>:
push   %r14
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%r14
movapd %xmm1,0x20(%rsp)
movapd %xmm0,0x10(%rsp)
mov    %rdi,%rbx
call   1030 <CSPL_Array_range@plt>
movapd %xmm0,(%rsp)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <CSPL_Array_min@plt>
movapd (%rsp),%xmm9
movapd 0x10(%rsp),%xmm8
movapd 0x20(%rsp),%xmm7
test   %r14,%r14
jle    1265 <CSPL_Array_scale+0x145>
subsd  %xmm8,%xmm7
cmp    $0x1,%r14
jne    117c <CSPL_Array_scale+0x5c>
xor    %eax,%eax
jmp    1240 <CSPL_Array_scale+0x120>
mov    %r14,%rax
and    $0xfffffffffffffffe,%rax
movapd %xmm0,%xmm2
unpcklpd %xmm0,%xmm2
movapd %xmm9,%xmm3
unpcklpd %xmm9,%xmm3
movapd %xmm7,%xmm1
unpcklpd %xmm7,%xmm1
movapd %xmm8,%xmm4
unpcklpd %xmm8,%xmm4
lea    -0x2(%rax),%rcx
mov    %rcx,%rdx
shr    %rdx
add    $0x1,%rdx
test   %rcx,%rcx
je     126d <CSPL_Array_scale+0x14d>
mov    %rdx,%rsi
and    $0xfffffffffffffffe,%rsi
xor    %ecx,%ecx
nopw   0x0(%rax,%rax,1)
movupd (%rbx,%rcx,8),%xmm5
movupd 0x10(%rbx,%rcx,8),%xmm6
subpd  %xmm2,%xmm5
divpd  %xmm3,%xmm5
mulpd  %xmm1,%xmm5
addpd  %xmm4,%xmm5
movupd %xmm5,(%rbx,%rcx,8)
subpd  %xmm2,%xmm6
divpd  %xmm3,%xmm6
mulpd  %xmm1,%xmm6
addpd  %xmm4,%xmm6
movupd %xmm6,0x10(%rbx,%rcx,8)
add    $0x4,%rcx
add    $0xfffffffffffffffe,%rsi
jne    11d0 <CSPL_Array_scale+0xb0>
test   $0x1,%dl
je     122f <CSPL_Array_scale+0x10f>
movupd (%rbx,%rcx,8),%xmm5
subpd  %xmm2,%xmm5
divpd  %xmm3,%xmm5
mulpd  %xmm5,%xmm1
addpd  %xmm4,%xmm1
movupd %xmm1,(%rbx,%rcx,8)
cmp    %r14,%rax
je     1265 <CSPL_Array_scale+0x145>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsd  (%rbx,%rax,8),%xmm1
subsd  %xmm0,%xmm1
divsd  %xmm9,%xmm1
mulsd  %xmm7,%xmm1
addsd  %xmm8,%xmm1
movsd  %xmm1,(%rbx,%rax,8)
add    $0x1,%rax
cmp    %rax,%r14
jne    1240 <CSPL_Array_scale+0x120>
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret
xor    %ecx,%ecx
test   $0x1,%dl
jne    1215 <CSPL_Array_scale+0xf5>
jmp    122f <CSPL_Array_scale+0x10f>

LLVM IR (-O0):
define void @CSPL_Array_scale(double* %0, double %1, double %2, i64 %3) {
%5 = alloca double*
%6 = alloca double
%7 = alloca double
%8 = alloca i64
%9 = alloca double
%10 = alloca double
%11 = alloca i64
store double* %0, double** %5
store double %1, double* %6
store double %2, double* %7
store i64 %3, i64* %8
%12 = load double*, double** %5
%13 = load i64, i64* %8
%14 = call double @CSPL_Array_range(double* %12, i64 %13)
store double %14, double* %9
%15 = load double*, double** %5
%16 = load i64, i64* %8
%17 = call double @CSPL_Array_min(double* %15, i64 %16)
store double %17, double* %10
store i64 0, i64* %11
br label %18
18: ; preds = %49, %4
%19 = load i64, i64* %11
%20 = load i64, i64* %8
%21 = icmp slt i64 %19, %20
br i1 %21, label %22, label %52
22: ; preds = %18
%23 = load double, double* %10
%24 = load double*, double** %5
%25 = load i64, i64* %11
%26 = getelementptr inbounds double, double* %24, i64 %25
%27 = load double, double* %26
%28 = fsub double %27, %23
store double %28, double* %26
%29 = load double, double* %9
%30 = load double*, double** %5
%31 = load i64, i64* %11
%32 = getelementptr inbounds double, double* %30, i64 %31
%33 = load double, double* %32
%34 = fdiv double %33, %29
store double %34, double* %32
%35 = load double, double* %7
%36 = load double, double* %6
%37 = fsub double %35, %36
%38 = load double*, double** %5
%39 = load i64, i64* %11
%40 = getelementptr inbounds double, double* %38, i64 %39
%41 = load double, double* %40
%42 = fmul double %41, %37
store double %42, double* %40
%43 = load double, double* %6
%44 = load double*, double** %5
%45 = load i64, i64* %11
%46 = getelementptr inbounds double, double* %44, i64 %45
%47 = load double, double* %46
%48 = fadd double %47, %43
store double %48, double* %46
br label %49
49: ; preds = %22
%50 = load i64, i64* %11
%51 = add nsw i64 %50, 1
store i64 %51, i64* %11
br label %18
52: ; preds = %18
ret void
}

LLVM IR (-O2):
define void @CSPL_Array_scale(double* %0, double %1, double %2, i64 %3) {
%5 = tail call double @CSPL_Array_range(double* %0, i64 %3)
%6 = tail call double @CSPL_Array_min(double* %0, i64 %3)
%7 = icmp sgt i64 %3, 0
br i1 %7, label %8, label %77
8: ; preds = %4
%9 = fsub double %2, %1
%10 = icmp eq i64 %3, 1
br i1 %10, label %65, label %11
11: ; preds = %8
%12 = and i64 %3, -2
%13 = insertelement <2 x double> poison, double %6, i64 0
%14 = shufflevector <2 x double> %13, <2 x double> poison, <2 x i32> zeroinitializer
%15 = insertelement <2 x double> poison, double %5, i64 0
%16 = shufflevector <2 x double> %15, <2 x double> poison, <2 x i32> zeroinitializer
%17 = insertelement <2 x double> poison, double %9, i64 0
%18 = shufflevector <2 x double> %17, <2 x double> poison, <2 x i32> zeroinitializer
%19 = insertelement <2 x double> poison, double %1, i64 0
%20 = shufflevector <2 x double> %19, <2 x double> poison, <2 x i32> zeroinitializer
%21 = add i64 %12, -2
%22 = lshr exact i64 %21, 1
%23 = add nuw i64 %22, 1
%24 = and i64 %23, 1
%25 = icmp eq i64 %21, 0
br i1 %25, label %51, label %26
26: ; preds = %11
%27 = and i64 %23, -2
br label %28
28: ; preds = %28, %26
%29 = phi i64 [ 0, %26 ], [ %48, %28 ]
%30 = phi i64 [ 0, %26 ], [ %49, %28 ]
%31 = getelementptr inbounds double, double* %0, i64 %29
%32 = bitcast double* %31 to <2 x double>*
%33 = load <2 x double>, <2 x double>* %32
%34 = fsub <2 x double> %33, %14
%35 = fdiv <2 x double> %34, %16
%36 = fmul <2 x double> %18, %35
%37 = fadd <2 x double> %36, %20
%38 = bitcast double* %31 to <2 x double>*
store <2 x double> %37, <2 x double>* %38
%39 = or i64 %29, 2
%40 = getelementptr inbounds double, double* %0, i64 %39
%41 = bitcast double* %40 to <2 x double>*
%42 = load <2 x double>, <2 x double>* %41
%43 = fsub <2 x double> %42, %14
%44 = fdiv <2 x double> %43, %16
%45 = fmul <2 x double> %18, %44
%46 = fadd <2 x double> %45, %20
%47 = bitcast double* %40 to <2 x double>*
store <2 x double> %46, <2 x double>* %47
%48 = add nuw i64 %29, 4
%49 = add nuw i64 %30, 2
%50 = icmp eq i64 %49, %27
br i1 %50, label %51, label %28
51: ; preds = %28, %11
%52 = phi i64 [ 0, %11 ], [ %48, %28 ]
%53 = icmp eq i64 %24, 0
br i1 %53, label %63, label %54
54: ; preds = %51
%55 = getelementptr inbounds double, double* %0, i64 %52
%56 = bitcast double* %55 to <2 x double>*
%57 = load <2 x double>, <2 x double>* %56
%58 = fsub <2 x double> %57, %14
%59 = fdiv <2 x double> %58, %16
%60 = fmul <2 x double> %18, %59
%61 = fadd <2 x double> %60, %20
%62 = bitcast double* %55 to <2 x double>*
store <2 x double> %61, <2 x double>* %62
br label %63
63: ; preds = %51, %54
%64 = icmp eq i64 %12, %3
br i1 %64, label %77, label %65
65: ; preds = %8, %63
%66 = phi i64 [ 0, %8 ], [ %12, %63 ]
br label %67
67: ; preds = %65, %67
%68 = phi i64 [ %75, %67 ], [ %66, %65 ]
%69 = getelementptr inbounds double, double* %0, i64 %68
%70 = load double, double* %69
%71 = fsub double %70, %6
%72 = fdiv double %71, %5
%73 = fmul double %9, %72
%74 = fadd double %73, %1
store double %74, double* %69
%75 = add nuw nsw i64 %68, 1
%76 = icmp eq i64 %75, %3
br i1 %76, label %77, label %67
77: ; preds = %67, %63, %4
ret void
}