int apply_binary_operation_on_byte(int tbit, int kbit, int operation) {
  if (operation == 0x00) {
    return ((tbit == '1') || (kbit == '1')) ? '1' : '0';
  } else if (operation == 0x01) {
    return ((tbit == '1') && (kbit == '1')) ? '1' : '0';
  } else if (operation == 0x02) {
    return (((tbit == '0') && (kbit == '1')) ||
            ((tbit == '1') && (kbit == '0')))
               ? '1'
               : '0';
  }
  return '?';
}


x86 assembly (clang, -O0):
<apply_binary_operation_on_byte>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    114b <apply_binary_operation_on_byte+0x4b>
mov    $0x1,%al
cmpl   $0x31,-0x8(%rbp)
mov    %al,-0x11(%rbp)
je     1130 <apply_binary_operation_on_byte+0x30>
cmpl   $0x31,-0xc(%rbp)
sete   %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%dl
mov    $0x30,%eax
mov    $0x31,%ecx
test   $0x1,%dl
cmovne %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    11f7 <apply_binary_operation_on_byte+0xf7>
cmpl   $0x1,-0x10(%rbp)
jne    1189 <apply_binary_operation_on_byte+0x89>
xor    %eax,%eax
cmpl   $0x31,-0x8(%rbp)
mov    %al,-0x12(%rbp)
jne    116e <apply_binary_operation_on_byte+0x6e>
cmpl   $0x31,-0xc(%rbp)
sete   %al
mov    %al,-0x12(%rbp)
mov    -0x12(%rbp),%dl
mov    $0x30,%eax
mov    $0x31,%ecx
test   $0x1,%dl
cmovne %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    11f7 <apply_binary_operation_on_byte+0xf7>
cmpl   $0x2,-0x10(%rbp)
jne    11e6 <apply_binary_operation_on_byte+0xe6>
cmpl   $0x30,-0x8(%rbp)
jne    11ac <apply_binary_operation_on_byte+0xac>
mov    $0x1,%al
cmpl   $0x31,-0xc(%rbp)
mov    %al,-0x13(%rbp)
je     11cb <apply_binary_operation_on_byte+0xcb>
xor    %eax,%eax
cmpl   $0x31,-0x8(%rbp)
mov    %al,-0x14(%rbp)
jne    11c5 <apply_binary_operation_on_byte+0xc5>
cmpl   $0x30,-0xc(%rbp)
sete   %al
mov    %al,-0x14(%rbp)
mov    -0x14(%rbp),%al
mov    %al,-0x13(%rbp)
mov    -0x13(%rbp),%dl
mov    $0x30,%eax
mov    $0x31,%ecx
test   $0x1,%dl
cmovne %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    11f7 <apply_binary_operation_on_byte+0xf7>
jmp    11eb <apply_binary_operation_on_byte+0xeb>
jmp    11f0 <apply_binary_operation_on_byte+0xf0>
movl   $0x3f,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<apply_binary_operation_on_byte>:
cmp    $0x2,%edx
je     111e <apply_binary_operation_on_byte+0x1e>
cmp    $0x1,%edx
je     113f <apply_binary_operation_on_byte+0x3f>
mov    $0x3f,%eax
test   %edx,%edx
jne    114f <apply_binary_operation_on_byte+0x4f>
cmp    $0x31,%edi
sete   %al
cmp    $0x31,%esi
jmp    1135 <apply_binary_operation_on_byte+0x35>
mov    %edi,%eax
xor    $0x30,%eax
mov    %esi,%ecx
xor    $0x31,%ecx
or     %eax,%ecx
sete   %al
xor    $0x31,%edi
xor    $0x30,%esi
or     %edi,%esi
sete   %cl
or     %al,%cl
movzbl %cl,%eax
jmp    114c <apply_binary_operation_on_byte+0x4c>
xor    $0x31,%edi
xor    $0x31,%esi
xor    %eax,%eax
or     %edi,%esi
sete   %al
or     $0x30,%eax
ret

