#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 sqrt(double);
void vec_norm(double *P, double *re, double *im, unsigned long N) {
  long j;
  for (j = 0; j < N; j++) {
    *(P + j) = sqrt((*(re + j) * *(re + j)) + (*(im + j) * *(im + j)));
  }
}


x86 assembly (clang, -O0):
<vec_norm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    119d <vec_norm+0x8d>
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1030 <sqrt@plt>
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1130 <vec_norm+0x20>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vec_norm>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rcx,%rcx
je     1210 <vec_norm+0x100>
mov    %rcx,%r12
mov    %rdx,%r15
mov    %rsi,%r13
mov    %rdi,%r14
cmp    $0x1,%rcx
jne    1172 <vec_norm+0x62>
xor    %ebx,%ebx
test   $0x1,%r12b
je     1210 <vec_norm+0x100>
movsd  0x0(%r13,%rbx,8),%xmm0
movsd  (%r15,%rbx,8),%xmm1
mulsd  %xmm1,%xmm1
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     1205 <vec_norm+0xf5>
sqrtsd %xmm0,%xmm0
jmp    120a <vec_norm+0xfa>
mov    %r12,%rbp
and    $0xfffffffffffffffe,%rbp
xor    %ebx,%ebx
xorpd  %xmm2,%xmm2
jmp    11a9 <vec_norm+0x99>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
call   1030 <sqrt@plt>
xorpd  %xmm2,%xmm2
movsd  %xmm0,0x8(%r14,%rbx,8)
add    $0x2,%rbx
cmp    %rbx,%rbp
je     1138 <vec_norm+0x28>
movsd  0x0(%r13,%rbx,8),%xmm0
movsd  (%r15,%rbx,8),%xmm1
mulsd  %xmm1,%xmm1
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
ucomisd %xmm2,%xmm0
jb     11d0 <vec_norm+0xc0>
sqrtsd %xmm0,%xmm0
jmp    11d9 <vec_norm+0xc9>
xchg   %ax,%ax
call   1030 <sqrt@plt>
xorpd  %xmm2,%xmm2
movsd  %xmm0,(%r14,%rbx,8)
movsd  0x8(%r13,%rbx,8),%xmm0
movsd  0x8(%r15,%rbx,8),%xmm1
mulsd  %xmm1,%xmm1
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
ucomisd %xmm2,%xmm0
jb     1190 <vec_norm+0x80>
sqrtsd %xmm0,%xmm0
jmp    1199 <vec_norm+0x89>
call   1030 <sqrt@plt>
movsd  %xmm0,(%r14,%rbx,8)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @vec_norm(double* %0, double* %1, double* %2, i64 %3) {
%5 = alloca double*
%6 = alloca double*
%7 = alloca double*
%8 = alloca i64
%9 = alloca i64
store double* %0, double** %5
store double* %1, double** %6
store double* %2, double** %7
store i64 %3, i64* %8
store i64 0, i64* %9
br label %10
10: ; preds = %37, %4
%11 = load i64, i64* %9
%12 = load i64, i64* %8
%13 = icmp ult i64 %11, %12
br i1 %13, label %14, label %40
14: ; preds = %10
%15 = load double*, double** %6
%16 = load i64, i64* %9
%17 = getelementptr inbounds double, double* %15, i64 %16
%18 = load double, double* %17
%19 = load double*, double** %6
%20 = load i64, i64* %9
%21 = getelementptr inbounds double, double* %19, i64 %20
%22 = load double, double* %21
%23 = load double*, double** %7
%24 = load i64, i64* %9
%25 = getelementptr inbounds double, double* %23, i64 %24
%26 = load double, double* %25
%27 = load double*, double** %7
%28 = load i64, i64* %9
%29 = getelementptr inbounds double, double* %27, i64 %28
%30 = load double, double* %29
%31 = fmul double %26, %30
%32 = call double @llvm.fmuladd.f64(double %18, double %22, double %31)
%33 = call double @sqrt(double %32)
%34 = load double*, double** %5
%35 = load i64, i64* %9
%36 = getelementptr inbounds double, double* %34, i64 %35
store double %33, double* %36
br label %37
37: ; preds = %14
%38 = load i64, i64* %9
%39 = add nsw i64 %38, 1
store i64 %39, i64* %9
br label %10
40: ; preds = %10
ret void
}

LLVM IR (-O2):
define void @vec_norm(double* nocapture writeonly %0, double* nocapture %1, double* nocapture %2, i64 %3) {
%5 = icmp eq i64 %3, 0
br i1 %5, label %46, label %6
6: ; preds = %4
%7 = and i64 %3, 1
%8 = icmp eq i64 %3, 1
br i1 %8, label %34, label %9
9: ; preds = %6
%10 = and i64 %3, -2
br label %11
11: ; preds = %11, %9
%12 = phi i64 [ 0, %9 ], [ %31, %11 ]
%13 = phi i64 [ 0, %9 ], [ %32, %11 ]
%14 = getelementptr inbounds double, double* %1, i64 %12
%15 = load double, double* %14
%16 = getelementptr inbounds double, double* %2, i64 %12
%17 = load double, double* %16
%18 = fmul double %17, %17
%19 = tail call double @llvm.fmuladd.f64(double %15, double %15, double %18)
%20 = tail call double @sqrt(double %19)
%21 = getelementptr inbounds double, double* %0, i64 %12
store double %20, double* %21
%22 = or i64 %12, 1
%23 = getelementptr inbounds double, double* %1, i64 %22
%24 = load double, double* %23
%25 = getelementptr inbounds double, double* %2, i64 %22
%26 = load double, double* %25
%27 = fmul double %26, %26
%28 = tail call double @llvm.fmuladd.f64(double %24, double %24, double %27)
%29 = tail call double @sqrt(double %28)
%30 = getelementptr inbounds double, double* %0, i64 %22
store double %29, double* %30
%31 = add nuw nsw i64 %12, 2
%32 = add i64 %13, 2
%33 = icmp eq i64 %32, %10
br i1 %33, label %34, label %11
34: ; preds = %11, %6
%35 = phi i64 [ 0, %6 ], [ %31, %11 ]
%36 = icmp eq i64 %7, 0
br i1 %36, label %46, label %37
37: ; preds = %34
%38 = getelementptr inbounds double, double* %1, i64 %35
%39 = load double, double* %38
%40 = getelementptr inbounds double, double* %2, i64 %35
%41 = load double, double* %40
%42 = fmul double %41, %41
%43 = tail call double @llvm.fmuladd.f64(double %39, double %39, double %42)
%44 = tail call double @sqrt(double %43)
%45 = getelementptr inbounds double, double* %0, i64 %35
store double %44, double* %45
br label %46
46: ; preds = %37, %34, %4
ret void
}