#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 num_points(int);
void normalize_range(double *values, int size, double rmin, double rmax) {
  double min = values[0], max = values[0], range = rmax - rmin;
  int x;
  for (x = 1; x < num_points(size); x++) {
    if (values[x] > max) {
      max = values[x];
    }
    if (values[x] < min) {
      min = values[x];
    }
  }
  for (x = 0; x < num_points(size); x++) {
    values[x] = (values[x] - min) / (max - min) * range + rmin;
  }
}


x86 assembly (clang, -O0):
<normalize_range>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  %xmm1,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movl   $0x1,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <num_points@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%eax
cmp    %ecx,%eax
jge    11df <normalize_range+0xcf>
mov    -0x8(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
ucomisd -0x30(%rbp),%xmm0
jbe    119e <normalize_range+0x8e>
mov    -0x8(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
movsd  -0x28(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11cc <normalize_range+0xbc>
mov    -0x8(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    11d1 <normalize_range+0xc1>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1159 <normalize_range+0x49>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <num_points@plt>
mov    %eax,%ecx
mov    -0x44(%rbp),%eax
cmp    %ecx,%eax
jge    124e <normalize_range+0x13e>
mov    -0x8(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
subsd  -0x28(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
subsd  -0x28(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  -0x38(%rbp),%xmm2
movsd  -0x18(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11e6 <normalize_range+0xd6>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<normalize_range>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
movsd  %xmm1,0x10(%rsp)
movsd  %xmm0,0x18(%rsp)
mov    %esi,%r14d
mov    %rdi,%rbx
movsd  (%rdi),%xmm0
movsd  %xmm0,(%rsp)
mov    %esi,%edi
call   1030 <num_points@plt>
cmp    $0x2,%eax
jl     1194 <normalize_range+0x84>
mov    $0x1,%ebp
movsd  (%rsp),%xmm3
movapd %xmm3,%xmm0
nopl   (%rax)
movsd  (%rbx,%rbp,8),%xmm1
movapd %xmm1,%xmm2
maxsd  %xmm0,%xmm2
movsd  %xmm2,(%rsp)
minsd  %xmm3,%xmm1
movsd  %xmm1,0x8(%rsp)
add    $0x1,%rbp
mov    %r14d,%edi
call   1030 <num_points@plt>
movsd  0x8(%rsp),%xmm2
movsd  (%rsp),%xmm1
cltq
movapd %xmm2,%xmm3
movapd %xmm1,%xmm0
cmp    %rax,%rbp
jl     1150 <normalize_range+0x40>
jmp    119d <normalize_range+0x8d>
movsd  (%rsp),%xmm2
movapd %xmm2,%xmm1
movsd  %xmm2,0x8(%rsp)
movsd  %xmm1,(%rsp)
mov    %r14d,%edi
call   1030 <num_points@plt>
movsd  0x8(%rsp),%xmm4
movsd  (%rsp),%xmm3
test   %eax,%eax
movsd  0x10(%rsp),%xmm1
movsd  0x18(%rsp),%xmm2
jle    1224 <normalize_range+0x114>
subsd  %xmm2,%xmm1
subsd  %xmm4,%xmm3
xor    %ebp,%ebp
movsd  %xmm1,0x10(%rsp)
movsd  %xmm3,(%rsp)
movsd  (%rbx,%rbp,8),%xmm0
subsd  %xmm4,%xmm0
divsd  %xmm3,%xmm0
mulsd  %xmm1,%xmm0
addsd  %xmm2,%xmm0
movsd  %xmm0,(%rbx,%rbp,8)
add    $0x1,%rbp
mov    %r14d,%edi
call   1030 <num_points@plt>
movsd  0x8(%rsp),%xmm4
movsd  (%rsp),%xmm3
movsd  0x18(%rsp),%xmm2
movsd  0x10(%rsp),%xmm1
cltq
cmp    %rax,%rbp
jl     11e0 <normalize_range+0xd0>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @normalize_range(double* %0, i32 %1, double %2, double %3) {
%5 = alloca double*
%6 = alloca i32
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca i32
store double* %0, double** %5
store i32 %1, i32* %6
store double %2, double* %7
store double %3, double* %8
%13 = load double*, double** %5
%14 = getelementptr inbounds double, double* %13, i64 0
%15 = load double, double* %14
store double %15, double* %9
%16 = load double*, double** %5
%17 = getelementptr inbounds double, double* %16, i64 0
%18 = load double, double* %17
store double %18, double* %10
%19 = load double, double* %8
%20 = load double, double* %7
%21 = fsub double %19, %20
store double %21, double* %11
store i32 1, i32* %12
br label %22
22: ; preds = %56, %4
%23 = load i32, i32* %12
%24 = load i32, i32* %6
%25 = call i32 @num_points(i32 %24)
%26 = icmp slt i32 %23, %25
br i1 %26, label %27, label %59
27: ; preds = %22
%28 = load double*, double** %5
%29 = load i32, i32* %12
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds double, double* %28, i64 %30
%32 = load double, double* %31
%33 = load double, double* %10
%34 = fcmp ogt double %32, %33
br i1 %34, label %35, label %41
35: ; preds = %27
%36 = load double*, double** %5
%37 = load i32, i32* %12
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds double, double* %36, i64 %38
%40 = load double, double* %39
store double %40, double* %10
br label %41
41: ; preds = %35, %27
%42 = load double*, double** %5
%43 = load i32, i32* %12
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds double, double* %42, i64 %44
%46 = load double, double* %45
%47 = load double, double* %9
%48 = fcmp olt double %46, %47
br i1 %48, label %49, label %55
49: ; preds = %41
%50 = load double*, double** %5
%51 = load i32, i32* %12
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds double, double* %50, i64 %52
%54 = load double, double* %53
store double %54, double* %9
br label %55
55: ; preds = %49, %41
br label %56
56: ; preds = %55
%57 = load i32, i32* %12
%58 = add nsw i32 %57, 1
store i32 %58, i32* %12
br label %22
59: ; preds = %22
store i32 0, i32* %12
br label %60
60: ; preds = %84, %59
%61 = load i32, i32* %12
%62 = load i32, i32* %6
%63 = call i32 @num_points(i32 %62)
%64 = icmp slt i32 %61, %63
br i1 %64, label %65, label %87
65: ; preds = %60
%66 = load double*, double** %5
%67 = load i32, i32* %12
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds double, double* %66, i64 %68
%70 = load double, double* %69
%71 = load double, double* %9
%72 = fsub double %70, %71
%73 = load double, double* %10
%74 = load double, double* %9
%75 = fsub double %73, %74
%76 = fdiv double %72, %75
%77 = load double, double* %11
%78 = load double, double* %7
%79 = call double @llvm.fmuladd.f64(double %76, double %77, double %78)
%80 = load double*, double** %5
%81 = load i32, i32* %12
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds double, double* %80, i64 %82
store double %79, double* %83
br label %84
84: ; preds = %65
%85 = load i32, i32* %12
%86 = add nsw i32 %85, 1
store i32 %86, i32* %12
br label %60
87: ; preds = %60
ret void
}

LLVM IR (-O2):
define void @normalize_range(double* nocapture %0, i32 %1, double %2, double %3) {
%5 = load double, double* %0
%6 = fsub double %3, %2
%7 = tail call i32 @num_points(i32 %1)
%8 = icmp sgt i32 %7, 1
br i1 %8, label %16, label %9
9: ; preds = %16, %4
%10 = phi double [ %5, %4 ], [ %23, %16 ]
%11 = phi double [ %5, %4 ], [ %25, %16 ]
%12 = tail call i32 @num_points(i32 %1)
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %41
14: ; preds = %9
%15 = fsub double %10, %11
br label %30
16: ; preds = %4, %16
%17 = phi i64 [ %26, %16 ], [ 1, %4 ]
%18 = phi double [ %25, %16 ], [ %5, %4 ]
%19 = phi double [ %23, %16 ], [ %5, %4 ]
%20 = getelementptr inbounds double, double* %0, i64 %17
%21 = load double, double* %20
%22 = fcmp ogt double %21, %19
%23 = select i1 %22, double %21, double %19
%24 = fcmp olt double %21, %18
%25 = select i1 %24, double %21, double %18
%26 = add nuw nsw i64 %17, 1
%27 = tail call i32 @num_points(i32 %1)
%28 = sext i32 %27 to i64
%29 = icmp slt i64 %26, %28
br i1 %29, label %16, label %9
30: ; preds = %14, %30
%31 = phi i64 [ 0, %14 ], [ %37, %30 ]
%32 = getelementptr inbounds double, double* %0, i64 %31
%33 = load double, double* %32
%34 = fsub double %33, %11
%35 = fdiv double %34, %15
%36 = tail call double @llvm.fmuladd.f64(double %35, double %6, double %2)
store double %36, double* %32
%37 = add nuw nsw i64 %31, 1
%38 = tail call i32 @num_points(i32 %1)
%39 = sext i32 %38 to i64
%40 = icmp slt i64 %37, %39
br i1 %40, label %30, label %41
41: ; preds = %30, %9
ret void
}