#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 fabs(double const);
double sqrt(double);
double xnrm2(int n, const double x_data[], int ix0) {
  double absxk;
  double scale;
  double t;
  double y;
  int k;
  int kend;
  y = 0.0;
  if (n >= 1) {
    if (n == 1) {
      y = fabs(x_data[ix0 - 1]);
    } else {
      scale = 3.3121686421112381E-170;
      kend = (ix0 + n) - 1;
      for (k = ix0; k <= kend; k++) {
        absxk = fabs(x_data[k - 1]);
        if (absxk > scale) {
          t = scale / absxk;
          y = y * t * t + 1.0;
          scale = absxk;
        } else {
          t = absxk / scale;
          y += t * t;
        }
      }
      y = scale * sqrt(y);
    }
  }
  return y;
}


x86 assembly (clang, -O0):
<xnrm2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
cmpl   $0x1,-0x4(%rbp)
jl     126c <xnrm2+0x15c>
cmpl   $0x1,-0x4(%rbp)
jne    1165 <xnrm2+0x55>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movaps 0xeb9(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    1267 <xnrm2+0x157>
movsd  0xe93(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x14(%rbp),%eax
add    -0x4(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x40(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x40(%rbp),%eax
jg     1242 <xnrm2+0x132>
mov    -0x10(%rbp),%rax
mov    -0x3c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movaps 0xe67(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
ucomisd -0x28(%rbp),%xmm0
jbe    1204 <xnrm2+0xf4>
movsd  -0x28(%rbp),%xmm0
divsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x38(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe1c(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    122f <xnrm2+0x11f>
movsd  -0x20(%rbp),%xmm0
divsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm2
movsd  -0x38(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    1234 <xnrm2+0x124>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1184 <xnrm2+0x74>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x38(%rbp),%xmm0
call   1030 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x48(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    126c <xnrm2+0x15c>
movsd  -0x38(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xnrm2>:
push   %rax
test   %edi,%edi
jle    112c <xnrm2+0x1c>
cmp    $0x1,%edi
jne    1135 <xnrm2+0x25>
movslq %edx,%rax
movsd  -0x8(%rsi,%rax,8),%xmm0
andps  0xee6(%rip),%xmm0
pop    %rax
ret
xorpd  %xmm4,%xmm4
jmp    11be <xnrm2+0xae>
add    %edx,%edi
movslq %edx,%rax
movslq %edi,%rcx
xorpd  %xmm0,%xmm0
movsd  0xeb7(%rip),%xmm4
movapd 0xebf(%rip),%xmm1
movsd  0xeaf(%rip),%xmm2
jmp    1175 <xnrm2+0x65>
nopl   0x0(%rax,%rax,1)
divsd  %xmm4,%xmm3
mulsd  %xmm3,%xmm3
addsd  %xmm3,%xmm0
add    $0x1,%rax
cmp    %rcx,%rax
jge    119b <xnrm2+0x8b>
movsd  -0x8(%rsi,%rax,8),%xmm3
andpd  %xmm1,%xmm3
ucomisd %xmm4,%xmm3
jbe    1160 <xnrm2+0x50>
divsd  %xmm3,%xmm4
mulsd  %xmm4,%xmm0
mulsd  %xmm4,%xmm0
addsd  %xmm2,%xmm0
movapd %xmm3,%xmm4
jmp    116c <xnrm2+0x5c>
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11ab <xnrm2+0x9b>
sqrtsd %xmm0,%xmm0
jmp    11ba <xnrm2+0xaa>
movsd  %xmm4,(%rsp)
call   1030 <sqrt@plt>
movsd  (%rsp),%xmm4
mulsd  %xmm0,%xmm4
movapd %xmm4,%xmm0
pop    %rax
ret

LLVM IR (-O0):
define double @xnrm2(i32 %0, double* %1, i32 %2) {
%4 = alloca i32
%5 = alloca double*
%6 = alloca i32
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca i32
%12 = alloca i32
store i32 %0, i32* %4
store double* %1, double** %5
store i32 %2, i32* %6
store double 0.000000e+00, double* %10
%13 = load i32, i32* %4
%14 = icmp sge i32 %13, 1
br i1 %14, label %15, label %75
15: ; preds = %3
%16 = load i32, i32* %4
%17 = icmp eq i32 %16, 1
br i1 %17, label %18, label %26
18: ; preds = %15
%19 = load double*, double** %5
%20 = load i32, i32* %6
%21 = sub nsw i32 %20, 1
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds double, double* %19, i64 %22
%24 = load double, double* %23
%25 = call double @llvm.fabs.f64(double %24)
store double %25, double* %10
br label %74
26: ; preds = %15
store double 0x1CC0000000000000, double* %8
%27 = load i32, i32* %6
%28 = load i32, i32* %4
%29 = add nsw i32 %27, %28
%30 = sub nsw i32 %29, 1
store i32 %30, i32* %12
%31 = load i32, i32* %6
store i32 %31, i32* %11
br label %32
32: ; preds = %66, %26
%33 = load i32, i32* %11
%34 = load i32, i32* %12
%35 = icmp sle i32 %33, %34
br i1 %35, label %36, label %69
36: ; preds = %32
%37 = load double*, double** %5
%38 = load i32, i32* %11
%39 = sub nsw i32 %38, 1
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds double, double* %37, i64 %40
%42 = load double, double* %41
%43 = call double @llvm.fabs.f64(double %42)
store double %43, double* %7
%44 = load double, double* %7
%45 = load double, double* %8
%46 = fcmp ogt double %44, %45
br i1 %46, label %47, label %57
47: ; preds = %36
%48 = load double, double* %8
%49 = load double, double* %7
%50 = fdiv double %48, %49
store double %50, double* %9
%51 = load double, double* %10
%52 = load double, double* %9
%53 = fmul double %51, %52
%54 = load double, double* %9
%55 = call double @llvm.fmuladd.f64(double %53, double %54, double 1.000000e+00)
store double %55, double* %10
%56 = load double, double* %7
store double %56, double* %8
br label %65
57: ; preds = %36
%58 = load double, double* %7
%59 = load double, double* %8
%60 = fdiv double %58, %59
store double %60, double* %9
%61 = load double, double* %9
%62 = load double, double* %9
%63 = load double, double* %10
%64 = call double @llvm.fmuladd.f64(double %61, double %62, double %63)
store double %64, double* %10
br label %65
65: ; preds = %57, %47
br label %66
66: ; preds = %65
%67 = load i32, i32* %11
%68 = add nsw i32 %67, 1
store i32 %68, i32* %11
br label %32
69: ; preds = %32
%70 = load double, double* %8
%71 = load double, double* %10
%72 = call double @sqrt(double %71)
%73 = fmul double %70, %72
store double %73, double* %10
br label %74
74: ; preds = %69, %18
br label %75
75: ; preds = %74, %3
%76 = load double, double* %10
ret double %76
}

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