#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*/ assert(int);
int compare_vectors_by_components(const void *a, const void *b) {
  static int dim = 0;
  if (!a) {
    const int *db = (const int *)b;
    return dim = *db;
  } else {
    assert(dim);
    const float *da = (const float *)a;
    const float *db = (const float *)b;
    for (int i = 0; i < dim; i++) {
      int r = (da[i] > db[i]) - (da[i] < db[i]);
      if (r)
        return r;
    }
    return 0;
  }
}


x86 assembly (clang, -O0):
<compare_vectors_by_components>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1147 <compare_vectors_by_components+0x37>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,0x2eed(%rip)
mov    %eax,-0x4(%rbp)
jmp    11f3 <compare_vectors_by_components+0xe3>
mov    0x2edf(%rip),%edi
call   1030 <assert@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    0x2eba(%rip),%eax
jge    11ec <compare_vectors_by_components+0xdc>
mov    -0x28(%rbp),%rax
movslq -0x34(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
mov    -0x30(%rbp),%rax
movslq -0x34(%rbp),%rcx
ucomiss (%rax,%rcx,4),%xmm0
seta   %al
and    $0x1,%al
movzbl %al,%eax
mov    -0x28(%rbp),%rcx
movslq -0x34(%rbp),%rdx
movss  (%rcx,%rdx,4),%xmm1
mov    -0x30(%rbp),%rcx
movslq -0x34(%rbp),%rdx
movss  (%rcx,%rdx,4),%xmm0
ucomiss %xmm1,%xmm0
seta   %cl
and    $0x1,%cl
movzbl %cl,%ecx
sub    %ecx,%eax
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
je     11d9 <compare_vectors_by_components+0xc9>
mov    -0x38(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11f3 <compare_vectors_by_components+0xe3>
jmp    11de <compare_vectors_by_components+0xce>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1169 <compare_vectors_by_components+0x59>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compare_vectors_by_components>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
test   %rdi,%rdi
je     116d <compare_vectors_by_components+0x5d>
mov    %rdi,%rbx
mov    0x2f07(%rip),%edi
call   1030 <assert@plt>
mov    0x2efc(%rip),%ecx
test   %ecx,%ecx
jle    1169 <compare_vectors_by_components+0x59>
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
movss  (%rbx,%rdx,4),%xmm0
movss  (%r14,%rdx,4),%xmm1
xor    %eax,%eax
ucomiss %xmm1,%xmm0
seta   %al
xor    %esi,%esi
ucomiss %xmm0,%xmm1
seta   %sil
sub    %esi,%eax
jne    1176 <compare_vectors_by_components+0x66>
add    $0x1,%rdx
cmp    %rdx,%rcx
jne    1140 <compare_vectors_by_components+0x30>
xor    %eax,%eax
jmp    1176 <compare_vectors_by_components+0x66>
mov    (%r14),%eax
mov    %eax,0x2eb6(%rip)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@compare_vectors_by_components.dim = internal global i32 0
define i32 @compare_vectors_by_components(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca float*
%8 = alloca float*
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%11 = load i8*, i8** %4
%12 = icmp ne i8* %11, null
br i1 %12, label %18, label %13
13: ; preds = %2
%14 = load i8*, i8** %5
%15 = bitcast i8* %14 to i32*
store i32* %15, i32** %6
%16 = load i32*, i32** %6
%17 = load i32, i32* %16
store i32 %17, i32* @compare_vectors_by_components.dim
store i32 %17, i32* %3
br label %64
18: ; preds = %2
%19 = load i32, i32* @compare_vectors_by_components.dim
%20 = call i32 @assert(i32 %19)
%21 = load i8*, i8** %4
%22 = bitcast i8* %21 to float*
store float* %22, float** %7
%23 = load i8*, i8** %5
%24 = bitcast i8* %23 to float*
store float* %24, float** %8
store i32 0, i32* %9
br label %25
25: ; preds = %60, %18
%26 = load i32, i32* %9
%27 = load i32, i32* @compare_vectors_by_components.dim
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %63
29: ; preds = %25
%30 = load float*, float** %7
%31 = load i32, i32* %9
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds float, float* %30, i64 %32
%34 = load float, float* %33
%35 = load float*, float** %8
%36 = load i32, i32* %9
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds float, float* %35, i64 %37
%39 = load float, float* %38
%40 = fcmp ogt float %34, %39
%41 = zext i1 %40 to i32
%42 = load float*, float** %7
%43 = load i32, i32* %9
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds float, float* %42, i64 %44
%46 = load float, float* %45
%47 = load float*, float** %8
%48 = load i32, i32* %9
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds float, float* %47, i64 %49
%51 = load float, float* %50
%52 = fcmp olt float %46, %51
%53 = zext i1 %52 to i32
%54 = sub nsw i32 %41, %53
store i32 %54, i32* %10
%55 = load i32, i32* %10
%56 = icmp ne i32 %55, 0
br i1 %56, label %57, label %59
57: ; preds = %29
%58 = load i32, i32* %10
store i32 %58, i32* %3
br label %64
59: ; preds = %29
br label %60
60: ; preds = %59
%61 = load i32, i32* %9
%62 = add nsw i32 %61, 1
store i32 %62, i32* %9
br label %25
63: ; preds = %25
store i32 0, i32* %3
br label %64
64: ; preds = %63, %57, %13
%65 = load i32, i32* %3
ret i32 %65
}

LLVM IR (-O2):
@compare_vectors_by_components.dim = internal unnamed_addr global i32 0
define i32 @compare_vectors_by_components(i8* %0, i8* nocapture %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = bitcast i8* %1 to i32*
%6 = load i32, i32* %5
store i32 %6, i32* @compare_vectors_by_components.dim
br label %31
7: ; preds = %2
%8 = load i32, i32* @compare_vectors_by_components.dim
%9 = tail call i32 @assert(i32 %8)
%10 = bitcast i8* %0 to float*
%11 = bitcast i8* %1 to float*
%12 = load i32, i32* @compare_vectors_by_components.dim
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %31
14: ; preds = %7
%15 = zext i32 %12 to i64
br label %18
16: ; preds = %18
%17 = icmp eq i64 %30, %15
br i1 %17, label %31, label %18
18: ; preds = %14, %16
%19 = phi i64 [ 0, %14 ], [ %30, %16 ]
%20 = getelementptr inbounds float, float* %10, i64 %19
%21 = load float, float* %20
%22 = getelementptr inbounds float, float* %11, i64 %19
%23 = load float, float* %22
%24 = fcmp ogt float %21, %23
%25 = zext i1 %24 to i32
%26 = fcmp olt float %21, %23
%27 = sext i1 %26 to i32
%28 = add nsw i32 %27, %25
%29 = icmp eq i32 %28, 0
%30 = add nuw nsw i64 %19, 1
br i1 %29, label %16, label %31
31: ; preds = %16, %18, %7, %4
%32 = phi i32 [ %6, %4 ], [ 0, %7 ], [ 0, %16 ], [ %28, %18 ]
ret i32 %32
}