#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) {
  unsigned short i = 0x0002;
  printf("Befor:%u\n", i);
  i = i | 0x10;
  printf("After:%u\n", i);
  int j = 3;
  printf("Befor:%u\n", i);
  i = i | 1 << j;
  printf("After:%u\n", i);
  i = 0x0012;
  printf("Before:%u\n", i);
  i = i & ~0x10;
  printf("After:%u\n", i);
  i = 0x0022;
  printf("Befor:%u\n", i);
  j = 5;
  i = i & ~(1 << j);
  printf("After:%u\n", i);
  i = 0x1010;
  if (i & 0x10) {
    printf("Fourth bit of 0x%x is set.\n", i);
  } else {
    printf("Fourth bit of 0x%x is not set.\n", i);
  }
  j = 3;
  if (i & (1 << j)) {
    printf("Bit number %d of 0x%x is set.\n", j, i);
  } else {
    printf("Bit number %d of 0x%x is not set.\n", j, i);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movw   $0x2,-0x6(%rbp)
movzwl -0x6(%rbp),%esi
lea    0xed0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movzwl -0x6(%rbp),%eax
or     $0x10,%eax
mov    %ax,-0x6(%rbp)
movzwl -0x6(%rbp),%esi
lea    0xebd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x3,-0xc(%rbp)
movzwl -0x6(%rbp),%esi
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movzwl -0x6(%rbp),%eax
mov    -0xc(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
or     %ecx,%eax
mov    %ax,-0x6(%rbp)
movzwl -0x6(%rbp),%esi
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movw   $0x12,-0x6(%rbp)
movzwl -0x6(%rbp),%esi
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movzwl -0x6(%rbp),%eax
and    $0xffffffef,%eax
mov    %ax,-0x6(%rbp)
movzwl -0x6(%rbp),%esi
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movw   $0x22,-0x6(%rbp)
movzwl -0x6(%rbp),%esi
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x5,-0xc(%rbp)
movzwl -0x6(%rbp),%eax
mov    -0xc(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
xor    $0xffffffff,%ecx
and    %ecx,%eax
mov    %ax,-0x6(%rbp)
movzwl -0x6(%rbp),%esi
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movw   $0x1010,-0x6(%rbp)
movzwl -0x6(%rbp),%eax
and    $0x10,%eax
cmp    $0x0,%eax
je     1241 <main+0x131>
movzwl -0x6(%rbp),%esi
lea    0xdea(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1253 <main+0x143>
movzwl -0x6(%rbp),%esi
lea    0xdef(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x3,-0xc(%rbp)
movzwl -0x6(%rbp),%eax
mov    -0xc(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     128f <main+0x17f>
mov    -0xc(%rbp),%esi
movzwl -0x6(%rbp),%edx
lea    0xdd8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12a4 <main+0x194>
mov    -0xc(%rbp),%esi
movzwl -0x6(%rbp),%edx
lea    0xddd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xee5(%rip),%r14
mov    %r14,%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xed9(%rip),%rbx
mov    %rbx,%rdi
mov    $0x12,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r14,%rdi
mov    $0x12,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x1a,%esi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xeaf(%rip),%rdi
mov    $0x12,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r14,%rdi
mov    $0x22,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe7a(%rip),%rdi
mov    $0x1010,%esi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe83(%rip),%rdi
mov    $0x3,%esi
mov    $0x1010,%edx
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [10 x i8] c"Befor:%u\0A\00"
@.str.1 = [10 x i8] c"After:%u\0A\00"
@.str.2 = [11 x i8] c"Before:%u\0A\00"
@.str.3 = [28 x i8] c"Fourth bit of 0x%x is set.\0A\00"
@.str.4 = [32 x i8] c"Fourth bit of 0x%x is not set.\0A\00"
@.str.5 = [31 x i8] c"Bit number %d of 0x%x is set.\0A\00"
@.str.6 = [35 x i8] c"Bit number %d of 0x%x is not set.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i16
%3 = alloca i32
store i32 0, i32* %1
store i16 2, i16* %2
%4 = load i16, i16* %2
%5 = zext i16 %4 to i32
%6 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = load i16, i16* %2
%8 = zext i16 %7 to i32
%9 = or i32 %8, 16
%10 = trunc i32 %9 to i16
store i16 %10, i16* %2
%11 = load i16, i16* %2
%12 = zext i16 %11 to i32
%13 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %12)
store i32 3, i32* %3
%14 = load i16, i16* %2
%15 = zext i16 %14 to i32
%16 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = load i16, i16* %2
%18 = zext i16 %17 to i32
%19 = load i32, i32* %3
%20 = shl i32 1, %19
%21 = or i32 %18, %20
%22 = trunc i32 %21 to i16
store i16 %22, i16* %2
%23 = load i16, i16* %2
%24 = zext i16 %23 to i32
%25 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %24)
store i16 18, i16* %2
%26 = load i16, i16* %2
%27 = zext i16 %26 to i32
%28 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %27)
%29 = load i16, i16* %2
%30 = zext i16 %29 to i32
%31 = and i32 %30, -17
%32 = trunc i32 %31 to i16
store i16 %32, i16* %2
%33 = load i16, i16* %2
%34 = zext i16 %33 to i32
%35 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %34)
store i16 34, i16* %2
%36 = load i16, i16* %2
%37 = zext i16 %36 to i32
%38 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %37)
store i32 5, i32* %3
%39 = load i16, i16* %2
%40 = zext i16 %39 to i32
%41 = load i32, i32* %3
%42 = shl i32 1, %41
%43 = xor i32 %42, -1
%44 = and i32 %40, %43
%45 = trunc i32 %44 to i16
store i16 %45, i16* %2
%46 = load i16, i16* %2
%47 = zext i16 %46 to i32
%48 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %47)
store i16 4112, i16* %2
%49 = load i16, i16* %2
%50 = zext i16 %49 to i32
%51 = and i32 %50, 16
%52 = icmp ne i32 %51, 0
br i1 %52, label %53, label %57
53: ; preds = %0
%54 = load i16, i16* %2
%55 = zext i16 %54 to i32
%56 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i32 %55)
br label %61
57: ; preds = %0
%58 = load i16, i16* %2
%59 = zext i16 %58 to i32
%60 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i32 %59)
br label %61
61: ; preds = %57, %53
store i32 3, i32* %3
%62 = load i16, i16* %2
%63 = zext i16 %62 to i32
%64 = load i32, i32* %3
%65 = shl i32 1, %64
%66 = and i32 %63, %65
%67 = icmp ne i32 %66, 0
br i1 %67, label %68, label %73
68: ; preds = %61
%69 = load i32, i32* %3
%70 = load i16, i16* %2
%71 = zext i16 %70 to i32
%72 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0), i32 %69, i32 %71)
br label %78
73: ; preds = %61
%74 = load i32, i32* %3
%75 = load i16, i16* %2
%76 = zext i16 %75 to i32
%77 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.6, i64 0, i64 0), i32 %74, i32 %76)
br label %78
78: ; preds = %73, %68
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"Befor:%u\0A\00"
@.str.1 = [10 x i8] c"After:%u\0A\00"
@.str.2 = [11 x i8] c"Before:%u\0A\00"
@.str.3 = [28 x i8] c"Fourth bit of 0x%x is set.\0A\00"
@.str.6 = [35 x i8] c"Bit number %d of 0x%x is not set.\0A\00"
define i32 @main() {
%1 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 2)
%2 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 18)
%3 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 18)
%4 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 26)
%5 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 18)
%6 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 2)
%7 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 34)
%8 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 2)
%9 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i32 4112)
%10 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.6, i64 0, i64 0), i32 3, i32 4112)
ret i32 0
}