#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 */
unsigned char convertBinToByte(char *);
char *convertByteToBin(unsigned char);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *, char *, int);
scalar_t__ strlen(char *);
char treatBits(char, char);
unsigned char *insertMessage(unsigned char *data, char *msg) {
  int i = 0, j = 0, cpt = 0, msgLength = 0;
  char c;
  char *byte = NULL, *curPixel = NULL;
  msgLength = (int)strlen(msg);
  printf("INFO: Insert message '%s' (%d)\n", msg, msgLength);
  for (i = 0; i < msgLength; i++) {
    c = msg[i];
    byte = convertByteToBin(c);
    for (j = 0; j < 8; j++) {
      curPixel = convertByteToBin(data[cpt]);
      curPixel[7] = treatBits(byte[j], curPixel[7]);
      data[cpt] = convertBinToByte(curPixel);
      cpt++;
    }
  }
  free(byte);
  free(curPixel);
  return (data);
}


x86 assembly (clang, -O0):
<insertMessage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%edx
lea    0xe4a(%rip),%rdi
call   1060 <printf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    1273 <insertMessage+0x113>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x21(%rbp)
movzbl -0x21(%rbp),%edi
call   1080 <convertByteToBin@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x8,-0x18(%rbp)
jge    1260 <insertMessage+0x100>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movzbl (%rax,%rcx,1),%edi
call   1080 <convertByteToBin@plt>
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
mov    -0x38(%rbp),%rax
movsbl %cl,%edi
movsbl 0x7(%rax),%esi
call   1040 <treatBits@plt>
mov    %al,%cl
mov    -0x38(%rbp),%rax
mov    %cl,0x7(%rax)
mov    -0x38(%rbp),%rdi
call   1070 <convertBinToByte@plt>
mov    %al,%dl
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11f0 <insertMessage+0x90>
jmp    1265 <insertMessage+0x105>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11c2 <insertMessage+0x62>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<insertMessage>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r12
mov    %rsi,%rdi
call   1050 <strlen@plt>
mov    %rax,%rbx
lea    0xe7d(%rip),%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1060 <printf@plt>
test   %ebx,%ebx
jle    1321 <insertMessage+0x1c1>
mov    %ebx,%eax
mov    %rax,(%rsp)
xor    %ebp,%ebp
xor    %r13d,%r13d
movzbl (%r14,%rbp,1),%edi
call   1080 <convertByteToBin@plt>
mov    %rax,%r15
movslq %r13d,%r13
movzbl (%r12,%r13,1),%edi
call   1080 <convertByteToBin@plt>
mov    %rax,%rbx
movsbl (%r15),%edi
movsbl 0x7(%rax),%esi
call   1040 <treatBits@plt>
mov    %al,0x7(%rbx)
mov    %rbx,%rdi
call   1070 <convertBinToByte@plt>
mov    %al,(%r12,%r13,1)
movzbl 0x1(%r12,%r13,1),%edi
call   1080 <convertByteToBin@plt>
mov    %rax,%rbx
movsbl 0x1(%r15),%edi
movsbl 0x7(%rax),%esi
call   1040 <treatBits@plt>
mov    %al,0x7(%rbx)
mov    %rbx,%rdi
call   1070 <convertBinToByte@plt>
mov    %al,0x1(%r12,%r13,1)
movzbl 0x2(%r12,%r13,1),%edi
call   1080 <convertByteToBin@plt>
mov    %rax,%rbx
movsbl 0x2(%r15),%edi
movsbl 0x7(%rax),%esi
call   1040 <treatBits@plt>
mov    %al,0x7(%rbx)
mov    %rbx,%rdi
call   1070 <convertBinToByte@plt>
mov    %al,0x2(%r12,%r13,1)
movzbl 0x3(%r12,%r13,1),%edi
call   1080 <convertByteToBin@plt>
mov    %rax,%rbx
movsbl 0x3(%r15),%edi
movsbl 0x7(%rax),%esi
call   1040 <treatBits@plt>
mov    %al,0x7(%rbx)
mov    %rbx,%rdi
call   1070 <convertBinToByte@plt>
mov    %al,0x3(%r12,%r13,1)
movzbl 0x4(%r12,%r13,1),%edi
call   1080 <convertByteToBin@plt>
mov    %rax,%rbx
movsbl 0x4(%r15),%edi
movsbl 0x7(%rax),%esi
call   1040 <treatBits@plt>
mov    %al,0x7(%rbx)
mov    %rbx,%rdi
call   1070 <convertBinToByte@plt>
mov    %al,0x4(%r12,%r13,1)
movzbl 0x5(%r12,%r13,1),%edi
call   1080 <convertByteToBin@plt>
mov    %rax,%rbx
movsbl 0x5(%r15),%edi
movsbl 0x7(%rax),%esi
call   1040 <treatBits@plt>
mov    %al,0x7(%rbx)
mov    %rbx,%rdi
call   1070 <convertBinToByte@plt>
mov    %al,0x5(%r12,%r13,1)
movzbl 0x6(%r12,%r13,1),%edi
call   1080 <convertByteToBin@plt>
mov    %rax,%rbx
movsbl 0x6(%r15),%edi
movsbl 0x7(%rax),%esi
call   1040 <treatBits@plt>
mov    %al,0x7(%rbx)
mov    %rbx,%rdi
call   1070 <convertBinToByte@plt>
mov    %al,0x6(%r12,%r13,1)
movzbl 0x7(%r12,%r13,1),%edi
call   1080 <convertByteToBin@plt>
mov    %rax,%rbx
movsbl 0x7(%r15),%edi
movsbl 0x7(%rax),%esi
call   1040 <treatBits@plt>
mov    %al,0x7(%rbx)
mov    %rbx,%rdi
call   1070 <convertBinToByte@plt>
mov    %al,0x7(%r12,%r13,1)
add    $0x8,%r13
add    $0x1,%rbp
cmp    %rbp,(%rsp)
jne    11a0 <insertMessage+0x40>
jmp    1326 <insertMessage+0x1c6>
xor    %r15d,%r15d
xor    %ebx,%ebx
mov    %r15,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [32 x i8] c"INFO: Insert message '%s' (%d)\0A\00"
define i8* @insertMessage(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8
%10 = alloca i8*
%11 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
store i8* null, i8** %10
store i8* null, i8** %11
%12 = load i8*, i8** %4
%13 = call i64 @strlen(i8* %12)
%14 = trunc i64 %13 to i32
store i32 %14, i32* %8
%15 = load i8*, i8** %4
%16 = load i32, i32* %8
%17 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %15, i32 %16)
store i32 0, i32* %5
br label %18
18: ; preds = %63, %2
%19 = load i32, i32* %5
%20 = load i32, i32* %8
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %66
22: ; preds = %18
%23 = load i8*, i8** %4
%24 = load i32, i32* %5
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = load i8, i8* %26
store i8 %27, i8* %9
%28 = load i8, i8* %9
%29 = call i8* @convertByteToBin(i8 zeroext %28)
store i8* %29, i8** %10
store i32 0, i32* %6
br label %30
30: ; preds = %59, %22
%31 = load i32, i32* %6
%32 = icmp slt i32 %31, 8
br i1 %32, label %33, label %62
33: ; preds = %30
%34 = load i8*, i8** %3
%35 = load i32, i32* %7
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
%38 = load i8, i8* %37
%39 = call i8* @convertByteToBin(i8 zeroext %38)
store i8* %39, i8** %11
%40 = load i8*, i8** %10
%41 = load i32, i32* %6
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %40, i64 %42
%44 = load i8, i8* %43
%45 = load i8*, i8** %11
%46 = getelementptr inbounds i8, i8* %45, i64 7
%47 = load i8, i8* %46
%48 = call signext i8 @treatBits(i8 signext %44, i8 signext %47)
%49 = load i8*, i8** %11
%50 = getelementptr inbounds i8, i8* %49, i64 7
store i8 %48, i8* %50
%51 = load i8*, i8** %11
%52 = call zeroext i8 @convertBinToByte(i8* %51)
%53 = load i8*, i8** %3
%54 = load i32, i32* %7
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8, i8* %53, i64 %55
store i8 %52, i8* %56
%57 = load i32, i32* %7
%58 = add nsw i32 %57, 1
store i32 %58, i32* %7
br label %59
59: ; preds = %33
%60 = load i32, i32* %6
%61 = add nsw i32 %60, 1
store i32 %61, i32* %6
br label %30
62: ; preds = %30
br label %63
63: ; preds = %62
%64 = load i32, i32* %5
%65 = add nsw i32 %64, 1
store i32 %65, i32* %5
br label %18
66: ; preds = %18
%67 = load i8*, i8** %10
%68 = call i32 @free(i8* %67)
%69 = load i8*, i8** %11
%70 = call i32 @free(i8* %69)
%71 = load i8*, i8** %3
ret i8* %71
}

