#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 *, ...);
int /*<<< orphan*/ qd_add(double *, double *, double *);
int /*<<< orphan*/ qd_copy(double *, double *);
int /*<<< orphan*/ qd_sqr(double *, double *);
int /*<<< orphan*/ qd_write(double *, int);
int cpu2norm_qd_in_c(int n, double *x, double *nrm) {
  int i;
  double qd_nrm[4], re_acc[4], im_acc[4];
  printf("The C function received as dimension %d\n", n);
  printf("The components of the vector :\n");
  qd_nrm[0] = 0.0;
  qd_nrm[1] = 0.0;
  qd_nrm[2] = 0.0;
  qd_nrm[3] = 0.0;
  for (i = 0; i < n; i++) {
    qd_write(&x[8 * i], 64);
    printf("  ");
    qd_write(&x[8 * i + 4], 64);
    printf("\n");
    qd_copy(&x[8 * i], re_acc);
    qd_sqr(re_acc, re_acc);
    qd_copy(&x[8 * i + 4], im_acc);
    qd_sqr(im_acc, im_acc);
    qd_add(re_acc, im_acc, re_acc);
    qd_add(qd_nrm, re_acc, qd_nrm);
  }
  printf("The square of the 2-norm is ");
  qd_write(qd_nrm, 64);
  printf("\n");
  nrm[0] = qd_nrm[0];
  nrm[1] = qd_nrm[1];
  nrm[2] = qd_nrm[2];
  nrm[3] = qd_nrm[3];
  return 0;
}


