#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 *BinString(char, char *, int);
int GetCharFromArray(char *, int const, char *);
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
void TestGetCharFromArrayEx(const char *fname, const int line, char *pixArray,
                            const int sz, const int result, char outChar) {
  char ch = 0, buf[9];
  int idx = 0, rc = 0;
  memset(buf, 0, sizeof(char) * 9);
  rc = GetCharFromArray(pixArray, sz, &ch);
  printf("[%s:%d] Get char from array (0x%p) of size (%d): {\n", fname, line,
         pixArray, sz);
  if (pixArray && sz > 1) {
    for (idx = 0; idx < sz; ++idx) {
      printf("    [%2d]: (0x%02.2x) \"%s\"\n", idx,
             (((int)pixArray[idx]) & 0x000000ff),
             BinString(pixArray[idx], buf, 9));
    }
    printf("} == (0x%02x) %c: ", result, result);
    if (sz >= 8) {
      ch = (char)ch;
      outChar = (char)outChar;
      printf("ch (0x%02x) == outChar (0x%02x) : %s\n", ch, outChar,
             (ch == outChar ? "true" : "false"));
      assert(ch == (char)outChar);
    }
  } else {
    printf("    [Empty or invalid array]\n");
  }
  assert(rc == result);
  printf("[OK]\n\n");
}


