#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*/ dlassq_(int *, double *, int *, double *, double *);
double fabs(double);
double sqrt(double);
double dnrm2(int n, double *restrict x, int incx) {
  int ix;
  double absxi, norm, scale, ssq;
  if (n < 1 || incx < 1)
    norm = 0.;
  else if (n == 1)
    norm = fabs(x[0]);
  else {
    scale = 0.;
    ssq = 1.;
    dlassq_(&n, x, &incx, &scale, &ssq);
    norm = scale * sqrt(ssq);
  }
  return norm;
}


x86 assembly (clang, -O0):
<dnrm2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0x1,-0x4(%rbp)
jl     1146 <dnrm2+0x26>
cmpl   $0x1,-0x14(%rbp)
jge    1153 <dnrm2+0x33>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    11d2 <dnrm2+0xb2>
cmpl   $0x1,-0x4(%rbp)
jne    117a <dnrm2+0x5a>
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
movaps 0xea4(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    11cd <dnrm2+0xad>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xe76(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x10(%rbp),%rsi
lea    -0x4(%rbp),%rdi
lea    -0x14(%rbp),%rdx
lea    -0x30(%rbp),%rcx
lea    -0x38(%rbp),%r8
call   1030 <dlassq_@plt>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x38(%rbp),%xmm0
call   1040 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    11d2 <dnrm2+0xb2>
movsd  -0x28(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dnrm2>:
sub    $0x28,%rsp
mov    %edi,0xc(%rsp)
mov    %edx,0x8(%rsp)
xorpd  %xmm2,%xmm2
test   %edi,%edi
jle    11af <dnrm2+0x8f>
test   %edx,%edx
jle    11af <dnrm2+0x8f>
cmp    $0x1,%edi
jne    114d <dnrm2+0x2d>
movsd  (%rsi),%xmm0
andps  0xeb8(%rip),%xmm0
add    $0x28,%rsp
ret
movq   $0x0,0x18(%rsp)
movabs $0x3ff0000000000000,%rax
mov    %rax,0x10(%rsp)
lea    0xc(%rsp),%rdi
lea    0x8(%rsp),%rdx
lea    0x18(%rsp),%rcx
lea    0x10(%rsp),%r8
call   1030 <dlassq_@plt>
movsd  0x18(%rsp),%xmm2
movsd  0x10(%rsp),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     119a <dnrm2+0x7a>
sqrtsd %xmm0,%xmm0
jmp    11ab <dnrm2+0x8b>
movsd  %xmm2,0x20(%rsp)
call   1040 <sqrt@plt>
movsd  0x20(%rsp),%xmm2
mulsd  %xmm0,%xmm2
movapd %xmm2,%xmm0
add    $0x28,%rsp
ret

LLVM IR (-O0):
define double @dnrm2(i32 %0, double* noalias %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 %18
17: ; preds = %14, %3
store double 0.000000e+00, double* %9
br label %34
18: ; preds = %14
%19 = load i32, i32* %4
%20 = icmp eq i32 %19, 1
br i1 %20, label %21, label %26
21: ; preds = %18
%22 = load double*, double** %5
%23 = getelementptr inbounds double, double* %22, i64 0
%24 = load double, double* %23
%25 = call double @llvm.fabs.f64(double %24)
store double %25, double* %9
br label %33
26: ; preds = %18
store double 0.000000e+00, double* %10
store double 1.000000e+00, double* %11
%27 = load double*, double** %5
%28 = call i32 @dlassq_(i32* %4, double* %27, i32* %6, double* %10, double* %11)
%29 = load double, double* %10
%30 = load double, double* %11
%31 = call double @sqrt(double %30)
%32 = fmul double %29, %31
store double %32, double* %9
br label %33
33: ; preds = %26, %21
br label %34
34: ; preds = %33, %17
%35 = load double, double* %9
ret double %35
}

LLVM IR (-O2):
define double @dnrm2(i32 %0, double* noalias %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca double
%7 = alloca double
store i32 %0, i32* %4
store i32 %2, i32* %5
%8 = bitcast double* %6 to i8*
%9 = bitcast double* %7 to i8*
%10 = icmp slt i32 %0, 1
%11 = icmp slt i32 %2, 1
%12 = or i1 %10, %11
br i1 %12, label %24, label %13
13: ; preds = %3
%14 = icmp eq i32 %0, 1
br i1 %14, label %15, label %18
15: ; preds = %13
%16 = load double, double* %1
%17 = tail call double @llvm.fabs.f64(double %16)
br label %24
18: ; preds = %13
store double 0.000000e+00, double* %6
store double 1.000000e+00, double* %7
%19 = call i32 @dlassq_(i32* %4, double* %1, i32* %5, double* %6, double* %7)
%20 = load double, double* %6
%21 = load double, double* %7
%22 = call double @sqrt(double %21)
%23 = fmul double %20, %22
br label %24
24: ; preds = %3, %15, %18
%25 = phi double [ %17, %15 ], [ %23, %18 ], [ 0.000000e+00, %3 ]
ret double %25
}