#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*/ dd_copy(double *, double *);
int /*<<< orphan*/ dd_inc(double *, double *);
int /*<<< orphan*/ dd_sqr(double *, double *);
int /*<<< orphan*/ dd_write(double *, int);
int /*<<< orphan*/ printf(char *, ...);
int cpu2norm_dd_in_c(int n, double *x, double *nrm) {
  int i;
  double dd_nrm[2], re_acc[2], im_acc[2];
  printf("The C function received as dimension %d\n", n);
  printf("The components of the vector :\n");
  dd_nrm[0] = 0.0;
  dd_nrm[1] = 0.0;
  for (i = 0; i < n; i++) {
    dd_write(&x[4 * i], 32);
    printf("  ");
    dd_write(&x[4 * i + 2], 32);
    printf("\n");
    dd_copy(&x[4 * i], re_acc);
    dd_sqr(re_acc, re_acc);
    dd_copy(&x[4 * i + 2], im_acc);
    dd_sqr(im_acc, im_acc);
    dd_inc(re_acc, im_acc);
    dd_inc(dd_nrm, re_acc);
  }
  printf("The square of the 2-norm is ");
  dd_write(dd_nrm, 32);
  printf("\n");
  nrm[0] = dd_nrm[0];
  nrm[1] = dd_nrm[1];
  return 0;
}