LLVM IR (-O2):
@.str = [32 x i8] c"INFO: Insert message '%s' (%d)\0A\00"
define i8* @insertMessage(i8* returned %0, i8* %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%4 = trunc i64 %3 to i32
%5 = tail call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %1, i32 %4)
%6 = icmp sgt i32 %4, 0
br i1 %6, label %7, label %98
7: ; preds = %2
%8 = and i64 %3, 4294967295
br label %9
9: ; preds = %7, %9
%10 = phi i64 [ 0, %7 ], [ %96, %9 ]
%11 = phi i64 [ 0, %7 ], [ %95, %9 ]
%12 = getelementptr inbounds i8, i8* %1, i64 %10
%13 = load i8, i8* %12
%14 = tail call i8* @convertByteToBin(i8 zeroext %13)
%15 = shl i64 %11, 32
%16 = ashr exact i64 %15, 32
%17 = getelementptr inbounds i8, i8* %0, i64 %16
%18 = load i8, i8* %17
%19 = tail call i8* @convertByteToBin(i8 zeroext %18)
%20 = load i8, i8* %14
%21 = getelementptr inbounds i8, i8* %19, i64 7
%22 = load i8, i8* %21
%23 = tail call signext i8 @treatBits(i8 signext %20, i8 signext %22)
store i8 %23, i8* %21
%24 = tail call zeroext i8 @convertBinToByte(i8* %19)
store i8 %24, i8* %17
%25 = add nsw i64 %16, 1
%26 = getelementptr inbounds i8, i8* %0, i64 %25
%27 = load i8, i8* %26
%28 = tail call i8* @convertByteToBin(i8 zeroext %27)
%29 = getelementptr inbounds i8, i8* %14, i64 1
%30 = load i8, i8* %29
%31 = getelementptr inbounds i8, i8* %28, i64 7
%32 = load i8, i8* %31
%33 = tail call signext i8 @treatBits(i8 signext %30, i8 signext %32)
store i8 %33, i8* %31
%34 = tail call zeroext i8 @convertBinToByte(i8* %28)
store i8 %34, i8* %26
%35 = add nsw i64 %16, 2
%36 = getelementptr inbounds i8, i8* %0, i64 %35
%37 = load i8, i8* %36
%38 = tail call i8* @convertByteToBin(i8 zeroext %37)
%39 = getelementptr inbounds i8, i8* %14, i64 2
%40 = load i8, i8* %39
%41 = getelementptr inbounds i8, i8* %38, i64 7
%42 = load i8, i8* %41
%43 = tail call signext i8 @treatBits(i8 signext %40, i8 signext %42)
store i8 %43, i8* %41
%44 = tail call zeroext i8 @convertBinToByte(i8* %38)
store i8 %44, i8* %36
%45 = add nsw i64 %16, 3
%46 = getelementptr inbounds i8, i8* %0, i64 %45
%47 = load i8, i8* %46
%48 = tail call i8* @convertByteToBin(i8 zeroext %47)
%49 = getelementptr inbounds i8, i8* %14, i64 3
%50 = load i8, i8* %49
%51 = getelementptr inbounds i8, i8* %48, i64 7
%52 = load i8, i8* %51
%53 = tail call signext i8 @treatBits(i8 signext %50, i8 signext %52)
store i8 %53, i8* %51
%54 = tail call zeroext i8 @convertBinToByte(i8* %48)
store i8 %54, i8* %46
%55 = add nsw i64 %16, 4
%56 = getelementptr inbounds i8, i8* %0, i64 %55
%57 = load i8, i8* %56
%58 = tail call i8* @convertByteToBin(i8 zeroext %57)
%59 = getelementptr inbounds i8, i8* %14, i64 4
%60 = load i8, i8* %59
%61 = getelementptr inbounds i8, i8* %58, i64 7
%62 = load i8, i8* %61
%63 = tail call signext i8 @treatBits(i8 signext %60, i8 signext %62)
store i8 %63, i8* %61
%64 = tail call zeroext i8 @convertBinToByte(i8* %58)
store i8 %64, i8* %56
%65 = add nsw i64 %16, 5
%66 = getelementptr inbounds i8, i8* %0, i64 %65
%67 = load i8, i8* %66
%68 = tail call i8* @convertByteToBin(i8 zeroext %67)
%69 = getelementptr inbounds i8, i8* %14, i64 5
%70 = load i8, i8* %69
%71 = getelementptr inbounds i8, i8* %68, i64 7
%72 = load i8, i8* %71
%73 = tail call signext i8 @treatBits(i8 signext %70, i8 signext %72)
store i8 %73, i8* %71
%74 = tail call zeroext i8 @convertBinToByte(i8* %68)
store i8 %74, i8* %66
%75 = add nsw i64 %16, 6
%76 = getelementptr inbounds i8, i8* %0, i64 %75
%77 = load i8, i8* %76
%78 = tail call i8* @convertByteToBin(i8 zeroext %77)
%79 = getelementptr inbounds i8, i8* %14, i64 6
%80 = load i8, i8* %79
%81 = getelementptr inbounds i8, i8* %78, i64 7
%82 = load i8, i8* %81
%83 = tail call signext i8 @treatBits(i8 signext %80, i8 signext %82)
store i8 %83, i8* %81
%84 = tail call zeroext i8 @convertBinToByte(i8* %78)
store i8 %84, i8* %76
%85 = add nsw i64 %16, 7
%86 = getelementptr inbounds i8, i8* %0, i64 %85
%87 = load i8, i8* %86
%88 = tail call i8* @convertByteToBin(i8 zeroext %87)
%89 = getelementptr inbounds i8, i8* %14, i64 7
%90 = load i8, i8* %89
%91 = getelementptr inbounds i8, i8* %88, i64 7
%92 = load i8, i8* %91
%93 = tail call signext i8 @treatBits(i8 signext %90, i8 signext %92)
store i8 %93, i8* %91
%94 = tail call zeroext i8 @convertBinToByte(i8* %88)
store i8 %94, i8* %86
%95 = add nsw i64 %16, 8
%96 = add nuw nsw i64 %10, 1
%97 = icmp eq i64 %96, %8
br i1 %97, label %98, label %9
98: ; preds = %9, %2
%99 = phi i8* [ null, %2 ], [ %14, %9 ]
%100 = phi i8* [ null, %2 ], [ %88, %9 ]
%101 = tail call i32 @free(i8* %99)
%102 = tail call i32 @free(i8* %100)
ret i8* %0
}