#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*/ assert(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int const);
const char *BinString(const unsigned char src, char *buf, const int bufSize) {
  assert(buf != NULL);
  assert(bufSize >= 8);
  memset(buf, 0, bufSize * sizeof(char));
  unsigned char val = src;
  int i = 0;
  for (; i < 8; ++i) {
    static const unsigned char mask = 0x80;
    buf[i] = ((mask & val) == mask ? '1' : '0');
    val = val << 1;
  }
  return buf;
}


x86 assembly (clang, -O0):
<BinString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
cmpl   $0x8,-0x14(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rdi
movslq -0x14(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1030 <memset@plt>
mov    -0x1(%rbp),%al
mov    %al,-0x15(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x8,-0x1c(%rbp)
jge    11c6 <BinString+0xa6>
movzbl -0x15(%rbp),%edx
and    $0x80,%edx
mov    $0x30,%eax
mov    $0x31,%ecx
cmp    $0x80,%edx
cmove  %ecx,%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
movzbl -0x15(%rbp),%eax
shl    $0x1,%eax
mov    %al,-0x15(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    117a <BinString+0x5a>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BinString>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %edi,%edi
test   %rsi,%rsi
setne  %dil
call   1040 <assert@plt>
xor    %edi,%edi
cmp    $0x8,%r14d
setge  %dil
call   1040 <assert@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r14d,%edx
call   1030 <memset@plt>
mov    %ebp,%eax
shr    $0x7,%al
or     $0x30,%al
mov    %al,(%rbx)
mov    %ebp,%eax
and    $0x40,%al
cmp    $0x1,%al
mov    $0x31,%al
sbb    $0x0,%al
mov    %al,0x1(%rbx)
mov    %ebp,%eax
and    $0x20,%al
cmp    $0x1,%al
mov    $0x31,%al
sbb    $0x0,%al
mov    %al,0x2(%rbx)
mov    %ebp,%eax
and    $0x10,%al
cmp    $0x1,%al
mov    $0x31,%al
sbb    $0x0,%al
mov    %al,0x3(%rbx)
mov    %ebp,%eax
and    $0x8,%al
cmp    $0x1,%al
mov    $0x31,%al
sbb    $0x0,%al
mov    $0x31,%cl
mov    %al,0x4(%rbx)
mov    %ebp,%eax
and    $0x4,%al
cmp    $0x1,%al
mov    $0x31,%al
sbb    $0x0,%al
mov    %al,0x5(%rbx)
mov    %ebp,%eax
and    $0x2,%al
cmp    $0x1,%al
sbb    $0x0,%cl
mov    %cl,0x6(%rbx)
and    $0x1,%bpl
or     $0x30,%bpl
mov    %bpl,0x7(%rbx)
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@BinString.mask = internal constant i8 -128
define i8* @BinString(i8 zeroext %0, i8* %1, i32 %2) {
%4 = alloca i8
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8
%8 = alloca i32
store i8 %0, i8* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = load i8*, i8** %5
%10 = icmp ne i8* %9, null
%11 = zext i1 %10 to i32
%12 = call i32 @assert(i32 %11)
%13 = load i32, i32* %6
%14 = icmp sge i32 %13, 8
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
%17 = load i8*, i8** %5
%18 = load i32, i32* %6
%19 = sext i32 %18 to i64
%20 = mul i64 %19, 1
%21 = trunc i64 %20 to i32
%22 = call i32 @memset(i8* %17, i32 0, i32 %21)
%23 = load i8, i8* %4
store i8 %23, i8* %7
store i32 0, i32* %8
br label %24
24: ; preds = %43, %3
%25 = load i32, i32* %8
%26 = icmp slt i32 %25, 8
br i1 %26, label %27, label %46
27: ; preds = %24
%28 = load i8, i8* %7
%29 = zext i8 %28 to i32
%30 = and i32 128, %29
%31 = icmp eq i32 %30, 128
%32 = zext i1 %31 to i64
%33 = select i1 %31, i32 49, i32 48
%34 = trunc i32 %33 to i8
%35 = load i8*, i8** %5
%36 = load i32, i32* %8
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
store i8 %34, i8* %38
%39 = load i8, i8* %7
%40 = zext i8 %39 to i32
%41 = shl i32 %40, 1
%42 = trunc i32 %41 to i8
store i8 %42, i8* %7
br label %43
43: ; preds = %27
%44 = load i32, i32* %8
%45 = add nsw i32 %44, 1
store i32 %45, i32* %8
br label %24
46: ; preds = %24
%47 = load i8*, i8** %5
ret i8* %47
}

LLVM IR (-O2):
define i8* @BinString(i8 zeroext %0, i8* returned %1, i32 %2) {
%4 = icmp ne i8* %1, null
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = icmp sgt i32 %2, 7
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = tail call i32 @memset(i8* %1, i32 0, i32 %2)
%11 = icmp sgt i8 %0, -1
%12 = select i1 %11, i8 48, i8 49
store i8 %12, i8* %1
%13 = and i8 %0, 64
%14 = icmp eq i8 %13, 0
%15 = select i1 %14, i8 48, i8 49
%16 = getelementptr inbounds i8, i8* %1, i64 1
store i8 %15, i8* %16
%17 = and i8 %0, 32
%18 = icmp eq i8 %17, 0
%19 = select i1 %18, i8 48, i8 49
%20 = getelementptr inbounds i8, i8* %1, i64 2
store i8 %19, i8* %20
%21 = and i8 %0, 16
%22 = icmp eq i8 %21, 0
%23 = select i1 %22, i8 48, i8 49
%24 = getelementptr inbounds i8, i8* %1, i64 3
store i8 %23, i8* %24
%25 = and i8 %0, 8
%26 = icmp eq i8 %25, 0
%27 = select i1 %26, i8 48, i8 49
%28 = getelementptr inbounds i8, i8* %1, i64 4
store i8 %27, i8* %28
%29 = and i8 %0, 4
%30 = icmp eq i8 %29, 0
%31 = select i1 %30, i8 48, i8 49
%32 = getelementptr inbounds i8, i8* %1, i64 5
store i8 %31, i8* %32
%33 = and i8 %0, 2
%34 = icmp eq i8 %33, 0
%35 = select i1 %34, i8 48, i8 49
%36 = getelementptr inbounds i8, i8* %1, i64 6
store i8 %35, i8* %36
%37 = and i8 %0, 1
%38 = or i8 %37, 48
%39 = getelementptr inbounds i8, i8* %1, i64 7
store i8 %38, i8* %39
ret i8* %1
}