#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*/ GHMM_LOG_PRINTF(int, char *, char *);
int /*<<< orphan*/ free(char *);
char *ighmm_mprintf(int /*<<< orphan*/ *, int /*<<< orphan*/, char *, int);
int ighmm_cvector_normalize(double *v, int len) {
  int i;
  double sum = 0.0;
  char *estr;
  for (i = 0; i < len; i++)
    sum += v[i];
  if (i > 0 && sum < 1E-8) {
    estr = ighmm_mprintf(NULL, 0,
                         "Can't normalize vector. Sum smaller than %g\n", 1E-8);
    GHMM_LOG_PRINTF(
        2,
        "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
        "2022-01-22/02-19-57/repos/lukefrasera/fatigueBSN/refs/heads/master/"
        "scripts/include/ghmm-0.9-rc3/ghmm/vector.c"
        ":"
        "ighmm_cvector_normalize"
        "("
        "69"
        "): ",
        estr);
    {
      if (estr) {
        free(estr);
        (estr) = NULL;
      } else {
        GHMM_LOG_PRINTF(
            0,
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/lukefrasera/fatigueBSN/refs/heads/"
            "master/scripts/include/ghmm-0.9-rc3/ghmm/vector.c"
            ":"
            "ighmm_cvector_normalize"
            "("
            "70"
            "): ",
            "Attempted m_free on NULL pointer. Bad program, BAD! No cookie for "
            "you.");
      }
    };
    return (-1);
  }
  for (i = 0; i < len; i++)
    v[i] /= sum;
  return 0;
}


