#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*/ printf(char *, ...);
double sqrt(double);
int cpu2norm_d_in_c(int n, double *x, double *nrm) {
  int i;
  *nrm = 0.0;
  printf("The C function received as dimension %d\n", n);
  printf("The components of the vector :\n");
  for (i = 0; i < n; i++) {
    printf("%22.15le  %22.15le\n", x[2 * i], x[2 * i + 1]);
    *nrm = *nrm + x[2 * i] * x[2 * i] + x[2 * i + 1] * x[2 * i + 1];
  }
  *nrm = sqrt(*nrm);
  printf("The 2-norms is %.15le\n", *nrm);
  return 0;
}


x86 assembly (clang, -O0):
<cpu2norm_d_in_c>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
mov    -0x4(%rbp),%esi
lea    0xeb8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1221 <cpu2norm_d_in_c+0x101>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
shl    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
shl    $0x1,%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm1
lea    0xeab(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
shl    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
shl    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
shl    $0x1,%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
shl    $0x1,%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1164 <cpu2norm_d_in_c+0x44>
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
call   1040 <sqrt@plt>
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
lea    0xe18(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cpu2norm_d_in_c>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%ebp
movq   $0x0,(%rdx)
lea    0xeb2(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xef6(%rip),%rdi
call   1030 <puts@plt>
test   %ebp,%ebp
jle    11c1 <cpu2norm_d_in_c+0x91>
mov    %ebp,%r12d
shl    $0x4,%r12
xor    %ebp,%ebp
lea    0xeb2(%rip),%r15
nopw   0x0(%rax,%rax,1)
movsd  (%rbx,%rbp,1),%xmm0
movsd  0x8(%rbx,%rbp,1),%xmm1
mov    %r15,%rdi
mov    $0x2,%al
call   1040 <printf@plt>
movsd  (%rbx,%rbp,1),%xmm1
movsd  0x8(%rbx,%rbp,1),%xmm0
mulsd  %xmm1,%xmm1
addsd  (%r14),%xmm1
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%r14)
add    $0x10,%rbp
cmp    %rbp,%r12
jne    1180 <cpu2norm_d_in_c+0x50>
jmp    11c6 <cpu2norm_d_in_c+0x96>
movsd  (%r14),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11d6 <cpu2norm_d_in_c+0xa6>
sqrtsd %xmm0,%xmm0
jmp    11db <cpu2norm_d_in_c+0xab>
call   1050 <sqrt@plt>
movsd  %xmm0,(%r14)
lea    0xe56(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [41 x i8] c"The C function received as dimension %d\0A\00"
@.str.1 = [32 x i8] c"The components of the vector :\0A\00"
@.str.2 = [20 x i8] c"%22.15le %22.15le\0A\00"
@.str.3 = [23 x i8] c"The 2-norms is %.15le\0A\00"
define i32 @cpu2norm_d_in_c(i32 %0, double* %1, double* %2) {
%4 = alloca i32
%5 = alloca double*
%6 = alloca double*
%7 = alloca i32
store i32 %0, i32* %4
store double* %1, double** %5
store double* %2, double** %6
%8 = load double*, double** %6
store double 0.000000e+00, double* %8
%9 = load i32, i32* %4
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %7
br label %12
12: ; preds = %62, %3
%13 = load i32, i32* %7
%14 = load i32, i32* %4
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %65
16: ; preds = %12
%17 = load double*, double** %5
%18 = load i32, i32* %7
%19 = mul nsw i32 2, %18
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds double, double* %17, i64 %20
%22 = load double, double* %21
%23 = load double*, double** %5
%24 = load i32, i32* %7
%25 = mul nsw i32 2, %24
%26 = add nsw i32 %25, 1
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds double, double* %23, i64 %27
%29 = load double, double* %28
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), double %22, double %29)
%31 = load double*, double** %6
%32 = load double, double* %31
%33 = load double*, double** %5
%34 = load i32, i32* %7
%35 = mul nsw i32 2, %34
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds double, double* %33, i64 %36
%38 = load double, double* %37
%39 = load double*, double** %5
%40 = load i32, i32* %7
%41 = mul nsw i32 2, %40
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds double, double* %39, i64 %42
%44 = load double, double* %43
%45 = call double @llvm.fmuladd.f64(double %38, double %44, double %32)
%46 = load double*, double** %5
%47 = load i32, i32* %7
%48 = mul nsw i32 2, %47
%49 = add nsw i32 %48, 1
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds double, double* %46, i64 %50
%52 = load double, double* %51
%53 = load double*, double** %5
%54 = load i32, i32* %7
%55 = mul nsw i32 2, %54
%56 = add nsw i32 %55, 1
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds double, double* %53, i64 %57
%59 = load double, double* %58
%60 = call double @llvm.fmuladd.f64(double %52, double %59, double %45)
%61 = load double*, double** %6
store double %60, double* %61
br label %62
62: ; preds = %16
%63 = load i32, i32* %7
%64 = add nsw i32 %63, 1
store i32 %64, i32* %7
br label %12
65: ; preds = %12
%66 = load double*, double** %6
%67 = load double, double* %66
%68 = call double @sqrt(double %67)
%69 = load double*, double** %6
store double %68, double* %69
%70 = load double*, double** %6
%71 = load double, double* %70
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), double %71)
ret i32 0
}

LLVM IR (-O2):
@.str = [41 x i8] c"The C function received as dimension %d\0A\00"
@.str.2 = [20 x i8] c"%22.15le %22.15le\0A\00"
@.str.3 = [23 x i8] c"The 2-norms is %.15le\0A\00"
@str = [31 x i8] c"The components of the vector :\00"
define i32 @cpu2norm_d_in_c(i32 %0, double* nocapture %1, double* nocapture %2) {
store double 0.000000e+00, double* %2
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %0)
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
%6 = icmp sgt i32 %0, 0
br i1 %6, label %9, label %7
7: ; preds = %3
%8 = load double, double* %2
br label %27
9: ; preds = %3
%10 = zext i32 %0 to i64
br label %11
11: ; preds = %9, %11
%12 = phi i64 [ 0, %9 ], [ %25, %11 ]
%13 = shl nuw nsw i64 %12, 1
%14 = getelementptr inbounds double, double* %1, i64 %13
%15 = load double, double* %14
%16 = or i64 %13, 1
%17 = getelementptr inbounds double, double* %1, i64 %16
%18 = load double, double* %17
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), double %15, double %18)
%20 = load double, double* %2
%21 = load double, double* %14
%22 = tail call double @llvm.fmuladd.f64(double %21, double %21, double %20)
%23 = load double, double* %17
%24 = tail call double @llvm.fmuladd.f64(double %23, double %23, double %22)
store double %24, double* %2
%25 = add nuw nsw i64 %12, 1
%26 = icmp eq i64 %25, %10
br i1 %26, label %27, label %11
27: ; preds = %11, %7
%28 = phi double [ %8, %7 ], [ %24, %11 ]
%29 = tail call double @sqrt(double %28)
store double %29, double* %2
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), double %29)
ret i32 0
}