#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*/ buf;

/* Variables and functions */
int /*<<< orphan*/ do_moan(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, int, int, int);
int /*<<< orphan*/ write(int, unsigned char *, int);
int /*<<< orphan*/ writestr(int, char *);
void put_char(unsigned char *c, int a) {
  static int ca = -1;
  if (ca != a) {
    char buf[1024];
    int mapf[8] = {0, 34, 32, 36, 31, 35, 33, 37};
    int mapb[8] = {40, 44, 42, 46, 41, 45, 43, 47};
    int h = (a & 0x8) ? 1 : 0;
    int f = mapf[a & 0x7];
    int b = mapb[(a >> 4) & 0x7];
    snprintf(buf, sizeof(buf) - 1, "\033[%d;%d;%dm", h, f, b);
    writestr(1, buf);
  }
  do_moan(write(1, c, 1), "write (1, c, 1)", 242);
}


x86 assembly (clang, -O0):
<put_char>:
push   %rbp
mov    %rsp,%rbp
sub    $0x460,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    0x2ee8(%rip),%eax
cmp    -0xc(%rbp),%eax
je     1254 <put_char+0x114>
mov    0xe98(%rip),%rax
mov    %rax,-0x430(%rbp)
mov    0xe92(%rip),%rax
mov    %rax,-0x428(%rbp)
mov    0xe8c(%rip),%rax
mov    %rax,-0x420(%rbp)
mov    0xe86(%rip),%rax
mov    %rax,-0x418(%rbp)
mov    0xe80(%rip),%rax
mov    %rax,-0x450(%rbp)
mov    0xe7a(%rip),%rax
mov    %rax,-0x448(%rbp)
mov    0xe74(%rip),%rax
mov    %rax,-0x440(%rbp)
mov    0xe6e(%rip),%rax
mov    %rax,-0x438(%rbp)
mov    -0xc(%rbp),%edx
and    $0x8,%edx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %eax,-0x454(%rbp)
mov    -0xc(%rbp),%eax
and    $0x7,%eax
cltq
mov    -0x430(%rbp,%rax,4),%eax
mov    %eax,-0x458(%rbp)
mov    -0xc(%rbp),%eax
sar    $0x4,%eax
and    $0x7,%eax
cltq
mov    -0x450(%rbp,%rax,4),%eax
mov    %eax,-0x45c(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x454(%rbp),%ecx
mov    -0x458(%rbp),%r8d
mov    -0x45c(%rbp),%r9d
mov    $0x3ff,%esi
lea    0xe02(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0x410(%rbp),%rsi
mov    $0x1,%edi
call   1050 <writestr@plt>
mov    -0x8(%rbp),%rsi
mov    $0x1,%edx
mov    %edx,%edi
call   1030 <write@plt>
mov    %eax,%edi
lea    0xddf(%rip),%rsi
mov    $0xf2,%edx
call   1060 <do_moan@plt>
add    $0x460,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<put_char>:
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %rdi,%rbx
cmp    $0xffffffff,%esi
je     119f <put_char+0x5f>
mov    %esi,%ecx
shr    $0x3,%ecx
and    $0x1,%ecx
mov    %esi,%eax
and    $0x7,%eax
lea    0xe9a(%rip),%rdx
mov    (%rdx,%rax,4),%r8d
shr    $0x4,%esi
and    $0x7,%esi
lea    0xea9(%rip),%rax
mov    (%rax,%rsi,4),%r9d
lea    0xebe(%rip),%rdx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x3ff,%esi
call   1040 <snprintf@plt>
mov    $0x1,%edi
mov    %r14,%rsi
call   1050 <writestr@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
lea    0xe94(%rip),%rsi
mov    %eax,%edi
mov    $0xf2,%edx
call   1060 <do_moan@plt>
add    $0x408,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@put_char.ca = internal global i32 -1
@__const.put_char.mapf = [8 x i32] [i32 0, i32 34, i32 32, i32 36, i32 31, i32 35, i32 33, i32 37]
@__const.put_char.mapb = [8 x i32] [i32 40, i32 44, i32 42, i32 46, i32 41, i32 45, i32 43, i32 47]
@.str = [12 x i8] c"\1B[%d;%d;%dm\00"
@.str.1 = [16 x i8] c"write (1, c, 1)\00"
define void @put_char(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [1024 x i8]
%6 = alloca [8 x i32]
%7 = alloca [8 x i32]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%11 = load i32, i32* @put_char.ca
%12 = load i32, i32* %4
%13 = icmp ne i32 %11, %12
br i1 %13, label %14, label %40
14: ; preds = %2
%15 = bitcast [8 x i32]* %6 to i8*
%16 = bitcast [8 x i32]* %7 to i8*
%17 = load i32, i32* %4
%18 = and i32 %17, 8
%19 = icmp ne i32 %18, 0
%20 = zext i1 %19 to i64
%21 = select i1 %19, i32 1, i32 0
store i32 %21, i32* %8
%22 = load i32, i32* %4
%23 = and i32 %22, 7
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [8 x i32], [8 x i32]* %6, i64 0, i64 %24
%26 = load i32, i32* %25
store i32 %26, i32* %9
%27 = load i32, i32* %4
%28 = ashr i32 %27, 4
%29 = and i32 %28, 7
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [8 x i32], [8 x i32]* %7, i64 0, i64 %30
%32 = load i32, i32* %31
store i32 %32, i32* %10
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%34 = load i32, i32* %8
%35 = load i32, i32* %9
%36 = load i32, i32* %10
%37 = call i32 @snprintf(i8* %33, i32 1023, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %34, i32 %35, i32 %36)
%38 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%39 = call i32 @writestr(i32 1, i8* %38)
br label %40
40: ; preds = %14, %2
%41 = load i8*, i8** %3
%42 = call i32 @write(i32 1, i8* %41, i32 1)
%43 = call i32 @do_moan(i32 %42, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 242)
ret void
}

LLVM IR (-O2):
@__const.put_char.mapf = [8 x i32] [i32 0, i32 34, i32 32, i32 36, i32 31, i32 35, i32 33, i32 37]
@__const.put_char.mapb = [8 x i32] [i32 40, i32 44, i32 42, i32 46, i32 41, i32 45, i32 43, i32 47]
@.str = [12 x i8] c"\1B[%d;%d;%dm\00"
@.str.1 = [16 x i8] c"write (1, c, 1)\00"
define void @put_char(i8* nocapture %0, i32 %1) {
%3 = alloca [1024 x i8]
%4 = icmp eq i32 %1, -1
br i1 %4, label %20, label %5
5: ; preds = %2
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%7 = lshr i32 %1, 3
%8 = and i32 %7, 1
%9 = and i32 %1, 7
%10 = zext i32 %9 to i64
%11 = getelementptr inbounds [8 x i32], [8 x i32]* @__const.put_char.mapf, i64 0, i64 %10
%12 = load i32, i32* %11
%13 = lshr i32 %1, 4
%14 = and i32 %13, 7
%15 = zext i32 %14 to i64
%16 = getelementptr inbounds [8 x i32], [8 x i32]* @__const.put_char.mapb, i64 0, i64 %15
%17 = load i32, i32* %16
%18 = call i32 @snprintf(i8* %6, i32 1023, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %8, i32 %12, i32 %17)
%19 = call i32 @writestr(i32 1, i8* %6)
br label %20
20: ; preds = %5, %2
%21 = call i32 @write(i32 1, i8* %0, i32 1)
%22 = call i32 @do_moan(i32 %21, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 242)
ret void
}