#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 uint32_t;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ insert_chars(char *, int const *, int /*<<< orphan*/,
                                int const);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ utf8str(int const, char *);
void insert_char(const int c, const uint32_t attr, const bool utf8) {
  static char t[8];
  if (utf8) {
    memset(t, 0, sizeof t);
    utf8str(c, t);
  } else {
    t[0] = c;
    t[1] = 0;
  }
  assert(c != 0);
  insert_chars(t, attr == -1 ? NULL : &attr, strlen(t), utf8);
}


x86 assembly (clang, -O0):
<insert_char>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1192 <insert_char+0x42>
lea    0x2ed7(%rip),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    -0x4(%rbp),%edi
lea    0x2ec1(%rip),%rsi
call   1070 <utf8str@plt>
jmp    11a2 <insert_char+0x52>
mov    -0x4(%rbp),%eax
mov    %al,0x2eae(%rip)
movb   $0x0,0x2ea8(%rip)
cmpl   $0x0,-0x4(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
cmpl   $0xffffffff,-0x8(%rbp)
jne    11c8 <insert_char+0x78>
xor    %eax,%eax
mov    %rax,-0x18(%rbp)
jmp    11d5 <insert_char+0x85>
lea    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    11d5 <insert_char+0x85>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    0x2e65(%rip),%rdi
call   1030 <strlen@plt>
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
mov    -0xc(%rbp),%ecx
lea    0x2e50(%rip),%rdi
call   1060 <insert_chars@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<insert_char>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %esi,%ebp
mov    %edi,%ebx
mov    %esi,0x4(%rsp)
test   %edx,%edx
je     1188 <insert_char+0x38>
lea    0x2edc(%rip),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    %ebx,%edi
mov    %r15,%rsi
call   1070 <utf8str@plt>
jmp    1195 <insert_char+0x45>
mov    %bl,0x2ebb(%rip)
movb   $0x0,0x2eb5(%rip)
xor    %edi,%edi
test   %ebx,%ebx
setne  %dil
call   1050 <assert@plt>
xor    %eax,%eax
cmp    $0xffffffff,%ebp
lea    0x4(%rsp),%rbx
cmove  %rax,%rbx
lea    0x2e92(%rip),%rbp
mov    %rbp,%rdi
call   1030 <strlen@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
mov    %r14d,%ecx
call   1060 <insert_chars@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@insert_char.t = internal global [8 x i8] zeroinitializer
define void @insert_char(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%7 = load i32, i32* %6
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %3
%10 = call i32 @memset(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @insert_char.t, i64 0, i64 0), i32 0, i32 8)
%11 = load i32, i32* %4
%12 = call i32 @utf8str(i32 %11, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @insert_char.t, i64 0, i64 0))
br label %16
13: ; preds = %3
%14 = load i32, i32* %4
%15 = trunc i32 %14 to i8
store i8 %15, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @insert_char.t, i64 0, i64 0)
store i8 0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @insert_char.t, i64 0, i64 1)
br label %16
16: ; preds = %13, %9
%17 = load i32, i32* %4
%18 = icmp ne i32 %17, 0
%19 = zext i1 %18 to i32
%20 = call i32 @assert(i32 %19)
%21 = load i32, i32* %5
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %24
23: ; preds = %16
br label %25
24: ; preds = %16
br label %25
25: ; preds = %24, %23
%26 = phi i32* [ null, %23 ], [ %5, %24 ]
%27 = call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @insert_char.t, i64 0, i64 0))
%28 = load i32, i32* %6
%29 = call i32 @insert_chars(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @insert_char.t, i64 0, i64 0), i32* %26, i32 %27, i32 %28)
ret void
}

LLVM IR (-O2):
@insert_char.t = internal global [8 x i8] zeroinitializer
define void @insert_char(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
store i32 %1, i32* %4
%5 = icmp eq i32 %2, 0
br i1 %5, label %9, label %6
6: ; preds = %3
%7 = tail call i32 @memset(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @insert_char.t, i64 0, i64 0), i32 0, i32 8)
%8 = tail call i32 @utf8str(i32 %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @insert_char.t, i64 0, i64 0))
br label %11
9: ; preds = %3
%10 = trunc i32 %0 to i8
store i8 %10, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @insert_char.t, i64 0, i64 0)
store i8 0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @insert_char.t, i64 0, i64 1)
br label %11
11: ; preds = %9, %6
%12 = icmp ne i32 %0, 0
%13 = zext i1 %12 to i32
%14 = tail call i32 @assert(i32 %13)
%15 = icmp eq i32 %1, -1
%16 = select i1 %15, i32* null, i32* %4
%17 = tail call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @insert_char.t, i64 0, i64 0))
%18 = call i32 @insert_chars(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @insert_char.t, i64 0, i64 0), i32* %16, i32 %17, i32 %2)
ret void
}