#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 */
scalar_t__ fabs(float);
int magCompIdx(const void *ip, const void *jp, void *dwt) {
  int i = *((int *)ip);
  int j = *((int *)jp);
  float a = ((float *)dwt)[i];
  float b = ((float *)dwt)[j];
  if (fabs(a) > fabs(b))
    return -1;
  else if (fabs(a) < fabs(b))
    return 1;
  else if (i < j)
    return -1;
  else if (i > j)
    return 1;
}


x86 assembly (clang, -O0):
<magCompIdx>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
movss  %xmm0,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
movss  %xmm0,-0x30(%rbp)
movss  -0x2c(%rbp),%xmm0
call   1030 <fabs@plt>
mov    %rax,-0x38(%rbp)
movss  -0x30(%rbp),%xmm0
call   1030 <fabs@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
cmp    %rcx,%rax
jle    118e <magCompIdx+0x7e>
movl   $0xffffffff,-0x4(%rbp)
jmp    1201 <magCompIdx+0xf1>
movss  -0x2c(%rbp),%xmm0
call   1030 <fabs@plt>
mov    %rax,-0x40(%rbp)
movss  -0x30(%rbp),%xmm0
call   1030 <fabs@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
cmp    %rcx,%rax
jge    11c2 <magCompIdx+0xb2>
movl   $0x1,-0x4(%rbp)
jmp    1201 <magCompIdx+0xf1>
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    11da <magCompIdx+0xca>
movl   $0xffffffff,-0x4(%rbp)
jmp    1201 <magCompIdx+0xf1>
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jle    11f2 <magCompIdx+0xe2>
movl   $0x1,-0x4(%rbp)
jmp    1201 <magCompIdx+0xf1>
jmp    11f7 <magCompIdx+0xe7>
jmp    11fc <magCompIdx+0xec>
jmp    1201 <magCompIdx+0xf1>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<magCompIdx>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
movslq (%rdi),%r14
movslq (%rsi),%r15
movss  (%rdx,%r14,4),%xmm0
movss  (%rdx,%r15,4),%xmm1
movss  %xmm1,0x8(%rsp)
movss  %xmm0,0xc(%rsp)
call   1030 <fabs@plt>
mov    %rax,%rbx
movss  0x8(%rsp),%xmm0
call   1030 <fabs@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
cmp    %rcx,%rbx
jg     118a <magCompIdx+0x7a>
movss  0xc(%rsp),%xmm0
call   1030 <fabs@plt>
mov    %rax,%rbx
movss  0x8(%rsp),%xmm0
call   1030 <fabs@plt>
mov    %rax,%rcx
mov    $0x1,%eax
cmp    %rcx,%rbx
jl     118a <magCompIdx+0x7a>
xor    %eax,%eax
cmp    %r15d,%r14d
setge  %al
add    %eax,%eax
add    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i32 @magCompIdx(i8* nocapture %0, i8* nocapture %1, i8* nocapture %2) {
%4 = bitcast i8* %0 to i32*
%5 = load i32, i32* %4
%6 = bitcast i8* %1 to i32*
%7 = load i32, i32* %6
%8 = bitcast i8* %2 to float*
%9 = sext i32 %5 to i64
%10 = getelementptr inbounds float, float* %8, i64 %9
%11 = load float, float* %10
%12 = sext i32 %7 to i64
%13 = getelementptr inbounds float, float* %8, i64 %12
%14 = load float, float* %13
%15 = tail call i64 @fabs(float %11)
%16 = tail call i64 @fabs(float %14)
%17 = icmp sgt i64 %15, %16
br i1 %17, label %25, label %18
18: ; preds = %3
%19 = tail call i64 @fabs(float %11)
%20 = tail call i64 @fabs(float %14)
%21 = icmp slt i64 %19, %20
br i1 %21, label %25, label %22
22: ; preds = %18
%23 = icmp slt i32 %5, %7
%24 = select i1 %23, i32 -1, i32 1
br label %25
25: ; preds = %22, %18, %3
%26 = phi i32 [ -1, %3 ], [ 1, %18 ], [ %24, %22 ]
ret i32 %26
}