#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 strncmp(char const *, char const *, int /*<<< orphan*/);
int /*<<< orphan*/ xmax(size_t, size_t);
size_t xstrlen(char const *);
int xstrcmp(const char *c1, const char *c2) {
  size_t s1 = xstrlen(c1);
  size_t s2 = xstrlen(c2);
  if (s1 == 0 && s2 == 0)
    return 0;
  if (s1 == 0)
    return -1;
  if (s2 == 0)
    return +1;
  return strncmp(c1, c2, xmax(s1, s2));
}


x86 assembly (clang, -O0):
<xstrcmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <xstrlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <xstrlen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    117c <xstrcmp+0x4c>
cmpq   $0x0,-0x28(%rbp)
jne    117c <xstrcmp+0x4c>
movl   $0x0,-0x4(%rbp)
jmp    11d9 <xstrcmp+0xa9>
cmpq   $0x0,-0x20(%rbp)
jne    1193 <xstrcmp+0x63>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d9 <xstrcmp+0xa9>
cmpq   $0x0,-0x28(%rbp)
jne    11aa <xstrcmp+0x7a>
movl   $0x1,-0x4(%rbp)
jmp    11d9 <xstrcmp+0xa9>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <xmax@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xstrcmp>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
call   1050 <xstrlen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1050 <xstrlen@plt>
xor    %edx,%edx
mov    %rbx,%rcx
or     %rax,%rcx
sete   %dl
add    $0xffffffff,%edx
mov    $0x1,%ecx
test   %rbx,%rbx
cmove  %edx,%ecx
je     1188 <xstrcmp+0x58>
test   %rax,%rax
je     1188 <xstrcmp+0x58>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1040 <xmax@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %eax,%edx
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <strncmp@plt>
mov    %ecx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i32 @xstrcmp(i8* %0, i8* %1) {
%3 = tail call i64 @xstrlen(i8* %0)
%4 = tail call i64 @xstrlen(i8* %1)
%5 = icmp eq i64 %3, 0
%6 = icmp eq i64 %4, 0
%7 = select i1 %5, i1 %6, i1 false
%8 = xor i1 %7, true
%9 = sext i1 %8 to i32
%10 = select i1 %5, i1 true, i1 %6
%11 = select i1 %5, i32 %9, i32 1
br i1 %10, label %15, label %12
12: ; preds = %2
%13 = tail call i32 @xmax(i64 %3, i64 %4)
%14 = tail call i32 @strncmp(i8* %0, i8* %1, i32 %13)
br label %15
15: ; preds = %2, %12
%16 = phi i32 [ %14, %12 ], [ %11, %2 ]
ret i32 %16
}