#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);
double pow(double, double const);
double dnrm3(const int n, double *restrict x, const int p) {
  int i;
  const double dp = (double)p;
  double absxi;
  double scale = 0., ssq = 1.;
  double nrm = 0.;
  if (n < 1)
    return 0.;
  else if (n == 1)
    return fabs(x[0]);
  for (i = 0; i < n; i++) {
    if (x[i] != 0) {
      absxi = fabs(x[i]);
      if (scale < absxi) {
        ssq = 1. + ssq * pow(scale / absxi, dp);
        scale = absxi;
      } else
        ssq += pow(absxi / scale, dp);
    }
  }
  nrm = scale * pow(ssq, 1. / dp);
  return nrm;
}


x86 assembly (clang, -O0):
<dnrm3>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cvtsi2sdl -0x1c(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  0xec4(%rip),%xmm0
movsd  %xmm0,-0x40(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
cmpl   $0x1,-0xc(%rbp)
jge    1160 <dnrm3+0x50>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12b1 <dnrm3+0x1a1>
cmpl   $0x1,-0xc(%rbp)
jne    1187 <dnrm3+0x77>
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
movaps 0xe97(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12b1 <dnrm3+0x1a1>
jmp    118c <dnrm3+0x7c>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1275 <dnrm3+0x165>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11c4 <dnrm3+0xb4>
jp     11c4 <dnrm3+0xb4>
jmp    1262 <dnrm3+0x152>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movaps 0xe38(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x38(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    123f <dnrm3+0x12f>
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x38(%rbp),%xmm0
divsd  -0x30(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
call   1030 <pow@plt>
movaps %xmm0,%xmm1
movsd  -0x50(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  0xdd9(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    125d <dnrm3+0x14d>
movsd  -0x30(%rbp),%xmm0
divsd  -0x38(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
call   1030 <pow@plt>
addsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
jmp    1262 <dnrm3+0x152>
jmp    1267 <dnrm3+0x157>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1193 <dnrm3+0x83>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  0xd74(%rip),%xmm1
divsd  -0x28(%rbp),%xmm1
call   1030 <pow@plt>
movaps %xmm0,%xmm1
movsd  -0x58(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dnrm3>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
test   %edi,%edi
jle    1136 <dnrm3+0x26>
mov    %rsi,%r14
cmp    $0x1,%edi
jne    113e <dnrm3+0x2e>
movsd  (%r14),%xmm0
andps  0xedf(%rip),%xmm0
jmp    1212 <dnrm3+0x102>
xorps  %xmm0,%xmm0
jmp    1212 <dnrm3+0x102>
cvtsi2sd %edx,%xmm0
movsd  %xmm0,0x10(%rsp)
mov    %edi,%r15d
movsd  0xead(%rip),%xmm2
xor    %ebx,%ebx
xorpd  %xmm0,%xmm0
jmp    1190 <dnrm3+0x80>
nopl   0x0(%rax,%rax,1)
divsd  %xmm0,%xmm1
movsd  %xmm0,(%rsp)
movapd %xmm1,%xmm0
movsd  0x10(%rsp),%xmm1
call   1030 <pow@plt>
movsd  0x18(%rsp),%xmm2
addsd  %xmm0,%xmm2
movsd  (%rsp),%xmm0
add    $0x1,%rbx
cmp    %rbx,%r15
je     11e3 <dnrm3+0xd3>
movsd  (%r14,%rbx,8),%xmm1
ucomisd 0xe6a(%rip),%xmm1
jne    11a2 <dnrm3+0x92>
jnp    1187 <dnrm3+0x77>
andpd  0xe66(%rip),%xmm1
ucomisd %xmm0,%xmm1
movsd  %xmm2,0x18(%rsp)
jbe    1160 <dnrm3+0x50>
divsd  %xmm1,%xmm0
movapd %xmm1,(%rsp)
movsd  0x10(%rsp),%xmm1
call   1030 <pow@plt>
movsd  0x18(%rsp),%xmm2
mulsd  %xmm0,%xmm2
addsd  0xe24(%rip),%xmm2
movapd (%rsp),%xmm0
jmp    1187 <dnrm3+0x77>
movsd  0xe15(%rip),%xmm1
divsd  0x10(%rsp),%xmm1
movsd  %xmm0,(%rsp)
movapd %xmm2,%xmm0
call   1030 <pow@plt>
movsd  (%rsp),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movsd  (%rsp),%xmm0
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

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