#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);
scalar_t__ MaskBit(char, char, char *);
scalar_t__ isprint(unsigned char);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
void TestMaskBit(char Pixel, char Bit, char result) {
  char c;
  char buf[9];
  memset(buf, 0, 9 * sizeof(char));
  printf("Test: Pixel [0x%02x '%c' %s] mixed with ", (unsigned char)Pixel,
         (unsigned char)(isprint((unsigned char)Pixel) ? Pixel : '.'),
         BinString(Pixel, buf, 8));
  printf("Bit [0x%02x '%c' %s] == ", (unsigned char)Bit,
         (unsigned char)(isprint((unsigned char)Bit) ? Bit : '.'),
         BinString(Bit, buf, 8));
  printf("[0x%02x '%c' %s] == ", (unsigned char)result,
         (unsigned char)(isprint((unsigned char)result) ? result : '.'),
         BinString(result, buf, 8));
  if (MaskBit(Pixel, Bit, &c) != 0) {
    printf("Function Failed!!\n");
    return;
  }
  if (c == result) {
    printf("OK!\n");
  } else
    printf("Failed\n");
}


x86 assembly (clang, -O0):
<TestMaskBit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %dl,%al
mov    %sil,%cl
mov    %dil,%dl
mov    %dl,-0x1(%rbp)
mov    %cl,-0x2(%rbp)
mov    %al,-0x3(%rbp)
lea    -0xd(%rbp),%rdi
xor    %esi,%esi
mov    $0x9,%edx
call   1040 <memset@plt>
movzbl -0x1(%rbp),%eax
mov    %eax,-0x14(%rbp)
movzbl -0x1(%rbp),%edi
call   1070 <isprint@plt>
cmp    $0x0,%rax
je     119f <TestMaskBit+0x4f>
movsbl -0x1(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    11ac <TestMaskBit+0x5c>
mov    $0x2e,%eax
mov    %eax,-0x18(%rbp)
jmp    11ac <TestMaskBit+0x5c>
mov    -0x18(%rbp),%eax
movzbl %al,%eax
mov    %eax,-0x20(%rbp)
mov    -0x1(%rbp),%al
lea    -0xd(%rbp),%rsi
mov    $0x8,%edx
movsbl %al,%edi
call   1050 <BinString@plt>
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    %rax,%rcx
lea    0xe27(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movzbl -0x2(%rbp),%eax
mov    %eax,-0x1c(%rbp)
movzbl -0x2(%rbp),%edi
call   1070 <isprint@plt>
cmp    $0x0,%rax
je     1206 <TestMaskBit+0xb6>
movsbl -0x2(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    1213 <TestMaskBit+0xc3>
mov    $0x2e,%eax
mov    %eax,-0x24(%rbp)
jmp    1213 <TestMaskBit+0xc3>
mov    -0x24(%rbp),%eax
movzbl %al,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2(%rbp),%al
lea    -0xd(%rbp),%rsi
mov    $0x8,%edx
movsbl %al,%edi
call   1050 <BinString@plt>
mov    -0x1c(%rbp),%esi
mov    -0x2c(%rbp),%edx
mov    %rax,%rcx
lea    0xde9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movzbl -0x3(%rbp),%eax
mov    %eax,-0x28(%rbp)
movzbl -0x3(%rbp),%edi
call   1070 <isprint@plt>
cmp    $0x0,%rax
je     126d <TestMaskBit+0x11d>
movsbl -0x3(%rbp),%eax
mov    %eax,-0x30(%rbp)
jmp    127a <TestMaskBit+0x12a>
mov    $0x2e,%eax
mov    %eax,-0x30(%rbp)
jmp    127a <TestMaskBit+0x12a>
mov    -0x30(%rbp),%eax
movzbl %al,%eax
mov    %eax,-0x34(%rbp)
mov    -0x3(%rbp),%al
lea    -0xd(%rbp),%rsi
mov    $0x8,%edx
movsbl %al,%edi
call   1050 <BinString@plt>
mov    -0x28(%rbp),%esi
mov    -0x34(%rbp),%edx
mov    %rax,%rcx
lea    0xd86(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1(%rbp),%al
lea    -0x4(%rbp),%rdx
movsbl %al,%edi
movsbl -0x2(%rbp),%esi
call   1060 <MaskBit@plt>
cmp    $0x0,%rax
je     12de <TestMaskBit+0x18e>
lea    0xd70(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    130f <TestMaskBit+0x1bf>
movsbl -0x4(%rbp),%eax
movsbl -0x3(%rbp),%ecx
cmp    %ecx,%eax
jne    1301 <TestMaskBit+0x1b1>
lea    0xd60(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    130f <TestMaskBit+0x1bf>
lea    0xd52(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<TestMaskBit>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,0x8(%rsp)
mov    %esi,%r12d
mov    %edi,%r13d
lea    0xf(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x9,%edx
call   1050 <memset@plt>
movzbl %r13b,%r15d
mov    %r15d,%edi
call   1080 <isprint@plt>
test   %rax,%rax
mov    $0x2e,%r14d
mov    %r15d,%ebp
cmove  %r14d,%ebp
mov    %r13d,%edi
mov    %rbx,%rsi
mov    $0x8,%edx
call   1060 <BinString@plt>
lea    0xe41(%rip),%rdi
mov    %r15d,%esi
mov    %ebp,%edx
mov    %rax,%rcx
xor    %eax,%eax
call   1040 <printf@plt>
movzbl %r12b,%ebx
mov    %ebx,%edi
call   1080 <isprint@plt>
test   %rax,%rax
mov    %ebx,%ebp
cmove  %r14d,%ebp
mov    %r12d,%edi
lea    0xf(%rsp),%r15
mov    %r15,%rsi
mov    $0x8,%edx
call   1060 <BinString@plt>
lea    0xe2b(%rip),%rdi
mov    %ebx,%esi
mov    %ebp,%edx
mov    %rax,%rcx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rsp),%ebx
movzbl %bl,%ebp
mov    %ebp,%edi
call   1080 <isprint@plt>
test   %rax,%rax
cmovne %ebp,%r14d
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x8,%edx
call   1060 <BinString@plt>
lea    0xdf6(%rip),%rdi
mov    %ebp,%esi
mov    %r14d,%edx
mov    %rax,%rcx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x7(%rsp),%rdx
mov    %r13d,%edi
mov    %r12d,%esi
call   1070 <MaskBit@plt>
cmp    %bpl,0x7(%rsp)
lea    0xde7(%rip),%rcx
lea    0xdd9(%rip),%rdx
cmove  %rcx,%rdx
test   %rax,%rax
lea    0xdd6(%rip),%rdi
cmove  %rdx,%rdi
call   1030 <puts@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [41 x i8] c"Test: Pixel [0x%02x '%c' %s] mixed with \00"
@.str.1 = [25 x i8] c"Bit [0x%02x '%c' %s] == \00"
@.str.2 = [21 x i8] c"[0x%02x '%c' %s] == \00"
@.str.3 = [19 x i8] c"Function Failed!!\0A\00"
@.str.4 = [5 x i8] c"OK!\0A\00"
@.str.5 = [8 x i8] c"Failed\0A\00"
define void @TestMaskBit(i8 signext %0, i8 signext %1, i8 signext %2) {
%4 = alloca i8
%5 = alloca i8
%6 = alloca i8
%7 = alloca i8
%8 = alloca [9 x i8]
store i8 %0, i8* %4
store i8 %1, i8* %5
store i8 %2, i8* %6
%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 = load i8, i8* %4
%12 = zext i8 %11 to i32
%13 = load i8, i8* %4
%14 = call i64 @isprint(i8 zeroext %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %3
%17 = load i8, i8* %4
%18 = sext i8 %17 to i32
br label %20
19: ; preds = %3
br label %20
20: ; preds = %19, %16
%21 = phi i32 [ %18, %16 ], [ 46, %19 ]
%22 = trunc i32 %21 to i8
%23 = zext i8 %22 to i32
%24 = load i8, i8* %4
%25 = getelementptr inbounds [9 x i8], [9 x i8]* %8, i64 0, i64 0
%26 = call i8* @BinString(i8 signext %24, i8* %25, i32 8)
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %12, i32 %23, i8* %26)
%28 = load i8, i8* %5
%29 = zext i8 %28 to i32
%30 = load i8, i8* %5
%31 = call i64 @isprint(i8 zeroext %30)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %20
%34 = load i8, i8* %5
%35 = sext i8 %34 to i32
br label %37
36: ; preds = %20
br label %37
37: ; preds = %36, %33
%38 = phi i32 [ %35, %33 ], [ 46, %36 ]
%39 = trunc i32 %38 to i8
%40 = zext i8 %39 to i32
%41 = load i8, i8* %5
%42 = getelementptr inbounds [9 x i8], [9 x i8]* %8, i64 0, i64 0
%43 = call i8* @BinString(i8 signext %41, i8* %42, i32 8)
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %29, i32 %40, i8* %43)
%45 = load i8, i8* %6
%46 = zext i8 %45 to i32
%47 = load i8, i8* %6
%48 = call i64 @isprint(i8 zeroext %47)
%49 = icmp ne i64 %48, 0
br i1 %49, label %50, label %53
50: ; preds = %37
%51 = load i8, i8* %6
%52 = sext i8 %51 to i32
br label %54
53: ; preds = %37
br label %54
54: ; preds = %53, %50
%55 = phi i32 [ %52, %50 ], [ 46, %53 ]
%56 = trunc i32 %55 to i8
%57 = zext i8 %56 to i32
%58 = load i8, i8* %6
%59 = getelementptr inbounds [9 x i8], [9 x i8]* %8, i64 0, i64 0
%60 = call i8* @BinString(i8 signext %58, i8* %59, i32 8)
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %46, i32 %57, i8* %60)
%62 = load i8, i8* %4
%63 = load i8, i8* %5
%64 = call i64 @MaskBit(i8 signext %62, i8 signext %63, i8* %7)
%65 = icmp ne i64 %64, 0
br i1 %65, label %66, label %68
66: ; preds = %54
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
br label %78
68: ; preds = %54
%69 = load i8, i8* %7
%70 = sext i8 %69 to i32
%71 = load i8, i8* %6
%72 = sext i8 %71 to i32
%73 = icmp eq i32 %70, %72
br i1 %73, label %74, label %76
74: ; preds = %68
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %78
76: ; preds = %68
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
br label %78
78: ; preds = %66, %76, %74
ret void
}

LLVM IR (-O2):
@.str = [41 x i8] c"Test: Pixel [0x%02x '%c' %s] mixed with \00"
@.str.1 = [25 x i8] c"Bit [0x%02x '%c' %s] == \00"
@.str.2 = [21 x i8] c"[0x%02x '%c' %s] == \00"
@str = [7 x i8] c"Failed\00"
@str.6 = [4 x i8] c"OK!\00"
@str.7 = [18 x i8] c"Function Failed!!\00"
define void @TestMaskBit(i8 signext %0, i8 signext %1, i8 signext %2) {
%4 = alloca i8
%5 = alloca [9 x i8]
%6 = getelementptr inbounds [9 x i8], [9 x i8]* %5, i64 0, i64 0
%7 = call i32 @memset(i8* %6, i32 0, i32 9)
%8 = zext i8 %0 to i32
%9 = call i64 @isprint(i8 zeroext %0)
%10 = icmp eq i64 %9, 0
%11 = select i1 %10, i32 46, i32 %8
%12 = call i8* @BinString(i8 signext %0, i8* %6, i32 8)
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %8, i32 %11, i8* %12)
%14 = zext i8 %1 to i32
%15 = call i64 @isprint(i8 zeroext %1)
%16 = icmp eq i64 %15, 0
%17 = select i1 %16, i32 46, i32 %14
%18 = call i8* @BinString(i8 signext %1, i8* %6, i32 8)
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %14, i32 %17, i8* %18)
%20 = zext i8 %2 to i32
%21 = call i64 @isprint(i8 zeroext %2)
%22 = icmp eq i64 %21, 0
%23 = select i1 %22, i32 46, i32 %20
%24 = call i8* @BinString(i8 signext %2, i8* %6, i32 8)
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %20, i32 %23, i8* %24)
%26 = call i64 @MaskBit(i8 signext %0, i8 signext %1, i8* %4)
%27 = icmp eq i64 %26, 0
%28 = load i8, i8* %4
%29 = icmp eq i8 %28, %2
%30 = select i1 %29, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @str.6, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0)
%31 = select i1 %27, i8* %30, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @str.7, i64 0, i64 0)
%32 = call i32 @puts(i8* dereferenceable(1) %31)
ret void
}