#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 *, int *);
__attribute__((visibility("default"))) char *
fcitx_utf8_get_nth_char(char *s, unsigned int n) {
  unsigned int l = 0;
  while (*s && l < n) {
    int chr;
    s = fcitx_utf8_get_char(s, &chr);
    l++;
  }
  return s;
}


x86 assembly (clang, -O0):
<fcitx_utf8_get_nth_char>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x15(%rbp)
je     1147 <fcitx_utf8_get_nth_char+0x37>
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
setb   %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    1157 <fcitx_utf8_get_nth_char+0x47>
jmp    1176 <fcitx_utf8_get_nth_char+0x66>
mov    -0x8(%rbp),%rdi
lea    -0x14(%rbp),%rsi
call   1030 <fcitx_utf8_get_char@plt>
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1126 <fcitx_utf8_get_nth_char+0x16>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fcitx_utf8_get_nth_char>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rax
cmpb   $0x0,(%rdi)
je     1149 <fcitx_utf8_get_nth_char+0x39>
mov    %esi,%ebp
test   %esi,%esi
je     1149 <fcitx_utf8_get_nth_char+0x39>
mov    $0x1,%ebx
lea    0xc(%rsp),%r14
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <fcitx_utf8_get_char@plt>
cmpb   $0x0,(%rax)
je     1149 <fcitx_utf8_get_nth_char+0x39>
lea    0x1(%rbx),%ecx
cmp    %ebp,%ebx
mov    %ecx,%ebx
jb     1130 <fcitx_utf8_get_nth_char+0x20>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i8* @fcitx_utf8_get_nth_char(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 0, i32* %5
br label %7
7: ; preds = %18, %2
%8 = load i8*, i8** %3
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %7
%13 = load i32, i32* %5
%14 = load i32, i32* %4
%15 = icmp ult i32 %13, %14
br label %16
16: ; preds = %12, %7
%17 = phi i1 [ false, %7 ], [ %15, %12 ]
br i1 %17, label %18, label %23
18: ; preds = %16
%19 = load i8*, i8** %3
%20 = call i8* @fcitx_utf8_get_char(i8* %19, i32* %6)
store i8* %20, i8** %3
%21 = load i32, i32* %5
%22 = add i32 %21, 1
store i32 %22, i32* %5
br label %7
23: ; preds = %16
%24 = load i8*, i8** %3
ret i8* %24
}

LLVM IR (-O2):
define i8* @fcitx_utf8_get_nth_char(i8* %0, i32 %1) {
%3 = alloca i32
%4 = load i8, i8* %0
%5 = icmp ne i8 %4, 0
%6 = icmp ne i32 %1, 0
%7 = and i1 %5, %6
br i1 %7, label %8, label %19
8: ; preds = %2
%9 = bitcast i32* %3 to i8*
br label %10
10: ; preds = %8, %10
%11 = phi i32 [ 0, %8 ], [ %14, %10 ]
%12 = phi i8* [ %0, %8 ], [ %13, %10 ]
%13 = call i8* @fcitx_utf8_get_char(i8* %12, i32* %3)
%14 = add nuw i32 %11, 1
%15 = load i8, i8* %13
%16 = icmp ne i8 %15, 0
%17 = icmp ult i32 %14, %1
%18 = select i1 %16, i1 %17, i1 false
br i1 %18, label %10, label %19
19: ; preds = %10, %2
%20 = phi i8* [ %0, %2 ], [ %13, %10 ]
ret i8* %20
}