#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 strlen(char const *);
int CompareStr(const char *S1, const char *S2) {
  int len1, len2;
  len1 = (S1 ? strlen(S1) : 0);
  len2 = (S2 ? strlen(S2) : 0);
  if ((len1 == 0) && (len2 == 0))
    return (0);
  if (len1 == 0)
    return (-1);
  if (len2 == 0)
    return (1);
  return (strcmp(S1, S2));
}


x86 assembly (clang, -O0):
<CompareStr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     114c <CompareStr+0x2c>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x24(%rbp)
jmp    1156 <CompareStr+0x36>
xor    %eax,%eax
mov    %eax,-0x24(%rbp)
jmp    1156 <CompareStr+0x36>
mov    -0x24(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1178 <CompareStr+0x58>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x28(%rbp)
jmp    1182 <CompareStr+0x62>
xor    %eax,%eax
mov    %eax,-0x28(%rbp)
jmp    1182 <CompareStr+0x62>
mov    -0x28(%rbp),%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    11a8 <CompareStr+0x88>
cmpl   $0x0,-0x20(%rbp)
jne    11a8 <CompareStr+0x88>
movl   $0x0,-0x4(%rbp)
jmp    11e4 <CompareStr+0xc4>
cmpl   $0x0,-0x1c(%rbp)
jne    11be <CompareStr+0x9e>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e4 <CompareStr+0xc4>
cmpl   $0x0,-0x20(%rbp)
jne    11d4 <CompareStr+0xb4>
movl   $0x1,-0x4(%rbp)
jmp    11e4 <CompareStr+0xc4>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcmp@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CompareStr>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
test   %rdi,%rdi
je     1173 <CompareStr+0x53>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
test   %r14,%r14
je     117a <CompareStr+0x5a>
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
xor    %edx,%edx
mov    %ebp,%eax
or     %ecx,%eax
sete   %dl
add    $0xffffffff,%edx
mov    $0x1,%eax
test   %ebp,%ebp
cmove  %edx,%eax
je     118d <CompareStr+0x6d>
test   %ecx,%ecx
je     118d <CompareStr+0x6d>
mov    %rbx,%rdi
mov    %r14,%rsi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <strcmp@plt>
xor    %ebp,%ebp
test   %r14,%r14
jne    113e <CompareStr+0x1e>
xor    %ecx,%ecx
test   %ebp,%ebp
setne  %cl
neg    %ecx
test   %ebp,%ebp
mov    $0x1,%eax
cmove  %ecx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @CompareStr(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %4
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i8*, i8** %4
%12 = call i32 @strlen(i8* %11)
br label %14
13: ; preds = %2
br label %14
14: ; preds = %13, %10
%15 = phi i32 [ %12, %10 ], [ 0, %13 ]
store i32 %15, i32* %6
%16 = load i8*, i8** %5
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = load i8*, i8** %5
%20 = call i32 @strlen(i8* %19)
br label %22
21: ; preds = %14
br label %22
22: ; preds = %21, %18
%23 = phi i32 [ %20, %18 ], [ 0, %21 ]
store i32 %23, i32* %7
%24 = load i32, i32* %6
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %22
%27 = load i32, i32* %7
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %26
store i32 0, i32* %3
br label %42
30: ; preds = %26, %22
%31 = load i32, i32* %6
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %30
store i32 -1, i32* %3
br label %42
34: ; preds = %30
%35 = load i32, i32* %7
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %34
store i32 1, i32* %3
br label %42
38: ; preds = %34
%39 = load i8*, i8** %4
%40 = load i8*, i8** %5
%41 = call i32 @strcmp(i8* %39, i8* %40)
store i32 %41, i32* %3
br label %42
42: ; preds = %38, %37, %33, %29
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
define i32 @CompareStr(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = tail call i32 @strlen(i8* %0)
br label %6
6: ; preds = %2, %4
%7 = phi i32 [ %5, %4 ], [ 0, %2 ]
%8 = icmp eq i8* %1, null
br i1 %8, label %9, label %14
9: ; preds = %6
%10 = icmp eq i32 %7, 0
%11 = xor i1 %10, true
%12 = sext i1 %11 to i32
%13 = select i1 %10, i32 %12, i32 1
br label %25
14: ; preds = %6
%15 = tail call i32 @strlen(i8* %1)
%16 = icmp eq i32 %15, 0
%17 = icmp eq i32 %7, 0
%18 = select i1 %17, i1 %16, i1 false
%19 = xor i1 %18, true
%20 = sext i1 %19 to i32
%21 = select i1 %17, i1 true, i1 %16
%22 = select i1 %17, i32 %20, i32 1
br i1 %21, label %25, label %23
23: ; preds = %14
%24 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* dereferenceable(1) %1)
br label %25
25: ; preds = %9, %14, %23
%26 = phi i32 [ %24, %23 ], [ %22, %14 ], [ %13, %9 ]
ret i32 %26
}