#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 strncmp_with_mismatch(const char *s1, const char *s2, register size_t n,
                          register size_t mismatch) {
  register unsigned char u1, u2;
  int cnt = 0;
  while (n-- > 0) {
    u1 = (unsigned char)*s1++;
    u2 = (unsigned char)*s2++;
    if (u1 != u2) {
      cnt++;
      if (cnt > mismatch)
        return u1 - u2;
    }
    if (u1 == '\0')
      return 0;
  }
  return 0;
}


x86 assembly (clang, -O0):
<strncmp_with_mismatch>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x20(%rbp)
cmp    $0x0,%rax
jbe    11b8 <strncmp_with_mismatch+0xb8>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%al
mov    %al,-0x29(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
mov    (%rax),%al
mov    %al,-0x2a(%rbp)
movzbl -0x29(%rbp),%eax
movzbl -0x2a(%rbp),%ecx
cmp    %ecx,%eax
je     119a <strncmp_with_mismatch+0x9a>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
movslq -0x30(%rbp),%rax
cmp    -0x28(%rbp),%rax
jbe    1195 <strncmp_with_mismatch+0x95>
movzbl -0x29(%rbp),%eax
movzbl -0x2a(%rbp),%ecx
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    11bf <strncmp_with_mismatch+0xbf>
jmp    119a <strncmp_with_mismatch+0x9a>
movzbl -0x29(%rbp),%eax
cmp    $0x0,%eax
jne    11b3 <strncmp_with_mismatch+0xb3>
movl   $0x0,-0x4(%rbp)
jmp    11bf <strncmp_with_mismatch+0xbf>
jmp    111b <strncmp_with_mismatch+0x1b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<strncmp_with_mismatch>:
push   %rbx
xor    %eax,%eax
xor    %r8d,%r8d
xor    %r9d,%r9d
jmp    1119 <strncmp_with_mismatch+0x19>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r8
test   %r10d,%r10d
je     113f <strncmp_with_mismatch+0x3f>
cmp    %r8,%rdx
je     113f <strncmp_with_mismatch+0x3f>
movzbl (%rdi,%r8,1),%r10d
movzbl (%rsi,%r8,1),%r11d
cmp    %r11b,%r10b
je     1110 <strncmp_with_mismatch+0x10>
add    $0x1,%r9d
movslq %r9d,%rbx
cmp    %rcx,%rbx
jbe    1110 <strncmp_with_mismatch+0x10>
sub    %r11d,%r10d
mov    %r10d,%eax
pop    %rbx
ret

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

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