LLVM IR (-O0):
define i32 @apply_binary_operation_on_byte(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%8 = load i32, i32* %7
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %20
10: ; preds = %3
%11 = load i32, i32* %5
%12 = icmp eq i32 %11, 49
br i1 %12, label %16, label %13
13: ; preds = %10
%14 = load i32, i32* %6
%15 = icmp eq i32 %14, 49
br label %16
16: ; preds = %13, %10
%17 = phi i1 [ true, %10 ], [ %15, %13 ]
%18 = zext i1 %17 to i64
%19 = select i1 %17, i32 49, i32 48
store i32 %19, i32* %4
br label %57
20: ; preds = %3
%21 = load i32, i32* %7
%22 = icmp eq i32 %21, 1
br i1 %22, label %23, label %33
23: ; preds = %20
%24 = load i32, i32* %5
%25 = icmp eq i32 %24, 49
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = load i32, i32* %6
%28 = icmp eq i32 %27, 49
br label %29
29: ; preds = %26, %23
%30 = phi i1 [ false, %23 ], [ %28, %26 ]
%31 = zext i1 %30 to i64
%32 = select i1 %30, i32 49, i32 48
store i32 %32, i32* %4
br label %57
33: ; preds = %20
%34 = load i32, i32* %7
%35 = icmp eq i32 %34, 2
br i1 %35, label %36, label %54
36: ; preds = %33
%37 = load i32, i32* %5
%38 = icmp eq i32 %37, 48
br i1 %38, label %39, label %42
39: ; preds = %36
%40 = load i32, i32* %6
%41 = icmp eq i32 %40, 49
br i1 %41, label %50, label %42
42: ; preds = %39, %36
%43 = load i32, i32* %5
%44 = icmp eq i32 %43, 49
br i1 %44, label %45, label %48
45: ; preds = %42
%46 = load i32, i32* %6
%47 = icmp eq i32 %46, 48
br label %48
48: ; preds = %45, %42
%49 = phi i1 [ false, %42 ], [ %47, %45 ]
br label %50
50: ; preds = %48, %39
%51 = phi i1 [ true, %39 ], [ %49, %48 ]
%52 = zext i1 %51 to i64
%53 = select i1 %51, i32 49, i32 48
store i32 %53, i32* %4
br label %57
54: ; preds = %33
br label %55
55: ; preds = %54
br label %56
56: ; preds = %55
store i32 63, i32* %4
br label %57
57: ; preds = %56, %50, %29, %16
%58 = load i32, i32* %4
ret i32 %58
}

LLVM IR (-O2):
define i32 @apply_binary_operation_on_byte(i32 %0, i32 %1, i32 %2) {
switch i32 %2, label %23 [
i32 0, label %4
i32 1, label %9
i32 2, label %14
]
4: ; preds = %3
%5 = icmp eq i32 %0, 49
%6 = icmp eq i32 %1, 49
%7 = or i1 %5, %6
%8 = select i1 %7, i32 49, i32 48
br label %23
9: ; preds = %3
%10 = icmp eq i32 %0, 49
%11 = icmp eq i32 %1, 49
%12 = and i1 %10, %11
%13 = select i1 %12, i32 49, i32 48
br label %23
14: ; preds = %3
%15 = icmp eq i32 %0, 48
%16 = icmp eq i32 %1, 49
%17 = and i1 %15, %16
%18 = icmp eq i32 %0, 49
%19 = icmp eq i32 %1, 48
%20 = and i1 %18, %19
%21 = or i1 %17, %20
%22 = select i1 %21, i32 49, i32 48
br label %23
23: ; preds = %3, %14, %9, %4
%24 = phi i32 [ %8, %4 ], [ %13, %9 ], [ %22, %14 ], [ 63, %3 ]
ret i32 %24
}