#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 ice_strcasecmp(char *, char *);
int /*<<< orphan*/ write_log(int /*<<< orphan*/, char *);
int /*<<< orphan*/ xa_debug(int, char *, char *, char *);
int compare_strings(const void *first, const void *second, void *param) {
  char *a1 = (char *)first, *a2 = (char *)second;
  if (!first || !second) {
    write_log(0, "WARNING: compare_strings called with null pointers");
    return 0;
  }
  xa_debug(4, "DEBUG: Comparing [%s] with [%s]", a1, a2);
  return (ice_strcasecmp(a1, a2));
}


x86 assembly (clang, -O0):
<compare_strings>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     116a <compare_strings+0x3a>
cmpq   $0x0,-0x18(%rbp)
jne    1184 <compare_strings+0x54>
xor    %edi,%edi
lea    0xe8d(%rip),%rsi
call   1040 <write_log@plt>
movl   $0x0,-0x4(%rbp)
jmp    11ad <compare_strings+0x7d>
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    $0x4,%edi
lea    0xe9b(%rip),%rsi
call   1030 <xa_debug@plt>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1050 <ice_strcasecmp@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compare_strings>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     116d <compare_strings+0x3d>
mov    %rsi,%r14
test   %rsi,%rsi
je     116d <compare_strings+0x3d>
mov    %rdi,%rbx
lea    0xee8(%rip),%rsi
mov    $0x4,%edi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1030 <xa_debug@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <ice_strcasecmp@plt>
lea    0xe8c(%rip),%rsi
xor    %edi,%edi
call   1040 <write_log@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [51 x i8] c"WARNING: compare_strings called with null pointers\00"
@.str.1 = [32 x i8] c"DEBUG: Comparing [%s] with [%s]\00"
define i32 @compare_strings(i8* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%10 = load i8*, i8** %5
store i8* %10, i8** %8
%11 = load i8*, i8** %6
store i8* %11, i8** %9
%12 = load i8*, i8** %5
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %17
14: ; preds = %3
%15 = load i8*, i8** %6
%16 = icmp ne i8* %15, null
br i1 %16, label %19, label %17
17: ; preds = %14, %3
%18 = call i32 @write_log(i32 0, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %4
br label %26
19: ; preds = %14
%20 = load i8*, i8** %8
%21 = load i8*, i8** %9
%22 = call i32 @xa_debug(i32 4, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %20, i8* %21)
%23 = load i8*, i8** %8
%24 = load i8*, i8** %9
%25 = call i32 @ice_strcasecmp(i8* %23, i8* %24)
store i32 %25, i32* %4
br label %26
26: ; preds = %19, %17
%27 = load i32, i32* %4
ret i32 %27
}

LLVM IR (-O2):
@.str = [51 x i8] c"WARNING: compare_strings called with null pointers\00"
@.str.1 = [32 x i8] c"DEBUG: Comparing [%s] with [%s]\00"
define i32 @compare_strings(i8* %0, i8* %1, i8* nocapture readnone %2) {
%4 = icmp ne i8* %0, null
%5 = icmp ne i8* %1, null
%6 = and i1 %4, %5
br i1 %6, label %9, label %7
7: ; preds = %3
%8 = tail call i32 @write_log(i32 0, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
br label %12
9: ; preds = %3
%10 = tail call i32 @xa_debug(i32 4, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %1)
%11 = tail call i32 @ice_strcasecmp(i8* %0, i8* %1)
br label %12
12: ; preds = %9, %7
%13 = phi i32 [ %11, %9 ], [ 0, %7 ]
ret i32 %13
}