#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 */
typedef int /*<<< orphan*/ input_val;

/* Variables and functions */
int /*<<< orphan*/ print_bits(unsigned char);
int /*<<< orphan*/ printf(char *, ...);
unsigned char update_bit(unsigned char, unsigned char);
int main(void) {
  unsigned char input_val[] = {
      0x00,
      0xff,
      (1 << 4) | (1 << (4 + 1)) | (1 << (4 - 1)),
      (1 << (4 + 1)) | (1 << (4 - 1)),
  };
  unsigned char bit_val[] = {0, 1};
  for (int i = 0; i < (sizeof(input_val) / sizeof(unsigned char)); i++) {
    for (int j = 0; j < 2; j++) {
      unsigned char result = update_bit(input_val[i], bit_val[j]);
      printf("When input is 0x%02x, and bit_val is %d, the result is ",
             input_val[i], bit_val[j]);
      print_bits(result);
      printf("%s", "\n");
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xebb(%rip),%eax
mov    %eax,-0x8(%rbp)
mov    0xeb5(%rip),%ax
mov    %ax,-0xa(%rbp)
movl   $0x0,-0x10(%rbp)
movslq -0x10(%rbp),%rax
cmp    $0x4,%rax
jae    11f4 <main+0xc4>
movl   $0x0,-0x14(%rbp)
cmpl   $0x2,-0x14(%rbp)
jge    11e1 <main+0xb1>
movslq -0x10(%rbp),%rax
mov    -0x8(%rbp,%rax,1),%cl
movslq -0x14(%rbp),%rax
movzbl %cl,%edi
movzbl -0xa(%rbp,%rax,1),%esi
call   1050 <update_bit@plt>
mov    %al,-0x15(%rbp)
movslq -0x10(%rbp),%rax
movzbl -0x8(%rbp,%rax,1),%esi
movslq -0x14(%rbp),%rax
movzbl -0xa(%rbp,%rax,1),%edx
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movzbl -0x15(%rbp),%edi
call   1040 <print_bits@plt>
lea    0xe79(%rip),%rdi
lea    0xe75(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    116f <main+0x3f>
jmp    11e6 <main+0xb6>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    115a <main+0x2a>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
xor    %edi,%edi
xor    %esi,%esi
call   1060 <update_bit@plt>
mov    %eax,%ebx
lea    0xeaa(%rip),%r14
mov    %r14,%rdi
xor    %esi,%esi
xor    %edx,%edx
xor    %eax,%eax
call   1040 <printf@plt>
movzbl %bl,%edi
call   1050 <print_bits@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %edi,%edi
mov    $0x1,%esi
call   1060 <update_bit@plt>
mov    %eax,%ebx
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x1,%edx
xor    %eax,%eax
call   1040 <printf@plt>
movzbl %bl,%edi
call   1050 <print_bits@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0xff,%edi
xor    %esi,%esi
call   1060 <update_bit@plt>
mov    %eax,%ebx
mov    %r14,%rdi
mov    $0xff,%esi
xor    %edx,%edx
xor    %eax,%eax
call   1040 <printf@plt>
movzbl %bl,%edi
call   1050 <print_bits@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0xff,%edi
mov    $0x1,%esi
call   1060 <update_bit@plt>
mov    %eax,%ebx
mov    %r14,%rdi
mov    $0xff,%esi
mov    $0x1,%edx
xor    %eax,%eax
call   1040 <printf@plt>
movzbl %bl,%edi
call   1050 <print_bits@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0x38,%edi
xor    %esi,%esi
call   1060 <update_bit@plt>
mov    %eax,%ebx
mov    %r14,%rdi
mov    $0x38,%esi
xor    %edx,%edx
xor    %eax,%eax
call   1040 <printf@plt>
movzbl %bl,%edi
call   1050 <print_bits@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0x38,%edi
mov    $0x1,%esi
call   1060 <update_bit@plt>
mov    %eax,%ebx
mov    %r14,%rdi
mov    $0x38,%esi
mov    $0x1,%edx
xor    %eax,%eax
call   1040 <printf@plt>
movzbl %bl,%edi
call   1050 <print_bits@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0x28,%edi
xor    %esi,%esi
call   1060 <update_bit@plt>
mov    %eax,%ebx
mov    %r14,%rdi
mov    $0x28,%esi
xor    %edx,%edx
xor    %eax,%eax
call   1040 <printf@plt>
movzbl %bl,%edi
call   1050 <print_bits@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0x28,%edi
mov    $0x1,%esi
call   1060 <update_bit@plt>
mov    %eax,%ebx
mov    %r14,%rdi
mov    $0x28,%esi
mov    $0x1,%edx
xor    %eax,%eax
call   1040 <printf@plt>
movzbl %bl,%edi
call   1050 <print_bits@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.input_val = [4 x i8] c"\00\FF8("
@__const.main.bit_val = [2 x i8] c"\00\01"
@.str = [56 x i8] c"When input is 0x%02x, and bit_val is %d, the result is \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [4 x i8]
%3 = alloca [2 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8
store i32 0, i32* %1
%7 = bitcast [4 x i8]* %2 to i8*
%8 = bitcast [2 x i8]* %3 to i8*
store i32 0, i32* %4
br label %9
9: ; preds = %45, %0
%10 = load i32, i32* %4
%11 = sext i32 %10 to i64
%12 = icmp ult i64 %11, 4
br i1 %12, label %13, label %48
13: ; preds = %9
store i32 0, i32* %5
br label %14
14: ; preds = %41, %13
%15 = load i32, i32* %5
%16 = icmp slt i32 %15, 2
br i1 %16, label %17, label %44
17: ; preds = %14
%18 = load i32, i32* %4
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 %19
%21 = load i8, i8* %20
%22 = load i32, i32* %5
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 %23
%25 = load i8, i8* %24
%26 = call zeroext i8 @update_bit(i8 zeroext %21, i8 zeroext %25)
store i8 %26, i8* %6
%27 = load i32, i32* %4
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 %28
%30 = load i8, i8* %29
%31 = zext i8 %30 to i32
%32 = load i32, i32* %5
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 %33
%35 = load i8, i8* %34
%36 = zext i8 %35 to i32
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), i32 %31, i32 %36)
%38 = load i8, i8* %6
%39 = call i32 @print_bits(i8 zeroext %38)
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %41
41: ; preds = %17
%42 = load i32, i32* %5
%43 = add nsw i32 %42, 1
store i32 %43, i32* %5
br label %14
44: ; preds = %14
br label %45
45: ; preds = %44
%46 = load i32, i32* %4
%47 = add nsw i32 %46, 1
store i32 %47, i32* %4
br label %9
48: ; preds = %9
ret i32 0
}

LLVM IR (-O2):
@.str = [56 x i8] c"When input is 0x%02x, and bit_val is %d, the result is \00"
define i32 @main() {
%1 = tail call zeroext i8 @update_bit(i8 zeroext 0, i8 zeroext 0)
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), i32 0, i32 0)
%3 = tail call i32 @print_bits(i8 zeroext %1)
%4 = tail call i32 @putchar(i32 10)
%5 = tail call zeroext i8 @update_bit(i8 zeroext 0, i8 zeroext 1)
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), i32 0, i32 1)
%7 = tail call i32 @print_bits(i8 zeroext %5)
%8 = tail call i32 @putchar(i32 10)
%9 = tail call zeroext i8 @update_bit(i8 zeroext -1, i8 zeroext 0)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), i32 255, i32 0)
%11 = tail call i32 @print_bits(i8 zeroext %9)
%12 = tail call i32 @putchar(i32 10)
%13 = tail call zeroext i8 @update_bit(i8 zeroext -1, i8 zeroext 1)
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), i32 255, i32 1)
%15 = tail call i32 @print_bits(i8 zeroext %13)
%16 = tail call i32 @putchar(i32 10)
%17 = tail call zeroext i8 @update_bit(i8 zeroext 56, i8 zeroext 0)
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), i32 56, i32 0)
%19 = tail call i32 @print_bits(i8 zeroext %17)
%20 = tail call i32 @putchar(i32 10)
%21 = tail call zeroext i8 @update_bit(i8 zeroext 56, i8 zeroext 1)
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), i32 56, i32 1)
%23 = tail call i32 @print_bits(i8 zeroext %21)
%24 = tail call i32 @putchar(i32 10)
%25 = tail call zeroext i8 @update_bit(i8 zeroext 40, i8 zeroext 0)
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), i32 40, i32 0)
%27 = tail call i32 @print_bits(i8 zeroext %25)
%28 = tail call i32 @putchar(i32 10)
%29 = tail call zeroext i8 @update_bit(i8 zeroext 40, i8 zeroext 1)
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), i32 40, i32 1)
%31 = tail call i32 @print_bits(i8 zeroext %29)
%32 = tail call i32 @putchar(i32 10)
ret i32 0
}