#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 strcmp(char const *, char const *);
int strcmpex(const char *c1, const char *c2) {
  if (c1 == NULL && c2 == NULL)
    return 0;
  if (c1 == NULL || c2 == NULL)
    return (c1 == NULL) ? -1 : 1;
  int res = strcmp(c1, c2);
  if (res < 0)
    return -1;
  if (res > 0)
    return 1;
  return res;
}


x86 assembly (clang, -O0):
<strcmpex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1142 <strcmpex+0x32>
cmpq   $0x0,-0x18(%rbp)
jne    1142 <strcmpex+0x32>
movl   $0x0,-0x4(%rbp)
jmp    11b7 <strcmpex+0xa7>
cmpq   $0x0,-0x10(%rbp)
je     1158 <strcmpex+0x48>
cmpq   $0x0,-0x18(%rbp)
jne    1175 <strcmpex+0x65>
mov    -0x10(%rbp),%rdx
mov    $0x1,%eax
mov    $0xffffffff,%ecx
cmp    $0x0,%rdx
cmove  %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    11b7 <strcmpex+0xa7>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcmp@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    119b <strcmpex+0x8b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b7 <strcmpex+0xa7>
cmpl   $0x0,-0x1c(%rbp)
jle    11b1 <strcmpex+0xa1>
movl   $0x1,-0x4(%rbp)
jmp    11b7 <strcmpex+0xa7>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strcmpex>:
xor    %eax,%eax
mov    %rdi,%rcx
or     %rsi,%rcx
je     113d <strcmpex+0x2d>
test   %rdi,%rdi
je     113e <strcmpex+0x2e>
test   %rsi,%rsi
je     113e <strcmpex+0x2e>
push   %rax
call   1030 <strcmp@plt>
xor    %ecx,%ecx
test   %eax,%eax
setne  %cl
mov    $0xffffffff,%eax
cmovns %ecx,%eax
add    $0x8,%rsp
ret
cmp    $0x1,%rdi
sbb    %eax,%eax
or     $0x1,%eax
ret

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

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