#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_entries(struct jx **a, struct jx **b) {
  int result;
  const char *x, *y;
  x = jx_lookup_string(*a, "type");
  if (!x)
    x = "unknown";
  y = jx_lookup_string(*b, "type");
  if (!y)
    y = "unknown";
  result = strcasecmp(x, y);
  if (result != 0)
    return result;
  x = jx_lookup_string(*a, "name");
  if (!x)
    x = "unknown";
  y = jx_lookup_string(*b, "name");
  if (!y)
    y = "unknown";
  return strcasecmp(x, y);
}


x86 assembly (clang, -O0):
<compare_entries>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xec2(%rip),%rsi
call   1030 <jx_lookup_string@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    115d <compare_entries+0x3d>
lea    0xeac(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
lea    0xe95(%rip),%rsi
call   1030 <jx_lookup_string@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    118a <compare_entries+0x6a>
lea    0xe7f(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1040 <strcasecmp@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     11af <compare_entries+0x8f>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1219 <compare_entries+0xf9>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xe50(%rip),%rsi
call   1030 <jx_lookup_string@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11dc <compare_entries+0xbc>
lea    0xe2d(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
lea    0xe23(%rip),%rsi
call   1030 <jx_lookup_string@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1209 <compare_entries+0xe9>
lea    0xe00(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1040 <strcasecmp@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compare_entries>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    (%rdi),%rdi
lea    0xec7(%rip),%r12
mov    %r12,%rsi
call   1030 <jx_lookup_string@plt>
mov    %rax,%rbx
test   %rax,%rax
lea    0xeb7(%rip),%r13
cmove  %r13,%rbx
mov    (%r14),%rdi
mov    %r12,%rsi
call   1030 <jx_lookup_string@plt>
test   %rax,%rax
cmove  %r13,%rax
mov    %rbx,%rdi
mov    %rax,%rsi
call   1040 <strcasecmp@plt>
test   %eax,%eax
je     117d <compare_entries+0x5d>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    (%r15),%rdi
lea    0xe86(%rip),%r15
mov    %r15,%rsi
call   1030 <jx_lookup_string@plt>
mov    %rax,%rbx
test   %rax,%rax
cmove  %r13,%rbx
mov    (%r14),%rdi
mov    %r15,%rsi
call   1030 <jx_lookup_string@plt>
test   %rax,%rax
cmovne %rax,%r13
mov    %rbx,%rdi
mov    %r13,%rsi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1040 <strcasecmp@plt>

LLVM IR (-O0):
%struct.jx = type { i32 }
@.str = [5 x i8] c"type\00"
@.str.1 = [8 x i8] c"unknown\00"
@.str.2 = [5 x i8] c"name\00"
define i32 @compare_entries(%struct.jx** %0, %struct.jx** %1) {
%3 = alloca i32
%4 = alloca %struct.jx**
%5 = alloca %struct.jx**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
store %struct.jx** %0, %struct.jx*** %4
store %struct.jx** %1, %struct.jx*** %5
%9 = load %struct.jx**, %struct.jx*** %4
%10 = load %struct.jx*, %struct.jx** %9
%11 = call i8* @jx_lookup_string(%struct.jx* %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %11, i8** %7
%12 = load i8*, i8** %7
%13 = icmp ne i8* %12, null
br i1 %13, label %15, label %14
14: ; preds = %2
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8** %7
br label %15
15: ; preds = %14, %2
%16 = load %struct.jx**, %struct.jx*** %5
%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** %8
%20 = icmp ne i8* %19, null
br i1 %20, label %22, label %21
21: ; preds = %15
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8** %8
br label %22
22: ; preds = %21, %15
%23 = load i8*, i8** %7
%24 = load i8*, i8** %8
%25 = call i32 @strcasecmp(i8* %23, i8* %24)
store i32 %25, i32* %6
%26 = load i32, i32* %6
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %22
%29 = load i32, i32* %6
store i32 %29, i32* %3
br label %48
30: ; preds = %22
%31 = load %struct.jx**, %struct.jx*** %4
%32 = load %struct.jx*, %struct.jx** %31
%33 = call i8* @jx_lookup_string(%struct.jx* %32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store i8* %33, i8** %7
%34 = load i8*, i8** %7
%35 = icmp ne i8* %34, null
br i1 %35, label %37, label %36
36: ; preds = %30
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8** %7
br label %37
37: ; preds = %36, %30
%38 = load %struct.jx**, %struct.jx*** %5
%39 = load %struct.jx*, %struct.jx** %38
%40 = call i8* @jx_lookup_string(%struct.jx* %39, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store i8* %40, i8** %8
%41 = load i8*, i8** %8
%42 = icmp ne i8* %41, null
br i1 %42, label %44, label %43
43: ; preds = %37
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8** %8
br label %44
44: ; preds = %43, %37
%45 = load i8*, i8** %7
%46 = load i8*, i8** %8
%47 = call i32 @strcasecmp(i8* %45, i8* %46)
store i32 %47, i32* %3
br label %48
48: ; preds = %44, %28
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
%struct.jx = type { i32 }
@.str = [5 x i8] c"type\00"
@.str.1 = [8 x i8] c"unknown\00"
@.str.2 = [5 x i8] c"name\00"
define i32 @compare_entries(%struct.jx** nocapture %0, %struct.jx** nocapture %1) {
%3 = load %struct.jx*, %struct.jx** %0
%4 = tail call i8* @jx_lookup_string(%struct.jx* %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i8* %4, null
%6 = select i1 %5, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %4
%7 = load %struct.jx*, %struct.jx** %1
%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* %8, null
%10 = select i1 %9, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %8
%11 = tail call i32 @strcasecmp(i8* %6, i8* %10)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %23
13: ; preds = %2
%14 = load %struct.jx*, %struct.jx** %0
%15 = tail call i8* @jx_lookup_string(%struct.jx* %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%16 = icmp eq i8* %15, null
%17 = select i1 %16, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %15
%18 = load %struct.jx*, %struct.jx** %1
%19 = tail call i8* @jx_lookup_string(%struct.jx* %18, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%20 = icmp eq i8* %19, null
%21 = select i1 %20, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %19
%22 = tail call i32 @strcasecmp(i8* %17, i8* %21)
br label %23
23: ; preds = %2, %13
%24 = phi i32 [ %22, %13 ], [ %11, %2 ]
ret i32 %24
}