#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 toupper(unsigned char);
int str_cmp(const char *s1, const char *s2) {
  int i = 0;
  while (toupper((unsigned char)s1[i]) == toupper((unsigned char)s2[i])) {
    if (s1[i] == '\0')
      return 0;
    i++;
  }
  return toupper((unsigned char)s1[i]) - toupper((unsigned char)s2[i]);
}


x86 assembly (clang, -O0):
<str_cmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movzbl (%rax,%rcx,1),%edi
call   1030 <toupper@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movzbl (%rax,%rcx,1),%edi
call   1030 <toupper@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
cmp    %ecx,%eax
jne    1188 <str_cmp+0x78>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    117a <str_cmp+0x6a>
movl   $0x0,-0x4(%rbp)
jmp    11b7 <str_cmp+0xa7>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1127 <str_cmp+0x17>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movzbl (%rax,%rcx,1),%edi
call   1030 <toupper@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movzbl (%rax,%rcx,1),%edi
call   1030 <toupper@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_cmp>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r12
movzbl (%rdi),%edi
call   1030 <toupper@plt>
mov    %eax,%ebp
movzbl (%r14),%edi
call   1030 <toupper@plt>
cmp    %eax,%ebp
jne    1173 <str_cmp+0x63>
xor    %r15d,%r15d
xor    %ebx,%ebx
nopl   (%rax)
cmpb   $0x0,(%r12,%rbx,1)
je     118f <str_cmp+0x7f>
lea    0x1(%rbx),%rbp
movzbl 0x1(%r12,%rbx,1),%edi
call   1030 <toupper@plt>
mov    %eax,%r13d
movzbl 0x1(%r14,%rbx,1),%edi
call   1030 <toupper@plt>
mov    %rbp,%rbx
cmp    %eax,%r13d
je     1140 <str_cmp+0x30>
mov    %ebp,%ebx
add    %rbp,%r12
jmp    1175 <str_cmp+0x65>
xor    %ebx,%ebx
movzbl (%r12),%edi
call   1030 <toupper@plt>
mov    %eax,%r15d
movzbl (%r14,%rbx,1),%edi
call   1030 <toupper@plt>
sub    %eax,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @str_cmp(i8* nocapture %0, i8* nocapture %1) {
%3 = load i8, i8* %0
%4 = tail call i32 @toupper(i8 zeroext %3)
%5 = load i8, i8* %1
%6 = tail call i32 @toupper(i8 zeroext %5)
%7 = icmp eq i32 %4, %6
br i1 %7, label %8, label %24
8: ; preds = %2, %13
%9 = phi i64 [ %14, %13 ], [ 0, %2 ]
%10 = phi i8* [ %15, %13 ], [ %0, %2 ]
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 0
br i1 %12, label %33, label %13
13: ; preds = %8
%14 = add nuw i64 %9, 1
%15 = getelementptr inbounds i8, i8* %0, i64 %14
%16 = load i8, i8* %15
%17 = tail call i32 @toupper(i8 zeroext %16)
%18 = getelementptr inbounds i8, i8* %1, i64 %14
%19 = load i8, i8* %18
%20 = tail call i32 @toupper(i8 zeroext %19)
%21 = icmp eq i32 %17, %20
br i1 %21, label %8, label %22
22: ; preds = %13
%23 = and i64 %14, 4294967295
br label %24
24: ; preds = %22, %2
%25 = phi i64 [ 0, %2 ], [ %23, %22 ]
%26 = phi i8* [ %0, %2 ], [ %15, %22 ]
%27 = getelementptr inbounds i8, i8* %1, i64 %25
%28 = load i8, i8* %26
%29 = tail call i32 @toupper(i8 zeroext %28)
%30 = load i8, i8* %27
%31 = tail call i32 @toupper(i8 zeroext %30)
%32 = sub nsw i32 %29, %31
br label %33
33: ; preds = %8, %24
%34 = phi i32 [ %32, %24 ], [ 0, %8 ]
ret i32 %34
}