#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__ isnormal(double);
void scaleScalar(double *gp, long no, double *zmin, double *zmax) {
  long j;
  int init = 0;
  double dz, *lgp;
  lgp = gp - 1;
  for (j = 0; j < no; j++) {
    if (init == 0) {
      if (isnormal(*(++lgp))) {
        *zmin = *zmax = *lgp;
        init = 1;
      }
    } else {
      if (*(++lgp) < *zmin)
        if (isnormal(*lgp))
          *zmin = *lgp;
      if (*lgp > *zmax)
        if (isnormal(*lgp))
          *zmax = *lgp;
    }
  }
  dz = (*zmax - *zmin);
  if (dz == 0) {
    dz = 1;
    *zmax += dz;
    *zmin -= dz;
  }
}


x86 assembly (clang, -O0):
<scaleScalar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x8(%rbp),%rax
add    $0xfffffffffffffff8,%rax
mov    %rax,-0x40(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x10(%rbp),%rax
jge    1251 <scaleScalar+0x141>
cmpl   $0x0,-0x2c(%rbp)
jne    11a2 <scaleScalar+0x92>
mov    -0x40(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x40(%rbp)
movsd  0x8(%rax),%xmm0
call   1030 <isnormal@plt>
cmp    $0x0,%rax
je     119d <scaleScalar+0x8d>
mov    -0x40(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
movl   $0x1,-0x2c(%rbp)
jmp    123b <scaleScalar+0x12b>
mov    -0x40(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x40(%rbp)
movsd  0x8(%rax),%xmm1
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
ucomisd %xmm1,%xmm0
jbe    11f4 <scaleScalar+0xe4>
mov    -0x40(%rbp),%rax
movsd  (%rax),%xmm0
call   1030 <isnormal@plt>
cmp    $0x0,%rax
je     11ef <scaleScalar+0xdf>
mov    -0x40(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    11f4 <scaleScalar+0xe4>
mov    -0x40(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x20(%rbp),%rax
ucomisd (%rax),%xmm0
jbe    1236 <scaleScalar+0x126>
mov    -0x40(%rbp),%rax
movsd  (%rax),%xmm0
call   1030 <isnormal@plt>
cmp    $0x0,%rax
je     1231 <scaleScalar+0x121>
mov    -0x40(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    1236 <scaleScalar+0x126>
jmp    123b <scaleScalar+0x12b>
jmp    1240 <scaleScalar+0x130>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1143 <scaleScalar+0x33>
mov    -0x20(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x18(%rbp),%rax
subsd  (%rax),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    12b1 <scaleScalar+0x1a1>
jp     12b1 <scaleScalar+0x1a1>
movsd  0xd7a(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
mov    -0x20(%rbp),%rax
addsd  (%rax),%xmm0
movsd  %xmm0,(%rax)
movsd  -0x38(%rbp),%xmm1
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,(%rax)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scaleScalar>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r15
test   %rsi,%rsi
jle    11c4 <scaleScalar+0xb4>
mov    %rsi,%r12
mov    %rdi,%r13
xor    %ebp,%ebp
xor    %ebx,%ebx
jmp    1169 <scaleScalar+0x59>
cs nopw 0x0(%rax,%rax,1)
call   1030 <isnormal@plt>
test   %rax,%rax
je     11c0 <scaleScalar+0xb0>
movsd  0x0(%r13,%rbx,8),%xmm0
movsd  %xmm0,(%r14)
movsd  %xmm0,(%r15)
mov    $0x1,%ebp
add    $0x1,%rbx
cmp    %rbx,%r12
je     11c4 <scaleScalar+0xb4>
movsd  0x0(%r13,%rbx,8),%xmm0
test   %ebp,%ebp
je     1140 <scaleScalar+0x30>
movsd  (%r15),%xmm1
ucomisd %xmm0,%xmm1
jbe    1195 <scaleScalar+0x85>
call   1030 <isnormal@plt>
test   %rax,%rax
je     1195 <scaleScalar+0x85>
movsd  0x0(%r13,%rbx,8),%xmm0
movsd  %xmm0,(%r15)
movsd  0x0(%r13,%rbx,8),%xmm0
mov    $0x1,%ebp
ucomisd (%r14),%xmm0
jbe    1160 <scaleScalar+0x50>
call   1030 <isnormal@plt>
test   %rax,%rax
je     1160 <scaleScalar+0x50>
movsd  0x0(%r13,%rbx,8),%xmm0
movsd  %xmm0,(%r14)
jmp    1160 <scaleScalar+0x50>
xor    %ebp,%ebp
jmp    1160 <scaleScalar+0x50>
movsd  (%r14),%xmm0
movapd %xmm0,%xmm1
subsd  (%r15),%xmm1
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm1
jne    11fd <scaleScalar+0xed>
jp     11fd <scaleScalar+0xed>
addsd  0xe1a(%rip),%xmm0
movsd  %xmm0,(%r14)
movsd  (%r15),%xmm0
addsd  0xe10(%rip),%xmm0
movsd  %xmm0,(%r15)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @scaleScalar(double* nocapture %0, i64 %1, double* nocapture %2, double* nocapture %3) {
%5 = icmp sgt i64 %1, 0
br i1 %5, label %6, label %41
6: ; preds = %4
%7 = getelementptr inbounds double, double* %0, i64 -1
br label %8
8: ; preds = %6, %37
%9 = phi double* [ %13, %37 ], [ %7, %6 ]
%10 = phi i32 [ %38, %37 ], [ 0, %6 ]
%11 = phi i64 [ %39, %37 ], [ 0, %6 ]
%12 = icmp eq i32 %10, 0
%13 = getelementptr inbounds double, double* %9, i64 1
%14 = load double, double* %13
br i1 %12, label %15, label %20
15: ; preds = %8
%16 = tail call i64 @isnormal(double %14)
%17 = icmp eq i64 %16, 0
br i1 %17, label %37, label %18
18: ; preds = %15
%19 = load double, double* %13
store double %19, double* %3
store double %19, double* %2
br label %37
20: ; preds = %8
%21 = load double, double* %2
%22 = fcmp olt double %14, %21
br i1 %22, label %23, label %28
23: ; preds = %20
%24 = tail call i64 @isnormal(double %14)
%25 = icmp eq i64 %24, 0
br i1 %25, label %28, label %26
26: ; preds = %23
%27 = load double, double* %13
store double %27, double* %2
br label %28
28: ; preds = %23, %26, %20
%29 = load double, double* %13
%30 = load double, double* %3
%31 = fcmp ogt double %29, %30
br i1 %31, label %32, label %37
32: ; preds = %28
%33 = tail call i64 @isnormal(double %29)
%34 = icmp eq i64 %33, 0
br i1 %34, label %37, label %35
35: ; preds = %32
%36 = load double, double* %13
store double %36, double* %3
br label %37
37: ; preds = %18, %15, %32, %35, %28
%38 = phi i32 [ 1, %18 ], [ 0, %15 ], [ 1, %35 ], [ 1, %32 ], [ 1, %28 ]
%39 = add nuw nsw i64 %11, 1
%40 = icmp eq i64 %39, %1
br i1 %40, label %41, label %8
41: ; preds = %37, %4
%42 = load double, double* %3
%43 = load double, double* %2
%44 = fsub double %42, %43
%45 = fcmp oeq double %44, 0.000000e+00
br i1 %45, label %46, label %50
46: ; preds = %41
%47 = fadd double %42, 1.000000e+00
store double %47, double* %3
%48 = load double, double* %2
%49 = fadd double %48, -1.000000e+00
store double %49, double* %2
br label %50
50: ; preds = %46, %41
ret void
}