#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 pow(double, double);
double sqrt(double);
double my_dnrm2_(int n, const double *x, int incx) {
  static double one = 1.0;
  static double zero = 0.0;
  int ix;
  double absxi, norm, scale, ssq;
  if (n < 1 || incx < 1)
    norm = zero;
  else if (n == 1)
    norm = fabs(x[0]);
  else {
    scale = zero;
    ssq = one;
    for (ix = 0; ix < 1 + (n - 1) * incx; ix += incx) {
      if (x[ix] != zero) {
        absxi = fabs(x[ix]);
        if (scale < absxi) {
          ssq = one + ssq * pow((scale / absxi), 2.0);
          scale = absxi;
        } else
          ssq += pow((absxi / scale), 2.0);
      }
    }
    norm = scale * sqrt(ssq);
  }
  return (norm);
}


x86 assembly (clang, -O0):
<my_dnrm2_>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0x1,-0x4(%rbp)
jl     1146 <my_dnrm2_+0x26>
cmpl   $0x1,-0x14(%rbp)
jge    1158 <my_dnrm2_+0x38>
movsd  0x2ef2(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    12c9 <my_dnrm2_+0x1a9>
cmpl   $0x1,-0x4(%rbp)
jne    117f <my_dnrm2_+0x5f>
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
movaps 0xe8f(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    12c4 <my_dnrm2_+0x1a4>
movsd  0x2eb9(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0x2e9c(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x4(%rbp),%ecx
sub    $0x1,%ecx
imul   -0x14(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    129f <my_dnrm2_+0x17f>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
ucomisd 0x2e73(%rip),%xmm0
jne    11de <my_dnrm2_+0xbe>
jp     11de <my_dnrm2_+0xbe>
jmp    128c <my_dnrm2_+0x16c>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movaps 0xe0e(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x30(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1266 <my_dnrm2_+0x146>
movsd  0x2e19(%rip),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x30(%rbp),%xmm0
divsd  -0x20(%rbp),%xmm0
movsd  0xdd8(%rip),%xmm1
call   1030 <pow@plt>
movsd  -0x48(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x40(%rbp),%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    1287 <my_dnrm2_+0x167>
movsd  -0x20(%rbp),%xmm0
divsd  -0x30(%rbp),%xmm0
movsd  0xd98(%rip),%xmm1
call   1030 <pow@plt>
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    128c <my_dnrm2_+0x16c>
jmp    1291 <my_dnrm2_+0x171>
mov    -0x14(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    11a0 <my_dnrm2_+0x80>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x38(%rbp),%xmm0
call   1040 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x50(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    12c9 <my_dnrm2_+0x1a9>
movsd  -0x28(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_dnrm2_>:
push   %rax
xorpd  %xmm6,%xmm6
test   %edi,%edi
jle    11dc <my_dnrm2_+0xcc>
test   %edx,%edx
jle    11dc <my_dnrm2_+0xcc>
cmp    $0x1,%edi
jne    1137 <my_dnrm2_+0x27>
movsd  (%rsi),%xmm0
andps  0xedb(%rip),%xmm0
pop    %rax
ret
add    $0xffffffff,%edi
imul   %edx,%edi
xorpd  %xmm1,%xmm1
test   %edi,%edi
js     11b1 <my_dnrm2_+0xa1>
mov    %edx,%eax
mov    %edi,%ecx
xorpd  %xmm2,%xmm2
movsd  0xeab(%rip),%xmm3
xor    %edx,%edx
movapd 0xeb1(%rip),%xmm4
movapd %xmm3,%xmm0
xorpd  %xmm6,%xmm6
jmp    1184 <my_dnrm2_+0x74>
nopl   0x0(%rax)
divsd  %xmm6,%xmm5
mulsd  %xmm5,%xmm5
addsd  %xmm5,%xmm0
add    %rax,%rdx
cmp    %rcx,%rdx
jg     11bd <my_dnrm2_+0xad>
movsd  (%rsi,%rdx,8),%xmm5
ucomisd %xmm2,%xmm5
jne    1191 <my_dnrm2_+0x81>
jnp    117c <my_dnrm2_+0x6c>
andpd  %xmm4,%xmm5
ucomisd %xmm6,%xmm5
jbe    1170 <my_dnrm2_+0x60>
divsd  %xmm5,%xmm6
mulsd  %xmm6,%xmm6
mulsd  %xmm6,%xmm0
addsd  %xmm3,%xmm0
movapd %xmm5,%xmm6
jmp    117c <my_dnrm2_+0x6c>
movsd  0xe47(%rip),%xmm0
xorpd  %xmm6,%xmm6
ucomisd %xmm1,%xmm0
jb     11c9 <my_dnrm2_+0xb9>
sqrtsd %xmm0,%xmm0
jmp    11d8 <my_dnrm2_+0xc8>
movsd  %xmm6,(%rsp)
call   1030 <sqrt@plt>
movsd  (%rsp),%xmm6
mulsd  %xmm0,%xmm6
movapd %xmm6,%xmm0
pop    %rax
ret

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

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