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


x86 assembly (clang, -O0):
<strnuppercmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <toupper@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <toupper@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x1c(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x1c(%rbp)
mov    %al,-0x21(%rbp)
jne    11ae <strnuppercmp+0x9e>
mov    -0x18(%rbp),%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x18(%rbp)
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x21(%rbp)
jbe    11ae <strnuppercmp+0x9e>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x21(%rbp)
je     11ae <strnuppercmp+0x9e>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1124 <strnuppercmp+0x14>
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strnuppercmp>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r12
mov    %rsi,(%rsp)
mov    %rdi,%r15
add    $0xffffffffffffffff,%r12
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
movzbl (%r15,%rbx,1),%r13d
movsbl %r13b,%edi
call   1030 <toupper@plt>
mov    %eax,%ebp
mov    (%rsp),%rax
movzbl (%rax,%rbx,1),%r14d
movsbl %r14b,%edi
call   1030 <toupper@plt>
sub    %eax,%ebp
jne    1169 <strnuppercmp+0x59>
cmp    %rbx,%r12
je     1169 <strnuppercmp+0x59>
test   %r13b,%r13b
je     1169 <strnuppercmp+0x59>
add    $0x1,%rbx
test   %r14b,%r14b
jne    1130 <strnuppercmp+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 @strnuppercmp(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
br label %8
8: ; preds = %37, %3
%9 = load i8*, i8** %4
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = call i32 @toupper(i32 %11)
%13 = load i8*, i8** %5
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = call i32 @toupper(i32 %15)
%17 = sub nsw i32 %12, %16
store i32 %17, i32* %7
br label %18
18: ; preds = %8
%19 = load i32, i32* %7
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %37
21: ; preds = %18
%22 = load i64, i64* %6
%23 = add i64 %22, -1
store i64 %23, i64* %6
%24 = icmp ugt i64 %23, 0
br i1 %24, label %25, label %37
25: ; preds = %21
%26 = load i8*, i8** %4
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %4
%28 = load i8, i8* %26
%29 = sext i8 %28 to i32
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %37
31: ; preds = %25
%32 = load i8*, i8** %5
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %5
%34 = load i8, i8* %32
%35 = sext i8 %34 to i32
%36 = icmp ne i32 %35, 0
br label %37
37: ; preds = %31, %25, %21, %18
%38 = phi i1 [ false, %25 ], [ false, %21 ], [ false, %18 ], [ %36, %31 ]
br i1 %38, label %8, label %39
39: ; preds = %37
%40 = load i32, i32* %7
ret i32 %40
}

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