#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(char const);
int WpeStrnccmp(const char *s1, const char *s2, int n) {
  for (; (n > 0) && (*s1) && (toupper(*s1) == toupper(*s2)); n--, s1++, s2++)
    ;
  return (n > 0 ? toupper(*s1) - toupper(*s2) : 0);
}


x86 assembly (clang, -O0):
<WpeStrnccmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x14(%rbp)
mov    %al,-0x15(%rbp)
jle    116f <WpeStrnccmp+0x5f>
mov    -0x8(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x15(%rbp)
je     116f <WpeStrnccmp+0x5f>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <toupper@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <toupper@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
sete   %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    117f <WpeStrnccmp+0x6f>
jmp    11aa <WpeStrnccmp+0x9a>
jmp    1184 <WpeStrnccmp+0x74>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1123 <WpeStrnccmp+0x13>
cmpl   $0x0,-0x14(%rbp)
jle    11de <WpeStrnccmp+0xce>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <toupper@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <toupper@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x20(%rbp)
jmp    11e8 <WpeStrnccmp+0xd8>
xor    %eax,%eax
mov    %eax,-0x20(%rbp)
jmp    11e8 <WpeStrnccmp+0xd8>
mov    -0x20(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<WpeStrnccmp>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %edx,%edx
jle    115f <WpeStrnccmp+0x4f>
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%r15
add    $0x1,%ebp
xor    %ebx,%ebx
nopl   0x0(%rax)
movzbl (%r15,%rbx,1),%eax
test   %al,%al
je     1163 <WpeStrnccmp+0x53>
movsbl %al,%edi
call   1030 <toupper@plt>
mov    %eax,%r12d
movsbl (%r14,%rbx,1),%edi
call   1030 <toupper@plt>
cmp    %eax,%r12d
jne    1167 <WpeStrnccmp+0x57>
add    $0xffffffff,%ebp
add    $0x1,%rbx
cmp    $0x1,%ebp
jg     1130 <WpeStrnccmp+0x20>
xor    %ebp,%ebp
jmp    1181 <WpeStrnccmp+0x71>
xor    %eax,%eax
jmp    116b <WpeStrnccmp+0x5b>
mov    (%r15,%rbx,1),%al
movsbl %al,%edi
call   1030 <toupper@plt>
mov    %eax,%ebp
movsbl (%r14,%rbx,1),%edi
call   1030 <toupper@plt>
sub    %eax,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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