#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 *darray(int, int);
double pow(int, double);
double *assign_GRnorm(double *mags, int N, double b, int Minf) {
  double dm;
  double norm;
  double *weights;
  double one;
  double mmax, mmin;
  double a = 1;
  if (N == 1) {
    weights = darray(1, 1);
    weights[1] = 1;
  } else {
    weights = darray(1, N);
    dm = mags[2] - mags[1];
    mmin = mags[1] - 0.5 * dm;
    mmax = mags[N] + 0.5 * dm;
    norm = Minf ? pow(10, a - b * mmin)
                : pow(10, a - b * mmin) - pow(10, a - b * mmax);
    for (int i = 1; i <= N; i++) {
      mmin = mags[i] - 0.5 * dm;
      mmax = mags[i] + 0.5 * dm;
      weights[i] = (pow(10, a - b * mmin) - pow(10, a - b * mmax)) / norm;
    }
    if (Minf)
      weights[N] = (pow(10, a - b * mmin)) / norm;
  }
  return weights;
}


x86 assembly (clang, -O0):
<assign_GRnorm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movsd  0xebe(%rip),%xmm0
movsd  %xmm0,-0x58(%rbp)
cmpl   $0x1,-0xc(%rbp)
jne    1177 <assign_GRnorm+0x57>
mov    $0x1,%esi
mov    %esi,%edi
call   1030 <darray@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
movsd  0xe93(%rip),%xmm0
movsd  %xmm0,0x8(%rax)
jmp    1420 <assign_GRnorm+0x300>
mov    -0xc(%rbp),%esi
mov    $0x1,%edi
call   1030 <darray@plt>
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm0
mov    -0x8(%rbp),%rax
subsd  0x8(%rax),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm1
movsd  -0x28(%rbp),%xmm0
movsd  0xe5b(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
movsd  -0x28(%rbp),%xmm0
movsd  0xe2c(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1235 <assign_GRnorm+0x115>
movsd  -0x58(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    $0xa,%edi
call   1040 <pow@plt>
movsd  %xmm0,-0x68(%rbp)
jmp    12bb <assign_GRnorm+0x19b>
movsd  -0x58(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    $0xa,%edi
call   1040 <pow@plt>
movsd  %xmm0,-0x70(%rbp)
movsd  -0x58(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    $0xa,%edi
call   1040 <pow@plt>
movaps %xmm0,%xmm1
movsd  -0x70(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x68(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x1,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     13c7 <assign_GRnorm+0x2a7>
mov    -0x8(%rbp),%rax
movslq -0x5c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
movsd  -0x28(%rbp),%xmm0
movsd  0xd1e(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x5c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
movsd  -0x28(%rbp),%xmm0
movsd  0xcef(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x58(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    $0xa,%edi
call   1040 <pow@plt>
movsd  %xmm0,-0x78(%rbp)
movsd  -0x58(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    $0xa,%edi
call   1040 <pow@plt>
movaps %xmm0,%xmm1
movsd  -0x78(%rbp),%xmm0
subsd  %xmm1,%xmm0
divsd  -0x30(%rbp),%xmm0
mov    -0x38(%rbp),%rax
movslq -0x5c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    12cc <assign_GRnorm+0x1ac>
cmpl   $0x0,-0x1c(%rbp)
je     141b <assign_GRnorm+0x2fb>
movsd  -0x58(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    $0xa,%edi
call   1040 <pow@plt>
divsd  -0x30(%rbp),%xmm0
mov    -0x38(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    1420 <assign_GRnorm+0x300>
mov    -0x38(%rbp),%rax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<assign_GRnorm>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
movapd %xmm0,0x10(%rsp)
cmp    $0x1,%esi
jne    115e <assign_GRnorm+0x3e>
mov    $0x1,%edi
mov    $0x1,%esi
call   1030 <darray@plt>
mov    %rax,%r15
movabs $0x3ff0000000000000,%rax
mov    %rax,0x8(%r15)
jmp    1347 <assign_GRnorm+0x227>
mov    %edx,%r14d
mov    %esi,%ebp
mov    %rdi,%r13
mov    $0x1,%edi
call   1030 <darray@plt>
mov    %rax,%r15
movsd  0x8(%r13),%xmm2
movsd  0x10(%r13),%xmm0
subsd  %xmm2,%xmm0
movsd  0xe75(%rip),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x28(%rsp)
addsd  %xmm1,%xmm2
movslq %ebp,%r12
test   %r14d,%r14d
movsd  %xmm0,0x8(%rsp)
movsd  %xmm2,0x20(%rsp)
je     11d3 <assign_GRnorm+0xb3>
movapd 0x10(%rsp),%xmm1
mulsd  %xmm2,%xmm1
movsd  0xe49(%rip),%xmm0
subsd  %xmm1,%xmm0
mov    $0xa,%edi
call   1040 <pow@plt>
movapd %xmm0,%xmm1
jmp    123c <assign_GRnorm+0x11c>
movsd  0xe35(%rip),%xmm1
mulsd  %xmm0,%xmm1
addsd  0x0(%r13,%r12,8),%xmm1
movsd  %xmm1,0x30(%rsp)
movapd 0x10(%rsp),%xmm1
mulsd  %xmm2,%xmm1
movsd  0xe0a(%rip),%xmm0
subsd  %xmm1,%xmm0
mov    $0xa,%edi
call   1040 <pow@plt>
movsd  %xmm0,(%rsp)
movsd  0x30(%rsp),%xmm1
mulsd  0x10(%rsp),%xmm1
movsd  0xde3(%rip),%xmm0
subsd  %xmm1,%xmm0
mov    $0xa,%edi
call   1040 <pow@plt>
movsd  (%rsp),%xmm1
subsd  %xmm0,%xmm1
test   %ebp,%ebp
movsd  0x8(%rsp),%xmm0
movsd  0x28(%rsp),%xmm2
movsd  %xmm1,(%rsp)
jle    1311 <assign_GRnorm+0x1f1>
movapd 0xdc3(%rip),%xmm3
xorpd  0x10(%rsp),%xmm3
movapd %xmm3,0x30(%rsp)
add    $0x1,%ebp
mov    $0x1,%ebx
mulsd  0xd97(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
nop
movsd  0x0(%r13,%rbx,8),%xmm1
addsd  %xmm1,%xmm2
addsd  %xmm0,%xmm1
movsd  %xmm1,0x48(%rsp)
movapd 0x30(%rsp),%xmm0
movsd  %xmm2,0x20(%rsp)
mulsd  %xmm2,%xmm0
movsd  0xd5b(%rip),%xmm1
addsd  %xmm1,%xmm0
mov    $0xa,%edi
call   1040 <pow@plt>
movsd  %xmm0,0x50(%rsp)
movsd  0x48(%rsp),%xmm0
mulsd  0x30(%rsp),%xmm0
addsd  0xd33(%rip),%xmm0
mov    $0xa,%edi
call   1040 <pow@plt>
movsd  0x28(%rsp),%xmm2
movsd  (%rsp),%xmm1
movsd  0x50(%rsp),%xmm3
subsd  %xmm0,%xmm3
movsd  0x8(%rsp),%xmm0
divsd  %xmm1,%xmm3
movsd  %xmm3,(%r15,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1280 <assign_GRnorm+0x160>
movsd  0x20(%rsp),%xmm0
test   %r14d,%r14d
je     1347 <assign_GRnorm+0x227>
movapd 0x10(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movsd  0xcda(%rip),%xmm0
subsd  %xmm1,%xmm0
mov    $0xa,%edi
call   1040 <pow@plt>
divsd  (%rsp),%xmm0
movsd  %xmm0,(%r15,%r12,8)
mov    %r15,%rax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double* @assign_GRnorm(double* %0, i32 %1, double %2, i32 %3) {
%5 = alloca double*
%6 = alloca i32
%7 = alloca double
%8 = alloca i32
%9 = alloca double
%10 = alloca double
%11 = alloca double*
%12 = alloca double
%13 = alloca double
%14 = alloca double
%15 = alloca double
%16 = alloca i32
store double* %0, double** %5
store i32 %1, i32* %6
store double %2, double* %7
store i32 %3, i32* %8
store double 1.000000e+00, double* %15
%17 = load i32, i32* %6
%18 = icmp eq i32 %17, 1
br i1 %18, label %19, label %23
19: ; preds = %4
%20 = call double* @darray(i32 1, i32 1)
store double* %20, double** %11
%21 = load double*, double** %11
%22 = getelementptr inbounds double, double* %21, i64 1
store double 1.000000e+00, double* %22
br label %128
23: ; preds = %4
%24 = load i32, i32* %6
%25 = call double* @darray(i32 1, i32 %24)
store double* %25, double** %11
%26 = load double*, double** %5
%27 = getelementptr inbounds double, double* %26, i64 2
%28 = load double, double* %27
%29 = load double*, double** %5
%30 = getelementptr inbounds double, double* %29, i64 1
%31 = load double, double* %30
%32 = fsub double %28, %31
store double %32, double* %9
%33 = load double*, double** %5
%34 = getelementptr inbounds double, double* %33, i64 1
%35 = load double, double* %34
%36 = load double, double* %9
%37 = call double @llvm.fmuladd.f64(double -5.000000e-01, double %36, double %35)
store double %37, double* %14
%38 = load double*, double** %5
%39 = load i32, i32* %6
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds double, double* %38, i64 %40
%42 = load double, double* %41
%43 = load double, double* %9
%44 = call double @llvm.fmuladd.f64(double 5.000000e-01, double %43, double %42)
store double %44, double* %13
%45 = load i32, i32* %8
%46 = icmp ne i32 %45, 0
br i1 %46, label %47, label %54
47: ; preds = %23
%48 = load double, double* %15
%49 = load double, double* %7
%50 = load double, double* %14
%51 = fneg double %49
%52 = call double @llvm.fmuladd.f64(double %51, double %50, double %48)
%53 = call double @pow(i32 10, double %52)
br label %68
54: ; preds = %23
%55 = load double, double* %15
%56 = load double, double* %7
%57 = load double, double* %14
%58 = fneg double %56
%59 = call double @llvm.fmuladd.f64(double %58, double %57, double %55)
%60 = call double @pow(i32 10, double %59)
%61 = load double, double* %15
%62 = load double, double* %7
%63 = load double, double* %13
%64 = fneg double %62
%65 = call double @llvm.fmuladd.f64(double %64, double %63, double %61)
%66 = call double @pow(i32 10, double %65)
%67 = fsub double %60, %66
br label %68
68: ; preds = %54, %47
%69 = phi double [ %53, %47 ], [ %67, %54 ]
store double %69, double* %10
store i32 1, i32* %16
br label %70
70: ; preds = %108, %68
%71 = load i32, i32* %16
%72 = load i32, i32* %6
%73 = icmp sle i32 %71, %72
br i1 %73, label %74, label %111
74: ; preds = %70
%75 = load double*, double** %5
%76 = load i32, i32* %16
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds double, double* %75, i64 %77
%79 = load double, double* %78
%80 = load double, double* %9
%81 = call double @llvm.fmuladd.f64(double -5.000000e-01, double %80, double %79)
store double %81, double* %14
%82 = load double*, double** %5
%83 = load i32, i32* %16
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds double, double* %82, i64 %84
%86 = load double, double* %85
%87 = load double, double* %9
%88 = call double @llvm.fmuladd.f64(double 5.000000e-01, double %87, double %86)
store double %88, double* %13
%89 = load double, double* %15
%90 = load double, double* %7
%91 = load double, double* %14
%92 = fneg double %90
%93 = call double @llvm.fmuladd.f64(double %92, double %91, double %89)
%94 = call double @pow(i32 10, double %93)
%95 = load double, double* %15
%96 = load double, double* %7
%97 = load double, double* %13
%98 = fneg double %96
%99 = call double @llvm.fmuladd.f64(double %98, double %97, double %95)
%100 = call double @pow(i32 10, double %99)
%101 = fsub double %94, %100
%102 = load double, double* %10
%103 = fdiv double %101, %102
%104 = load double*, double** %11
%105 = load i32, i32* %16
%106 = sext i32 %105 to i64
%107 = getelementptr inbounds double, double* %104, i64 %106
store double %103, double* %107
br label %108
108: ; preds = %74
%109 = load i32, i32* %16
%110 = add nsw i32 %109, 1
store i32 %110, i32* %16
br label %70
111: ; preds = %70
%112 = load i32, i32* %8
%113 = icmp ne i32 %112, 0
br i1 %113, label %114, label %127
114: ; preds = %111
%115 = load double, double* %15
%116 = load double, double* %7
%117 = load double, double* %14
%118 = fneg double %116
%119 = call double @llvm.fmuladd.f64(double %118, double %117, double %115)
%120 = call double @pow(i32 10, double %119)
%121 = load double, double* %10
%122 = fdiv double %120, %121
%123 = load double*, double** %11
%124 = load i32, i32* %6
%125 = sext i32 %124 to i64
%126 = getelementptr inbounds double, double* %123, i64 %125
store double %122, double* %126
br label %127
127: ; preds = %114, %111
br label %128
128: ; preds = %127, %19
%129 = load double*, double** %11
ret double* %129
}

LLVM IR (-O2):
define double* @assign_GRnorm(double* nocapture %0, i32 %1, double %2, i32 %3) {
%5 = icmp eq i32 %1, 1
br i1 %5, label %6, label %9
6: ; preds = %4
%7 = tail call double* @darray(i32 1, i32 1)
%8 = getelementptr inbounds double, double* %7, i64 1
store double 1.000000e+00, double* %8
br label %63
9: ; preds = %4
%10 = tail call double* @darray(i32 1, i32 %1)
%11 = getelementptr inbounds double, double* %0, i64 2
%12 = load double, double* %11
%13 = getelementptr inbounds double, double* %0, i64 1
%14 = load double, double* %13
%15 = fsub double %12, %14
%16 = tail call double @llvm.fmuladd.f64(double %15, double -5.000000e-01, double %14)
%17 = sext i32 %1 to i64
%18 = icmp eq i32 %3, 0
br i1 %18, label %23, label %19
19: ; preds = %9
%20 = fneg double %2
%21 = tail call double @llvm.fmuladd.f64(double %20, double %16, double 1.000000e+00)
%22 = tail call double @pow(i32 10, double %21)
br label %33
23: ; preds = %9
%24 = getelementptr inbounds double, double* %0, i64 %17
%25 = load double, double* %24
%26 = tail call double @llvm.fmuladd.f64(double %15, double 5.000000e-01, double %25)
%27 = fneg double %2
%28 = tail call double @llvm.fmuladd.f64(double %27, double %16, double 1.000000e+00)
%29 = tail call double @pow(i32 10, double %28)
%30 = tail call double @llvm.fmuladd.f64(double %27, double %26, double 1.000000e+00)
%31 = tail call double @pow(i32 10, double %30)
%32 = fsub double %29, %31
br label %33
33: ; preds = %23, %19
%34 = phi double [ %22, %19 ], [ %32, %23 ]
%35 = icmp slt i32 %1, 1
br i1 %35, label %40, label %36
36: ; preds = %33
%37 = fneg double %2
%38 = add nuw i32 %1, 1
%39 = zext i32 %38 to i64
br label %42
40: ; preds = %42, %33
%41 = phi double [ %16, %33 ], [ %46, %42 ]
br i1 %18, label %63, label %57
42: ; preds = %36, %42
%43 = phi i64 [ 1, %36 ], [ %55, %42 ]
%44 = getelementptr inbounds double, double* %0, i64 %43
%45 = load double, double* %44
%46 = tail call double @llvm.fmuladd.f64(double %15, double -5.000000e-01, double %45)
%47 = tail call double @llvm.fmuladd.f64(double %15, double 5.000000e-01, double %45)
%48 = tail call double @llvm.fmuladd.f64(double %37, double %46, double 1.000000e+00)
%49 = tail call double @pow(i32 10, double %48)
%50 = tail call double @llvm.fmuladd.f64(double %37, double %47, double 1.000000e+00)
%51 = tail call double @pow(i32 10, double %50)
%52 = fsub double %49, %51
%53 = fdiv double %52, %34
%54 = getelementptr inbounds double, double* %10, i64 %43
store double %53, double* %54
%55 = add nuw nsw i64 %43, 1
%56 = icmp eq i64 %55, %39
br i1 %56, label %40, label %42
57: ; preds = %40
%58 = fneg double %2
%59 = tail call double @llvm.fmuladd.f64(double %58, double %41, double 1.000000e+00)
%60 = tail call double @pow(i32 10, double %59)
%61 = fdiv double %60, %34
%62 = getelementptr inbounds double, double* %10, i64 %17
store double %61, double* %62
br label %63
63: ; preds = %40, %57, %6
%64 = phi double* [ %7, %6 ], [ %10, %57 ], [ %10, %40 ]
ret double* %64
}