#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*/ normalize(double *, int);
int rand();
void vq_rand_init(const double *data, int nb_vectors, double *codebook,
                  int nb_entries, int n) {
  int i;
  int j;
  for (i = 0; i < nb_entries; i++) {
    int id;
    id = rand() % nb_vectors;
    for (j = 0; j < n; j++) {
      codebook[i * n + j] = data[id * n + j] + .01 * (rand() % 3 - 1);
    }
    normalize(&codebook[i * n], n);
  }
}


x86 assembly (clang, -O0):
<vq_rand_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1202 <vq_rand_init+0xe2>
mov    $0x0,%al
call   1040 <rand@plt>
cltd
idivl  -0xc(%rbp)
mov    %edx,-0x2c(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    11d8 <vq_rand_init+0xb8>
mov    -0x8(%rbp),%rax
mov    -0x2c(%rbp),%ecx
imul   -0x20(%rbp),%ecx
add    -0x28(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    $0x0,%al
call   1040 <rand@plt>
movsd  -0x38(%rbp),%xmm1
mov    $0x3,%ecx
cltd
idiv   %ecx
sub    $0x1,%edx
cvtsi2sd %edx,%xmm0
movsd  0xe54(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
imul   -0x20(%rbp),%ecx
add    -0x28(%rbp),%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1162 <vq_rand_init+0x42>
mov    -0x18(%rbp),%rdi
mov    -0x24(%rbp),%eax
imul   -0x20(%rbp),%eax
cltq
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x20(%rbp),%esi
call   1030 <normalize@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1141 <vq_rand_init+0x21>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vq_rand_init>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rdx,0x10(%rsp)
mov    %esi,0x4(%rsp)
mov    %rdi,0x18(%rsp)
test   %ecx,%ecx
jle    123c <vq_rand_init+0x11c>
mov    %r8d,%ebx
movslq %r8d,%rax
mov    %ecx,%ecx
mov    %rcx,0x28(%rsp)
mov    %eax,%r15d
mov    %rax,0x8(%rsp)
lea    0x0(,%rax,8),%rax
mov    %rax,0x20(%rsp)
mov    0x10(%rsp),%r14
xor    %r13d,%r13d
mov    %r8d,(%rsp)
jmp    11ad <vq_rand_init+0x8d>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r13,%r12
imul   0x8(%rsp),%r12
mov    0x10(%rsp),%rax
lea    (%rax,%r12,8),%rdi
mov    %ebx,%esi
call   1030 <normalize@plt>
add    $0x1,%r13
add    0x20(%rsp),%r14
cmp    0x28(%rsp),%r13
je     123c <vq_rand_init+0x11c>
xor    %eax,%eax
call   1040 <rand@plt>
test   %ebx,%ebx
jle    1180 <vq_rand_init+0x60>
cltd
idivl  0x4(%rsp)
imul   %ebx,%edx
mov    %r13,%r12
imul   0x8(%rsp),%r12
movslq %edx,%rax
mov    0x18(%rsp),%rcx
lea    (%rcx,%rax,8),%rbp
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
movsd  0x0(%rbp,%rbx,8),%xmm0
movsd  %xmm0,0x30(%rsp)
xor    %eax,%eax
call   1040 <rand@plt>
cltq
imul   $0x55555556,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,2),%ecx
not    %ecx
add    %ecx,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0xde1(%rip),%xmm0
addsd  0x30(%rsp),%xmm0
movsd  %xmm0,(%r14,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%r15
jne    11e0 <vq_rand_init+0xc0>
mov    (%rsp),%ebx
jmp    1189 <vq_rand_init+0x69>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @vq_rand_init(double* %0, i32 %1, double* %2, i32 %3, i32 %4) {
%6 = alloca double*
%7 = alloca i32
%8 = alloca double*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store double* %0, double** %6
store i32 %1, i32* %7
store double* %2, double** %8
store i32 %3, i32* %9
store i32 %4, i32* %10
store i32 0, i32* %11
br label %14
14: ; preds = %61, %5
%15 = load i32, i32* %11
%16 = load i32, i32* %9
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %64
18: ; preds = %14
%19 = call i32 (...) @rand()
%20 = load i32, i32* %7
%21 = srem i32 %19, %20
store i32 %21, i32* %13
store i32 0, i32* %12
br label %22
22: ; preds = %49, %18
%23 = load i32, i32* %12
%24 = load i32, i32* %10
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %52
26: ; preds = %22
%27 = load double*, double** %6
%28 = load i32, i32* %13
%29 = load i32, i32* %10
%30 = mul nsw i32 %28, %29
%31 = load i32, i32* %12
%32 = add nsw i32 %30, %31
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds double, double* %27, i64 %33
%35 = load double, double* %34
%36 = call i32 (...) @rand()
%37 = srem i32 %36, 3
%38 = sub nsw i32 %37, 1
%39 = sitofp i32 %38 to double
%40 = call double @llvm.fmuladd.f64(double 1.000000e-02, double %39, double %35)
%41 = load double*, double** %8
%42 = load i32, i32* %11
%43 = load i32, i32* %10
%44 = mul nsw i32 %42, %43
%45 = load i32, i32* %12
%46 = add nsw i32 %44, %45
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds double, double* %41, i64 %47
store double %40, double* %48
br label %49
49: ; preds = %26
%50 = load i32, i32* %12
%51 = add nsw i32 %50, 1
store i32 %51, i32* %12
br label %22
52: ; preds = %22
%53 = load double*, double** %8
%54 = load i32, i32* %11
%55 = load i32, i32* %10
%56 = mul nsw i32 %54, %55
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds double, double* %53, i64 %57
%59 = load i32, i32* %10
%60 = call i32 @normalize(double* %58, i32 %59)
br label %61
61: ; preds = %52
%62 = load i32, i32* %11
%63 = add nsw i32 %62, 1
store i32 %63, i32* %11
br label %14
64: ; preds = %14
ret void
}

LLVM IR (-O2):
define void @vq_rand_init(double* nocapture %0, i32 %1, double* %2, i32 %3, i32 %4) {
%6 = icmp sgt i32 %3, 0
br i1 %6, label %7, label %42
7: ; preds = %5
%8 = icmp sgt i32 %4, 0
%9 = sext i32 %4 to i64
%10 = zext i32 %3 to i64
%11 = zext i32 %4 to i64
br label %12
12: ; preds = %7, %36
%13 = phi i64 [ 0, %7 ], [ %40, %36 ]
%14 = tail call i32 (...) @rand()
br i1 %8, label %17, label %15
15: ; preds = %12
%16 = mul nsw i64 %13, %9
br label %36
17: ; preds = %12
%18 = srem i32 %14, %1
%19 = mul nsw i32 %18, %4
%20 = mul nsw i64 %13, %9
%21 = sext i32 %19 to i64
br label %22
22: ; preds = %17, %22
%23 = phi i64 [ 0, %17 ], [ %34, %22 ]
%24 = add nsw i64 %23, %21
%25 = getelementptr inbounds double, double* %0, i64 %24
%26 = load double, double* %25
%27 = tail call i32 (...) @rand()
%28 = srem i32 %27, 3
%29 = add nsw i32 %28, -1
%30 = sitofp i32 %29 to double
%31 = tail call double @llvm.fmuladd.f64(double %30, double 1.000000e-02, double %26)
%32 = add nsw i64 %23, %20
%33 = getelementptr inbounds double, double* %2, i64 %32
store double %31, double* %33
%34 = add nuw nsw i64 %23, 1
%35 = icmp eq i64 %34, %11
br i1 %35, label %36, label %22
36: ; preds = %22, %15
%37 = phi i64 [ %16, %15 ], [ %20, %22 ]
%38 = getelementptr inbounds double, double* %2, i64 %37
%39 = tail call i32 @normalize(double* %38, i32 %4)
%40 = add nuw nsw i64 %13, 1
%41 = icmp eq i64 %40, %10
br i1 %41, label %42, label %12
42: ; preds = %36, %5
ret void
}