#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 */
char *fcitx_utf8_get_char(char const *, int *);
__attribute__((visibility("default"))) int
fcitx_utf8_strncmp(const char *s1, const char *s2, int n) {
  int c1, c2;
  int i;
  for (i = 0; i < n; i++) {
    if (!(*s1 && 0x80)) {
      if (*s1 != *s2)
        return 1;
      if (*s1 == 0)
        return 0;
      s1++;
      s2++;
    } else {
      s1 = fcitx_utf8_get_char(s1, &c1);
      s2 = fcitx_utf8_get_char(s2, &c2);
      if (c1 != c2)
        return 1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<fcitx_utf8_strncmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11f3 <fcitx_utf8_strncmp+0xe3>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11a1 <fcitx_utf8_strncmp+0x91>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
mov    -0x18(%rbp),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1168 <fcitx_utf8_strncmp+0x58>
movl   $0x1,-0x4(%rbp)
jmp    11fa <fcitx_utf8_strncmp+0xea>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1184 <fcitx_utf8_strncmp+0x74>
movl   $0x0,-0x4(%rbp)
jmp    11fa <fcitx_utf8_strncmp+0xea>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11e0 <fcitx_utf8_strncmp+0xd0>
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <fcitx_utf8_get_char@plt>
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x24(%rbp),%rsi
call   1030 <fcitx_utf8_get_char@plt>
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x24(%rbp),%eax
je     11db <fcitx_utf8_strncmp+0xcb>
movl   $0x1,-0x4(%rbp)
jmp    11fa <fcitx_utf8_strncmp+0xea>
jmp    11e0 <fcitx_utf8_strncmp+0xd0>
jmp    11e5 <fcitx_utf8_strncmp+0xd5>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    112a <fcitx_utf8_strncmp+0x1a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fcitx_utf8_strncmp>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %r14d,%r14d
test   %edx,%edx
jle    1184 <fcitx_utf8_strncmp+0x74>
mov    %edx,%ebp
mov    %rsi,%r15
mov    %rdi,%rbx
lea    0x4(%rsp),%r12
mov    %rsp,%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmpb   $0x0,(%rbx)
je     1171 <fcitx_utf8_strncmp+0x61>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1030 <fcitx_utf8_get_char@plt>
mov    %rax,%rbx
mov    %r15,%rdi
mov    %r13,%rsi
call   1030 <fcitx_utf8_get_char@plt>
mov    %rax,%r15
mov    0x4(%rsp),%eax
cmp    (%rsp),%eax
jne    117e <fcitx_utf8_strncmp+0x6e>
add    $0xffffffff,%ebp
jne    1140 <fcitx_utf8_strncmp+0x30>
jmp    1184 <fcitx_utf8_strncmp+0x74>
xor    %r14d,%r14d
cmpb   $0x0,(%r15)
setne  %r14b
jmp    1184 <fcitx_utf8_strncmp+0x74>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @fcitx_utf8_strncmp(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = bitcast i32* %4 to i8*
%7 = bitcast i32* %5 to i8*
%8 = icmp sgt i32 %2, 0
br i1 %8, label %11, label %28
9: ; preds = %21
%10 = icmp eq i32 %27, %2
br i1 %10, label %28, label %11
11: ; preds = %3, %9
%12 = phi i32 [ %27, %9 ], [ 0, %3 ]
%13 = phi i8* [ %23, %9 ], [ %1, %3 ]
%14 = phi i8* [ %22, %9 ], [ %0, %3 ]
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %11
%18 = load i8, i8* %13
%19 = icmp ne i8 %18, 0
%20 = zext i1 %19 to i32
br label %28
21: ; preds = %11
%22 = call i8* @fcitx_utf8_get_char(i8* %14, i32* %4)
%23 = call i8* @fcitx_utf8_get_char(i8* %13, i32* %5)
%24 = load i32, i32* %4
%25 = load i32, i32* %5
%26 = icmp eq i32 %24, %25
%27 = add nuw nsw i32 %12, 1
br i1 %26, label %9, label %28
28: ; preds = %21, %9, %3, %17
%29 = phi i32 [ %20, %17 ], [ 0, %3 ], [ 1, %21 ], [ 0, %9 ]
ret i32 %29
}