#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 *malloc(int);
int strcmp(char *, char *);
int strlen(char const *);
char tolower(char const);
int strcasecmp(const char *s1, const char *s2) {
  int i, ret;
  char *cp1, *cp2;
  cp1 = malloc(strlen(s1) + 1);
  cp2 = malloc(strlen(s2) + 1);
  for (i = 0; i < strlen(s1) + 1; i++)
    cp1[i] = tolower(s1[i]);
  for (i = 0; i < strlen(s2) + 1; i++)
    cp2[i] = tolower(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   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 <strcasecmp+0x90>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%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 <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 <strcasecmp+0xe2>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%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 <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):
<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 <strcasecmp+0x73>
mov    $0xffffffffffffffff,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
movsbl 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 <strcasecmp+0x50>
mov    %r12,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
js     1203 <strcasecmp+0xb3>
mov    $0xffffffffffffffff,%rbx
cs nopw 0x0(%rax,%rax,1)
movsbl 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 <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 @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* @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* @malloc(i32 %15)
store i8* %16, i8** %8
store i32 0, i32* %5
br label %17
17: ; preds = %34, %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 %37
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 = call signext i8 @tolower(i8 signext %28)
%30 = load i8*, i8** %7
%31 = load i32, i32* %5
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
store i8 %29, i8* %33
br label %34
34: ; preds = %23
%35 = load i32, i32* %5
%36 = add nsw i32 %35, 1
store i32 %36, i32* %5
br label %17
37: ; preds = %17
store i32 0, i32* %5
br label %38
38: ; preds = %55, %37
%39 = load i32, i32* %5
%40 = load i8*, i8** %4
%41 = call i32 @strlen(i8* %40)
%42 = add nsw i32 %41, 1
%43 = icmp slt i32 %39, %42
br i1 %43, label %44, label %58
44: ; preds = %38
%45 = load i8*, i8** %4
%46 = load i32, i32* %5
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %45, i64 %47
%49 = load i8, i8* %48
%50 = call signext i8 @tolower(i8 signext %49)
%51 = load i8*, i8** %8
%52 = load i32, i32* %5
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %51, i64 %53
store i8 %50, i8* %54
br label %55
55: ; preds = %44
%56 = load i32, i32* %5
%57 = add nsw i32 %56, 1
store i32 %57, i32* %5
br label %38
58: ; preds = %38
%59 = load i8*, i8** %7
%60 = load i8*, i8** %8
%61 = call i32 @strcmp(i8* %59, i8* %60)
store i32 %61, i32* %6
%62 = load i8*, i8** %7
%63 = call i32 @free(i8* %62)
%64 = load i8*, i8** %8
%65 = call i32 @free(i8* %64)
%66 = load i32, i32* %6
ret i32 %66
}

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* @malloc(i32 %4)
%6 = tail call i32 @strlen(i8* %1)
%7 = add nsw i32 %6, 1
%8 = tail call i8* @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 %34, label %24
14: ; preds = %2, %14
%15 = phi i64 [ %20, %14 ], [ 0, %2 ]
%16 = getelementptr inbounds i8, i8* %0, i64 %15
%17 = load i8, i8* %16
%18 = tail call signext i8 @tolower(i8 signext %17)
%19 = getelementptr inbounds i8, i8* %5, i64 %15
store i8 %18, i8* %19
%20 = add nuw nsw i64 %15, 1
%21 = tail call i32 @strlen(i8* %0)
%22 = sext i32 %21 to i64
%23 = icmp slt i64 %15, %22
br i1 %23, label %14, label %11
24: ; preds = %11, %24
%25 = phi i64 [ %30, %24 ], [ 0, %11 ]
%26 = getelementptr inbounds i8, i8* %1, i64 %25
%27 = load i8, i8* %26
%28 = tail call signext i8 @tolower(i8 signext %27)
%29 = getelementptr inbounds i8, i8* %8, i64 %25
store i8 %28, i8* %29
%30 = add nuw nsw i64 %25, 1
%31 = tail call i32 @strlen(i8* %1)
%32 = sext i32 %31 to i64
%33 = icmp slt i64 %25, %32
br i1 %33, label %24, label %34
34: ; preds = %24, %11
%35 = tail call i32 @strcmp(i8* dereferenceable(1) %5, i8* dereferenceable(1) %8)
%36 = tail call i32 @free(i8* %5)
%37 = tail call i32 @free(i8* %8)
ret i32 %35
}