#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 int /*<<< orphan*/ uint32_t;
typedef int /*<<< orphan*/ uint16_t;

/* Variables and functions */
int /*<<< orphan*/ tb_change_cell(int, int, int /*<<< orphan*/,
                                  int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ tb_utf8_char_to_unicode(int /*<<< orphan*/ *, char const *);
void print_tb(const char *str, int x, int y, uint16_t fg, uint16_t bg) {
  while (*str) {
    uint32_t uni;
    str += tb_utf8_char_to_unicode(&uni, str);
    tb_change_cell(x, y, uni, fg, bg);
    x++;
  }
}


x86 assembly (clang, -O0):
<print_tb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     1186 <print_tb+0x66>
mov    -0x8(%rbp),%rsi
lea    -0x1c(%rbp),%rdi
call   1030 <tb_utf8_char_to_unicode@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x14(%rbp),%ecx
mov    -0x18(%rbp),%r8d
call   1040 <tb_change_cell@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1139 <print_tb+0x19>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_tb>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8d,(%rsp)
cmpb   $0x0,(%rdi)
je     1176 <print_tb+0x56>
mov    %ecx,%r15d
mov    %edx,%r12d
mov    %esi,%ebp
mov    %rdi,%rbx
nop
lea    0x4(%rsp),%rdi
mov    %rbx,%rsi
call   1030 <tb_utf8_char_to_unicode@plt>
movslq %eax,%r13
lea    (%rbx,%r13,1),%r14
mov    0x4(%rsp),%edx
mov    %ebp,%edi
mov    %r12d,%esi
mov    %r15d,%ecx
mov    (%rsp),%r8d
call   1040 <tb_change_cell@plt>
add    $0x1,%ebp
cmpb   $0x0,(%rbx,%r13,1)
mov    %r14,%rbx
jne    1140 <print_tb+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @print_tb(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
br label %12
12: ; preds = %16, %5
%13 = load i8*, i8** %6
%14 = load i8, i8* %13
%15 = icmp ne i8 %14, 0
br i1 %15, label %16, label %30
16: ; preds = %12
%17 = load i8*, i8** %6
%18 = call i32 @tb_utf8_char_to_unicode(i32* %11, i8* %17)
%19 = load i8*, i8** %6
%20 = sext i32 %18 to i64
%21 = getelementptr inbounds i8, i8* %19, i64 %20
store i8* %21, i8** %6
%22 = load i32, i32* %7
%23 = load i32, i32* %8
%24 = load i32, i32* %11
%25 = load i32, i32* %9
%26 = load i32, i32* %10
%27 = call i32 @tb_change_cell(i32 %22, i32 %23, i32 %24, i32 %25, i32 %26)
%28 = load i32, i32* %7
%29 = add nsw i32 %28, 1
store i32 %29, i32* %7
br label %12
30: ; preds = %12
ret void
}

LLVM IR (-O2):
define void @print_tb(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = load i8, i8* %0
%8 = icmp eq i8 %7, 0
br i1 %8, label %22, label %9
9: ; preds = %5
%10 = bitcast i32* %6 to i8*
br label %11
11: ; preds = %9, %11
%12 = phi i8* [ %0, %9 ], [ %16, %11 ]
%13 = phi i32 [ %1, %9 ], [ %19, %11 ]
%14 = call i32 @tb_utf8_char_to_unicode(i32* %6, i8* %12)
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %12, i64 %15
%17 = load i32, i32* %6
%18 = call i32 @tb_change_cell(i32 %13, i32 %2, i32 %17, i32 %3, i32 %4)
%19 = add nsw i32 %13, 1
%20 = load i8, i8* %16
%21 = icmp eq i8 %20, 0
br i1 %21, label %22, label %11
22: ; preds = %11, %5
ret void
}