#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 dmodule(double *, int);
void normalize_vector(double *Q, int n) {
  double nor = dmodule(Q, n);
  int i = 0;
  if (nor <= 0)
    return;
  for (i = 1; i <= n; i++) {
    Q[i] = Q[i] / nor;
  }
}


x86 assembly (clang, -O0):
<normalize_vector>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <dmodule@plt>
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x18(%rbp),%xmm0
jb     114a <normalize_vector+0x3a>
jmp    118a <normalize_vector+0x7a>
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     118a <normalize_vector+0x7a>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
divsd  -0x18(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1151 <normalize_vector+0x41>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<normalize_vector>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
call   1030 <dmodule@plt>
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
jae    11e7 <normalize_vector+0xd7>
test   %ebp,%ebp
jle    11e7 <normalize_vector+0xd7>
mov    %ebp,%eax
mov    $0x1,%ecx
cmp    $0x2,%ebp
jb     11c7 <normalize_vector+0xb7>
mov    %eax,%ecx
and    $0xfffffffe,%ecx
movapd %xmm0,%xmm1
unpcklpd %xmm0,%xmm1
lea    -0x2(%rcx),%rsi
mov    %rsi,%rdx
shr    %rdx
add    $0x1,%rdx
test   %rsi,%rsi
je     11ee <normalize_vector+0xde>
mov    %rdx,%rdi
and    $0xfffffffffffffffe,%rdi
mov    $0x1,%esi
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movupd (%rbx,%rsi,8),%xmm2
movupd 0x10(%rbx,%rsi,8),%xmm3
divpd  %xmm1,%xmm2
movupd %xmm2,(%rbx,%rsi,8)
divpd  %xmm1,%xmm3
movupd %xmm3,0x10(%rbx,%rsi,8)
add    $0x4,%rsi
add    $0xfffffffffffffffe,%rdi
jne    1180 <normalize_vector+0x70>
test   $0x1,%dl
je     11bb <normalize_vector+0xab>
movupd (%rbx,%rsi,8),%xmm2
divpd  %xmm1,%xmm2
movupd %xmm2,(%rbx,%rsi,8)
cmp    %rcx,%rax
je     11e7 <normalize_vector+0xd7>
mov    %rax,%rcx
or     $0x1,%rcx
add    $0x1,%rax
nopl   0x0(%rax,%rax,1)
movsd  (%rbx,%rcx,8),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,(%rbx,%rcx,8)
add    $0x1,%rcx
cmp    %rcx,%rax
jne    11d0 <normalize_vector+0xc0>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    $0x1,%esi
test   $0x1,%dl
jne    11ad <normalize_vector+0x9d>
jmp    11bb <normalize_vector+0xab>

LLVM IR (-O0):
define void @normalize_vector(double* %0, i32 %1) {
%3 = alloca double*
%4 = alloca i32
%5 = alloca double
%6 = alloca i32
store double* %0, double** %3
store i32 %1, i32* %4
%7 = load double*, double** %3
%8 = load i32, i32* %4
%9 = call double @dmodule(double* %7, i32 %8)
store double %9, double* %5
store i32 0, i32* %6
%10 = load double, double* %5
%11 = fcmp ole double %10, 0.000000e+00
br i1 %11, label %12, label %13
12: ; preds = %2
br label %33
13: ; preds = %2
store i32 1, i32* %6
br label %14
14: ; preds = %30, %13
%15 = load i32, i32* %6
%16 = load i32, i32* %4
%17 = icmp sle i32 %15, %16
br i1 %17, label %18, label %33
18: ; preds = %14
%19 = load double*, double** %3
%20 = load i32, i32* %6
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds double, double* %19, i64 %21
%23 = load double, double* %22
%24 = load double, double* %5
%25 = fdiv double %23, %24
%26 = load double*, double** %3
%27 = load i32, i32* %6
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds double, double* %26, i64 %28
store double %25, double* %29
br label %30
30: ; preds = %18
%31 = load i32, i32* %6
%32 = add nsw i32 %31, 1
store i32 %32, i32* %6
br label %14
33: ; preds = %12, %14
ret void
}

LLVM IR (-O2):
define void @normalize_vector(double* %0, i32 %1) {
%3 = tail call double @dmodule(double* %0, i32 %1)
%4 = fcmp ole double %3, 0.000000e+00
%5 = icmp slt i32 %1, 1
%6 = or i1 %4, %5
br i1 %6, label %64, label %7
7: ; preds = %2
%8 = add nuw i32 %1, 1
%9 = zext i32 %8 to i64
%10 = add nsw i64 %9, -1
%11 = icmp ult i64 %10, 2
br i1 %11, label %55, label %12
12: ; preds = %7
%13 = and i64 %10, -2
%14 = or i64 %10, 1
%15 = insertelement <2 x double> poison, double %3, i64 0
%16 = shufflevector <2 x double> %15, <2 x double> poison, <2 x i32> zeroinitializer
%17 = add nsw i64 %13, -2
%18 = lshr exact i64 %17, 1
%19 = add nuw i64 %18, 1
%20 = and i64 %19, 1
%21 = icmp eq i64 %17, 0
br i1 %21, label %44, label %22
22: ; preds = %12
%23 = and i64 %19, -2
br label %24
24: ; preds = %24, %22
%25 = phi i64 [ 0, %22 ], [ %39, %24 ]
%26 = phi i64 [ 0, %22 ], [ %40, %24 ]
%27 = or i64 %25, 1
%28 = getelementptr inbounds double, double* %0, i64 %27
%29 = bitcast double* %28 to <2 x double>*
%30 = load <2 x double>, <2 x double>* %29
%31 = fdiv <2 x double> %30, %16
%32 = bitcast double* %28 to <2 x double>*
store <2 x double> %31, <2 x double>* %32
%33 = or i64 %25, 3
%34 = getelementptr inbounds double, double* %0, i64 %33
%35 = bitcast double* %34 to <2 x double>*
%36 = load <2 x double>, <2 x double>* %35
%37 = fdiv <2 x double> %36, %16
%38 = bitcast double* %34 to <2 x double>*
store <2 x double> %37, <2 x double>* %38
%39 = add nuw i64 %25, 4
%40 = add nuw i64 %26, 2
%41 = icmp eq i64 %40, %23
br i1 %41, label %42, label %24
42: ; preds = %24
%43 = or i64 %39, 1
br label %44
44: ; preds = %42, %12
%45 = phi i64 [ 1, %12 ], [ %43, %42 ]
%46 = icmp eq i64 %20, 0
br i1 %46, label %53, label %47
47: ; preds = %44
%48 = getelementptr inbounds double, double* %0, i64 %45
%49 = bitcast double* %48 to <2 x double>*
%50 = load <2 x double>, <2 x double>* %49
%51 = fdiv <2 x double> %50, %16
%52 = bitcast double* %48 to <2 x double>*
store <2 x double> %51, <2 x double>* %52
br label %53
53: ; preds = %44, %47
%54 = icmp eq i64 %10, %13
br i1 %54, label %64, label %55
55: ; preds = %7, %53
%56 = phi i64 [ 1, %7 ], [ %14, %53 ]
br label %57
57: ; preds = %55, %57
%58 = phi i64 [ %62, %57 ], [ %56, %55 ]
%59 = getelementptr inbounds double, double* %0, i64 %58
%60 = load double, double* %59
%61 = fdiv double %60, %3
store double %61, double* %59
%62 = add nuw nsw i64 %58, 1
%63 = icmp eq i64 %62, %9
br i1 %63, label %64, label %57
64: ; preds = %57, %53, %2
ret void
}