#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);
float vnormf(float const *, int);
int compare_vectors_by_length(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;
    float na = vnormf(da, dim);
    float nb = vnormf(db, dim);
    return (na > nb) - (na < nb);
  }
}


x86 assembly (clang, -O0):
<compare_vectors_by_length>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1157 <compare_vectors_by_length+0x37>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,0x2ee5(%rip)
mov    %eax,-0x4(%rbp)
jmp    11c6 <compare_vectors_by_length+0xa6>
mov    0x2ed7(%rip),%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    0x2eb8(%rip),%esi
call   1030 <vnormf@plt>
movss  %xmm0,-0x34(%rbp)
mov    -0x30(%rbp),%rdi
mov    0x2ea4(%rip),%esi
call   1030 <vnormf@plt>
movss  %xmm0,-0x38(%rbp)
movss  -0x34(%rbp),%xmm0
ucomiss -0x38(%rbp),%xmm0
seta   %al
and    $0x1,%al
movzbl %al,%eax
movss  -0x34(%rbp),%xmm1
movss  -0x38(%rbp),%xmm0
ucomiss %xmm1,%xmm0
seta   %cl
and    $0x1,%cl
movzbl %cl,%ecx
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compare_vectors_by_length>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
test   %rdi,%rdi
je     1176 <compare_vectors_by_length+0x56>
mov    %rdi,%rbx
mov    0x2eff(%rip),%edi
call   1040 <assert@plt>
mov    0x2ef4(%rip),%esi
mov    %rbx,%rdi
call   1030 <vnormf@plt>
movss  %xmm0,0x4(%rsp)
mov    0x2ee0(%rip),%esi
mov    %r14,%rdi
call   1030 <vnormf@plt>
xor    %eax,%eax
movss  0x4(%rsp),%xmm1
ucomiss %xmm0,%xmm1
seta   %al
xor    %ecx,%ecx
ucomiss %xmm1,%xmm0
seta   %cl
sub    %ecx,%eax
jmp    117f <compare_vectors_by_length+0x5f>
mov    (%r14),%eax
mov    %eax,0x2eb5(%rip)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@compare_vectors_by_length.dim = internal global i32 0
define i32 @compare_vectors_by_length(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca float*
%8 = alloca float*
%9 = alloca float
%10 = alloca float
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_length.dim
store i32 %17, i32* %3
br label %40
18: ; preds = %2
%19 = load i32, i32* @compare_vectors_by_length.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
%25 = load float*, float** %7
%26 = load i32, i32* @compare_vectors_by_length.dim
%27 = call float @vnormf(float* %25, i32 %26)
store float %27, float* %9
%28 = load float*, float** %8
%29 = load i32, i32* @compare_vectors_by_length.dim
%30 = call float @vnormf(float* %28, i32 %29)
store float %30, float* %10
%31 = load float, float* %9
%32 = load float, float* %10
%33 = fcmp ogt float %31, %32
%34 = zext i1 %33 to i32
%35 = load float, float* %9
%36 = load float, float* %10
%37 = fcmp olt float %35, %36
%38 = zext i1 %37 to i32
%39 = sub nsw i32 %34, %38
store i32 %39, i32* %3
br label %40
40: ; preds = %18, %13
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
@compare_vectors_by_length.dim = internal unnamed_addr global i32 0
define i32 @compare_vectors_by_length(i8* %0, i8* %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_length.dim
br label %21
7: ; preds = %2
%8 = load i32, i32* @compare_vectors_by_length.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_length.dim
%13 = tail call float @vnormf(float* %10, i32 %12)
%14 = load i32, i32* @compare_vectors_by_length.dim
%15 = tail call float @vnormf(float* %11, i32 %14)
%16 = fcmp ogt float %13, %15
%17 = zext i1 %16 to i32
%18 = fcmp olt float %13, %15
%19 = sext i1 %18 to i32
%20 = add nsw i32 %19, %17
br label %21
21: ; preds = %7, %4
%22 = phi i32 [ %20, %7 ], [ %6, %4 ]
ret i32 %22
}