#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 readTagCharacter(char const **);
int toupper(int);
int tagnuppercmp(const char *s1, const char *s2, size_t n) {
  int result;
  int c1, c2;
  do {
    c1 = *s1++;
    c2 = readTagCharacter(&s2);
    result = toupper(c1) - toupper(c2);
  } while (result == 0 && --n > 0 && c1 != '\0' && c2 != '\0');
  return result;
}


x86 assembly (clang, -O0):
<tagnuppercmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movsbl (%rax),%eax
mov    %eax,-0x20(%rbp)
lea    -0x10(%rbp),%rdi
call   1040 <readTagCharacter@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%edi
call   1030 <toupper@plt>
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%edi
call   1030 <toupper@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x1c(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x1c(%rbp)
mov    %al,-0x29(%rbp)
jne    11b5 <tagnuppercmp+0x95>
mov    -0x18(%rbp),%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x18(%rbp)
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x29(%rbp)
jbe    11b5 <tagnuppercmp+0x95>
xor    %eax,%eax
cmpl   $0x0,-0x20(%rbp)
mov    %al,-0x29(%rbp)
je     11b5 <tagnuppercmp+0x95>
cmpl   $0x0,-0x24(%rbp)
setne  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    1134 <tagnuppercmp+0x14>
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tagnuppercmp>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r12
mov    %rdi,%r14
mov    %rsi,(%rsp)
add    $0xffffffffffffffff,%r12
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
movzbl (%r14,%rbx,1),%r15d
movsbl %r15b,%ebp
mov    %rsp,%rdi
call   1040 <readTagCharacter@plt>
mov    %eax,%r13d
mov    %ebp,%edi
call   1030 <toupper@plt>
mov    %eax,%ebp
mov    %r13d,%edi
call   1030 <toupper@plt>
sub    %eax,%ebp
jne    117c <tagnuppercmp+0x5c>
cmp    %rbx,%r12
je     117c <tagnuppercmp+0x5c>
test   %r15b,%r15b
je     117c <tagnuppercmp+0x5c>
add    $0x1,%rbx
test   %r13d,%r13d
jne    1140 <tagnuppercmp+0x20>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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