#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 */
char toupper(int /*<<< orphan*/);
int gmx_strcasecmp(const char *str1, const char *str2) {
  char ch1, ch2;
  do {
    ch1 = toupper(*(str1++));
    ch2 = toupper(*(str2++));
    if (ch1 != ch2)
      return (ch1 - ch2);
  } while (ch1);
  return 0;
}


x86 assembly (clang, -O0):
<gmx_strcasecmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl (%rax),%edi
call   1030 <toupper@plt>
mov    %al,-0x19(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movsbl (%rax),%edi
call   1030 <toupper@plt>
mov    %al,-0x1a(%rbp)
movsbl -0x19(%rbp),%eax
movsbl -0x1a(%rbp),%ecx
cmp    %ecx,%eax
je     1176 <gmx_strcasecmp+0x66>
movsbl -0x19(%rbp),%eax
movsbl -0x1a(%rbp),%ecx
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    118c <gmx_strcasecmp+0x7c>
jmp    117b <gmx_strcasecmp+0x6b>
cmpb   $0x0,-0x19(%rbp)
jne    1120 <gmx_strcasecmp+0x10>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gmx_strcasecmp>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
xor    %ebx,%ebx
nop
movsbl (%r15,%rbx,1),%edi
call   1030 <toupper@plt>
mov    %eax,%ebp
movsbl (%r14,%rbx,1),%edi
call   1030 <toupper@plt>
cmp    %al,%bpl
jne    1148 <gmx_strcasecmp+0x38>
add    $0x1,%rbx
test   %bpl,%bpl
jne    1120 <gmx_strcasecmp+0x10>
xor    %eax,%eax
jmp    1151 <gmx_strcasecmp+0x41>
movsbl %al,%ecx
movsbl %bpl,%eax
sub    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @gmx_strcasecmp(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8
%7 = alloca i8
store i8* %0, i8** %4
store i8* %1, i8** %5
br label %8
8: ; preds = %31, %2
%9 = load i8*, i8** %4
%10 = getelementptr inbounds i8, i8* %9, i32 1
store i8* %10, i8** %4
%11 = load i8, i8* %9
%12 = sext i8 %11 to i32
%13 = call signext i8 @toupper(i32 %12)
store i8 %13, i8* %6
%14 = load i8*, i8** %5
%15 = getelementptr inbounds i8, i8* %14, i32 1
store i8* %15, i8** %5
%16 = load i8, i8* %14
%17 = sext i8 %16 to i32
%18 = call signext i8 @toupper(i32 %17)
store i8 %18, i8* %7
%19 = load i8, i8* %6
%20 = sext i8 %19 to i32
%21 = load i8, i8* %7
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %20, %22
br i1 %23, label %24, label %30
24: ; preds = %8
%25 = load i8, i8* %6
%26 = sext i8 %25 to i32
%27 = load i8, i8* %7
%28 = sext i8 %27 to i32
%29 = sub nsw i32 %26, %28
store i32 %29, i32* %3
br label %35
30: ; preds = %8
br label %31
31: ; preds = %30
%32 = load i8, i8* %6
%33 = icmp ne i8 %32, 0
br i1 %33, label %8, label %34
34: ; preds = %31
store i32 0, i32* %3
br label %35
35: ; preds = %34, %24
%36 = load i32, i32* %3
ret i32 %36
}

LLVM IR (-O2):
define i32 @gmx_strcasecmp(i8* nocapture %0, i8* nocapture %1) {
br label %3
3: ; preds = %17, %2
%4 = phi i8* [ %1, %2 ], [ %18, %17 ]
%5 = phi i8* [ %0, %2 ], [ %19, %17 ]
%6 = load i8, i8* %5
%7 = sext i8 %6 to i32
%8 = tail call signext i8 @toupper(i32 %7)
%9 = load i8, i8* %4
%10 = sext i8 %9 to i32
%11 = tail call signext i8 @toupper(i32 %10)
%12 = icmp eq i8 %8, %11
br i1 %12, label %17, label %13
13: ; preds = %3
%14 = sext i8 %11 to i32
%15 = sext i8 %8 to i32
%16 = sub nsw i32 %15, %14
br label %21
17: ; preds = %3
%18 = getelementptr inbounds i8, i8* %4, i64 1
%19 = getelementptr inbounds i8, i8* %5, i64 1
%20 = icmp eq i8 %8, 0
br i1 %20, label %21, label %3
21: ; preds = %17, %13
%22 = phi i32 [ %16, %13 ], [ 0, %17 ]
ret i32 %22
}