x86 assembly (clang, -O0):
<cpu2norm_dd_in_c>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x4(%rbp),%esi
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeae(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
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    127b <cpu2norm_dd_in_c+0x12b>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%eax
shl    $0x2,%eax
cltq
shl    $0x3,%rax
add    %rax,%rdi
mov    $0x20,%esi
call   1060 <dd_write@plt>
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%eax
shl    $0x2,%eax
add    $0x2,%eax
cltq
shl    $0x3,%rax
add    %rax,%rdi
mov    $0x20,%esi
call   1060 <dd_write@plt>
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%eax
shl    $0x2,%eax
cltq
shl    $0x3,%rax
add    %rax,%rdi
lea    -0x40(%rbp),%rsi
call   1070 <dd_copy@plt>
lea    -0x40(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1050 <dd_sqr@plt>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%eax
shl    $0x2,%eax
add    $0x2,%eax
cltq
shl    $0x3,%rax
add    %rax,%rdi
lea    -0x50(%rbp),%rsi
call   1070 <dd_copy@plt>
lea    -0x50(%rbp),%rdi
lea    -0x50(%rbp),%rsi
call   1050 <dd_sqr@plt>
lea    -0x40(%rbp),%rdi
lea    -0x50(%rbp),%rsi
call   1030 <dd_inc@plt>
lea    -0x30(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1030 <dd_inc@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1199 <cpu2norm_dd_in_c+0x49>
lea    0xdca(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x30(%rbp),%rdi
mov    $0x20,%esi
call   1060 <dd_write@plt>
lea    0xda9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movsd  -0x30(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x28(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,0x8(%rax)
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cpu2norm_dd_in_c>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rdx,0x18(%rsp)
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe71(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xeaa(%rip),%rdi
call   1040 <puts@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
test   %ebp,%ebp
jle    1256 <cpu2norm_dd_in_c+0xe6>
mov    %ebp,%r15d
lea    0x30(%rsp),%r12
lea    0x20(%rsp),%r13
mov    %rsp,%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
mov    $0x20,%esi
call   1080 <dd_write@plt>
lea    0xe45(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x10(%rbx),%r14
mov    %r14,%rdi
mov    $0x20,%esi
call   1080 <dd_write@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1090 <dd_copy@plt>
mov    %r12,%rdi
mov    %r12,%rsi
call   1070 <dd_sqr@plt>
mov    %r14,%rdi
mov    %r13,%rsi
call   1090 <dd_copy@plt>
mov    %r13,%rdi
mov    %r13,%rsi
call   1070 <dd_sqr@plt>
mov    %r12,%rdi
mov    %r13,%rsi
call   1050 <dd_inc@plt>
mov    %rbp,%rdi
mov    %r12,%rsi
call   1050 <dd_inc@plt>
add    $0x20,%rbx
add    $0xffffffffffffffff,%r15
jne    11d0 <cpu2norm_dd_in_c+0x60>
lea    0xdcf(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rsp,%rdi
mov    $0x20,%esi
call   1080 <dd_write@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
movaps (%rsp),%xmm0
mov    0x18(%rsp),%rax
movups %xmm0,(%rax)
xor    %eax,%eax
add    $0x48,%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_dd_in_c(i32 %0, double* %1, double* %2) {
%4 = alloca i32
%5 = alloca double*
%6 = alloca double*
%7 = alloca i32
%8 = alloca [2 x double]
%9 = alloca [2 x double]
%10 = alloca [2 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 [2 x double], [2 x double]* %8, i64 0, i64 0
store double 0.000000e+00, double* %14
%15 = getelementptr inbounds [2 x double], [2 x double]* %8, i64 0, i64 1
store double 0.000000e+00, double* %15
store i32 0, i32* %7
br label %16
16: ; preds = %63, %3
%17 = load i32, i32* %7
%18 = load i32, i32* %4
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %66
20: ; preds = %16
%21 = load double*, double** %5
%22 = load i32, i32* %7
%23 = mul nsw i32 4, %22
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds double, double* %21, i64 %24
%26 = call i32 @dd_write(double* %25, i32 32)
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%28 = load double*, double** %5
%29 = load i32, i32* %7
%30 = mul nsw i32 4, %29
%31 = add nsw i32 %30, 2
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds double, double* %28, i64 %32
%34 = call i32 @dd_write(double* %33, i32 32)
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%36 = load double*, double** %5
%37 = load i32, i32* %7
%38 = mul nsw i32 4, %37
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds double, double* %36, i64 %39
%41 = getelementptr inbounds [2 x double], [2 x double]* %9, i64 0, i64 0
%42 = call i32 @dd_copy(double* %40, double* %41)
%43 = getelementptr inbounds [2 x double], [2 x double]* %9, i64 0, i64 0
%44 = getelementptr inbounds [2 x double], [2 x double]* %9, i64 0, i64 0
%45 = call i32 @dd_sqr(double* %43, double* %44)
%46 = load double*, double** %5
%47 = load i32, i32* %7
%48 = mul nsw i32 4, %47
%49 = add nsw i32 %48, 2
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds double, double* %46, i64 %50
%52 = getelementptr inbounds [2 x double], [2 x double]* %10, i64 0, i64 0
%53 = call i32 @dd_copy(double* %51, double* %52)
%54 = getelementptr inbounds [2 x double], [2 x double]* %10, i64 0, i64 0
%55 = getelementptr inbounds [2 x double], [2 x double]* %10, i64 0, i64 0
%56 = call i32 @dd_sqr(double* %54, double* %55)
%57 = getelementptr inbounds [2 x double], [2 x double]* %9, i64 0, i64 0
%58 = getelementptr inbounds [2 x double], [2 x double]* %10, i64 0, i64 0
%59 = call i32 @dd_inc(double* %57, double* %58)
%60 = getelementptr inbounds [2 x double], [2 x double]* %8, i64 0, i64 0
%61 = getelementptr inbounds [2 x double], [2 x double]* %9, i64 0, i64 0
%62 = call i32 @dd_inc(double* %60, double* %61)
br label %63
63: ; preds = %20
%64 = load i32, i32* %7
%65 = add nsw i32 %64, 1
store i32 %65, i32* %7
br label %16
66: ; preds = %16
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
%68 = getelementptr inbounds [2 x double], [2 x double]* %8, i64 0, i64 0
%69 = call i32 @dd_write(double* %68, i32 32)
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%71 = getelementptr inbounds [2 x double], [2 x double]* %8, i64 0, i64 0
%72 = load double, double* %71
%73 = load double*, double** %6
%74 = getelementptr inbounds double, double* %73, i64 0
store double %72, double* %74
%75 = getelementptr inbounds [2 x double], [2 x double]* %8, i64 0, i64 1
%76 = load double, double* %75
%77 = load double*, double** %6
%78 = getelementptr inbounds double, double* %77, i64 1
store double %76, double* %78
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_dd_in_c(i32 %0, double* %1, double* nocapture writeonly %2) {
%4 = alloca <2 x double>
%5 = alloca [2 x double]
%6 = alloca [2 x double]
%7 = bitcast <2 x double>* %4 to i8*
%8 = bitcast [2 x double]* %5 to i8*
%9 = bitcast [2 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 <2 x double>, <2 x double>* %4, i64 0, i64 0
%13 = icmp sgt i32 %0, 0
%14 = bitcast <2 x double>* %4 to i8*
br i1 %13, label %15, label %37
15: ; preds = %3
%16 = getelementptr inbounds [2 x double], [2 x double]* %5, i64 0, i64 0
%17 = getelementptr inbounds [2 x double], [2 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, 2
%22 = getelementptr inbounds double, double* %1, i64 %21
%23 = call i32 @dd_write(double* %22, i32 32)
%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, 2
%26 = getelementptr inbounds double, double* %1, i64 %25
%27 = call i32 @dd_write(double* %26, i32 32)
%28 = call i32 @putchar(i32 10)
%29 = call i32 @dd_copy(double* %22, double* %16)
%30 = call i32 @dd_sqr(double* %16, double* %16)
%31 = call i32 @dd_copy(double* %26, double* %17)
%32 = call i32 @dd_sqr(double* %17, double* %17)
%33 = call i32 @dd_inc(double* %16, double* %17)
%34 = call i32 @dd_inc(double* %12, double* %16)
%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 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
%39 = call i32 @dd_write(double* %12, i32 32)
%40 = call i32 @putchar(i32 10)
%41 = load <2 x double>, <2 x double>* %4
%42 = bitcast double* %2 to <2 x double>*
store <2 x double> %41, <2 x double>* %42
ret i32 0
}