#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 */
int /*<<< orphan*/ kputch(int);
int /*<<< orphan*/ uartputc(int);
void printchar(char **str, int c) {
  if ((int)str == -1) {
    if (c == 0x100) {
      uartputc('\b');
      uartputc(' ');
      uartputc('\b');
    } else {
      uartputc(c);
    }
  } else if (str) {
    **str = c;
    ++(*str);
  } else {
    (void)kputch(c);
  }
}


x86 assembly (clang, -O0):
<printchar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
cmp    $0xffffffff,%eax
jne    1179 <printchar+0x59>
cmpl   $0x100,-0xc(%rbp)
jne    116c <printchar+0x4c>
mov    $0x8,%edi
call   1030 <uartputc@plt>
mov    $0x20,%edi
call   1030 <uartputc@plt>
mov    $0x8,%edi
call   1030 <uartputc@plt>
jmp    1174 <printchar+0x54>
mov    -0xc(%rbp),%edi
call   1030 <uartputc@plt>
jmp    11b2 <printchar+0x92>
cmpq   $0x0,-0x8(%rbp)
je     11a5 <printchar+0x85>
mov    -0xc(%rbp),%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
jmp    11ad <printchar+0x8d>
mov    -0xc(%rbp),%edi
call   1040 <kputch@plt>
jmp    11b2 <printchar+0x92>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printchar>:
push   %rax
cmp    $0xffffffff,%edi
je     1137 <printchar+0x17>
test   %rdi,%rdi
je     115e <printchar+0x3e>
mov    (%rdi),%rax
mov    %sil,(%rax)
addq   $0x1,(%rdi)
pop    %rax
ret
cmp    $0x100,%esi
jne    1166 <printchar+0x46>
mov    $0x8,%edi
call   1030 <uartputc@plt>
mov    $0x20,%edi
call   1030 <uartputc@plt>
mov    $0x8,%edi
pop    %rax
jmp    1030 <uartputc@plt>
mov    %esi,%edi
pop    %rax
jmp    1040 <kputch@plt>
mov    %esi,%edi
pop    %rax
jmp    1030 <uartputc@plt>

LLVM IR (-O0):
define void @printchar(i8** %0, i32 %1) {
%3 = alloca i8**
%4 = alloca i32
store i8** %0, i8*** %3
store i32 %1, i32* %4
%5 = load i8**, i8*** %3
%6 = ptrtoint i8** %5 to i32
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %19
8: ; preds = %2
%9 = load i32, i32* %4
%10 = icmp eq i32 %9, 256
br i1 %10, label %11, label %15
11: ; preds = %8
%12 = call i32 @uartputc(i32 8)
%13 = call i32 @uartputc(i32 32)
%14 = call i32 @uartputc(i32 8)
br label %18
15: ; preds = %8
%16 = load i32, i32* %4
%17 = call i32 @uartputc(i32 %16)
br label %18
18: ; preds = %15, %11
br label %34
19: ; preds = %2
%20 = load i8**, i8*** %3
%21 = icmp ne i8** %20, null
br i1 %21, label %22, label %30
22: ; preds = %19
%23 = load i32, i32* %4
%24 = trunc i32 %23 to i8
%25 = load i8**, i8*** %3
%26 = load i8*, i8** %25
store i8 %24, i8* %26
%27 = load i8**, i8*** %3
%28 = load i8*, i8** %27
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %27
br label %33
30: ; preds = %19
%31 = load i32, i32* %4
%32 = call i32 @kputch(i32 %31)
br label %33
33: ; preds = %30, %22
br label %34
34: ; preds = %33, %18
ret void
}

LLVM IR (-O2):
define void @printchar(i8** %0, i32 %1) {
%3 = ptrtoint i8** %0 to i64
%4 = trunc i64 %3 to i32
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %14
6: ; preds = %2
%7 = icmp eq i32 %1, 256
br i1 %7, label %8, label %12
8: ; preds = %6
%9 = tail call i32 @uartputc(i32 8)
%10 = tail call i32 @uartputc(i32 32)
%11 = tail call i32 @uartputc(i32 8)
br label %23
12: ; preds = %6
%13 = tail call i32 @uartputc(i32 %1)
br label %23
14: ; preds = %2
%15 = icmp eq i8** %0, null
br i1 %15, label %21, label %16
16: ; preds = %14
%17 = trunc i32 %1 to i8
%18 = load i8*, i8** %0
store i8 %17, i8* %18
%19 = load i8*, i8** %0
%20 = getelementptr inbounds i8, i8* %19, i64 1
store i8* %20, i8** %0
br label %23
21: ; preds = %14
%22 = tail call i32 @kputch(i32 %1)
br label %23
23: ; preds = %16, %21, %8, %12
ret void
}