x86 assembly (clang, -O0):
<TestGetCharFromArrayEx>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %r9b,%al
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    %al,-0x21(%rbp)
movb   $0x0,-0x22(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
lea    -0x2b(%rbp),%rdi
xor    %esi,%esi
mov    $0x9,%edx
call   1040 <memset@plt>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
lea    -0x22(%rbp),%rdx
call   1070 <GetCharFromArray@plt>
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    -0x1c(%rbp),%r8d
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpq   $0x0,-0x18(%rbp)
je     12bf <TestGetCharFromArrayEx+0x16f>
cmpl   $0x1,-0x1c(%rbp)
jle    12bf <TestGetCharFromArrayEx+0x16f>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1245 <TestGetCharFromArrayEx+0xf5>
mov    -0x30(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x30(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
and    $0xff,%eax
mov    %eax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    (%rax,%rcx,1),%al
lea    -0x2b(%rbp),%rsi
mov    $0x9,%edx
movsbl %al,%edi
call   1060 <BinString@plt>
mov    -0x3c(%rbp),%esi
mov    -0x38(%rbp),%edx
mov    %rax,%rcx
lea    0xe04(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11de <TestGetCharFromArrayEx+0x8e>
mov    -0x20(%rbp),%esi
mov    -0x20(%rbp),%edx
lea    0xdfe(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x8,-0x1c(%rbp)
jl     12ba <TestGetCharFromArrayEx+0x16a>
mov    -0x22(%rbp),%al
mov    %al,-0x22(%rbp)
mov    -0x21(%rbp),%al
mov    %al,-0x21(%rbp)
movsbl -0x22(%rbp),%esi
movsbl -0x21(%rbp),%edx
movsbl -0x22(%rbp),%edi
movsbl -0x21(%rbp),%r8d
lea    0xe07(%rip),%rcx
lea    0xdfb(%rip),%rax
cmp    %r8d,%edi
cmove  %rax,%rcx
lea    0xdc7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsbl -0x22(%rbp),%eax
movsbl -0x21(%rbp),%ecx
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
jmp    12cd <TestGetCharFromArrayEx+0x17d>
lea    0xdce(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x34(%rbp),%eax
cmp    -0x20(%rbp),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
lea    0xdcb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<TestGetCharFromArrayEx>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9d,0x18(%rsp)
mov    %r8d,%r15d
mov    %ecx,%ebx
mov    %rdx,%rbp
mov    %esi,%r14d
mov    %rdi,%r13
movb   $0x0,0xf(%rsp)
lea    0x1f(%rsp),%rdi
xor    %esi,%esi
mov    $0x9,%edx
call   1050 <memset@plt>
lea    0xf(%rsp),%rdx
mov    %rbp,%rdi
mov    %ebx,%esi
call   1080 <GetCharFromArray@plt>
mov    %eax,%r12d
lea    0xe50(%rip),%rdi
mov    %r13,%rsi
mov    %r14d,%edx
mov    %rbp,%rcx
mov    %ebx,%r8d
xor    %eax,%eax
call   1040 <printf@plt>
test   %rbp,%rbp
je     1297 <TestGetCharFromArrayEx+0x137>
cmp    $0x2,%ebx
jl     1297 <TestGetCharFromArrayEx+0x137>
mov    %r12d,0x10(%rsp)
mov    %r15d,0x14(%rsp)
mov    %ebx,%r12d
lea    0x1f(%rsp),%r13
lea    0xe46(%rip),%rbx
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsbl 0x0(%rbp,%r14,1),%edi
movzbl %dil,%r15d
mov    %r13,%rsi
mov    $0x9,%edx
call   1070 <BinString@plt>
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %r15d,%edx
mov    %rax,%rcx
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%r14
cmp    %r14,%r12
jne    1200 <TestGetCharFromArrayEx+0xa0>
lea    0xe16(%rip),%rdi
mov    0x14(%rsp),%r15d
mov    %r15d,%esi
mov    %r15d,%edx
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x8,%r12d
mov    0x10(%rsp),%r12d
jl     12a3 <TestGetCharFromArrayEx+0x143>
movsbl 0xf(%rsp),%esi
movsbl 0x18(%rsp),%ebx
cmp    %bl,%sil
lea    0xe1e(%rip),%rax
lea    0xe1c(%rip),%rcx
cmove  %rax,%rcx
lea    0xde6(%rip),%rdi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
cmp    %bl,0xf(%rsp)
sete   %dil
call   1060 <assert@plt>
jmp    12a3 <TestGetCharFromArrayEx+0x143>
lea    0xdf6(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
cmp    %r15d,%r12d
sete   %dil
call   1060 <assert@plt>
lea    0xdf9(%rip),%rdi
call   1030 <puts@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [52 x i8] c"[%s:%d] Get char from array (0x%p) of size (%d): {\0A\00"
@.str.1 = [28 x i8] c" [%2d]: (0x%02.2x) \22%s\22\0A\00"
@.str.2 = [19 x i8] c"} == (0x%02x) %c: \00"
@.str.3 = [38 x i8] c"ch (0x%02x) == outChar (0x%02x) : %s\0A\00"
@.str.4 = [5 x i8] c"true\00"
@.str.5 = [6 x i8] c"false\00"
@.str.6 = [30 x i8] c" [Empty or invalid array]\0A\00"
@.str.7 = [7 x i8] c"[OK]\0A\0A\00"
define void @TestGetCharFromArrayEx(i8* %0, i32 %1, i8* %2, i32 %3, i32 %4, i8 signext %5) {
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8
%13 = alloca i8
%14 = alloca [9 x i8]
%15 = alloca i32
%16 = alloca i32
store i8* %0, i8** %7
store i32 %1, i32* %8
store i8* %2, i8** %9
store i32 %3, i32* %10
store i32 %4, i32* %11
store i8 %5, i8* %12
store i8 0, i8* %13
store i32 0, i32* %15
store i32 0, i32* %16
%17 = getelementptr inbounds [9 x i8], [9 x i8]* %14, i64 0, i64 0
%18 = call i32 @memset(i8* %17, i32 0, i32 9)
%19 = load i8*, i8** %9
%20 = load i32, i32* %10
%21 = call i32 @GetCharFromArray(i8* %19, i32 %20, i8* %13)
store i32 %21, i32* %16
%22 = load i8*, i8** %7
%23 = load i32, i32* %8
%24 = load i8*, i8** %9
%25 = load i32, i32* %10
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), i8* %22, i32 %23, i8* %24, i32 %25)
%27 = load i8*, i8** %9
%28 = icmp ne i8* %27, null
br i1 %28, label %29, label %86
29: ; preds = %6
%30 = load i32, i32* %10
%31 = icmp sgt i32 %30, 1
br i1 %31, label %32, label %86
32: ; preds = %29
store i32 0, i32* %15
br label %33
33: ; preds = %54, %32
%34 = load i32, i32* %15
%35 = load i32, i32* %10
%36 = icmp slt i32 %34, %35
br i1 %36, label %37, label %57
37: ; preds = %33
%38 = load i32, i32* %15
%39 = load i8*, i8** %9
%40 = load i32, i32* %15
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = and i32 %44, 255
%46 = load i8*, i8** %9
%47 = load i32, i32* %15
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %46, i64 %48
%50 = load i8, i8* %49
%51 = getelementptr inbounds [9 x i8], [9 x i8]* %14, i64 0, i64 0
%52 = call i8* @BinString(i8 signext %50, i8* %51, i32 9)
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %38, i32 %45, i8* %52)
br label %54
54: ; preds = %37
%55 = load i32, i32* %15
%56 = add nsw i32 %55, 1
store i32 %56, i32* %15
br label %33
57: ; preds = %33
%58 = load i32, i32* %11
%59 = load i32, i32* %11
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %58, i32 %59)
%61 = load i32, i32* %10
%62 = icmp sge i32 %61, 8
br i1 %62, label %63, label %85
63: ; preds = %57
%64 = load i8, i8* %13
store i8 %64, i8* %13
%65 = load i8, i8* %12
store i8 %65, i8* %12
%66 = load i8, i8* %13
%67 = sext i8 %66 to i32
%68 = load i8, i8* %12
%69 = sext i8 %68 to i32
%70 = load i8, i8* %13
%71 = sext i8 %70 to i32
%72 = load i8, i8* %12
%73 = sext i8 %72 to i32
%74 = icmp eq i32 %71, %73
%75 = zext i1 %74 to i64
%76 = select i1 %74, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0)
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i32 %67, i32 %69, i8* %76)
%78 = load i8, i8* %13
%79 = sext i8 %78 to i32
%80 = load i8, i8* %12
%81 = sext i8 %80 to i32
%82 = icmp eq i32 %79, %81
%83 = zext i1 %82 to i32
%84 = call i32 @assert(i32 %83)
br label %85
85: ; preds = %63, %57
br label %88
86: ; preds = %29, %6
%87 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0))
br label %88
88: ; preds = %86, %85
%89 = load i32, i32* %16
%90 = load i32, i32* %11
%91 = icmp eq i32 %89, %90
%92 = zext i1 %91 to i32
%93 = call i32 @assert(i32 %92)
%94 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [52 x i8] c"[%s:%d] Get char from array (0x%p) of size (%d): {\0A\00"
@.str.1 = [28 x i8] c" [%2d]: (0x%02.2x) \22%s\22\0A\00"
@.str.2 = [19 x i8] c"} == (0x%02x) %c: \00"
@.str.3 = [38 x i8] c"ch (0x%02x) == outChar (0x%02x) : %s\0A\00"
@.str.4 = [5 x i8] c"true\00"
@.str.5 = [6 x i8] c"false\00"
@str = [29 x i8] c" [Empty or invalid array]\00"
@str.8 = [6 x i8] c"[OK]\0A\00"
define void @TestGetCharFromArrayEx(i8* %0, i32 %1, i8* %2, i32 %3, i32 %4, i8 signext %5) {
%7 = alloca i8
%8 = alloca [9 x i8]
store i8 0, i8* %7
%9 = getelementptr inbounds [9 x i8], [9 x i8]* %8, i64 0, i64 0
%10 = call i32 @memset(i8* %9, i32 0, i32 9)
%11 = call i32 @GetCharFromArray(i8* %2, i32 %3, i8* %7)
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %1, i8* %2, i32 %3)
%13 = icmp ne i8* %2, null
%14 = icmp sgt i32 %3, 1
%15 = and i1 %13, %14
br i1 %15, label %16, label %42
16: ; preds = %6
%17 = zext i32 %3 to i64
br label %18
18: ; preds = %16, %18
%19 = phi i64 [ 0, %16 ], [ %26, %18 ]
%20 = getelementptr inbounds i8, i8* %2, i64 %19
%21 = load i8, i8* %20
%22 = zext i8 %21 to i32
%23 = call i8* @BinString(i8 signext %21, i8* %9, i32 9)
%24 = trunc i64 %19 to i32
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %24, i32 %22, i8* %23)
%26 = add nuw nsw i64 %19, 1
%27 = icmp eq i64 %26, %17
br i1 %27, label %28, label %18
28: ; preds = %18
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %4, i32 %4)
%30 = icmp sgt i32 %3, 7
br i1 %30, label %31, label %44
31: ; preds = %28
%32 = load i8, i8* %7
%33 = sext i8 %32 to i32
%34 = sext i8 %5 to i32
%35 = icmp eq i8 %32, %5
%36 = select i1 %35, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0)
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i32 %33, i32 %34, i8* %36)
%38 = load i8, i8* %7
%39 = icmp eq i8 %38, %5
%40 = zext i1 %39 to i32
%41 = call i32 @assert(i32 %40)
br label %44
42: ; preds = %6
%43 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
br label %44
44: ; preds = %28, %31, %42
%45 = icmp eq i32 %11, %4
%46 = zext i1 %45 to i32
%47 = call i32 @assert(i32 %46)
%48 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str.8, i64 0, i64 0))
ret void
}