#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 */
struct jx {
  int dummy;
};

/* Variables and functions */
char *jx_lookup_string(struct jx *, char *);
int strcasecmp(char const *, char const *);
int compare_jx(const void *a, const void *b) {
  struct jx **pa = (struct jx **)a;
  struct jx **pb = (struct jx **)b;
  const char *sa = jx_lookup_string(*pa, "name");
  const char *sb = jx_lookup_string(*pb, "name");
  if (!sa)
    sa = "unknown";
  if (!sb)
    sb = "unknown";
  return strcasecmp(sa, sb);
}


x86 assembly (clang, -O0):
<compare_jx>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
lea    0xeb2(%rip),%rsi
call   1030 <jx_lookup_string@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
lea    0xe9b(%rip),%rsi
call   1030 <jx_lookup_string@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1184 <compare_jx+0x64>
lea    0xe85(%rip),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    119a <compare_jx+0x7a>
lea    0xe6f(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1040 <strcasecmp@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compare_jx>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    (%rdi),%rdi
lea    0xece(%rip),%r14
mov    %r14,%rsi
call   1030 <jx_lookup_string@plt>
mov    %rax,%rbx
mov    (%r15),%rdi
mov    %r14,%rsi
call   1030 <jx_lookup_string@plt>
test   %rbx,%rbx
lea    0xeb3(%rip),%rsi
cmove  %rsi,%rbx
test   %rax,%rax
cmovne %rax,%rsi
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <strcasecmp@plt>

LLVM IR (-O0):
%struct.jx = type { i32 }
@.str = [5 x i8] c"name\00"
@.str.1 = [8 x i8] c"unknown\00"
define i32 @compare_jx(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca %struct.jx**
%6 = alloca %struct.jx**
%7 = alloca i8*
%8 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%9 = load i8*, i8** %3
%10 = bitcast i8* %9 to %struct.jx**
store %struct.jx** %10, %struct.jx*** %5
%11 = load i8*, i8** %4
%12 = bitcast i8* %11 to %struct.jx**
store %struct.jx** %12, %struct.jx*** %6
%13 = load %struct.jx**, %struct.jx*** %5
%14 = load %struct.jx*, %struct.jx** %13
%15 = call i8* @jx_lookup_string(%struct.jx* %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %15, i8** %7
%16 = load %struct.jx**, %struct.jx*** %6
%17 = load %struct.jx*, %struct.jx** %16
%18 = call i8* @jx_lookup_string(%struct.jx* %17, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %18, i8** %8
%19 = load i8*, i8** %7
%20 = icmp ne i8* %19, null
br i1 %20, label %22, label %21
21: ; preds = %2
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8** %7
br label %22
22: ; preds = %21, %2
%23 = load i8*, i8** %8
%24 = icmp ne i8* %23, null
br i1 %24, label %26, label %25
25: ; preds = %22
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8** %8
br label %26
26: ; preds = %25, %22
%27 = load i8*, i8** %7
%28 = load i8*, i8** %8
%29 = call i32 @strcasecmp(i8* %27, i8* %28)
ret i32 %29
}

LLVM IR (-O2):
%struct.jx = type { i32 }
@.str = [5 x i8] c"name\00"
@.str.1 = [8 x i8] c"unknown\00"
define i32 @compare_jx(i8* nocapture %0, i8* nocapture %1) {
%3 = bitcast i8* %0 to %struct.jx**
%4 = bitcast i8* %1 to %struct.jx**
%5 = load %struct.jx*, %struct.jx** %3
%6 = tail call i8* @jx_lookup_string(%struct.jx* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%7 = load %struct.jx*, %struct.jx** %4
%8 = tail call i8* @jx_lookup_string(%struct.jx* %7, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i8* %6, null
%10 = select i1 %9, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %6
%11 = icmp eq i8* %8, null
%12 = select i1 %11, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %8
%13 = tail call i32 @strcasecmp(i8* %10, i8* %12)
ret i32 %13
}