#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*/ HINSERT(double *, int *, int *, int, double, int, int *);
void HBUILD(double HA[], int HJ[], int HK[], int N, int *HOPS) {
  int H, JV, K, KK;
  double V;
  *HOPS = 0;
  for (K = 1; K <= N; K++) {
    KK = K;
    V = HA[K];
    JV = HJ[K];
    HINSERT(HA, HJ, HK, KK, V, JV, &H);
    (*HOPS) += H;
  }
}


x86 assembly (clang, -O0):
<HBUILD>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movl   $0x0,(%rax)
movl   $0x1,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jg     11a8 <HBUILD+0x98>
mov    -0x34(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x38(%rbp),%ecx
movsd  -0x40(%rbp),%xmm0
mov    -0x30(%rbp),%r8d
lea    -0x2c(%rbp),%r9
call   1030 <HINSERT@plt>
mov    -0x2c(%rbp),%ecx
mov    -0x28(%rbp),%rax
add    (%rax),%ecx
mov    %ecx,(%rax)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    113c <HBUILD+0x2c>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<HBUILD>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
movl   $0x0,(%r8)
test   %ecx,%ecx
jle    116f <HBUILD+0x5f>
mov    %r8,%r14
mov    %ecx,%r12d
mov    %rdx,%r15
mov    %rsi,%r13
mov    %rdi,%rbx
add    $0x1,%r12d
mov    $0x1,%ebp
xchg   %ax,%ax
movsd  (%rbx,%rbp,8),%xmm0
mov    0x0(%r13,%rbp,4),%r8d
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r15,%rdx
mov    %ebp,%ecx
lea    0x4(%rsp),%r9
call   1030 <HINSERT@plt>
mov    0x4(%rsp),%eax
add    %eax,(%r14)
add    $0x1,%rbp
cmp    %rbp,%r12
jne    1140 <HBUILD+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @HBUILD(double* %0, i32* %1, i32* %2, i32 %3, i32* nocapture %4) {
%6 = alloca i32
%7 = bitcast i32* %6 to i8*
store i32 0, i32* %4
%8 = icmp slt i32 %3, 1
br i1 %8, label %25, label %9
9: ; preds = %5
%10 = add nuw i32 %3, 1
%11 = zext i32 %10 to i64
br label %12
12: ; preds = %9, %12
%13 = phi i64 [ 1, %9 ], [ %23, %12 ]
%14 = getelementptr inbounds double, double* %0, i64 %13
%15 = load double, double* %14
%16 = getelementptr inbounds i32, i32* %1, i64 %13
%17 = load i32, i32* %16
%18 = trunc i64 %13 to i32
%19 = call i32 @HINSERT(double* %0, i32* %1, i32* %2, i32 %18, double %15, i32 %17, i32* %6)
%20 = load i32, i32* %6
%21 = load i32, i32* %4
%22 = add nsw i32 %21, %20
store i32 %22, i32* %4
%23 = add nuw nsw i64 %13, 1
%24 = icmp eq i64 %23, %11
br i1 %24, label %25, label %12
25: ; preds = %12, %5
ret void
}