int celix_utils_compareServiceIdsAndRanking(long svcIdA, long svcRankA,
                                            long svcIdB, long svcRankB) {
  int result;
  if (svcIdA == svcIdB) {
    result = 0;
  } else if (svcRankA != svcRankB) {
    result = svcRankA < svcRankB ? 1 : -1;
  } else {
    result = svcIdA < svcIdB ? -1 : 1;
  }
  return result;
}


x86 assembly (clang, -O0):
<celix_utils_compareServiceIdsAndRanking>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rax
cmp    -0x18(%rbp),%rax
jne    112e <celix_utils_compareServiceIdsAndRanking+0x2e>
movl   $0x0,-0x24(%rbp)
jmp    117c <celix_utils_compareServiceIdsAndRanking+0x7c>
mov    -0x10(%rbp),%rax
cmp    -0x20(%rbp),%rax
je     115c <celix_utils_compareServiceIdsAndRanking+0x5c>
mov    -0x10(%rbp),%rdx
mov    -0x20(%rbp),%rsi
mov    $0xffffffff,%eax
mov    $0x1,%ecx
cmp    %rsi,%rdx
cmovl  %ecx,%eax
mov    %eax,-0x24(%rbp)
jmp    1177 <celix_utils_compareServiceIdsAndRanking+0x77>
mov    -0x8(%rbp),%rdx
mov    -0x18(%rbp),%rsi
mov    $0x1,%eax
mov    $0xffffffff,%ecx
cmp    %rsi,%rdx
cmovl  %ecx,%eax
mov    %eax,-0x24(%rbp)
jmp    117c <celix_utils_compareServiceIdsAndRanking+0x7c>
mov    -0x24(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<celix_utils_compareServiceIdsAndRanking>:
xor    %eax,%eax
cmp    %rdx,%rdi
je     1121 <celix_utils_compareServiceIdsAndRanking+0x21>
cmp    %rcx,%rsi
jne    1116 <celix_utils_compareServiceIdsAndRanking+0x16>
xor    %eax,%eax
cmp    %rdx,%rdi
setge  %al
jmp    111c <celix_utils_compareServiceIdsAndRanking+0x1c>
setl   %al
movzbl %al,%eax
add    %eax,%eax
add    $0xffffffff,%eax
ret

LLVM IR (-O0):
define i32 @celix_utils_compareServiceIdsAndRanking(i64 %0, i64 %1, i64 %2, i64 %3) {
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i32
store i64 %0, i64* %5
store i64 %1, i64* %6
store i64 %2, i64* %7
store i64 %3, i64* %8
%10 = load i64, i64* %5
%11 = load i64, i64* %7
%12 = icmp eq i64 %10, %11
br i1 %12, label %13, label %14
13: ; preds = %4
store i32 0, i32* %9
br label %31
14: ; preds = %4
%15 = load i64, i64* %6
%16 = load i64, i64* %8
%17 = icmp ne i64 %15, %16
br i1 %17, label %18, label %24
18: ; preds = %14
%19 = load i64, i64* %6
%20 = load i64, i64* %8
%21 = icmp slt i64 %19, %20
%22 = zext i1 %21 to i64
%23 = select i1 %21, i32 1, i32 -1
store i32 %23, i32* %9
br label %30
24: ; preds = %14
%25 = load i64, i64* %5
%26 = load i64, i64* %7
%27 = icmp slt i64 %25, %26
%28 = zext i1 %27 to i64
%29 = select i1 %27, i32 -1, i32 1
store i32 %29, i32* %9
br label %30
30: ; preds = %24, %18
br label %31
31: ; preds = %30, %13
%32 = load i32, i32* %9
ret i32 %32
}

LLVM IR (-O2):
define i32 @celix_utils_compareServiceIdsAndRanking(i64 %0, i64 %1, i64 %2, i64 %3) {
%5 = icmp eq i64 %0, %2
br i1 %5, label %14, label %6
6: ; preds = %4
%7 = icmp eq i64 %1, %3
br i1 %7, label %11, label %8
8: ; preds = %6
%9 = icmp slt i64 %1, %3
%10 = select i1 %9, i32 1, i32 -1
br label %14
11: ; preds = %6
%12 = icmp slt i64 %0, %2
%13 = select i1 %12, i32 -1, i32 1
br label %14
14: ; preds = %4, %8, %11
%15 = phi i32 [ %10, %8 ], [ %13, %11 ], [ 0, %4 ]
ret i32 %15
}