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

/* Variables and functions */
int /*<<< orphan*/ addch(int /*<<< orphan*/);
int /*<<< orphan*/ itoc(int, char);
int /*<<< orphan*/ rep(char, int);
void draw_u8(int x) {
  x = x == 0 ? 0 : (1 << x);
  int hspace = 8 - 4;
  int left_hspace = hspace / 2;
  int right_hspace = hspace - left_hspace;
  rep(' ', left_hspace);
  int div = 1000;
  for (int8_t i = 0; i < 4; ++i) {
    addch(itoc((x / div) % 10, x < div ? ' ' : '0'));
    div /= 10;
  }
  rep(' ', right_hspace);
}


x86 assembly (clang, -O0):
<draw_u8>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    114f <draw_u8+0x1f>
xor    %eax,%eax
mov    %eax,-0x1c(%rbp)
jmp    115c <draw_u8+0x2c>
mov    -0x4(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x4,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
sub    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%esi
mov    $0x20,%edi
call   1030 <rep@plt>
movl   $0x3e8,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x4,-0x18(%rbp)
jge    11f6 <draw_u8+0xc6>
mov    -0x4(%rbp),%eax
cltd
idivl  -0x14(%rbp)
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
mov    -0x4(%rbp),%edx
mov    -0x14(%rbp),%esi
mov    $0x30,%eax
mov    $0x20,%ecx
cmp    %esi,%edx
cmovl  %ecx,%eax
movsbl %al,%esi
call   1050 <itoc@plt>
mov    %eax,%edi
call   1040 <addch@plt>
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    119b <draw_u8+0x6b>
mov    -0x10(%rbp),%esi
mov    $0x20,%edi
call   1030 <rep@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<draw_u8>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ecx
mov    $0x1,%ebx
shl    %cl,%ebx
test   %edi,%edi
cmove  %edi,%ebx
mov    $0x20,%edi
mov    $0x2,%esi
call   1030 <rep@plt>
movslq %ebx,%r14
imul   $0x10624dd3,%r14,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x26,%rax
add    %ecx,%eax
movslq %eax,%rdi
imul   $0x66666667,%rdi,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%edi
xor    %esi,%esi
cmp    $0x3e8,%r14d
setge  %sil
shl    $0x4,%esi
or     $0x20,%esi
call   1050 <itoc@plt>
mov    %eax,%edi
call   1040 <addch@plt>
imul   $0x51eb851f,%r14,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x25,%rax
add    %ecx,%eax
movslq %eax,%rdi
imul   $0x66666667,%rdi,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%edi
xor    %esi,%esi
cmp    $0x64,%r14d
setge  %sil
shl    $0x4,%esi
or     $0x20,%esi
call   1050 <itoc@plt>
mov    %eax,%edi
call   1040 <addch@plt>
imul   $0x66666667,%r14,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
movslq %eax,%rbx
imul   $0x66666667,%rbx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
mov    %ebx,%edi
sub    %eax,%edi
xor    %esi,%esi
cmp    $0xa,%r14d
setge  %sil
shl    $0x4,%esi
or     $0x20,%esi
call   1050 <itoc@plt>
mov    %eax,%edi
call   1040 <addch@plt>
add    %ebx,%ebx
lea    (%rbx,%rbx,4),%eax
mov    %r14d,%edi
sub    %eax,%edi
xor    %esi,%esi
test   %r14d,%r14d
setg   %sil
shl    $0x4,%esi
or     $0x20,%esi
call   1050 <itoc@plt>
mov    %eax,%edi
call   1040 <addch@plt>
mov    $0x20,%edi
mov    $0x2,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <rep@plt>

LLVM IR (-O0):
define void @draw_u8(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %2
%8 = load i32, i32* %2
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %1
br label %14
11: ; preds = %1
%12 = load i32, i32* %2
%13 = shl i32 1, %12
br label %14
14: ; preds = %11, %10
%15 = phi i32 [ 0, %10 ], [ %13, %11 ]
store i32 %15, i32* %2
store i32 4, i32* %3
%16 = load i32, i32* %3
%17 = sdiv i32 %16, 2
store i32 %17, i32* %4
%18 = load i32, i32* %3
%19 = load i32, i32* %4
%20 = sub nsw i32 %18, %19
store i32 %20, i32* %5
%21 = load i32, i32* %4
%22 = call i32 @rep(i8 signext 32, i32 %21)
store i32 1000, i32* %6
store i32 0, i32* %7
br label %23
23: ; preds = %41, %14
%24 = load i32, i32* %7
%25 = icmp slt i32 %24, 4
br i1 %25, label %26, label %44
26: ; preds = %23
%27 = load i32, i32* %2
%28 = load i32, i32* %6
%29 = sdiv i32 %27, %28
%30 = srem i32 %29, 10
%31 = load i32, i32* %2
%32 = load i32, i32* %6
%33 = icmp slt i32 %31, %32
%34 = zext i1 %33 to i64
%35 = select i1 %33, i32 32, i32 48
%36 = trunc i32 %35 to i8
%37 = call i32 @itoc(i32 %30, i8 signext %36)
%38 = call i32 @addch(i32 %37)
%39 = load i32, i32* %6
%40 = sdiv i32 %39, 10
store i32 %40, i32* %6
br label %41
41: ; preds = %26
%42 = load i32, i32* %7
%43 = add nsw i32 %42, 1
store i32 %43, i32* %7
br label %23
44: ; preds = %23
%45 = load i32, i32* %5
%46 = call i32 @rep(i8 signext 32, i32 %45)
ret void
}

LLVM IR (-O2):
define void @draw_u8(i32 %0) {
%2 = icmp eq i32 %0, 0
%3 = shl nuw i32 1, %0
%4 = select i1 %2, i32 0, i32 %3
%5 = tail call i32 @rep(i8 signext 32, i32 2)
%6 = sdiv i32 %4, 1000
%7 = srem i32 %6, 10
%8 = icmp slt i32 %4, 1000
%9 = select i1 %8, i8 32, i8 48
%10 = tail call i32 @itoc(i32 %7, i8 signext %9)
%11 = tail call i32 @addch(i32 %10)
%12 = sdiv i32 %4, 100
%13 = srem i32 %12, 10
%14 = icmp slt i32 %4, 100
%15 = select i1 %14, i8 32, i8 48
%16 = tail call i32 @itoc(i32 %13, i8 signext %15)
%17 = tail call i32 @addch(i32 %16)
%18 = sdiv i32 %4, 10
%19 = srem i32 %18, 10
%20 = icmp slt i32 %4, 10
%21 = select i1 %20, i8 32, i8 48
%22 = tail call i32 @itoc(i32 %19, i8 signext %21)
%23 = tail call i32 @addch(i32 %22)
%24 = srem i32 %4, 10
%25 = icmp slt i32 %4, 1
%26 = select i1 %25, i8 32, i8 48
%27 = tail call i32 @itoc(i32 %24, i8 signext %26)
%28 = tail call i32 @addch(i32 %27)
%29 = tail call i32 @rep(i8 signext 32, i32 2)
ret void
}