#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 */
typedef size_t uint32_t;

/* Variables and functions */
char *fcitx_utf8_get_char(char const *, size_t *);
__attribute__((visibility("default"))) char *
fcitx_utf8_get_nth_char(const char *s, uint32_t n) {
  size_t l = 0;
  while (*s && l < n) {
    uint32_t chr;
    s = fcitx_utf8_get_char(s, &chr);
    l++;
  }
  return (char *)s;
}


x86 assembly (clang, -O0):
<fcitx_utf8_get_nth_char>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x21(%rbp)
je     114b <fcitx_utf8_get_nth_char+0x3b>
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
setb   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    115b <fcitx_utf8_get_nth_char+0x4b>
jmp    117d <fcitx_utf8_get_nth_char+0x6d>
mov    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <fcitx_utf8_get_char@plt>
mov    %rax,-0x8(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1128 <fcitx_utf8_get_nth_char+0x18>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fcitx_utf8_get_nth_char>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rax
cmpb   $0x0,(%rdi)
je     115c <fcitx_utf8_get_nth_char+0x4c>
mov    %rsi,%r15
test   %rsi,%rsi
je     115c <fcitx_utf8_get_nth_char+0x4c>
mov    $0x1,%ebx
lea    0x8(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <fcitx_utf8_get_char@plt>
cmpb   $0x0,(%rax)
je     115c <fcitx_utf8_get_nth_char+0x4c>
lea    0x1(%rbx),%rcx
cmp    %r15,%rbx
mov    %rcx,%rbx
jb     1140 <fcitx_utf8_get_nth_char+0x30>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @fcitx_utf8_get_nth_char(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
store i8* %0, i8** %3
store i64 %1, i64* %4
store i64 0, i64* %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 i64, i64* %5
%14 = load i64, i64* %4
%15 = icmp ult i64 %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, i64* %6)
store i8* %20, i8** %3
%21 = load i64, i64* %5
%22 = add i64 %21, 1
store i64 %22, i64* %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, i64 %1) {
%3 = alloca i64
%4 = load i8, i8* %0
%5 = icmp ne i8 %4, 0
%6 = icmp ne i64 %1, 0
%7 = and i1 %5, %6
br i1 %7, label %8, label %19
8: ; preds = %2
%9 = bitcast i64* %3 to i8*
br label %10
10: ; preds = %8, %10
%11 = phi i64 [ 0, %8 ], [ %14, %10 ]
%12 = phi i8* [ %0, %8 ], [ %13, %10 ]
%13 = call i8* @fcitx_utf8_get_char(i8* %12, i64* %3)
%14 = add nuw i64 %11, 1
%15 = load i8, i8* %13
%16 = icmp ne i8 %15, 0
%17 = icmp ult i64 %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
}