#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*/ MaskBit(char, char, char *);
int /*<<< orphan*/ printf(char *);
int EmbedChar(int arrsize, char eb, char *source, char *dest) {
  int idx;
  char pixel;
  char bitshift;
  char buff[9];
  buff[8] = 0;
  bitshift = eb;
  if (source == NULL || dest == NULL) {
    printf("Invalid Data! \n");
    return -1;
  }
  if (arrsize < 8) {
    printf("Array to small!\n");
    return -1;
  }
  for (idx = 0; idx < 8; idx++) {
    pixel = source[idx];
    MaskBit(pixel, bitshift, dest + idx);
    bitshift >>= 1;
    bitshift &= 0x7f;
  }
  return 0;
}


x86 assembly (clang, -O0):
<EmbedChar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %edi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movb   $0x0,-0x27(%rbp)
mov    -0x9(%rbp),%al
mov    %al,-0x26(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1159 <EmbedChar+0x39>
cmpq   $0x0,-0x20(%rbp)
jne    1171 <EmbedChar+0x51>
lea    0xea0(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f7 <EmbedChar+0xd7>
cmpl   $0x8,-0x8(%rbp)
jge    1193 <EmbedChar+0x73>
lea    0xe8e(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f7 <EmbedChar+0xd7>
movl   $0x0,-0x24(%rbp)
cmpl   $0x8,-0x24(%rbp)
jge    11f0 <EmbedChar+0xd0>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%cl
mov    -0x26(%rbp),%al
mov    -0x20(%rbp),%rdx
movslq -0x24(%rbp),%rsi
add    %rsi,%rdx
movsbl %cl,%edi
movsbl %al,%esi
call   1040 <MaskBit@plt>
movsbl -0x26(%rbp),%eax
sar    $0x1,%eax
mov    %al,-0x26(%rbp)
movsbl -0x26(%rbp),%eax
and    $0x7f,%eax
mov    %al,-0x26(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    119a <EmbedChar+0x7a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<EmbedChar>:
push   %rbp
push   %r14
push   %rbx
test   %rdx,%rdx
je     113f <EmbedChar+0x1f>
mov    %rcx,%r14
test   %rcx,%rcx
je     113f <EmbedChar+0x1f>
cmp    $0x8,%edi
jge    1155 <EmbedChar+0x35>
lea    0xec3(%rip),%rdi
jmp    1146 <EmbedChar+0x26>
lea    0xeca(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
jmp    1200 <EmbedChar+0xe0>
mov    %rdx,%rbx
movsbl (%rdx),%edi
movsbl %sil,%ebp
mov    %ebp,%esi
mov    %r14,%rdx
call   1040 <MaskBit@plt>
mov    %ebp,%eax
shr    %al
movsbl 0x1(%rbx),%edi
lea    0x1(%r14),%rdx
movzbl %al,%esi
call   1040 <MaskBit@plt>
mov    %ebp,%eax
shr    $0x2,%al
movsbl 0x2(%rbx),%edi
lea    0x2(%r14),%rdx
movzbl %al,%esi
call   1040 <MaskBit@plt>
mov    %ebp,%eax
shr    $0x3,%al
movsbl 0x3(%rbx),%edi
lea    0x3(%r14),%rdx
movzbl %al,%esi
call   1040 <MaskBit@plt>
mov    %ebp,%eax
shr    $0x4,%al
movsbl 0x4(%rbx),%edi
lea    0x4(%r14),%rdx
movzbl %al,%esi
call   1040 <MaskBit@plt>
mov    %ebp,%eax
shr    $0x5,%al
movsbl 0x5(%rbx),%edi
lea    0x5(%r14),%rdx
movzbl %al,%esi
call   1040 <MaskBit@plt>
mov    %ebp,%eax
shr    $0x6,%al
movsbl 0x6(%rbx),%edi
lea    0x6(%r14),%rdx
movzbl %al,%esi
call   1040 <MaskBit@plt>
shr    $0x7,%bpl
movsbl 0x7(%rbx),%edi
add    $0x7,%r14
movzbl %bpl,%esi
mov    %r14,%rdx
call   1040 <MaskBit@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@str = [16 x i8] c"Array to small!\00"
@str.2 = [15 x i8] c"Invalid Data! \00"
define i32 @EmbedChar(i32 %0, i8 signext %1, i8* %2, i8* %3) {
%5 = icmp eq i8* %2, null
%6 = icmp eq i8* %3, null
%7 = or i1 %5, %6
br i1 %7, label %8, label %10
8: ; preds = %4
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.2, i64 0, i64 0))
br label %52
10: ; preds = %4
%11 = icmp slt i32 %0, 8
br i1 %11, label %50, label %12
12: ; preds = %10
%13 = load i8, i8* %2
%14 = tail call i32 @MaskBit(i8 signext %13, i8 signext %1, i8* %3)
%15 = lshr i8 %1, 1
%16 = getelementptr inbounds i8, i8* %2, i64 1
%17 = load i8, i8* %16
%18 = getelementptr inbounds i8, i8* %3, i64 1
%19 = tail call i32 @MaskBit(i8 signext %17, i8 signext %15, i8* %18)
%20 = lshr i8 %1, 2
%21 = getelementptr inbounds i8, i8* %2, i64 2
%22 = load i8, i8* %21
%23 = getelementptr inbounds i8, i8* %3, i64 2
%24 = tail call i32 @MaskBit(i8 signext %22, i8 signext %20, i8* %23)
%25 = lshr i8 %1, 3
%26 = getelementptr inbounds i8, i8* %2, i64 3
%27 = load i8, i8* %26
%28 = getelementptr inbounds i8, i8* %3, i64 3
%29 = tail call i32 @MaskBit(i8 signext %27, i8 signext %25, i8* %28)
%30 = lshr i8 %1, 4
%31 = getelementptr inbounds i8, i8* %2, i64 4
%32 = load i8, i8* %31
%33 = getelementptr inbounds i8, i8* %3, i64 4
%34 = tail call i32 @MaskBit(i8 signext %32, i8 signext %30, i8* %33)
%35 = lshr i8 %1, 5
%36 = getelementptr inbounds i8, i8* %2, i64 5
%37 = load i8, i8* %36
%38 = getelementptr inbounds i8, i8* %3, i64 5
%39 = tail call i32 @MaskBit(i8 signext %37, i8 signext %35, i8* %38)
%40 = lshr i8 %1, 6
%41 = getelementptr inbounds i8, i8* %2, i64 6
%42 = load i8, i8* %41
%43 = getelementptr inbounds i8, i8* %3, i64 6
%44 = tail call i32 @MaskBit(i8 signext %42, i8 signext %40, i8* %43)
%45 = lshr i8 %1, 7
%46 = getelementptr inbounds i8, i8* %2, i64 7
%47 = load i8, i8* %46
%48 = getelementptr inbounds i8, i8* %3, i64 7
%49 = tail call i32 @MaskBit(i8 signext %47, i8 signext %45, i8* %48)
br label %52
50: ; preds = %10
%51 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
br label %52
52: ; preds = %12, %50, %8
%53 = phi i32 [ -1, %8 ], [ -1, %50 ], [ 0, %12 ]
ret i32 %53
}