#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*/ find_array_two_min(float const *, int, float *, float *,
                                      int *, int *);
void find_the_two_nearest_keys(const float *dist, int n1, int n2, int *indexA,
                               int *indexB, float *distA, float *distB) {
  for (int i = 0; i < n1; i++) {
    int iA, iB;
    float dA, dB;
    find_array_two_min(&dist[i * n2], n2, &dA, &dB, &iA, &iB);
    indexA[i] = iA;
    indexB[i] = iB;
    distA[i] = dA;
    distB[i] = dB;
  }
}


x86 assembly (clang, -O0):
<find_the_two_nearest_keys>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11bf <find_the_two_nearest_keys+0xaf>
mov    -0x8(%rbp),%rdi
mov    -0x2c(%rbp),%eax
imul   -0x10(%rbp),%eax
cltq
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x10(%rbp),%esi
lea    -0x38(%rbp),%rdx
lea    -0x3c(%rbp),%rcx
lea    -0x30(%rbp),%r8
lea    -0x34(%rbp),%r9
call   1030 <find_array_two_min@plt>
mov    -0x30(%rbp),%edx
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x34(%rbp),%edx
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
movss  -0x38(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
movss  -0x3c(%rbp),%xmm0
mov    0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1139 <find_the_two_nearest_keys+0x29>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_the_two_nearest_keys>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %edx,0xc(%rsp)
test   %esi,%esi
jle    11ac <find_the_two_nearest_keys+0x9c>
mov    %r9,%r12
mov    %r8,%rbp
mov    %rcx,%r14
mov    %rdi,%rbx
movslq 0xc(%rsp),%r13
mov    %esi,%eax
mov    %rax,0x20(%rsp)
shl    $0x2,%r13
xor    %r15d,%r15d
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    0xc(%rsp),%esi
lea    0x14(%rsp),%rdx
lea    0x10(%rsp),%rcx
lea    0x1c(%rsp),%r8
lea    0x18(%rsp),%r9
call   1030 <find_array_two_min@plt>
mov    0x1c(%rsp),%eax
mov    %eax,(%r14,%r15,4)
mov    0x18(%rsp),%eax
mov    %eax,0x0(%rbp,%r15,4)
movss  0x14(%rsp),%xmm0
movss  %xmm0,(%r12,%r15,4)
movss  0x10(%rsp),%xmm0
mov    0x60(%rsp),%rax
movss  %xmm0,(%rax,%r15,4)
add    $0x1,%r15
add    %r13,%rbx
cmp    %r15,0x20(%rsp)
jne    1150 <find_the_two_nearest_keys+0x40>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @find_the_two_nearest_keys(float* %0, i32 %1, i32 %2, i32* nocapture writeonly %3, i32* nocapture writeonly %4, float* nocapture writeonly %5, float* nocapture writeonly %6) {
%8 = alloca i32
%9 = alloca i32
%10 = alloca float
%11 = alloca float
%12 = icmp sgt i32 %1, 0
br i1 %12, label %13, label %20
13: ; preds = %7
%14 = bitcast i32* %8 to i8*
%15 = bitcast i32* %9 to i8*
%16 = bitcast float* %10 to i8*
%17 = bitcast float* %11 to i8*
%18 = sext i32 %2 to i64
%19 = zext i32 %1 to i64
br label %21
20: ; preds = %21, %7
ret void
21: ; preds = %13, %21
%22 = phi i64 [ 0, %13 ], [ %34, %21 ]
%23 = mul nsw i64 %22, %18
%24 = getelementptr inbounds float, float* %0, i64 %23
%25 = call i32 @find_array_two_min(float* %24, i32 %2, float* %10, float* %11, i32* %8, i32* %9)
%26 = load i32, i32* %8
%27 = getelementptr inbounds i32, i32* %3, i64 %22
store i32 %26, i32* %27
%28 = load i32, i32* %9
%29 = getelementptr inbounds i32, i32* %4, i64 %22
store i32 %28, i32* %29
%30 = load float, float* %10
%31 = getelementptr inbounds float, float* %5, i64 %22
store float %30, float* %31
%32 = load float, float* %11
%33 = getelementptr inbounds float, float* %6, i64 %22
store float %32, float* %33
%34 = add nuw nsw i64 %22, 1
%35 = icmp eq i64 %34, %19
br i1 %35, label %20, label %21
}