#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 *);
scalar_t__ malloc(int);
int strcmp(char *, char *);
int strlen(char const *);
char tolower(int);
int compat_strcasecmp(const char *s1, const char *s2) {
  int i, ret;
  char *cp1, *cp2;
  cp1 = (char *)malloc(strlen(s1) + 1);
  cp2 = (char *)malloc(strlen(s2) + 1);
  for (i = 0; i < strlen(s1) + 1; i++)
    cp1[i] = tolower((int)(unsigned char)s1[i]);
  for (i = 0; i < strlen(s2) + 1; i++)
    cp2[i] = tolower((int)(unsigned char)s2[i]);
  ret = strcmp(cp1, cp2);
  free(cp1);
  free(cp2);
  return ret;
}


x86 assembly (clang, -O0):
<compat_strcasecmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%edi
add    $0x1,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%edi
add    $0x1,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
add    $0x1,%ecx
cmp    %ecx,%eax
jge    11e0 <compat_strcasecmp+0x90>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movzbl (%rax,%rcx,1),%edi
call   1060 <tolower@plt>
mov    %al,%dl
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1195 <compat_strcasecmp+0x45>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
add    $0x1,%ecx
cmp    %ecx,%eax
jge    1232 <compat_strcasecmp+0xe2>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movzbl (%rax,%rcx,1),%edi
call   1060 <tolower@plt>
mov    %al,%dl
mov    -0x28(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11e7 <compat_strcasecmp+0x97>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1050 <strcmp@plt>
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compat_strcasecmp>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r12
mov    %rdi,%r13
call   1040 <strlen@plt>
lea    0x1(%rax),%edi
call   1070 <malloc@plt>
mov    %rax,%r14
mov    %r12,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%edi
call   1070 <malloc@plt>
mov    %rax,%r15
mov    %r13,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
js     11c3 <compat_strcasecmp+0x73>
mov    $0xffffffffffffffff,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
movzbl 0x1(%r13,%rbx,1),%edi
call   1060 <tolower@plt>
mov    %al,0x1(%r14,%rbx,1)
mov    %r13,%rdi
call   1040 <strlen@plt>
cltq
add    $0x1,%rbx
cmp    %rax,%rbx
jl     11a0 <compat_strcasecmp+0x50>
mov    %r12,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
js     1203 <compat_strcasecmp+0xb3>
mov    $0xffffffffffffffff,%rbx
cs nopw 0x0(%rax,%rax,1)
movzbl 0x1(%r12,%rbx,1),%edi
call   1060 <tolower@plt>
mov    %al,0x1(%r15,%rbx,1)
mov    %r12,%rdi
call   1040 <strlen@plt>
cltq
add    $0x1,%rbx
cmp    %rax,%rbx
jl     11e0 <compat_strcasecmp+0x90>
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <strcmp@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @compat_strcasecmp(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%9 = load i8*, i8** %3
%10 = call i32 @strlen(i8* %9)
%11 = add nsw i32 %10, 1
%12 = call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to i8*
store i8* %13, i8** %7
%14 = load i8*, i8** %4
%15 = call i32 @strlen(i8* %14)
%16 = add nsw i32 %15, 1
%17 = call i64 @malloc(i32 %16)
%18 = inttoptr i64 %17 to i8*
store i8* %18, i8** %8
store i32 0, i32* %5
br label %19
19: ; preds = %37, %2
%20 = load i32, i32* %5
%21 = load i8*, i8** %3
%22 = call i32 @strlen(i8* %21)
%23 = add nsw i32 %22, 1
%24 = icmp slt i32 %20, %23
br i1 %24, label %25, label %40
25: ; preds = %19
%26 = load i8*, i8** %3
%27 = load i32, i32* %5
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
%30 = load i8, i8* %29
%31 = zext i8 %30 to i32
%32 = call signext i8 @tolower(i32 %31)
%33 = load i8*, i8** %7
%34 = load i32, i32* %5
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
store i8 %32, i8* %36
br label %37
37: ; preds = %25
%38 = load i32, i32* %5
%39 = add nsw i32 %38, 1
store i32 %39, i32* %5
br label %19
40: ; preds = %19
store i32 0, i32* %5
br label %41
41: ; preds = %59, %40
%42 = load i32, i32* %5
%43 = load i8*, i8** %4
%44 = call i32 @strlen(i8* %43)
%45 = add nsw i32 %44, 1
%46 = icmp slt i32 %42, %45
br i1 %46, label %47, label %62
47: ; preds = %41
%48 = load i8*, i8** %4
%49 = load i32, i32* %5
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %48, i64 %50
%52 = load i8, i8* %51
%53 = zext i8 %52 to i32
%54 = call signext i8 @tolower(i32 %53)
%55 = load i8*, i8** %8
%56 = load i32, i32* %5
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8, i8* %55, i64 %57
store i8 %54, i8* %58
br label %59
59: ; preds = %47
%60 = load i32, i32* %5
%61 = add nsw i32 %60, 1
store i32 %61, i32* %5
br label %41
62: ; preds = %41
%63 = load i8*, i8** %7
%64 = load i8*, i8** %8
%65 = call i32 @strcmp(i8* %63, i8* %64)
store i32 %65, i32* %6
%66 = load i8*, i8** %7
%67 = call i32 @free(i8* %66)
%68 = load i8*, i8** %8
%69 = call i32 @free(i8* %68)
%70 = load i32, i32* %6
ret i32 %70
}

LLVM IR (-O2):
define i32 @compat_strcasecmp(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = add nsw i32 %3, 1
%5 = tail call i64 @malloc(i32 %4)
%6 = inttoptr i64 %5 to i8*
%7 = tail call i32 @strlen(i8* %1)
%8 = add nsw i32 %7, 1
%9 = tail call i64 @malloc(i32 %8)
%10 = inttoptr i64 %9 to i8*
%11 = tail call i32 @strlen(i8* %0)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %16, %2
%14 = tail call i32 @strlen(i8* %1)
%15 = icmp slt i32 %14, 0
br i1 %15, label %38, label %27
16: ; preds = %2, %16
%17 = phi i64 [ %23, %16 ], [ 0, %2 ]
%18 = getelementptr inbounds i8, i8* %0, i64 %17
%19 = load i8, i8* %18
%20 = zext i8 %19 to i32
%21 = tail call signext i8 @tolower(i32 %20)
%22 = getelementptr inbounds i8, i8* %6, i64 %17
store i8 %21, i8* %22
%23 = add nuw nsw i64 %17, 1
%24 = tail call i32 @strlen(i8* %0)
%25 = sext i32 %24 to i64
%26 = icmp slt i64 %17, %25
br i1 %26, label %16, label %13
27: ; preds = %13, %27
%28 = phi i64 [ %34, %27 ], [ 0, %13 ]
%29 = getelementptr inbounds i8, i8* %1, i64 %28
%30 = load i8, i8* %29
%31 = zext i8 %30 to i32
%32 = tail call signext i8 @tolower(i32 %31)
%33 = getelementptr inbounds i8, i8* %10, i64 %28
store i8 %32, i8* %33
%34 = add nuw nsw i64 %28, 1
%35 = tail call i32 @strlen(i8* %1)
%36 = sext i32 %35 to i64
%37 = icmp slt i64 %28, %36
br i1 %37, label %27, label %38
38: ; preds = %27, %13
%39 = tail call i32 @strcmp(i8* dereferenceable(1) %6, i8* dereferenceable(1) %10)
%40 = tail call i32 @free(i8* %6)
%41 = tail call i32 @free(i8* %10)
ret i32 %39
}