#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*/ decimal_to_bin(size_t, size_t, size_t *);
size_t *malloc(size_t);
size_t popcount(size_t);
void str_to_bin(const char *str, const size_t str_size, const size_t max_size,
                size_t **bits, size_t *bits_size) {
  size_t mask = max_size;
  size_t number_bits_size = popcount(mask);
  *bits_size = number_bits_size * str_size;
  size_t size = (sizeof *bits) * (*bits_size);
  size_t *s = malloc(size);
  size_t i, j;
  for (i = 0; i < str_size; i++) {
    decimal_to_bin(mask, (size_t)str[i], (size_t *)s + i * number_bits_size);
  }
  *bits = (size_t *)s;
}


x86 assembly (clang, -O0):
<str_to_bin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <popcount@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rcx
imul   -0x10(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
shl    $0x3,%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
call   1040 <malloc@plt>
mov    %rax,-0x48(%rbp)
movq   $0x0,-0x50(%rbp)
mov    -0x50(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11de <str_to_bin+0xae>
mov    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    -0x50(%rbp),%rcx
movsbq (%rax,%rcx,1),%rsi
mov    -0x48(%rbp),%rdx
mov    -0x50(%rbp),%rax
imul   -0x38(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdx
call   1050 <decimal_to_bin@plt>
mov    -0x50(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
jmp    1195 <str_to_bin+0x65>
mov    -0x48(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_to_bin>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8,%rbp
mov    %rcx,0x10(%rsp)
mov    %rdx,%r15
mov    %rsi,%r13
mov    %rdi,%r12
mov    %rdx,%rdi
call   1030 <popcount@plt>
mov    %rax,%rbx
mov    %rax,%rdi
imul   %r13,%rdi
mov    %rdi,0x0(%rbp)
shl    $0x3,%rdi
call   1040 <malloc@plt>
mov    %rax,0x8(%rsp)
test   %r13,%r13
je     11ac <str_to_bin+0x7c>
shl    $0x3,%rbx
xor    %r14d,%r14d
mov    0x8(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbq (%r12,%r14,1),%rsi
mov    %r15,%rdi
mov    %rbp,%rdx
call   1050 <decimal_to_bin@plt>
add    $0x1,%r14
add    %rbx,%rbp
cmp    %r14,%r13
jne    1190 <str_to_bin+0x60>
mov    0x10(%rsp),%rax
mov    0x8(%rsp),%rcx
mov    %rcx,(%rax)
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @str_to_bin(i8* %0, i64 %1, i64 %2, i64** %3, i64* %4) {
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64**
%10 = alloca i64*
%11 = alloca i64
%12 = alloca i64
%13 = alloca i64
%14 = alloca i64*
%15 = alloca i64
%16 = alloca i64
store i8* %0, i8** %6
store i64 %1, i64* %7
store i64 %2, i64* %8
store i64** %3, i64*** %9
store i64* %4, i64** %10
%17 = load i64, i64* %8
store i64 %17, i64* %11
%18 = load i64, i64* %11
%19 = call i64 @popcount(i64 %18)
store i64 %19, i64* %12
%20 = load i64, i64* %12
%21 = load i64, i64* %7
%22 = mul i64 %20, %21
%23 = load i64*, i64** %10
store i64 %22, i64* %23
%24 = load i64*, i64** %10
%25 = load i64, i64* %24
%26 = mul i64 8, %25
store i64 %26, i64* %13
%27 = load i64, i64* %13
%28 = call i64* @malloc(i64 %27)
store i64* %28, i64** %14
store i64 0, i64* %15
br label %29
29: ; preds = %46, %5
%30 = load i64, i64* %15
%31 = load i64, i64* %7
%32 = icmp ult i64 %30, %31
br i1 %32, label %33, label %49
33: ; preds = %29
%34 = load i64, i64* %11
%35 = load i8*, i8** %6
%36 = load i64, i64* %15
%37 = getelementptr inbounds i8, i8* %35, i64 %36
%38 = load i8, i8* %37
%39 = sext i8 %38 to i64
%40 = load i64*, i64** %14
%41 = load i64, i64* %15
%42 = load i64, i64* %12
%43 = mul i64 %41, %42
%44 = getelementptr inbounds i64, i64* %40, i64 %43
%45 = call i32 @decimal_to_bin(i64 %34, i64 %39, i64* %44)
br label %46
46: ; preds = %33
%47 = load i64, i64* %15
%48 = add i64 %47, 1
store i64 %48, i64* %15
br label %29
49: ; preds = %29
%50 = load i64*, i64** %14
%51 = load i64**, i64*** %9
store i64* %50, i64** %51
ret void
}

LLVM IR (-O2):
define void @str_to_bin(i8* nocapture %0, i64 %1, i64 %2, i64** nocapture writeonly %3, i64* nocapture writeonly %4) {
%6 = tail call i64 @popcount(i64 %2)
%7 = mul i64 %6, %1
store i64 %7, i64* %4
%8 = shl i64 %7, 3
%9 = tail call i64* @malloc(i64 %8)
%10 = icmp eq i64 %1, 0
br i1 %10, label %21, label %11
11: ; preds = %5, %11
%12 = phi i64 [ %19, %11 ], [ 0, %5 ]
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = load i8, i8* %13
%15 = sext i8 %14 to i64
%16 = mul i64 %12, %6
%17 = getelementptr inbounds i64, i64* %9, i64 %16
%18 = tail call i32 @decimal_to_bin(i64 %2, i64 %15, i64* %17)
%19 = add nuw i64 %12, 1
%20 = icmp eq i64 %19, %1
br i1 %20, label %21, label %11
21: ; preds = %11, %5
store i64* %9, i64** %3
ret void
}