#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*/ BGBMID_Wave_UpdateHistogram(float *, float, float);
int BGBMID_Wave_GenerateHistogram(float *hist, short *sb, int sl) {
  float h, lh;
  int i, j, k;
  for (i = 0; i < 16; i++)
    hist[i] = 0;
  lh = 0;
  for (i = 0; i < sl; i++) {
    h = sb[i];
    BGBMID_Wave_UpdateHistogram(hist, h, lh);
    lh = h;
  }
  return (0);
}


x86 assembly (clang, -O0):
<BGBMID_Wave_GenerateHistogram>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0x10,-0x20(%rbp)
jge    1152 <BGBMID_Wave_GenerateHistogram+0x42>
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
xorps  %xmm0,%xmm0
movss  %xmm0,(%rax,%rcx,4)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    112a <BGBMID_Wave_GenerateHistogram+0x1a>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11ad <BGBMID_Wave_GenerateHistogram+0x9d>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
movswl (%rax,%rcx,2),%eax
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
movss  -0x18(%rbp),%xmm0
movss  -0x1c(%rbp),%xmm1
call   1030 <BGBMID_Wave_UpdateHistogram@plt>
movss  -0x18(%rbp),%xmm0
movss  %xmm0,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1161 <BGBMID_Wave_GenerateHistogram+0x51>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BGBMID_Wave_GenerateHistogram>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
xorps  %xmm0,%xmm0
movups %xmm0,0x30(%rdi)
movups %xmm0,0x20(%rdi)
movups %xmm0,0x10(%rdi)
movups %xmm0,(%rdi)
test   %edx,%edx
jle    1169 <BGBMID_Wave_GenerateHistogram+0x59>
mov    %rsi,%r14
mov    %rdi,%r12
mov    %edx,%r15d
xorps  %xmm1,%xmm1
xor    %ebx,%ebx
nopl   0x0(%rax)
movswl (%r14,%rbx,2),%eax
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
movss  %xmm0,0x4(%rsp)
mov    %r12,%rdi
call   1030 <BGBMID_Wave_UpdateHistogram@plt>
add    $0x1,%rbx
movss  0x4(%rsp),%xmm1
cmp    %rbx,%r15
jne    1140 <BGBMID_Wave_GenerateHistogram+0x30>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @BGBMID_Wave_GenerateHistogram(float* %0, i16* %1, i32 %2) {
%4 = alloca float*
%5 = alloca i16*
%6 = alloca i32
%7 = alloca float
%8 = alloca float
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store float* %0, float** %4
store i16* %1, i16** %5
store i32 %2, i32* %6
store i32 0, i32* %9
br label %12
12: ; preds = %20, %3
%13 = load i32, i32* %9
%14 = icmp slt i32 %13, 16
br i1 %14, label %15, label %23
15: ; preds = %12
%16 = load float*, float** %4
%17 = load i32, i32* %9
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds float, float* %16, i64 %18
store float 0.000000e+00, float* %19
br label %20
20: ; preds = %15
%21 = load i32, i32* %9
%22 = add nsw i32 %21, 1
store i32 %22, i32* %9
br label %12
23: ; preds = %12
store float 0.000000e+00, float* %8
store i32 0, i32* %9
br label %24
24: ; preds = %40, %23
%25 = load i32, i32* %9
%26 = load i32, i32* %6
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %43
28: ; preds = %24
%29 = load i16*, i16** %5
%30 = load i32, i32* %9
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i16, i16* %29, i64 %31
%33 = load i16, i16* %32
%34 = sitofp i16 %33 to float
store float %34, float* %7
%35 = load float*, float** %4
%36 = load float, float* %7
%37 = load float, float* %8
%38 = call i32 @BGBMID_Wave_UpdateHistogram(float* %35, float %36, float %37)
%39 = load float, float* %7
store float %39, float* %8
br label %40
40: ; preds = %28
%41 = load i32, i32* %9
%42 = add nsw i32 %41, 1
store i32 %42, i32* %9
br label %24
43: ; preds = %24
ret i32 0
}

LLVM IR (-O2):
define i32 @BGBMID_Wave_GenerateHistogram(float* %0, i16* nocapture %1, i32 %2) {
%4 = bitcast float* %0 to i8*
%5 = icmp sgt i32 %2, 0
br i1 %5, label %6, label %17
6: ; preds = %3
%7 = zext i32 %2 to i64
br label %8
8: ; preds = %6, %8
%9 = phi i64 [ 0, %6 ], [ %15, %8 ]
%10 = phi float [ 0.000000e+00, %6 ], [ %13, %8 ]
%11 = getelementptr inbounds i16, i16* %1, i64 %9
%12 = load i16, i16* %11
%13 = sitofp i16 %12 to float
%14 = tail call i32 @BGBMID_Wave_UpdateHistogram(float* %0, float %13, float %10)
%15 = add nuw nsw i64 %9, 1
%16 = icmp eq i64 %15, %7
br i1 %16, label %17, label %8
17: ; preds = %8, %3
ret i32 0
}