#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 gln_strncasecmp(char const *, char const *, size_t);
size_t strlen(char const *);
int gln_strcasecmp(const char *s1, const char *s2) {
  size_t s1len, s2len;
  int result;
  s1len = strlen(s1);
  s2len = strlen(s2);
  result = gln_strncasecmp(s1, s2, s1len < s2len ? s1len : s2len);
  if (result < 0 || result > 0)
    return result;
  else
    return s1len < s2len ? -1 : s1len > s2len ? 1 : 0;
}


x86 assembly (clang, -O0):
<gln_strcasecmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    1175 <gln_strcasecmp+0x55>
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
jmp    117d <gln_strcasecmp+0x5d>
mov    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x38(%rbp),%rsi
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rdx
call   1040 <gln_strncasecmp@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jl     11a5 <gln_strcasecmp+0x85>
cmpl   $0x0,-0x2c(%rbp)
jle    11b0 <gln_strcasecmp+0x90>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11e9 <gln_strcasecmp+0xc9>
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    11cb <gln_strcasecmp+0xab>
mov    $0xffffffff,%eax
mov    %eax,-0x4c(%rbp)
jmp    11e3 <gln_strcasecmp+0xc3>
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rsi
xor    %eax,%eax
mov    $0x1,%ecx
cmp    %rsi,%rdx
cmova  %ecx,%eax
mov    %eax,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gln_strcasecmp>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <strlen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1030 <strlen@plt>
xor    %ecx,%ecx
cmp    %rax,%rbx
cmovae %rax,%rbx
seta   %cl
mov    $0xffffffff,%ebp
cmovae %ecx,%ebp
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1040 <gln_strncasecmp@plt>
test   %eax,%eax
cmove  %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @gln_strcasecmp(i8* %0, i8* %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%5 = icmp ult i64 %3, %4
%6 = select i1 %5, i64 %3, i64 %4
%7 = tail call i32 @gln_strncasecmp(i8* %0, i8* %1, i64 %6)
%8 = icmp eq i32 %7, 0
%9 = icmp ugt i64 %3, %4
%10 = zext i1 %9 to i32
%11 = select i1 %5, i32 -1, i32 %10
%12 = select i1 %8, i32 %11, i32 %7
ret i32 %12
}