#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 /*<<< orphan*/ isnan(double);
double sqrt(double);
void rescalesigma_chi2(int N, double *sig, double chi2val) {
  int i;
  double factor;
  factor = sqrt(chi2val);
  for (i = 0; i < N; i++) {
    if (sig[i] > 0. && !isnan(sig[i]))
      sig[i] = sig[i] * factor;
  }
}


x86 assembly (clang, -O0):
<rescalesigma_chi2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1040 <sqrt@plt>
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11bd <rescalesigma_chi2+0x9d>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11aa <rescalesigma_chi2+0x8a>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1030 <isnan@plt>
cmp    $0x0,%eax
jne    11aa <rescalesigma_chi2+0x8a>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mulsd  -0x28(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    11af <rescalesigma_chi2+0x8f>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    114a <rescalesigma_chi2+0x2a>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rescalesigma_chi2>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %edi,%ebp
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     113d <rescalesigma_chi2+0x1d>
sqrtsd %xmm0,%xmm0
jmp    1142 <rescalesigma_chi2+0x22>
call   1040 <sqrt@plt>
movsd  %xmm0,0x8(%rsp)
test   %ebp,%ebp
jle    1196 <rescalesigma_chi2+0x76>
mov    %ebp,%ebp
xor    %ebx,%ebx
xorpd  %xmm1,%xmm1
jmp    1169 <rescalesigma_chi2+0x49>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%rbx
cmp    %rbx,%rbp
je     1196 <rescalesigma_chi2+0x76>
movsd  (%r14,%rbx,8),%xmm0
ucomisd %xmm1,%xmm0
jbe    1160 <rescalesigma_chi2+0x40>
call   1030 <isnan@plt>
xorpd  %xmm1,%xmm1
test   %eax,%eax
jne    1160 <rescalesigma_chi2+0x40>
movsd  (%r14,%rbx,8),%xmm0
mulsd  0x8(%rsp),%xmm0
movsd  %xmm0,(%r14,%rbx,8)
jmp    1160 <rescalesigma_chi2+0x40>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @rescalesigma_chi2(i32 %0, double* %1, double %2) {
%4 = alloca i32
%5 = alloca double*
%6 = alloca double
%7 = alloca i32
%8 = alloca double
store i32 %0, i32* %4
store double* %1, double** %5
store double %2, double* %6
%9 = load double, double* %6
%10 = call double @sqrt(double %9)
store double %10, double* %8
store i32 0, i32* %7
br label %11
11: ; preds = %43, %3
%12 = load i32, i32* %7
%13 = load i32, i32* %4
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %46
15: ; preds = %11
%16 = load double*, double** %5
%17 = load i32, i32* %7
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds double, double* %16, i64 %18
%20 = load double, double* %19
%21 = fcmp ogt double %20, 0.000000e+00
br i1 %21, label %22, label %42
22: ; preds = %15
%23 = load double*, double** %5
%24 = load i32, i32* %7
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds double, double* %23, i64 %25
%27 = load double, double* %26
%28 = call i32 @isnan(double %27)
%29 = icmp ne i32 %28, 0
br i1 %29, label %42, label %30
30: ; preds = %22
%31 = load double*, double** %5
%32 = load i32, i32* %7
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds double, double* %31, i64 %33
%35 = load double, double* %34
%36 = load double, double* %8
%37 = fmul double %35, %36
%38 = load double*, double** %5
%39 = load i32, i32* %7
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds double, double* %38, i64 %40
store double %37, double* %41
br label %42
42: ; preds = %30, %22, %15
br label %43
43: ; preds = %42
%44 = load i32, i32* %7
%45 = add nsw i32 %44, 1
store i32 %45, i32* %7
br label %11
46: ; preds = %11
ret void
}

LLVM IR (-O2):
define void @rescalesigma_chi2(i32 %0, double* nocapture %1, double %2) {
%4 = tail call double @sqrt(double %2)
%5 = icmp sgt i32 %0, 0
br i1 %5, label %6, label %22
6: ; preds = %3
%7 = zext i32 %0 to i64
br label %8
8: ; preds = %6, %19
%9 = phi i64 [ 0, %6 ], [ %20, %19 ]
%10 = getelementptr inbounds double, double* %1, i64 %9
%11 = load double, double* %10
%12 = fcmp ogt double %11, 0.000000e+00
br i1 %12, label %13, label %19
13: ; preds = %8
%14 = tail call i32 @isnan(double %11)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = load double, double* %10
%18 = fmul double %4, %17
store double %18, double* %10
br label %19
19: ; preds = %8, %13, %16
%20 = add nuw nsw i64 %9, 1
%21 = icmp eq i64 %20, %7
br i1 %21, label %22, label %8
22: ; preds = %19, %3
ret void
}