#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 */
char convertBinToByte(char *);
char *convertByteToBin(unsigned char);
int /*<<< orphan*/ free(char *);
char *malloc(int);
char *extractMessage(unsigned char *data, int length) {
  int i = 0, j = 0, cpt = 0;
  char *tmp = NULL, *result = malloc((8) * sizeof(char)),
       *msg = malloc((length + 1) * sizeof(char));
  for (i = 0; i < length; i++) {
    for (j = 0; j < 8; j++) {
      tmp = convertByteToBin(data[cpt]);
      result[j] = tmp[7];
      cpt++;
    }
    msg[i] = convertBinToByte(result);
  }
  msg[length + 1] = '\0';
  free(tmp);
  free(result);
  return (msg);
}


x86 assembly (clang, -O0):
<extractMessage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    $0x8,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1217 <extractMessage+0xd7>
movl   $0x0,-0x14(%rbp)
cmpl   $0x8,-0x14(%rbp)
jge    11f3 <extractMessage+0xb3>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%edi
call   1060 <convertByteToBin@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    0x7(%rax),%dl
mov    -0x28(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11ab <extractMessage+0x6b>
mov    -0x28(%rbp),%rdi
call   1040 <convertBinToByte@plt>
mov    %al,%dl
mov    -0x30(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1198 <extractMessage+0x58>
mov    -0x30(%rbp),%rax
mov    -0xc(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extractMessage>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %esi,%r14d
mov    %rdi,%r12
mov    $0x8,%edi
call   1050 <malloc@plt>
mov    %rax,%r13
movslq %r14d,%rbx
lea    0x1(%rbx),%rbp
mov    %ebp,%edi
call   1050 <malloc@plt>
test   %ebx,%ebx
jle    125a <extractMessage+0x11a>
mov    %rbp,0x8(%rsp)
mov    %r14d,%ecx
mov    %rcx,0x10(%rsp)
xor    %r15d,%r15d
xor    %r14d,%r14d
nopw   0x0(%rax,%rax,1)
movslq %r14d,%r14
movzbl (%r12,%r14,1),%edi
mov    %rax,%rbp
call   1060 <convertByteToBin@plt>
movzbl 0x7(%rax),%eax
mov    %al,0x0(%r13)
movzbl 0x1(%r12,%r14,1),%edi
call   1060 <convertByteToBin@plt>
movzbl 0x7(%rax),%eax
mov    %al,0x1(%r13)
movzbl 0x2(%r12,%r14,1),%edi
call   1060 <convertByteToBin@plt>
movzbl 0x7(%rax),%eax
mov    %al,0x2(%r13)
movzbl 0x3(%r12,%r14,1),%edi
call   1060 <convertByteToBin@plt>
movzbl 0x7(%rax),%eax
mov    %al,0x3(%r13)
movzbl 0x4(%r12,%r14,1),%edi
call   1060 <convertByteToBin@plt>
movzbl 0x7(%rax),%eax
mov    %al,0x4(%r13)
movzbl 0x5(%r12,%r14,1),%edi
call   1060 <convertByteToBin@plt>
movzbl 0x7(%rax),%eax
mov    %al,0x5(%r13)
movzbl 0x6(%r12,%r14,1),%edi
call   1060 <convertByteToBin@plt>
movzbl 0x7(%rax),%eax
mov    %al,0x6(%r13)
movzbl 0x7(%r12,%r14,1),%edi
call   1060 <convertByteToBin@plt>
mov    %rax,%rbx
movzbl 0x7(%rax),%eax
mov    %al,0x7(%r13)
add    $0x8,%r14
mov    %r13,%rdi
call   1040 <convertBinToByte@plt>
mov    %al,0x0(%rbp,%r15,1)
mov    %rbp,%rax
add    $0x1,%r15
cmp    %r15,0x10(%rsp)
jne    1190 <extractMessage+0x50>
mov    0x8(%rsp),%rbp
jmp    125c <extractMessage+0x11c>
xor    %ebx,%ebx
movb   $0x0,(%rax,%rbp,1)
mov    %rbx,%rdi
mov    %rax,%rbx
call   1030 <free@plt>
mov    %r13,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @extractMessage(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
store i8* null, i8** %8
%11 = call i8* @malloc(i32 8)
store i8* %11, i8** %9
%12 = load i32, i32* %4
%13 = add nsw i32 %12, 1
%14 = sext i32 %13 to i64
%15 = mul i64 %14, 1
%16 = trunc i64 %15 to i32
%17 = call i8* @malloc(i32 %16)
store i8* %17, i8** %10
store i32 0, i32* %5
br label %18
18: ; preds = %52, %2
%19 = load i32, i32* %5
%20 = load i32, i32* %4
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %55
22: ; preds = %18
store i32 0, i32* %6
br label %23
23: ; preds = %42, %22
%24 = load i32, i32* %6
%25 = icmp slt i32 %24, 8
br i1 %25, label %26, label %45
26: ; preds = %23
%27 = load i8*, i8** %3
%28 = load i32, i32* %7
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i8, i8* %30
%32 = call i8* @convertByteToBin(i8 zeroext %31)
store i8* %32, i8** %8
%33 = load i8*, i8** %8
%34 = getelementptr inbounds i8, i8* %33, i64 7
%35 = load i8, i8* %34
%36 = load i8*, i8** %9
%37 = load i32, i32* %6
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %36, i64 %38
store i8 %35, i8* %39
%40 = load i32, i32* %7
%41 = add nsw i32 %40, 1
store i32 %41, i32* %7
br label %42
42: ; preds = %26
%43 = load i32, i32* %6
%44 = add nsw i32 %43, 1
store i32 %44, i32* %6
br label %23
45: ; preds = %23
%46 = load i8*, i8** %9
%47 = call signext i8 @convertBinToByte(i8* %46)
%48 = load i8*, i8** %10
%49 = load i32, i32* %5
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %48, i64 %50
store i8 %47, i8* %51
br label %52
52: ; preds = %45
%53 = load i32, i32* %5
%54 = add nsw i32 %53, 1
store i32 %54, i32* %5
br label %18
55: ; preds = %18
%56 = load i8*, i8** %10
%57 = load i32, i32* %4
%58 = add nsw i32 %57, 1
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8, i8* %56, i64 %59
store i8 0, i8* %60
%61 = load i8*, i8** %8
%62 = call i32 @free(i8* %61)
%63 = load i8*, i8** %9
%64 = call i32 @free(i8* %63)
%65 = load i8*, i8** %10
ret i8* %65
}

LLVM IR (-O2):
define noalias i8* @extractMessage(i8* nocapture %0, i32 %1) {
%3 = tail call dereferenceable_or_null(8) i8* @malloc(i32 8)
%4 = add nsw i32 %1, 1
%5 = tail call i8* @malloc(i32 %4)
%6 = icmp sgt i32 %1, 0
br i1 %6, label %7, label %73
7: ; preds = %2
%8 = zext i32 %1 to i64
%9 = getelementptr inbounds i8, i8* %3, i64 1
%10 = getelementptr inbounds i8, i8* %3, i64 2
%11 = getelementptr inbounds i8, i8* %3, i64 3
%12 = getelementptr inbounds i8, i8* %3, i64 4
%13 = getelementptr inbounds i8, i8* %3, i64 5
%14 = getelementptr inbounds i8, i8* %3, i64 6
%15 = getelementptr inbounds i8, i8* %3, i64 7
br label %16
16: ; preds = %7, %16
%17 = phi i64 [ 0, %7 ], [ %71, %16 ]
%18 = phi i64 [ 0, %7 ], [ %68, %16 ]
%19 = shl i64 %18, 32
%20 = ashr exact i64 %19, 32
%21 = getelementptr inbounds i8, i8* %0, i64 %20
%22 = load i8, i8* %21
%23 = tail call i8* @convertByteToBin(i8 zeroext %22)
%24 = getelementptr inbounds i8, i8* %23, i64 7
%25 = load i8, i8* %24
store i8 %25, i8* %3
%26 = add nsw i64 %20, 1
%27 = getelementptr inbounds i8, i8* %0, i64 %26
%28 = load i8, i8* %27
%29 = tail call i8* @convertByteToBin(i8 zeroext %28)
%30 = getelementptr inbounds i8, i8* %29, i64 7
%31 = load i8, i8* %30
store i8 %31, i8* %9
%32 = add nsw i64 %20, 2
%33 = getelementptr inbounds i8, i8* %0, i64 %32
%34 = load i8, i8* %33
%35 = tail call i8* @convertByteToBin(i8 zeroext %34)
%36 = getelementptr inbounds i8, i8* %35, i64 7
%37 = load i8, i8* %36
store i8 %37, i8* %10
%38 = add nsw i64 %20, 3
%39 = getelementptr inbounds i8, i8* %0, i64 %38
%40 = load i8, i8* %39
%41 = tail call i8* @convertByteToBin(i8 zeroext %40)
%42 = getelementptr inbounds i8, i8* %41, i64 7
%43 = load i8, i8* %42
store i8 %43, i8* %11
%44 = add nsw i64 %20, 4
%45 = getelementptr inbounds i8, i8* %0, i64 %44
%46 = load i8, i8* %45
%47 = tail call i8* @convertByteToBin(i8 zeroext %46)
%48 = getelementptr inbounds i8, i8* %47, i64 7
%49 = load i8, i8* %48
store i8 %49, i8* %12
%50 = add nsw i64 %20, 5
%51 = getelementptr inbounds i8, i8* %0, i64 %50
%52 = load i8, i8* %51
%53 = tail call i8* @convertByteToBin(i8 zeroext %52)
%54 = getelementptr inbounds i8, i8* %53, i64 7
%55 = load i8, i8* %54
store i8 %55, i8* %13
%56 = add nsw i64 %20, 6
%57 = getelementptr inbounds i8, i8* %0, i64 %56
%58 = load i8, i8* %57
%59 = tail call i8* @convertByteToBin(i8 zeroext %58)
%60 = getelementptr inbounds i8, i8* %59, i64 7
%61 = load i8, i8* %60
store i8 %61, i8* %14
%62 = add nsw i64 %20, 7
%63 = getelementptr inbounds i8, i8* %0, i64 %62
%64 = load i8, i8* %63
%65 = tail call i8* @convertByteToBin(i8 zeroext %64)
%66 = getelementptr inbounds i8, i8* %65, i64 7
%67 = load i8, i8* %66
store i8 %67, i8* %15
%68 = add nsw i64 %20, 8
%69 = tail call signext i8 @convertBinToByte(i8* %3)
%70 = getelementptr inbounds i8, i8* %5, i64 %17
store i8 %69, i8* %70
%71 = add nuw nsw i64 %17, 1
%72 = icmp eq i64 %71, %8
br i1 %72, label %73, label %16
73: ; preds = %16, %2
%74 = phi i8* [ null, %2 ], [ %65, %16 ]
%75 = sext i32 %4 to i64
%76 = getelementptr inbounds i8, i8* %5, i64 %75
store i8 0, i8* %76
%77 = tail call i32 @free(i8* %74)
%78 = tail call i32 @free(i8* %3)
ret i8* %5
}