#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 /*<<< orphan*/ printf(char *, int);
int main(void) {
  int posicao = 6;
  int valor = 0;
  valor |= 1 << posicao;
  printf("Ligou o bit: %d\n", valor);
  int resultado = (valor >> posicao) & 1;
  printf("O bit está: %d\n", resultado);
  valor &= ~(1 << posicao);
  printf("Desligou o bit: %d\n", valor);
  resultado = (valor >> posicao) & 1;
  printf("O bit está: %d\n", resultado);
  valor ^= 1 << posicao;
  printf("Inverteu o bit: %d\n", valor);
  valor |= 16;
  printf("Ligou o 4. bit: %d\n", valor);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x6,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x4(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xec0(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
mov    -0x4(%rbp),%ecx
sar    %cl,%eax
and    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xeb4(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
xor    $0xffffffff,%eax
and    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xea3(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
mov    -0x4(%rbp),%ecx
sar    %cl,%eax
and    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe75(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
xor    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe7b(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
or     $0x10,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe77(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xee8(%rip),%rdi
mov    $0x40,%esi
call   1030 <printf@plt>
lea    0xee8(%rip),%rbx
mov    %rbx,%rdi
mov    $0x1,%esi
call   1030 <printf@plt>
lea    0xee5(%rip),%rdi
xor    %esi,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <printf@plt>
lea    0xee1(%rip),%rdi
mov    $0x40,%esi
call   1030 <printf@plt>
lea    0xee4(%rip),%rdi
mov    $0x50,%esi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [17 x i8] c"Ligou o bit: %d\0A\00"
@.str.1 = [17 x i8] c"O bit est\C3\A1: %d\0A\00"
@.str.2 = [20 x i8] c"Desligou o bit: %d\0A\00"
@.str.3 = [20 x i8] c"Inverteu o bit: %d\0A\00"
@.str.4 = [20 x i8] c"Ligou o 4. bit: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 6, i32* %1
store i32 0, i32* %2
%4 = load i32, i32* %1
%5 = shl i32 1, %4
%6 = load i32, i32* %2
%7 = or i32 %6, %5
store i32 %7, i32* %2
%8 = load i32, i32* %2
%9 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = load i32, i32* %2
%11 = load i32, i32* %1
%12 = ashr i32 %10, %11
%13 = and i32 %12, 1
store i32 %13, i32* %3
%14 = load i32, i32* %3
%15 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = load i32, i32* %1
%17 = shl i32 1, %16
%18 = xor i32 %17, -1
%19 = load i32, i32* %2
%20 = and i32 %19, %18
store i32 %20, i32* %2
%21 = load i32, i32* %2
%22 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %21)
%23 = load i32, i32* %2
%24 = load i32, i32* %1
%25 = ashr i32 %23, %24
%26 = and i32 %25, 1
store i32 %26, i32* %3
%27 = load i32, i32* %3
%28 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %27)
%29 = load i32, i32* %1
%30 = shl i32 1, %29
%31 = load i32, i32* %2
%32 = xor i32 %31, %30
store i32 %32, i32* %2
%33 = load i32, i32* %2
%34 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %33)
%35 = load i32, i32* %2
%36 = or i32 %35, 16
store i32 %36, i32* %2
%37 = load i32, i32* %2
%38 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i32 %37)
ret i32 0
}

LLVM IR (-O2):
@.str = [17 x i8] c"Ligou o bit: %d\0A\00"
@.str.1 = [17 x i8] c"O bit est\C3\A1: %d\0A\00"
@.str.2 = [20 x i8] c"Desligou o bit: %d\0A\00"
@.str.3 = [20 x i8] c"Inverteu o bit: %d\0A\00"
@.str.4 = [20 x i8] c"Ligou o 4. bit: %d\0A\00"
define i32 @main() {
%1 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 64)
%2 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 1)
%3 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 0)
%4 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 0)
%5 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 64)
%6 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i32 80)
ret i32 0
}