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

/* Variables and functions */
int /*<<< orphan*/ memset(char *, int, int);
int /*<<< orphan*/ printBinary(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stringToBinary(char *, char *);
int strlen(char *);
int main() {
  char *texto = "10110000";
  printf("[original] %s\n", texto);
  printf("tamanho do texto original %d, multiplo de 8 ? (%d)\n",
         (int)strlen(texto), (int)(strlen(texto) % 8 + 1) % 2);
  if (strlen(texto) % 8)
    return 0;
  char resultado[strlen(texto) / 8];
  memset(&resultado[0], 0x0, sizeof(resultado));
  stringToBinary(texto, resultado);
  printf("[resultado] ");
  for (int i = 0; i < strlen(texto) / 8; i++)
    printBinary((int)resultado[i]);
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe94(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x28(%rbp),%esi
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
add    $0x1,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
lea    0xe68(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     11dd <main+0x8d>
movl   $0x0,-0x4(%rbp)
jmp    12a0 <main+0x150>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
add    $0x7,%ecx
test   %eax,%eax
cmovs  %ecx,%eax
sar    $0x3,%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x30(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x20(%rbp)
mov    %eax,%edx
xor    %esi,%esi
call   1070 <memset@plt>
mov    -0x30(%rbp),%rsi
mov    -0x10(%rbp),%rdi
call   1030 <stringToBinary@plt>
lea    0xe19(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
cmp    %ecx,%eax
jge    1284 <main+0x134>
mov    -0x30(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1060 <printBinary@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1241 <main+0xf1>
lea    0xdbf(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
lea    0xe97(%rip),%rdi
lea    0xe87(%rip),%r14
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0x7(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0xf8,%ecx
sub    %ecx,%eax
add    $0x1,%al
mov    %eax,%ecx
shr    $0x7,%cl
add    %al,%cl
and    $0xfe,%cl
sub    %cl,%al
movsbl %al,%edx
lea    0xe5b(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
test   $0x7,%al
jne    1276 <main+0x116>
lea    0xe23(%rip),%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0x7(%rax),%edx
test   %eax,%eax
cmovns %eax,%edx
mov    %rsp,%r15
sar    $0x3,%edx
lea    0xf(%rdx),%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%r12
sub    %rax,%r12
mov    %r12,%rsp
mov    %r12,%rdi
xor    %esi,%esi
call   1080 <memset@plt>
mov    %r14,%rdi
mov    %r12,%rsi
call   1040 <stringToBinary@plt>
lea    0xe2c(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
cmp    $0x8,%eax
jl     1269 <main+0x109>
xor    %ebx,%ebx
lea    0xdc3(%rip),%r14
nopl   (%rax)
movsbl (%r12,%rbx,1),%edi
call   1070 <printBinary@plt>
add    $0x1,%rbx
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0x7(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
sar    $0x3,%ecx
movslq %ecx,%rax
cmp    %rax,%rbx
jl     1240 <main+0xe0>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r15,%rsp
xor    %eax,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"10110000\00"
@.str.1 = [15 x i8] c"[original] %s\0A\00"
@.str.2 = [52 x i8] c"tamanho do texto original %d, multiplo de 8 ? (%d)\0A\00"
@.str.3 = [13 x i8] c"[resultado] \00"
@.str.4 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
store i32 0, i32* %1
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8** %2
%6 = load i8*, i8** %2
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%8 = load i8*, i8** %2
%9 = call i32 @strlen(i8* %8)
%10 = load i8*, i8** %2
%11 = call i32 @strlen(i8* %10)
%12 = srem i32 %11, 8
%13 = add nsw i32 %12, 1
%14 = srem i32 %13, 2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0), i32 %9, i32 %14)
%16 = load i8*, i8** %2
%17 = call i32 @strlen(i8* %16)
%18 = srem i32 %17, 8
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %0
store i32 0, i32* %1
br label %53
21: ; preds = %0
%22 = load i8*, i8** %2
%23 = call i32 @strlen(i8* %22)
%24 = sdiv i32 %23, 8
%25 = zext i32 %24 to i64
%26 = call i8* @llvm.stacksave()
store i8* %26, i8** %3
%27 = alloca i8, i64 %25
store i64 %25, i64* %4
%28 = getelementptr inbounds i8, i8* %27, i64 0
%29 = trunc i64 %25 to i32
%30 = call i32 @memset(i8* %28, i32 0, i32 %29)
%31 = load i8*, i8** %2
%32 = call i32 @stringToBinary(i8* %31, i8* %27)
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %5
br label %34
34: ; preds = %47, %21
%35 = load i32, i32* %5
%36 = load i8*, i8** %2
%37 = call i32 @strlen(i8* %36)
%38 = sdiv i32 %37, 8
%39 = icmp slt i32 %35, %38
br i1 %39, label %40, label %50
40: ; preds = %34
%41 = load i32, i32* %5
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %27, i64 %42
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = call i32 @printBinary(i32 %45)
br label %47
47: ; preds = %40
%48 = load i32, i32* %5
%49 = add nsw i32 %48, 1
store i32 %49, i32* %5
br label %34
50: ; preds = %34
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %1
%52 = load i8*, i8** %3
br label %53
53: ; preds = %50, %20
%54 = load i32, i32* %1
ret i32 %54
}

LLVM IR (-O2):
@.str = [9 x i8] c"10110000\00"
@.str.1 = [15 x i8] c"[original] %s\0A\00"
@.str.2 = [52 x i8] c"tamanho do texto original %d, multiplo de 8 ? (%d)\0A\00"
@.str.3 = [13 x i8] c"[resultado] \00"
define i32 @main() {
%1 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%2 = tail call i32 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%4 = srem i32 %3, 8
%5 = trunc i32 %4 to i8
%6 = add nsw i8 %5, 1
%7 = srem i8 %6, 2
%8 = sext i8 %7 to i32
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0), i32 %2, i32 %8)
%10 = tail call i32 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%11 = and i32 %10, 7
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %37
13: ; preds = %0
%14 = tail call i32 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%15 = sdiv i32 %14, 8
%16 = zext i32 %15 to i64
%17 = tail call i8* @llvm.stacksave()
%18 = alloca i8, i64 %16
%19 = call i32 @memset(i8* %18, i32 0, i32 %15)
%20 = call i32 @stringToBinary(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %18)
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%22 = call i32 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%23 = icmp sgt i32 %22, 7
br i1 %23, label %26, label %24
24: ; preds = %26, %13
%25 = call i32 @putchar(i32 10)
br label %37
26: ; preds = %13, %26
%27 = phi i64 [ %32, %26 ], [ 0, %13 ]
%28 = getelementptr inbounds i8, i8* %18, i64 %27
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = call i32 @printBinary(i32 %30)
%32 = add nuw nsw i64 %27, 1
%33 = call i32 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%34 = sdiv i32 %33, 8
%35 = sext i32 %34 to i64
%36 = icmp slt i64 %32, %35
br i1 %36, label %26, label %24
37: ; preds = %0, %24
ret i32 0
}