#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*/ strcmp(char *, char *);
int compare_strings(const void *kk1, const void *kk2) {
  char *k1, *k2;
  k1 = (char *)kk1;
  k2 = (char *)kk2;
  if (k1 == k2)
    return 1;
  else if (k1 == 0 || k2 == 0)
    return 0;
  else
    return !strcmp(k1, k2);
}


x86 assembly (clang, -O0):
<compare_strings>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jne    114a <compare_strings+0x3a>
movl   $0x1,-0x4(%rbp)
jmp    1189 <compare_strings+0x79>
cmpq   $0x0,-0x20(%rbp)
je     1160 <compare_strings+0x50>
cmpq   $0x0,-0x28(%rbp)
jne    116c <compare_strings+0x5c>
movl   $0x0,-0x4(%rbp)
jmp    1189 <compare_strings+0x79>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compare_strings>:
cmp    %rsi,%rdi
je     1135 <compare_strings+0x25>
xor    %eax,%eax
test   %rdi,%rdi
je     1134 <compare_strings+0x24>
test   %rsi,%rsi
je     1134 <compare_strings+0x24>
push   %rax
call   1030 <strcmp@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
sete   %al
add    $0x8,%rsp
ret
mov    $0x1,%eax
ret

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

LLVM IR (-O2):
define i32 @compare_strings(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, %1
br i1 %3, label %12, label %4
4: ; preds = %2
%5 = icmp eq i8* %0, null
%6 = icmp eq i8* %1, null
%7 = or i1 %5, %6
br i1 %7, label %12, label %8
8: ; preds = %4
%9 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* dereferenceable(1) %1)
%10 = icmp eq i32 %9, 0
%11 = zext i1 %10 to i32
br label %12
12: ; preds = %4, %2, %8
%13 = phi i32 [ %11, %8 ], [ 1, %2 ], [ 0, %4 ]
ret i32 %13
}