#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 embed(char *, int, char *, char **);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *, ...);
void TestEmbedChar(char *image_data, int data_length, char *message,
                   int resultf, char *resultem) {
  char *encoded = NULL;
  int rcembed;
  int idx;
  rcembed = embed(image_data, data_length, message, &encoded);
  if (rcembed != resultf) {
    printf("Test Failed\n");
    if (encoded != NULL) {
      free(encoded);
      encoded = NULL;
    }
    return;
  } else {
    printf("Yay it worked! WoooHoo!!!\n");
  }
  if (image_data != NULL) {
    printf("Compare arrays:\n");
    printf("  encode:    result:");
    for (idx = 0; idx < data_length; idx++) {
      if ((idx % 8) == 0) {
        printf("\n");
      }
      printf("%3d: 0x%02x == 0x%02x (%s)\n", idx, (unsigned char)encoded[idx],
             (unsigned char)resultem[idx],
             ((unsigned char)encoded[idx] == (unsigned char)resultem[idx]
                  ? "true"
                  : "false"));
    }
  }
  printf("\n\n");
  if (encoded != NULL) {
    free(encoded);
    encoded = NULL;
  }
}


x86 assembly (clang, -O0):
<TestEmbedChar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
lea    -0x30(%rbp),%rcx
call   1050 <embed@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x1c(%rbp),%eax
je     11a4 <TestEmbedChar+0x74>
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpq   $0x0,-0x30(%rbp)
je     119f <TestEmbedChar+0x6f>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x30(%rbp)
jmp    12a2 <TestEmbedChar+0x172>
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpq   $0x0,-0x8(%rbp)
je     1278 <TestEmbedChar+0x148>
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1273 <TestEmbedChar+0x143>
mov    -0x38(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    120e <TestEmbedChar+0xde>
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x38(%rbp),%esi
mov    -0x30(%rbp),%rax
movslq -0x38(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
mov    -0x28(%rbp),%rax
movslq -0x38(%rbp),%rcx
movzbl (%rax,%rcx,1),%ecx
mov    -0x30(%rbp),%rax
movslq -0x38(%rbp),%rdi
movzbl (%rax,%rdi,1),%edi
mov    -0x28(%rbp),%rax
movslq -0x38(%rbp),%r8
movzbl (%rax,%r8,1),%r9d
lea    0xe26(%rip),%r8
lea    0xe1a(%rip),%rax
cmp    %r9d,%edi
cmove  %rax,%r8
lea    0xdf0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    11e0 <TestEmbedChar+0xb0>
jmp    1278 <TestEmbedChar+0x148>
lea    0xdf6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpq   $0x0,-0x30(%rbp)
je     12a2 <TestEmbedChar+0x172>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x30(%rbp)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<TestEmbedChar>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r12
mov    %ecx,%r15d
mov    %esi,%r14d
mov    %rdi,%rbp
movq   $0x0,(%rsp)
mov    %rsp,%rcx
call   1070 <embed@plt>
cmp    %r15d,%eax
jne    120d <TestEmbedChar+0xbd>
lea    0xeb5(%rip),%rdi
call   1050 <puts@plt>
test   %rbp,%rbp
je     1216 <TestEmbedChar+0xc6>
lea    0xeba(%rip),%rdi
call   1050 <puts@plt>
lea    0xe58(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
test   %r14d,%r14d
jle    1216 <TestEmbedChar+0xc6>
mov    %r14d,%ebx
lea    0xe73(%rip),%r15
lea    0xe71(%rip),%r13
lea    0xe49(%rip),%r14
xor    %ebp,%ebp
jmp    11fb <TestEmbedChar+0xab>
mov    (%rsp),%rax
movzbl (%rax,%rbp,1),%edx
movzbl (%r12,%rbp,1),%ecx
cmp    %cl,%dl
mov    %r13,%r8
cmove  %r15,%r8
mov    %r14,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
je     1216 <TestEmbedChar+0xc6>
test   $0x7,%bpl
jne    11d0 <TestEmbedChar+0x80>
mov    $0xa,%edi
call   1040 <putchar@plt>
jmp    11d0 <TestEmbedChar+0x80>
lea    0xe52(%rip),%rdi
jmp    121d <TestEmbedChar+0xcd>
lea    0xe12(%rip),%rdi
call   1050 <puts@plt>
mov    (%rsp),%rdi
test   %rdi,%rdi
je     1230 <TestEmbedChar+0xe0>
call   1030 <free@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"Test Failed\0A\00"
@.str.1 = [27 x i8] c"Yay it worked! WoooHoo!!!\0A\00"
@.str.2 = [17 x i8] c"Compare arrays:\0A\00"
@.str.3 = [21 x i8] c" encode: result:\00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [28 x i8] c"%3d: 0x%02x == 0x%02x (%s)\0A\00"
@.str.6 = [5 x i8] c"true\00"
@.str.7 = [6 x i8] c"false\00"
@.str.8 = [3 x i8] c"\0A\0A\00"
define void @TestEmbedChar(i8* %0, i32 %1, i8* %2, i32 %3, i8* %4) {
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
store i8* %4, i8** %10
store i8* null, i8** %11
%14 = load i8*, i8** %6
%15 = load i32, i32* %7
%16 = load i8*, i8** %8
%17 = call i32 @embed(i8* %14, i32 %15, i8* %16, i8** %11)
store i32 %17, i32* %12
%18 = load i32, i32* %12
%19 = load i32, i32* %9
%20 = icmp ne i32 %18, %19
br i1 %20, label %21, label %29
21: ; preds = %5
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%23 = load i8*, i8** %11
%24 = icmp ne i8* %23, null
br i1 %24, label %25, label %28
25: ; preds = %21
%26 = load i8*, i8** %11
%27 = call i32 @free(i8* %26)
store i8* null, i8** %11
br label %28
28: ; preds = %25, %21
br label %88
29: ; preds = %5
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %31
31: ; preds = %29
%32 = load i8*, i8** %6
%33 = icmp ne i8* %32, null
br i1 %33, label %34, label %81
34: ; preds = %31
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %13
br label %37
37: ; preds = %77, %34
%38 = load i32, i32* %13
%39 = load i32, i32* %7
%40 = icmp slt i32 %38, %39
br i1 %40, label %41, label %80
41: ; preds = %37
%42 = load i32, i32* %13
%43 = srem i32 %42, 8
%44 = icmp eq i32 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %41
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %47
47: ; preds = %45, %41
%48 = load i32, i32* %13
%49 = load i8*, i8** %11
%50 = load i32, i32* %13
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %49, i64 %51
%53 = load i8, i8* %52
%54 = zext i8 %53 to i32
%55 = load i8*, i8** %10
%56 = load i32, i32* %13
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8, i8* %55, i64 %57
%59 = load i8, i8* %58
%60 = zext i8 %59 to i32
%61 = load i8*, i8** %11
%62 = load i32, i32* %13
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i8, i8* %61, i64 %63
%65 = load i8, i8* %64
%66 = zext i8 %65 to i32
%67 = load i8*, i8** %10
%68 = load i32, i32* %13
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds i8, i8* %67, i64 %69
%71 = load i8, i8* %70
%72 = zext i8 %71 to i32
%73 = icmp eq i32 %66, %72
%74 = zext i1 %73 to i64
%75 = select i1 %73, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0)
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i32 %48, i32 %54, i32 %60, i8* %75)
br label %77
77: ; preds = %47
%78 = load i32, i32* %13
%79 = add nsw i32 %78, 1
store i32 %79, i32* %13
br label %37
80: ; preds = %37
br label %81
81: ; preds = %80, %31
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
%83 = load i8*, i8** %11
%84 = icmp ne i8* %83, null
br i1 %84, label %85, label %88
85: ; preds = %81
%86 = load i8*, i8** %11
%87 = call i32 @free(i8* %86)
store i8* null, i8** %11
br label %88
88: ; preds = %28, %85, %81
ret void
}

LLVM IR (-O2):
@.str.3 = [21 x i8] c" encode: result:\00"
@.str.5 = [28 x i8] c"%3d: 0x%02x == 0x%02x (%s)\0A\00"
@.str.6 = [5 x i8] c"true\00"
@.str.7 = [6 x i8] c"false\00"
@str = [26 x i8] c"Yay it worked! WoooHoo!!!\00"
@str.9 = [2 x i8] c"\0A\00"
@str.10 = [16 x i8] c"Compare arrays:\00"
@str.11 = [12 x i8] c"Test Failed\00"
define void @TestEmbedChar(i8* %0, i32 %1, i8* %2, i32 %3, i8* nocapture %4) {
%6 = alloca i8*
%7 = bitcast i8** %6 to i8*
store i8* null, i8** %6
%8 = call i32 @embed(i8* %0, i32 %1, i8* %2, i8** %6)
%9 = icmp eq i32 %8, %3
br i1 %9, label %14, label %10
10: ; preds = %5
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.11, i64 0, i64 0))
%12 = load i8*, i8** %6
%13 = icmp eq i8* %12, null
br i1 %13, label %50, label %47
14: ; preds = %5
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
%16 = icmp eq i8* %0, null
br i1 %16, label %43, label %17
17: ; preds = %14
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.10, i64 0, i64 0))
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%20 = icmp sgt i32 %1, 0
br i1 %20, label %21, label %43
21: ; preds = %17
%22 = zext i32 %1 to i64
br label %23
23: ; preds = %21, %30
%24 = phi i64 [ 0, %21 ], [ %41, %30 ]
%25 = trunc i64 %24 to i32
%26 = and i32 %25, 7
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %23
%29 = call i32 @putchar(i32 10)
br label %30
30: ; preds = %28, %23
%31 = load i8*, i8** %6
%32 = getelementptr inbounds i8, i8* %31, i64 %24
%33 = load i8, i8* %32
%34 = zext i8 %33 to i32
%35 = getelementptr inbounds i8, i8* %4, i64 %24
%36 = load i8, i8* %35
%37 = zext i8 %36 to i32
%38 = icmp eq i8 %33, %36
%39 = select i1 %38, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0)
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i32 %25, i32 %34, i32 %37, i8* %39)
%41 = add nuw nsw i64 %24, 1
%42 = icmp eq i64 %41, %22
br i1 %42, label %43, label %23
43: ; preds = %30, %17, %14
%44 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.9, i64 0, i64 0))
%45 = load i8*, i8** %6
%46 = icmp eq i8* %45, null
br i1 %46, label %50, label %47
47: ; preds = %43, %10
%48 = phi i8* [ %12, %10 ], [ %45, %43 ]
%49 = call i32 @free(i8* %48)
br label %50
50: ; preds = %47, %43, %10
ret void
}