#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 *safe_malloc(int);
int strcmp(char *, char *);
int strlen(char const *);
char tolower(int);
int strcasecmp(const char *s1, const char *s2) {
  int i, ret;
  char *cp1, *cp2;
  cp1 = safe_malloc(strlen(s1) + 1);
  cp2 = safe_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):
<strcasecmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%edi
add    $0x1,%edi
call   1040 <safe_malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%edi
add    $0x1,%edi
call   1040 <safe_malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
add    $0x1,%ecx
cmp    %ecx,%eax
jge    11e0 <strcasecmp+0x90>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movzbl (%rax,%rcx,1),%edi
call   1070 <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 <strcasecmp+0x45>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
add    $0x1,%ecx
cmp    %ecx,%eax
jge    1232 <strcasecmp+0xe2>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movzbl (%rax,%rcx,1),%edi
call   1070 <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 <strcasecmp+0x97>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1060 <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):
<strcasecmp>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r12
mov    %rdi,%r13
call   1050 <strlen@plt>
lea    0x1(%rax),%edi
call   1040 <safe_malloc@plt>
mov    %rax,%r14
mov    %r12,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edi
call   1040 <safe_malloc@plt>
mov    %rax,%r15
mov    %r13,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
js     11c3 <strcasecmp+0x73>
mov    $0xffffffffffffffff,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
movzbl 0x1(%r13,%rbx,1),%edi
call   1070 <tolower@plt>
mov    %al,0x1(%r14,%rbx,1)
mov    %r13,%rdi
call   1050 <strlen@plt>
cltq
add    $0x1,%rbx
cmp    %rax,%rbx
jl     11a0 <strcasecmp+0x50>
mov    %r12,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
js     1203 <strcasecmp+0xb3>
mov    $0xffffffffffffffff,%rbx
cs nopw 0x0(%rax,%rax,1)
movzbl 0x1(%r12,%rbx,1),%edi
call   1070 <tolower@plt>
mov    %al,0x1(%r15,%rbx,1)
mov    %r12,%rdi
call   1050 <strlen@plt>
cltq
add    $0x1,%rbx
cmp    %rax,%rbx
jl     11e0 <strcasecmp+0x90>
mov    %r14,%rdi
mov    %r15,%rsi
call   1060 <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 @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 i8* @safe_malloc(i32 %11)
store i8* %12, i8** %7
%13 = load i8*, i8** %4
%14 = call i32 @strlen(i8* %13)
%15 = add nsw i32 %14, 1
%16 = call i8* @safe_malloc(i32 %15)
store i8* %16, i8** %8
store i32 0, i32* %5
br label %17
17: ; preds = %35, %2
%18 = load i32, i32* %5
%19 = load i8*, i8** %3
%20 = call i32 @strlen(i8* %19)
%21 = add nsw i32 %20, 1
%22 = icmp slt i32 %18, %21
br i1 %22, label %23, label %38
23: ; preds = %17
%24 = load i8*, i8** %3
%25 = load i32, i32* %5
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = load i8, i8* %27
%29 = zext i8 %28 to i32
%30 = call signext i8 @tolower(i32 %29)
%31 = load i8*, i8** %7
%32 = load i32, i32* %5
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
store i8 %30, i8* %34
br label %35
35: ; preds = %23
%36 = load i32, i32* %5
%37 = add nsw i32 %36, 1
store i32 %37, i32* %5
br label %17
38: ; preds = %17
store i32 0, i32* %5
br label %39
39: ; preds = %57, %38
%40 = load i32, i32* %5
%41 = load i8*, i8** %4
%42 = call i32 @strlen(i8* %41)
%43 = add nsw i32 %42, 1
%44 = icmp slt i32 %40, %43
br i1 %44, label %45, label %60
45: ; preds = %39
%46 = load i8*, i8** %4
%47 = load i32, i32* %5
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %46, i64 %48
%50 = load i8, i8* %49
%51 = zext i8 %50 to i32
%52 = call signext i8 @tolower(i32 %51)
%53 = load i8*, i8** %8
%54 = load i32, i32* %5
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8, i8* %53, i64 %55
store i8 %52, i8* %56
br label %57
57: ; preds = %45
%58 = load i32, i32* %5
%59 = add nsw i32 %58, 1
store i32 %59, i32* %5
br label %39
60: ; preds = %39
%61 = load i8*, i8** %7
%62 = load i8*, i8** %8
%63 = call i32 @strcmp(i8* %61, i8* %62)
store i32 %63, i32* %6
%64 = load i8*, i8** %7
%65 = call i32 @free(i8* %64)
%66 = load i8*, i8** %8
%67 = call i32 @free(i8* %66)
%68 = load i32, i32* %6
ret i32 %68
}

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