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

/* Variables and functions */
char *boolstr(uint8_t n) {
  static char buf[9];
  unsigned int i;
  for (i = 0; i < 8; i++) {
    buf[i] = (n & 0x80) ? '1' : '0';
    n <<= 1;
  }
  buf[8] = 0;
  return buf;
}


x86 assembly (clang, -O0):
<boolstr>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x8,-0x8(%rbp)
jae    1159 <boolstr+0x59>
mov    -0x4(%rbp),%edx
and    $0x80,%edx
mov    $0x30,%eax
mov    $0x31,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,%dl
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
lea    0x2ee2(%rip),%rax
mov    %dl,(%rax,%rcx,1)
mov    -0x4(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    110e <boolstr+0xe>
movb   $0x0,0x2ec9(%rip)
lea    0x2eba(%rip),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<boolstr>:
movd   %edi,%xmm0
pshufd $0x0,%xmm0,%xmm0
movdqa 0xeef(%rip),%xmm1
pand   %xmm0,%xmm1
pand   0xef3(%rip),%xmm0
pxor   %xmm2,%xmm2
pcmpeqd %xmm2,%xmm0
pcmpeqd %xmm2,%xmm1
packssdw %xmm0,%xmm1
packsswb %xmm1,%xmm1
pmovmskb %xmm1,%esi
mov    %esi,%r10d
and    $0x2,%r10b
shr    %r10b
mov    %esi,%edi
and    $0x4,%dil
shr    $0x2,%dil
mov    %esi,%r8d
and    $0x8,%r8b
shr    $0x3,%r8b
mov    %esi,%r9d
and    $0x10,%r9b
shr    $0x4,%r9b
mov    %esi,%edx
and    $0x20,%dl
shr    $0x5,%dl
mov    %esi,%ecx
and    $0x40,%cl
shr    $0x6,%cl
mov    %esi,%eax
sar    $0x7,%al
add    $0x31,%al
mov    %al,0x2ea5(%rip)
lea    0x2e9e(%rip),%rax
xor    $0x31,%cl
mov    %cl,0x2e96(%rip)
xor    $0x31,%dl
mov    %dl,0x2e8e(%rip)
xor    $0x31,%r9b
mov    %r9b,0x2e84(%rip)
xor    $0x31,%r8b
mov    %r8b,0x2e7a(%rip)
xor    $0x31,%dil
mov    %dil,0x2e70(%rip)
xor    $0x31,%r10b
mov    %r10b,0x2e66(%rip)
and    $0x1,%sil
xor    $0x31,%sil
mov    %sil,0x2e58(%rip)
movb   $0x0,0x2e52(%rip)
ret

LLVM IR (-O0):
@boolstr.buf = internal global [9 x i8] zeroinitializer
define i8* @boolstr(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
br label %4
4: ; preds = %19, %1
%5 = load i32, i32* %3
%6 = icmp ult i32 %5, 8
br i1 %6, label %7, label %22
7: ; preds = %4
%8 = load i32, i32* %2
%9 = and i32 %8, 128
%10 = icmp ne i32 %9, 0
%11 = zext i1 %10 to i64
%12 = select i1 %10, i32 49, i32 48
%13 = trunc i32 %12 to i8
%14 = load i32, i32* %3
%15 = zext i32 %14 to i64
%16 = getelementptr inbounds [9 x i8], [9 x i8]* @boolstr.buf, i64 0, i64 %15
store i8 %13, i8* %16
%17 = load i32, i32* %2
%18 = shl i32 %17, 1
store i32 %18, i32* %2
br label %19
19: ; preds = %7
%20 = load i32, i32* %3
%21 = add i32 %20, 1
store i32 %21, i32* %3
br label %4
22: ; preds = %4
store i8 0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @boolstr.buf, i64 0, i64 8)
ret i8* getelementptr inbounds ([9 x i8], [9 x i8]* @boolstr.buf, i64 0, i64 0)
}

LLVM IR (-O2):
@boolstr.buf = internal global [9 x i8] zeroinitializer
define i8* @boolstr(i32 %0) {
%2 = insertelement <8 x i32> poison, i32 %0, i64 0
%3 = shufflevector <8 x i32> %2, <8 x i32> poison, <8 x i32> zeroinitializer
%4 = and <8 x i32> %3, <i32 1, i32 2, i32 4, i32 8, i32 16, i32 32, i32 64, i32 128>
%5 = icmp eq <8 x i32> %4, zeroinitializer
%6 = extractelement <8 x i1> %5, i64 7
%7 = select i1 %6, i8 48, i8 49
store i8 %7, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @boolstr.buf, i64 0, i64 0)
%8 = extractelement <8 x i1> %5, i64 6
%9 = select i1 %8, i8 48, i8 49
store i8 %9, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @boolstr.buf, i64 0, i64 1)
%10 = extractelement <8 x i1> %5, i64 5
%11 = select i1 %10, i8 48, i8 49
store i8 %11, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @boolstr.buf, i64 0, i64 2)
%12 = extractelement <8 x i1> %5, i64 4
%13 = select i1 %12, i8 48, i8 49
store i8 %13, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @boolstr.buf, i64 0, i64 3)
%14 = extractelement <8 x i1> %5, i64 3
%15 = select i1 %14, i8 48, i8 49
store i8 %15, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @boolstr.buf, i64 0, i64 4)
%16 = extractelement <8 x i1> %5, i64 2
%17 = select i1 %16, i8 48, i8 49
store i8 %17, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @boolstr.buf, i64 0, i64 5)
%18 = extractelement <8 x i1> %5, i64 1
%19 = select i1 %18, i8 48, i8 49
store i8 %19, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @boolstr.buf, i64 0, i64 6)
%20 = extractelement <8 x i1> %5, i64 0
%21 = select i1 %20, i8 48, i8 49
store i8 %21, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @boolstr.buf, i64 0, i64 7)
store i8 0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @boolstr.buf, i64 0, i64 8)
ret i8* getelementptr inbounds ([9 x i8], [9 x i8]* @boolstr.buf, i64 0, i64 0)
}