#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*/ free(char *);
char *lowercase(int /*<<< orphan*/);
scalar_t__ strlen(char const *);
int /*<<< orphan*/ strndup(char const *, scalar_t__);
int strcmpi(const char *s1, const char *s2) {
  char *s1_lower = lowercase(strndup(s1, strlen(s1) + 1));
  char *s2_lower = lowercase(strndup(s2, strlen(s2) + 1));
  int result = 0;
  const char *c1 = s1_lower;
  const char *c2 = s2_lower;
  while (*c1 != '\0' || *c2 != '\0') {
    if (*c1++ != *c2++) {
      result = -1;
      break;
    }
  }
  free(s1_lower);
  free(s2_lower);
  return result;
}


x86 assembly (clang, -O0):
<strcmpi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x48(%rbp),%rdi
mov    %rax,%rsi
add    $0x1,%rsi
call   1050 <strndup@plt>
mov    %eax,%edi
call   1060 <lowercase@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    %rax,%rsi
add    $0x1,%rsi
call   1050 <strndup@plt>
mov    %eax,%edi
call   1060 <lowercase@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0x0,%ecx
mov    %al,-0x49(%rbp)
jne    11e4 <strcmpi+0xa4>
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x49(%rbp)
mov    -0x49(%rbp),%al
test   $0x1,%al
jne    11f4 <strcmpi+0xb4>
jmp    1231 <strcmpi+0xf1>
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x30(%rbp)
movsbl (%rax),%eax
mov    -0x38(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x38(%rbp)
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     122c <strcmpi+0xec>
movl   $0xffffffff,-0x24(%rbp)
jmp    1231 <strcmpi+0xf1>
jmp    11bf <strcmpi+0x7f>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x24(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strcmpi>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <strlen@plt>
lea    0x1(%rax),%rsi
mov    %rbx,%rdi
call   1050 <strndup@plt>
mov    %eax,%edi
call   1060 <lowercase@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rsi
mov    %r14,%rdi
call   1050 <strndup@plt>
mov    %eax,%edi
call   1060 <lowercase@plt>
mov    %rax,%r12
xor    %r14d,%r14d
xor    %eax,%eax
nopl   0x0(%rax)
movzbl (%r15,%rax,1),%ebx
movzbl (%r12,%rax,1),%edx
mov    %ebx,%ecx
or     %dl,%cl
je     11ae <strcmpi+0x6e>
add    $0x1,%rax
cmp    %dl,%bl
je     1190 <strcmpi+0x50>
mov    $0xffffffff,%r14d
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @strcmpi(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%10 = load i8*, i8** %3
%11 = load i8*, i8** %3
%12 = call i64 @strlen(i8* %11)
%13 = add nsw i64 %12, 1
%14 = call i32 @strndup(i8* %10, i64 %13)
%15 = call i8* @lowercase(i32 %14)
store i8* %15, i8** %5
%16 = load i8*, i8** %4
%17 = load i8*, i8** %4
%18 = call i64 @strlen(i8* %17)
%19 = add nsw i64 %18, 1
%20 = call i32 @strndup(i8* %16, i64 %19)
%21 = call i8* @lowercase(i32 %20)
store i8* %21, i8** %6
store i32 0, i32* %7
%22 = load i8*, i8** %5
store i8* %22, i8** %8
%23 = load i8*, i8** %6
store i8* %23, i8** %9
br label %24
24: ; preds = %47, %2
%25 = load i8*, i8** %8
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp ne i32 %27, 0
br i1 %28, label %34, label %29
29: ; preds = %24
%30 = load i8*, i8** %9
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp ne i32 %32, 0
br label %34
34: ; preds = %29, %24
%35 = phi i1 [ true, %24 ], [ %33, %29 ]
br i1 %35, label %36, label %48
36: ; preds = %34
%37 = load i8*, i8** %8
%38 = getelementptr inbounds i8, i8* %37, i32 1
store i8* %38, i8** %8
%39 = load i8, i8* %37
%40 = sext i8 %39 to i32
%41 = load i8*, i8** %9
%42 = getelementptr inbounds i8, i8* %41, i32 1
store i8* %42, i8** %9
%43 = load i8, i8* %41
%44 = sext i8 %43 to i32
%45 = icmp ne i32 %40, %44
br i1 %45, label %46, label %47
46: ; preds = %36
store i32 -1, i32* %7
br label %48
47: ; preds = %36
br label %24
48: ; preds = %46, %34
%49 = load i8*, i8** %5
%50 = call i32 @free(i8* %49)
%51 = load i8*, i8** %6
%52 = call i32 @free(i8* %51)
%53 = load i32, i32* %7
ret i32 %53
}

LLVM IR (-O2):
define i32 @strcmpi(i8* %0, i8* %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = add nsw i64 %3, 1
%5 = tail call i32 @strndup(i8* %0, i64 %4)
%6 = tail call i8* @lowercase(i32 %5)
%7 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%8 = add nsw i64 %7, 1
%9 = tail call i32 @strndup(i8* %1, i64 %8)
%10 = tail call i8* @lowercase(i32 %9)
br label %11
11: ; preds = %19, %2
%12 = phi i8* [ %6, %2 ], [ %20, %19 ]
%13 = phi i8* [ %10, %2 ], [ %21, %19 ]
%14 = load i8, i8* %12
%15 = icmp eq i8 %14, 0
%16 = load i8, i8* %13
%17 = icmp eq i8 %16, 0
%18 = select i1 %15, i1 %17, i1 false
br i1 %18, label %23, label %19
19: ; preds = %11
%20 = getelementptr inbounds i8, i8* %12, i64 1
%21 = getelementptr inbounds i8, i8* %13, i64 1
%22 = icmp eq i8 %14, %16
br i1 %22, label %11, label %23
23: ; preds = %11, %19
%24 = phi i32 [ -1, %19 ], [ 0, %11 ]
%25 = tail call i32 @free(i8* %6)
%26 = tail call i32 @free(i8* %10)
ret i32 %24
}