x86 assembly (clang, -O0):
<ighmm_cvector_normalize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    117f <ighmm_cvector_normalize+0x4f>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    114e <ighmm_cvector_normalize+0x1e>
cmpl   $0x0,-0x18(%rbp)
jle    120b <ighmm_cvector_normalize+0xdb>
movsd  0xe6f(%rip),%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    120b <ighmm_cvector_normalize+0xdb>
xor    %eax,%eax
mov    %eax,%edi
xor    %ecx,%ecx
lea    0xe5f(%rip),%rdx
mov    %ecx,%esi
call   1040 <ighmm_mprintf@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdx
mov    $0x2,%edi
lea    0xe71(%rip),%rsi
call   1050 <GHMM_LOG_PRINTF@plt>
cmpq   $0x0,-0x28(%rbp)
je     11ea <ighmm_cvector_normalize+0xba>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x28(%rbp)
jmp    11ff <ighmm_cvector_normalize+0xcf>
xor    %edi,%edi
lea    0xf0e(%rip),%rsi
lea    0xfd3(%rip),%rdx
call   1050 <GHMM_LOG_PRINTF@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    124e <ighmm_cvector_normalize+0x11e>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1247 <ighmm_cvector_normalize+0x117>
movsd  -0x20(%rbp),%xmm1
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1212 <ighmm_cvector_normalize+0xe2>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ighmm_cvector_normalize>:
push   %rbx
test   %esi,%esi
jle    12d7 <ighmm_cvector_normalize+0x1a7>
mov    %esi,%ebx
lea    -0x1(%rbx),%rcx
mov    %ebx,%eax
and    $0x7,%eax
cmp    $0x7,%rcx
jae    1152 <ighmm_cvector_normalize+0x22>
xorpd  %xmm0,%xmm0
xor    %edx,%edx
jmp    1198 <ighmm_cvector_normalize+0x68>
mov    %ebx,%ecx
and    $0xfffffff8,%ecx
xorpd  %xmm0,%xmm0
xor    %edx,%edx
nopl   (%rax)
addsd  (%rdi,%rdx,8),%xmm0
addsd  0x8(%rdi,%rdx,8),%xmm0
addsd  0x10(%rdi,%rdx,8),%xmm0
addsd  0x18(%rdi,%rdx,8),%xmm0
addsd  0x20(%rdi,%rdx,8),%xmm0
addsd  0x28(%rdi,%rdx,8),%xmm0
addsd  0x30(%rdi,%rdx,8),%xmm0
addsd  0x38(%rdi,%rdx,8),%xmm0
add    $0x8,%rdx
cmp    %rdx,%rcx
jne    1160 <ighmm_cvector_normalize+0x30>
test   %rax,%rax
je     11be <ighmm_cvector_normalize+0x8e>
lea    (%rdi,%rdx,8),%rcx
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
addsd  (%rcx,%rdx,8),%xmm0
add    $0x1,%rdx
cmp    %rdx,%rax
jne    11b0 <ighmm_cvector_normalize+0x80>
test   %esi,%esi
jle    1208 <ighmm_cvector_normalize+0xd8>
movsd  0xe36(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    1208 <ighmm_cvector_normalize+0xd8>
lea    0xe31(%rip),%rdx
xor    %edi,%edi
xor    %esi,%esi
xor    %ecx,%ecx
call   1040 <ighmm_mprintf@plt>
mov    %rax,%rbx
lea    0xe49(%rip),%rsi
mov    $0x2,%edi
mov    %rax,%rdx
call   1050 <GHMM_LOG_PRINTF@plt>
test   %rbx,%rbx
je     121c <ighmm_cvector_normalize+0xec>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    1231 <ighmm_cvector_normalize+0x101>
test   %esi,%esi
jle    12d7 <ighmm_cvector_normalize+0x1a7>
cmp    $0x1,%esi
jne    1238 <ighmm_cvector_normalize+0x108>
xor    %edx,%edx
jmp    12c0 <ighmm_cvector_normalize+0x190>
lea    0xede(%rip),%rsi
lea    0xfa3(%rip),%rdx
xor    %edi,%edi
call   1050 <GHMM_LOG_PRINTF@plt>
mov    $0xffffffff,%eax
pop    %rbx
ret
mov    %ebx,%edx
and    $0xfffffffe,%edx
movapd %xmm0,%xmm1
unpcklpd %xmm0,%xmm1
lea    -0x2(%rdx),%rcx
mov    %rcx,%rax
shr    %rax
add    $0x1,%rax
test   %rcx,%rcx
je     12db <ighmm_cvector_normalize+0x1ab>
mov    %rax,%rcx
and    $0xfffffffffffffffe,%rcx
xor    %esi,%esi
cs nopw 0x0(%rax,%rax,1)
nop
movupd (%rdi,%rsi,8),%xmm2
movupd 0x10(%rdi,%rsi,8),%xmm3
divpd  %xmm1,%xmm2
movupd %xmm2,(%rdi,%rsi,8)
divpd  %xmm1,%xmm3
movupd %xmm3,0x10(%rdi,%rsi,8)
add    $0x4,%rsi
add    $0xfffffffffffffffe,%rcx
jne    1270 <ighmm_cvector_normalize+0x140>
test   $0x1,%al
je     12aa <ighmm_cvector_normalize+0x17a>
movupd (%rdi,%rsi,8),%xmm2
divpd  %xmm1,%xmm2
movupd %xmm2,(%rdi,%rsi,8)
xor    %eax,%eax
cmp    %rbx,%rdx
je     1236 <ighmm_cvector_normalize+0x106>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsd  (%rdi,%rdx,8),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,(%rdi,%rdx,8)
add    $0x1,%rdx
cmp    %rdx,%rbx
jne    12c0 <ighmm_cvector_normalize+0x190>
xor    %eax,%eax
pop    %rbx
ret
xor    %esi,%esi
test   $0x1,%al
jne    129c <ighmm_cvector_normalize+0x16c>
jmp    12aa <ighmm_cvector_normalize+0x17a>

LLVM IR (-O0):
@.str = [45 x i8] c"Can't normalize vector. Sum smaller than %g\0A\00"
@.str.1 = [204 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/lukefrasera/fatigueBSN/refs/heads/master/scripts/include/ghmm-0.9-rc3/ghmm/vector.c:ighmm_cvector_normalize(69): \00"
@.str.2 = [204 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/lukefrasera/fatigueBSN/refs/heads/master/scripts/include/ghmm-0.9-rc3/ghmm/vector.c:ighmm_cvector_normalize(70): \00"
@.str.3 = [71 x i8] c"Attempted m_free on NULL pointer. Bad program, BAD! No cookie for you.\00"
define i32 @ighmm_cvector_normalize(double* %0, i32 %1) {
%3 = alloca i32
%4 = alloca double*
%5 = alloca i32
%6 = alloca i32
%7 = alloca double
%8 = alloca i8*
store double* %0, double** %4
store i32 %1, i32* %5
store double 0.000000e+00, double* %7
store i32 0, i32* %6
br label %9
9: ; preds = %21, %2
%10 = load i32, i32* %6
%11 = load i32, i32* %5
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %24
13: ; preds = %9
%14 = load double*, double** %4
%15 = load i32, i32* %6
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds double, double* %14, i64 %16
%18 = load double, double* %17
%19 = load double, double* %7
%20 = fadd double %19, %18
store double %20, double* %7
br label %21
21: ; preds = %13
%22 = load i32, i32* %6
%23 = add nsw i32 %22, 1
store i32 %23, i32* %6
br label %9
24: ; preds = %9
%25 = load i32, i32* %6
%26 = icmp sgt i32 %25, 0
br i1 %26, label %27, label %42
27: ; preds = %24
%28 = load double, double* %7
%29 = fcmp olt double %28, 1.000000e-08
br i1 %29, label %30, label %42
30: ; preds = %27
%31 = call i8* @ighmm_mprintf(i32* null, i32 0, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 0)
store i8* %31, i8** %8
%32 = load i8*, i8** %8
%33 = call i32 @GHMM_LOG_PRINTF(i32 2, i8* getelementptr inbounds ([204 x i8], [204 x i8]* @.str.1, i64 0, i64 0), i8* %32)
%34 = load i8*, i8** %8
%35 = icmp ne i8* %34, null
br i1 %35, label %36, label %39
36: ; preds = %30
%37 = load i8*, i8** %8
%38 = call i32 @free(i8* %37)
store i8* null, i8** %8
br label %41
39: ; preds = %30
%40 = call i32 @GHMM_LOG_PRINTF(i32 0, i8* getelementptr inbounds ([204 x i8], [204 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.3, i64 0, i64 0))
br label %41
41: ; preds = %39, %36
store i32 -1, i32* %3
br label %59
42: ; preds = %27, %24
store i32 0, i32* %6
br label %43
43: ; preds = %55, %42
%44 = load i32, i32* %6
%45 = load i32, i32* %5
%46 = icmp slt i32 %44, %45
br i1 %46, label %47, label %58
47: ; preds = %43
%48 = load double, double* %7
%49 = load double*, double** %4
%50 = load i32, i32* %6
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds double, double* %49, i64 %51
%53 = load double, double* %52
%54 = fdiv double %53, %48
store double %54, double* %52
br label %55
55: ; preds = %47
%56 = load i32, i32* %6
%57 = add nsw i32 %56, 1
store i32 %57, i32* %6
br label %43
58: ; preds = %43
store i32 0, i32* %3
br label %59
59: ; preds = %58, %41
%60 = load i32, i32* %3
ret i32 %60
}

LLVM IR (-O2):
@.str = [45 x i8] c"Can't normalize vector. Sum smaller than %g\0A\00"
@.str.1 = [204 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/lukefrasera/fatigueBSN/refs/heads/master/scripts/include/ghmm-0.9-rc3/ghmm/vector.c:ighmm_cvector_normalize(69): \00"
@.str.2 = [204 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/lukefrasera/fatigueBSN/refs/heads/master/scripts/include/ghmm-0.9-rc3/ghmm/vector.c:ighmm_cvector_normalize(70): \00"
@.str.3 = [71 x i8] c"Attempted m_free on NULL pointer. Bad program, BAD! No cookie for you.\00"
define i32 @ighmm_cvector_normalize(double* nocapture %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %128
4: ; preds = %2
%5 = zext i32 %1 to i64
%6 = add nsw i64 %5, -1
%7 = and i64 %5, 7
%8 = icmp ult i64 %6, 7
br i1 %8, label %49, label %9
9: ; preds = %4
%10 = and i64 %5, 4294967288
br label %11
11: ; preds = %11, %9
%12 = phi i64 [ 0, %9 ], [ %46, %11 ]
%13 = phi double [ 0.000000e+00, %9 ], [ %45, %11 ]
%14 = phi i64 [ 0, %9 ], [ %47, %11 ]
%15 = getelementptr inbounds double, double* %0, i64 %12
%16 = load double, double* %15
%17 = fadd double %13, %16
%18 = or i64 %12, 1
%19 = getelementptr inbounds double, double* %0, i64 %18
%20 = load double, double* %19
%21 = fadd double %17, %20
%22 = or i64 %12, 2
%23 = getelementptr inbounds double, double* %0, i64 %22
%24 = load double, double* %23
%25 = fadd double %21, %24
%26 = or i64 %12, 3
%27 = getelementptr inbounds double, double* %0, i64 %26
%28 = load double, double* %27
%29 = fadd double %25, %28
%30 = or i64 %12, 4
%31 = getelementptr inbounds double, double* %0, i64 %30
%32 = load double, double* %31
%33 = fadd double %29, %32
%34 = or i64 %12, 5
%35 = getelementptr inbounds double, double* %0, i64 %34
%36 = load double, double* %35
%37 = fadd double %33, %36
%38 = or i64 %12, 6
%39 = getelementptr inbounds double, double* %0, i64 %38
%40 = load double, double* %39
%41 = fadd double %37, %40
%42 = or i64 %12, 7
%43 = getelementptr inbounds double, double* %0, i64 %42
%44 = load double, double* %43
%45 = fadd double %41, %44
%46 = add nuw nsw i64 %12, 8
%47 = add i64 %14, 8
%48 = icmp eq i64 %47, %10
br i1 %48, label %49, label %11
49: ; preds = %11, %4
%50 = phi double [ undef, %4 ], [ %45, %11 ]
%51 = phi i64 [ 0, %4 ], [ %46, %11 ]
%52 = phi double [ 0.000000e+00, %4 ], [ %45, %11 ]
%53 = icmp eq i64 %7, 0
br i1 %53, label %64, label %54
54: ; preds = %49, %54
%55 = phi i64 [ %61, %54 ], [ %51, %49 ]
%56 = phi double [ %60, %54 ], [ %52, %49 ]
%57 = phi i64 [ %62, %54 ], [ 0, %49 ]
%58 = getelementptr inbounds double, double* %0, i64 %55
%59 = load double, double* %58
%60 = fadd double %56, %59
%61 = add nuw nsw i64 %55, 1
%62 = add i64 %57, 1
%63 = icmp eq i64 %62, %7
br i1 %63, label %64, label %54
64: ; preds = %54, %49
%65 = phi double [ %50, %49 ], [ %60, %54 ]
%66 = fcmp olt double %65, 1.000000e-08
%67 = select i1 %3, i1 %66, i1 false
br i1 %67, label %113, label %68
68: ; preds = %64
br i1 %3, label %69, label %128
69: ; preds = %68
%70 = zext i32 %1 to i64
%71 = icmp eq i32 %1, 1
br i1 %71, label %111, label %72
72: ; preds = %69
%73 = and i64 %5, 4294967294
%74 = insertelement <2 x double> poison, double %65, i64 0
%75 = shufflevector <2 x double> %74, <2 x double> poison, <2 x i32> zeroinitializer
%76 = add nsw i64 %73, -2
%77 = lshr exact i64 %76, 1
%78 = add nuw i64 %77, 1
%79 = and i64 %78, 1
%80 = icmp eq i64 %76, 0
br i1 %80, label %100, label %81
81: ; preds = %72
%82 = and i64 %78, -2
br label %83
83: ; preds = %83, %81
%84 = phi i64 [ 0, %81 ], [ %97, %83 ]
%85 = phi i64 [ 0, %81 ], [ %98, %83 ]
%86 = getelementptr inbounds double, double* %0, i64 %84
%87 = bitcast double* %86 to <2 x double>*
%88 = load <2 x double>, <2 x double>* %87
%89 = fdiv <2 x double> %88, %75
%90 = bitcast double* %86 to <2 x double>*
store <2 x double> %89, <2 x double>* %90
%91 = or i64 %84, 2
%92 = getelementptr inbounds double, double* %0, i64 %91
%93 = bitcast double* %92 to <2 x double>*
%94 = load <2 x double>, <2 x double>* %93
%95 = fdiv <2 x double> %94, %75
%96 = bitcast double* %92 to <2 x double>*
store <2 x double> %95, <2 x double>* %96
%97 = add nuw i64 %84, 4
%98 = add nuw i64 %85, 2
%99 = icmp eq i64 %98, %82
br i1 %99, label %100, label %83
100: ; preds = %83, %72
%101 = phi i64 [ 0, %72 ], [ %97, %83 ]
%102 = icmp eq i64 %79, 0
br i1 %102, label %109, label %103
103: ; preds = %100
%104 = getelementptr inbounds double, double* %0, i64 %101
%105 = bitcast double* %104 to <2 x double>*
%106 = load <2 x double>, <2 x double>* %105
%107 = fdiv <2 x double> %106, %75
%108 = bitcast double* %104 to <2 x double>*
store <2 x double> %107, <2 x double>* %108
br label %109
109: ; preds = %100, %103
%110 = icmp eq i64 %73, %5
br i1 %110, label %128, label %111
111: ; preds = %69, %109
%112 = phi i64 [ 0, %69 ], [ %73, %109 ]
br label %121
113: ; preds = %64
%114 = tail call i8* @ighmm_mprintf(i32* null, i32 0, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 0)
%115 = tail call i32 @GHMM_LOG_PRINTF(i32 2, i8* getelementptr inbounds ([204 x i8], [204 x i8]* @.str.1, i64 0, i64 0), i8* %114)
%116 = icmp eq i8* %114, null
br i1 %116, label %119, label %117
117: ; preds = %113
%118 = tail call i32 @free(i8* %114)
br label %128
119: ; preds = %113
%120 = tail call i32 @GHMM_LOG_PRINTF(i32 0, i8* getelementptr inbounds ([204 x i8], [204 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.3, i64 0, i64 0))
br label %128
121: ; preds = %111, %121
%122 = phi i64 [ %126, %121 ], [ %112, %111 ]
%123 = getelementptr inbounds double, double* %0, i64 %122
%124 = load double, double* %123
%125 = fdiv double %124, %65
store double %125, double* %123
%126 = add nuw nsw i64 %122, 1
%127 = icmp eq i64 %126, %70
br i1 %127, label %128, label %121
128: ; preds = %121, %109, %2, %68, %117, %119
%129 = phi i32 [ -1, %119 ], [ -1, %117 ], [ 0, %68 ], [ 0, %2 ], [ 0, %109 ], [ 0, %121 ]
ret i32 %129
}