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

/* Variables and functions */
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ puts(char *);
scalar_t__ strtoul(char *, int /*<<< orphan*/ *, int);
size_t makeByteArray(unsigned char *array, const char *binaryDigits,
                     const int bits) {
  size_t byteC = 0;
  size_t bitC = 0;
  unsigned char byte[8];
  for (int i = 0; i < bits; i++) {
    switch (bitC) {
    case 0:
    case 1:
    case 2:
    case 3:
    case 4:
    case 5:
    case 6:
      byte[bitC++] = binaryDigits[i];
      break;
    case 7:
      byte[bitC] = binaryDigits[i];
      unsigned char ch = (unsigned char)strtoul((char *)byte, NULL, 2);
      array[byteC++] = ch;
      bitC = 0;
      memset(byte, 0, sizeof(byte));
      break;
    default:
      puts("BUG!");
      break;
    }
  }
  return byteC;
}


x86 assembly (clang, -O0):
<makeByteArray>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1230 <makeByteArray+0x100>
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
sub    $0x7,%rax
jb     1190 <makeByteArray+0x60>
jmp    117d <makeByteArray+0x4d>
mov    -0x40(%rbp),%rax
sub    $0x7,%rax
je     11b3 <makeByteArray+0x83>
jmp    1211 <makeByteArray+0xe1>
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
mov    -0x28(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x28(%rbp)
mov    %cl,-0x30(%rbp,%rax,1)
jmp    121d <makeByteArray+0xed>
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
mov    -0x28(%rbp),%rax
mov    %cl,-0x30(%rbp,%rax,1)
lea    -0x30(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x2,%edx
call   1050 <strtoul@plt>
mov    %al,-0x35(%rbp)
mov    -0x35(%rbp),%dl
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %rcx,%rsi
add    $0x1,%rsi
mov    %rsi,-0x20(%rbp)
mov    %dl,(%rax,%rcx,1)
movq   $0x0,-0x28(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
jmp    121d <makeByteArray+0xed>
lea    0xde8(%rip),%rdi
call   1030 <puts@plt>
jmp    1222 <makeByteArray+0xf2>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    115a <makeByteArray+0x2a>
mov    -0x20(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<makeByteArray>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edx,%edx
jle    11c3 <makeByteArray+0x93>
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %edx,%ebp
xor    %r13d,%r13d
xor    %r15d,%r15d
xor    %r12d,%r12d
jmp    1176 <makeByteArray+0x46>
cs nopw 0x0(%rax,%rax,1)
movzbl (%rbx,%r13,1),%eax
mov    %al,(%rsp,%r12,1)
add    $0x1,%r12
add    $0x1,%r13
cmp    %r13,%rbp
je     11c6 <makeByteArray+0x96>
cmp    $0x7,%r12
jb     1160 <makeByteArray+0x30>
jne    11b5 <makeByteArray+0x85>
movzbl (%rbx,%r13,1),%eax
mov    %al,0x7(%rsp)
mov    %rsp,%r12
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x2,%edx
call   1050 <strtoul@plt>
mov    %al,(%r14,%r15,1)
add    $0x1,%r15
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
xor    %r12d,%r12d
jmp    116d <makeByteArray+0x3d>
lea    0xe44(%rip),%rdi
call   1030 <puts@plt>
jmp    116d <makeByteArray+0x3d>
xor    %r15d,%r15d
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"BUG!\00"
define i64 @makeByteArray(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i64
%8 = alloca i64
%9 = alloca [8 x i8]
%10 = alloca i32
%11 = alloca i8
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i64 0, i64* %7
store i64 0, i64* %8
store i32 0, i32* %10
br label %12
12: ; preds = %48, %3
%13 = load i32, i32* %10
%14 = load i32, i32* %6
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %51
16: ; preds = %12
%17 = load i64, i64* %8
switch i64 %17, label %45 [
i64 0, label %18
i64 1, label %18
i64 2, label %18
i64 3, label %18
i64 4, label %18
i64 5, label %18
i64 6, label %18
i64 7, label %27
]
18: ; preds = %16, %16, %16, %16, %16, %16, %16
%19 = load i8*, i8** %5
%20 = load i32, i32* %10
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
%23 = load i8, i8* %22
%24 = load i64, i64* %8
%25 = add i64 %24, 1
store i64 %25, i64* %8
%26 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 %24
store i8 %23, i8* %26
br label %47
27: ; preds = %16
%28 = load i8*, i8** %5
%29 = load i32, i32* %10
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
%32 = load i8, i8* %31
%33 = load i64, i64* %8
%34 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 %33
store i8 %32, i8* %34
%35 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 0
%36 = call i64 @strtoul(i8* %35, i32* null, i32 2)
%37 = trunc i64 %36 to i8
store i8 %37, i8* %11
%38 = load i8, i8* %11
%39 = load i8*, i8** %4
%40 = load i64, i64* %7
%41 = add i64 %40, 1
store i64 %41, i64* %7
%42 = getelementptr inbounds i8, i8* %39, i64 %40
store i8 %38, i8* %42
store i64 0, i64* %8
%43 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 0
%44 = call i32 @memset(i8* %43, i32 0, i32 8)
br label %47
45: ; preds = %16
%46 = call i32 @puts(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %47
47: ; preds = %45, %27, %18
br label %48
48: ; preds = %47
%49 = load i32, i32* %10
%50 = add nsw i32 %49, 1
store i32 %50, i32* %10
br label %12
51: ; preds = %12
%52 = load i64, i64* %7
ret i64 %52
}

LLVM IR (-O2):
@.str = [5 x i8] c"BUG!\00"
define i64 @makeByteArray(i8* nocapture writeonly %0, i8* nocapture %1, i32 %2) {
%4 = alloca [8 x i8]
%5 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 0
%6 = icmp sgt i32 %2, 0
br i1 %6, label %7, label %10
7: ; preds = %3
%8 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 7
%9 = zext i32 %2 to i64
br label %12
10: ; preds = %31, %3
%11 = phi i64 [ 0, %3 ], [ %33, %31 ]
ret i64 %11
12: ; preds = %7, %31
%13 = phi i64 [ 0, %7 ], [ %34, %31 ]
%14 = phi i64 [ 0, %7 ], [ %33, %31 ]
%15 = phi i64 [ 0, %7 ], [ %32, %31 ]
switch i64 %15, label %29 [
i64 0, label %16
i64 1, label %16
i64 2, label %16
i64 3, label %16
i64 4, label %16
i64 5, label %16
i64 6, label %16
i64 7, label %21
]
16: ; preds = %12, %12, %12, %12, %12, %12, %12
%17 = getelementptr inbounds i8, i8* %1, i64 %13
%18 = load i8, i8* %17
%19 = add nuw nsw i64 %15, 1
%20 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 %15
store i8 %18, i8* %20
br label %31
21: ; preds = %12
%22 = getelementptr inbounds i8, i8* %1, i64 %13
%23 = load i8, i8* %22
store i8 %23, i8* %8
%24 = call i64 @strtoul(i8* nocapture %5, i32* null, i32 2)
%25 = trunc i64 %24 to i8
%26 = add i64 %14, 1
%27 = getelementptr inbounds i8, i8* %0, i64 %14
store i8 %25, i8* %27
%28 = call i32 @memset(i8* %5, i32 0, i32 8)
br label %31
29: ; preds = %12
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %31
31: ; preds = %16, %21, %29
%32 = phi i64 [ %15, %29 ], [ 0, %21 ], [ %19, %16 ]
%33 = phi i64 [ %14, %29 ], [ %26, %21 ], [ %14, %16 ]
%34 = add nuw nsw i64 %13, 1
%35 = icmp eq i64 %34, %9
br i1 %35, label %10, label %12
}