x86 assembly (clang, -O0):
<cpu2norm_qd_in_c>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x4(%rbp),%esi
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeab(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1296 <cpu2norm_qd_in_c+0x146>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%eax
shl    $0x3,%eax
cltq
shl    $0x3,%rax
add    %rax,%rdi
mov    $0x40,%esi
call   1060 <qd_write@plt>
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%eax
shl    $0x3,%eax
add    $0x4,%eax
cltq
shl    $0x3,%rax
add    %rax,%rdi
mov    $0x40,%esi
call   1060 <qd_write@plt>
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%eax
shl    $0x3,%eax
cltq
shl    $0x3,%rax
add    %rax,%rdi
lea    -0x60(%rbp),%rsi
call   1070 <qd_copy@plt>
lea    -0x60(%rbp),%rdi
lea    -0x60(%rbp),%rsi
call   1040 <qd_sqr@plt>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%eax
shl    $0x3,%eax
add    $0x4,%eax
cltq
shl    $0x3,%rax
add    %rax,%rdi
lea    -0x80(%rbp),%rsi
call   1070 <qd_copy@plt>
lea    -0x80(%rbp),%rdi
lea    -0x80(%rbp),%rsi
call   1040 <qd_sqr@plt>
lea    -0x60(%rbp),%rdi
lea    -0x80(%rbp),%rsi
lea    -0x60(%rbp),%rdx
call   1050 <qd_add@plt>
lea    -0x40(%rbp),%rdi
lea    -0x60(%rbp),%rsi
lea    -0x40(%rbp),%rdx
call   1050 <qd_add@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11ac <cpu2norm_qd_in_c+0x5c>
lea    0xdaf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x40(%rbp),%rdi
mov    $0x40,%esi
call   1060 <qd_write@plt>
lea    0xd8e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsd  -0x40(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x38(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,0x8(%rax)
movsd  -0x30(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,0x10(%rax)
movsd  -0x28(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,0x18(%rax)
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cpu2norm_qd_in_c>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    %rdx,0x8(%rsp)
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe71(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xeaa(%rip),%rdi
call   1040 <puts@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movaps %xmm0,0x20(%rsp)
test   %ebp,%ebp
jle    125c <cpu2norm_qd_in_c+0xec>
mov    %ebp,%r15d
lea    0x50(%rsp),%r12
lea    0x30(%rsp),%r13
lea    0x10(%rsp),%rbp
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x40,%esi
call   1080 <qd_write@plt>
lea    0xe45(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x20(%rbx),%r14
mov    %r14,%rdi
mov    $0x40,%esi
call   1080 <qd_write@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1090 <qd_copy@plt>
mov    %r12,%rdi
mov    %r12,%rsi
call   1060 <qd_sqr@plt>
mov    %r14,%rdi
mov    %r13,%rsi
call   1090 <qd_copy@plt>
mov    %r13,%rdi
mov    %r13,%rsi
call   1060 <qd_sqr@plt>
mov    %r12,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
call   1070 <qd_add@plt>
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %rbp,%rdx
call   1070 <qd_add@plt>
add    $0x40,%rbx
add    $0xffffffffffffffff,%r15
jne    11d0 <cpu2norm_qd_in_c+0x60>
lea    0xdc9(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x10(%rsp),%rdi
mov    $0x40,%esi
call   1080 <qd_write@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
movaps 0x10(%rsp),%xmm0
mov    0x8(%rsp),%rax
movups %xmm0,(%rax)
movaps 0x20(%rsp),%xmm0
movups %xmm0,0x10(%rax)
xor    %eax,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
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 = [3 x i8] c" \00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [29 x i8] c"The square of the 2-norm is \00"
define i32 @cpu2norm_qd_in_c(i32 %0, double* %1, double* %2) {
%4 = alloca i32
%5 = alloca double*
%6 = alloca double*
%7 = alloca i32
%8 = alloca [4 x double]
%9 = alloca [4 x double]
%10 = alloca [4 x double]
store i32 %0, i32* %4
store double* %1, double** %5
store double* %2, double** %6
%11 = load i32, i32* %4
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
%14 = getelementptr inbounds [4 x double], [4 x double]* %8, i64 0, i64 0
store double 0.000000e+00, double* %14
%15 = getelementptr inbounds [4 x double], [4 x double]* %8, i64 0, i64 1
store double 0.000000e+00, double* %15
%16 = getelementptr inbounds [4 x double], [4 x double]* %8, i64 0, i64 2
store double 0.000000e+00, double* %16
%17 = getelementptr inbounds [4 x double], [4 x double]* %8, i64 0, i64 3
store double 0.000000e+00, double* %17
store i32 0, i32* %7
br label %18
18: ; preds = %67, %3
%19 = load i32, i32* %7
%20 = load i32, i32* %4
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %70
22: ; preds = %18
%23 = load double*, double** %5
%24 = load i32, i32* %7
%25 = mul nsw i32 8, %24
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds double, double* %23, i64 %26
%28 = call i32 @qd_write(double* %27, i32 64)
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%30 = load double*, double** %5
%31 = load i32, i32* %7
%32 = mul nsw i32 8, %31
%33 = add nsw i32 %32, 4
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds double, double* %30, i64 %34
%36 = call i32 @qd_write(double* %35, i32 64)
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%38 = load double*, double** %5
%39 = load i32, i32* %7
%40 = mul nsw i32 8, %39
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds double, double* %38, i64 %41
%43 = getelementptr inbounds [4 x double], [4 x double]* %9, i64 0, i64 0
%44 = call i32 @qd_copy(double* %42, double* %43)
%45 = getelementptr inbounds [4 x double], [4 x double]* %9, i64 0, i64 0
%46 = getelementptr inbounds [4 x double], [4 x double]* %9, i64 0, i64 0
%47 = call i32 @qd_sqr(double* %45, double* %46)
%48 = load double*, double** %5
%49 = load i32, i32* %7
%50 = mul nsw i32 8, %49
%51 = add nsw i32 %50, 4
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds double, double* %48, i64 %52
%54 = getelementptr inbounds [4 x double], [4 x double]* %10, i64 0, i64 0
%55 = call i32 @qd_copy(double* %53, double* %54)
%56 = getelementptr inbounds [4 x double], [4 x double]* %10, i64 0, i64 0
%57 = getelementptr inbounds [4 x double], [4 x double]* %10, i64 0, i64 0
%58 = call i32 @qd_sqr(double* %56, double* %57)
%59 = getelementptr inbounds [4 x double], [4 x double]* %9, i64 0, i64 0
%60 = getelementptr inbounds [4 x double], [4 x double]* %10, i64 0, i64 0
%61 = getelementptr inbounds [4 x double], [4 x double]* %9, i64 0, i64 0
%62 = call i32 @qd_add(double* %59, double* %60, double* %61)
%63 = getelementptr inbounds [4 x double], [4 x double]* %8, i64 0, i64 0
%64 = getelementptr inbounds [4 x double], [4 x double]* %9, i64 0, i64 0
%65 = getelementptr inbounds [4 x double], [4 x double]* %8, i64 0, i64 0
%66 = call i32 @qd_add(double* %63, double* %64, double* %65)
br label %67
67: ; preds = %22
%68 = load i32, i32* %7
%69 = add nsw i32 %68, 1
store i32 %69, i32* %7
br label %18
70: ; preds = %18
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
%72 = getelementptr inbounds [4 x double], [4 x double]* %8, i64 0, i64 0
%73 = call i32 @qd_write(double* %72, i32 64)
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%75 = getelementptr inbounds [4 x double], [4 x double]* %8, i64 0, i64 0
%76 = load double, double* %75
%77 = load double*, double** %6
%78 = getelementptr inbounds double, double* %77, i64 0
store double %76, double* %78
%79 = getelementptr inbounds [4 x double], [4 x double]* %8, i64 0, i64 1
%80 = load double, double* %79
%81 = load double*, double** %6
%82 = getelementptr inbounds double, double* %81, i64 1
store double %80, double* %82
%83 = getelementptr inbounds [4 x double], [4 x double]* %8, i64 0, i64 2
%84 = load double, double* %83
%85 = load double*, double** %6
%86 = getelementptr inbounds double, double* %85, i64 2
store double %84, double* %86
%87 = getelementptr inbounds [4 x double], [4 x double]* %8, i64 0, i64 3
%88 = load double, double* %87
%89 = load double*, double** %6
%90 = getelementptr inbounds double, double* %89, i64 3
store double %88, double* %90
ret i32 0
}

LLVM IR (-O2):
@.str = [41 x i8] c"The C function received as dimension %d\0A\00"
@.str.2 = [3 x i8] c" \00"
@.str.4 = [29 x i8] c"The square of the 2-norm is \00"
@str = [31 x i8] c"The components of the vector :\00"
define i32 @cpu2norm_qd_in_c(i32 %0, double* %1, double* nocapture writeonly %2) {
%4 = alloca [4 x double]
%5 = alloca [4 x double]
%6 = alloca [4 x double]
%7 = bitcast [4 x double]* %4 to i8*
%8 = bitcast [4 x double]* %5 to i8*
%9 = bitcast [4 x double]* %6 to i8*
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %0)
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
%12 = getelementptr inbounds [4 x double], [4 x double]* %4, i64 0, i64 0
%13 = icmp sgt i32 %0, 0
%14 = bitcast [4 x double]* %4 to i8*
br i1 %13, label %15, label %37
15: ; preds = %3
%16 = getelementptr inbounds [4 x double], [4 x double]* %5, i64 0, i64 0
%17 = getelementptr inbounds [4 x double], [4 x double]* %6, i64 0, i64 0
%18 = zext i32 %0 to i64
br label %19
19: ; preds = %15, %19
%20 = phi i64 [ 0, %15 ], [ %35, %19 ]
%21 = shl nsw i64 %20, 3
%22 = getelementptr inbounds double, double* %1, i64 %21
%23 = call i32 @qd_write(double* %22, i32 64)
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%25 = or i64 %21, 4
%26 = getelementptr inbounds double, double* %1, i64 %25
%27 = call i32 @qd_write(double* %26, i32 64)
%28 = call i32 @putchar(i32 10)
%29 = call i32 @qd_copy(double* %22, double* %16)
%30 = call i32 @qd_sqr(double* %16, double* %16)
%31 = call i32 @qd_copy(double* %26, double* %17)
%32 = call i32 @qd_sqr(double* %17, double* %17)
%33 = call i32 @qd_add(double* %16, double* %17, double* %16)
%34 = call i32 @qd_add(double* %12, double* %16, double* %12)
%35 = add nuw nsw i64 %20, 1
%36 = icmp eq i64 %35, %18
br i1 %36, label %37, label %19
37: ; preds = %19, %3
%38 = getelementptr inbounds [4 x double], [4 x double]* %4, i64 0, i64 2
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
%40 = call i32 @qd_write(double* %12, i32 64)
%41 = call i32 @putchar(i32 10)
%42 = bitcast [4 x double]* %4 to <2 x double>*
%43 = load <2 x double>, <2 x double>* %42
%44 = bitcast double* %2 to <2 x double>*
store <2 x double> %43, <2 x double>* %44
%45 = getelementptr inbounds double, double* %2, i64 2
%46 = bitcast double* %38 to <2 x double>*
%47 = load <2 x double>, <2 x double>* %46
%48 = bitcast double* %45 to <2 x double>*
store <2 x double> %47, <2 x double>* %48
ret i32 0
}