#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 uint8_t;
typedef int uint16_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
void print_char(char output) {
  static uint16_t count = 0;
  static uint8_t new_line = 1;
  if (new_line) {
    printf("%04d: ", count);
    new_line = 0;
  }
  if (output == '\x00') {
    printf("\033[0;45m");
    printf(" %02X", (uint8_t)output);
    printf("\033[0;34m");
  } else {
    printf(" %02X", (uint8_t)output);
    printf("\033[0;34m");
  }
  count++;
  if ((count % 8) == 0) {
    printf("\n");
    new_line = 1;
  }
}


x86 assembly (clang, -O0):
<print_char>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
cmpl   $0x0,0x2f03(%rip)
je     1149 <print_char+0x39>
mov    0x2eff(%rip),%esi
lea    0xec8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,0x2edf(%rip)
movsbl -0x1(%rbp),%eax
cmp    $0x0,%eax
jne    1189 <print_char+0x79>
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsbl -0x1(%rbp),%esi
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe98(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11a9 <print_char+0x99>
movsbl -0x1(%rbp),%esi
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e81(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2e78(%rip)
mov    0x2e72(%rip),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11e7 <print_char+0xd7>
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,0x2e41(%rip)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_char>:
push   %rbx
mov    %edi,%ebx
cmpb   $0x0,0x2f0e(%rip)
jne    1147 <print_char+0x27>
mov    0x2f02(%rip),%esi
lea    0xec7(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movb   $0x1,0x2ef1(%rip)
test   %bl,%bl
je     1150 <print_char+0x30>
movsbl %bl,%ebx
jmp    1160 <print_char+0x40>
lea    0xeb0(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xea8(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe9e(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2eb0(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2ea7(%rip)
test   $0x7,%al
je     1193 <print_char+0x73>
pop    %rbx
ret
mov    $0xa,%edi
call   1030 <putchar@plt>
movb   $0x0,0x2e94(%rip)
pop    %rbx
ret

LLVM IR (-O0):
@print_char.count = internal global i32 0
@print_char.new_line = internal global i32 1
@.str = [7 x i8] c"%04d: \00"
@.str.1 = [8 x i8] c"\1B[0;45m\00"
@.str.2 = [6 x i8] c" %02X\00"
@.str.3 = [8 x i8] c"\1B[0;34m\00"
@.str.4 = [2 x i8] c"\0A\00"
define void @print_char(i8 signext %0) {
%2 = alloca i8
store i8 %0, i8* %2
%3 = load i32, i32* @print_char.new_line
%4 = icmp ne i32 %3, 0
br i1 %4, label %5, label %8
5: ; preds = %1
%6 = load i32, i32* @print_char.count
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %6)
store i32 0, i32* @print_char.new_line
br label %8
8: ; preds = %5, %1
%9 = load i8, i8* %2
%10 = sext i8 %9 to i32
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %18
12: ; preds = %8
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%14 = load i8, i8* %2
%15 = sext i8 %14 to i32
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %15)
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %23
18: ; preds = %8
%19 = load i8, i8* %2
%20 = sext i8 %19 to i32
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %20)
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %23
23: ; preds = %18, %12
%24 = load i32, i32* @print_char.count
%25 = add nsw i32 %24, 1
store i32 %25, i32* @print_char.count
%26 = load i32, i32* @print_char.count
%27 = srem i32 %26, 8
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %23
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* @print_char.new_line
br label %31
31: ; preds = %29, %23
ret void
}

LLVM IR (-O2):
@print_char.count = internal unnamed_addr global i32 0
@print_char.new_line = internal unnamed_addr global i1 false
@.str = [7 x i8] c"%04d: \00"
@.str.1 = [8 x i8] c"\1B[0;45m\00"
@.str.2 = [6 x i8] c" %02X\00"
@.str.3 = [8 x i8] c"\1B[0;34m\00"
define void @print_char(i8 signext %0) {
%2 = load i1, i1* @print_char.new_line
br i1 %2, label %6, label %3
3: ; preds = %1
%4 = load i32, i32* @print_char.count
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %4)
store i1 true, i1* @print_char.new_line
br label %6
6: ; preds = %3, %1
%7 = icmp eq i8 %0, 0
br i1 %7, label %8, label %10
8: ; preds = %6
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %12
10: ; preds = %6
%11 = sext i8 %0 to i32
br label %12
12: ; preds = %10, %8
%13 = phi i32 [ %11, %10 ], [ 0, %8 ]
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %13)
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%16 = load i32, i32* @print_char.count
%17 = add nsw i32 %16, 1
store i32 %17, i32* @print_char.count
%18 = and i32 %17, 7
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %12
%21 = tail call i32 @putchar(i32 10)
store i1 false, i1* @print_char.new_line
br label %22
22: ; preds = %20, %12
ret void
}