#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*/ exit(int);
double norm_of_a_vector(int, double *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scale_a_vector(int, double, double *);
void normalize_a_vector(int dim, double *vec) {
  double sum;
  sum = norm_of_a_vector(dim, vec);
  if (sum < 1.0E-10) {
    printf("\n\n Error in function normalize a vector()");
    printf("\nNorm of the vector is too small - norm = %f\n", sum);
    exit(1);
  }
  scale_a_vector(dim, 1.0 / sum, vec);
}


x86 assembly (clang, -O0):
<normalize_a_vector>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1050 <norm_of_a_vector@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  0xe98(%rip),%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    119e <normalize_a_vector+0x5e>
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsd  -0x18(%rbp),%xmm0
lea    0xead(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x4(%rbp),%edi
movsd  0xe5f(%rip),%xmm0
divsd  -0x18(%rbp),%xmm0
mov    -0x10(%rbp),%rsi
call   1040 <scale_a_vector@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<normalize_a_vector>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
call   1050 <norm_of_a_vector@plt>
movapd %xmm0,%xmm1
movsd  0xea7(%rip),%xmm0
ucomisd %xmm1,%xmm0
ja     117b <normalize_a_vector+0x3b>
movsd  0xea1(%rip),%xmm0
divsd  %xmm1,%xmm0
mov    %ebp,%edi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <scale_a_vector@plt>
lea    0xe8e(%rip),%rdi
xor    %eax,%eax
movsd  %xmm1,(%rsp)
call   1030 <printf@plt>
lea    0xea5(%rip),%rdi
movsd  (%rsp),%xmm0
mov    $0x1,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [42 x i8] c"\0A\0A Error in function normalize a vector()\00"
@.str.1 = [46 x i8] c"\0ANorm of the vector is too small - norm = %f\0A\00"
define void @normalize_a_vector(i32 %0, double* %1) {
%3 = alloca i32
%4 = alloca double*
%5 = alloca double
store i32 %0, i32* %3
store double* %1, double** %4
%6 = load i32, i32* %3
%7 = load double*, double** %4
%8 = call double @norm_of_a_vector(i32 %6, double* %7)
store double %8, double* %5
%9 = load double, double* %5
%10 = fcmp olt double %9, 1.000000e-10
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%13 = load double, double* %5
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), double %13)
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = load i32, i32* %3
%18 = load double, double* %5
%19 = fdiv double 1.000000e+00, %18
%20 = load double*, double** %4
%21 = call i32 @scale_a_vector(i32 %17, double %19, double* %20)
ret void
}

LLVM IR (-O2):
@.str = [42 x i8] c"\0A\0A Error in function normalize a vector()\00"
@.str.1 = [46 x i8] c"\0ANorm of the vector is too small - norm = %f\0A\00"
define void @normalize_a_vector(i32 %0, double* %1) {
%3 = tail call double @norm_of_a_vector(i32 %0, double* %1)
%4 = fcmp olt double %3, 1.000000e-10
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), double %3)
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = fdiv double 1.000000e+00, %3
%11 = tail call i32 @scale_a_vector(i32 %0, double %10, double* %1)
ret void
}