#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 main(void) {
  unsigned char a = 0x33;
  unsigned char b = 0x0F;
  unsigned char AandB = 0x03;
  unsigned char AorB = 0x3F;
  unsigned char AxorB = 0x3C;
  unsigned char notA = 0xCC;
  unsigned char notB = 0xF0;
  if ((unsigned char)(a & b) != AandB)
    printf("AND Fail!\n");
  if ((unsigned char)(a | b) != AorB)
    printf("OR Fail!\n");
  if ((unsigned char)(a ^ b) != AxorB)
    printf("XOR Fail!\n");
  if ((unsigned char)(~a) != notA)
    printf("NOT A Fail!\n");
  if ((unsigned char)(~b) != notB)
    printf("NOT B Fail!\n");
  unsigned char allOn = 0xFF;
  if ((unsigned char)(allOn << 1) != 0xFE)
    printf("<< Fail!");
  if ((unsigned char)(allOn >> 4) != 0x0F)
    printf(">> Fail!");
  unsigned char tmp = 0xFF;
  tmp <<= 1;
  tmp = tmp << -1;
  int outsmartCompiler = -1;
  tmp = tmp << outsmartCompiler;
  int intA = 123;
  intA = intA << 32;
  tmp = tmp << 8;
  signed int allOnSigned = -1;
  printf("Bitshift right on a signed type keeps the most left bit...\n");
  if ((allOnSigned >> 1) == -1)
    printf("...set to one.\n");
  else if ((allOnSigned >> 1) == 0x7F)
    printf("...set to zero.\n");
  else
    printf("huh?\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movb   $0x33,-0x5(%rbp)
movb   $0xf,-0x6(%rbp)
movb   $0x3,-0x7(%rbp)
movb   $0x3f,-0x8(%rbp)
movb   $0x3c,-0x9(%rbp)
movb   $0xcc,-0xa(%rbp)
movb   $0xf0,-0xb(%rbp)
movzbl -0x5(%rbp),%eax
movzbl -0x6(%rbp),%ecx
and    %ecx,%eax
movzbl %al,%eax
movzbl -0x7(%rbp),%ecx
cmp    %ecx,%eax
je     1160 <main+0x50>
lea    0xea5(%rip),%rdi
call   1030 <printf@plt>
movzbl -0x5(%rbp),%eax
movzbl -0x6(%rbp),%ecx
or     %ecx,%eax
movzbl %al,%eax
movzbl -0x8(%rbp),%ecx
cmp    %ecx,%eax
je     1185 <main+0x75>
lea    0xe8c(%rip),%rdi
call   1030 <printf@plt>
movzbl -0x5(%rbp),%eax
movzbl -0x6(%rbp),%ecx
xor    %ecx,%eax
movzbl %al,%eax
movzbl -0x9(%rbp),%ecx
cmp    %ecx,%eax
je     11aa <main+0x9a>
lea    0xe66(%rip),%rdi
call   1030 <printf@plt>
movzbl -0x5(%rbp),%eax
xor    $0xffffffff,%eax
movzbl %al,%eax
movzbl -0xa(%rbp),%ecx
cmp    %ecx,%eax
je     11cc <main+0xbc>
lea    0xe4f(%rip),%rdi
call   1030 <printf@plt>
movzbl -0x6(%rbp),%eax
xor    $0xffffffff,%eax
movzbl %al,%eax
movzbl -0xb(%rbp),%ecx
cmp    %ecx,%eax
je     11ee <main+0xde>
lea    0xe3a(%rip),%rdi
call   1030 <printf@plt>
movb   $0xff,-0xc(%rbp)
movzbl -0xc(%rbp),%eax
shl    $0x1,%eax
movzbl %al,%eax
cmp    $0xfe,%eax
je     1213 <main+0x103>
lea    0xe22(%rip),%rdi
call   1030 <printf@plt>
movzbl -0xc(%rbp),%eax
sar    $0x4,%eax
movzbl %al,%eax
cmp    $0xf,%eax
je     1232 <main+0x122>
lea    0xe0c(%rip),%rdi
call   1030 <printf@plt>
movb   $0xff,-0xd(%rbp)
movzbl -0xd(%rbp),%eax
shl    $0x1,%eax
mov    %al,-0xd(%rbp)
movzbl -0xd(%rbp),%eax
mov    $0xffffffff,%ecx
shl    %cl,%eax
mov    %al,-0xd(%rbp)
movl   $0xffffffff,-0x14(%rbp)
movzbl -0xd(%rbp),%eax
mov    -0x14(%rbp),%ecx
shl    %cl,%eax
mov    %al,-0xd(%rbp)
movl   $0x7b,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    $0x20,%ecx
shl    %cl,%eax
mov    %eax,-0x18(%rbp)
movzbl -0xd(%rbp),%eax
shl    $0x8,%eax
mov    %al,-0xd(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
lea    0xdb5(%rip),%rdi
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
sar    $0x1,%eax
cmp    $0xffffffff,%eax
jne    12b2 <main+0x1a2>
lea    0xdd6(%rip),%rdi
call   1030 <printf@plt>
jmp    12e3 <main+0x1d3>
mov    -0x1c(%rbp),%eax
sar    $0x1,%eax
cmp    $0x7f,%eax
jne    12d2 <main+0x1c2>
lea    0xdc6(%rip),%rdi
call   1030 <printf@plt>
jmp    12de <main+0x1ce>
lea    0xdc6(%rip),%rdi
call   1030 <printf@plt>
jmp    12e3 <main+0x1d3>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xee8(%rip),%rdi
call   1030 <puts@plt>
lea    0xf17(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [11 x i8] c"AND Fail!\0A\00"
@.str.1 = [10 x i8] c"OR Fail!\0A\00"
@.str.2 = [11 x i8] c"XOR Fail!\0A\00"
@.str.3 = [13 x i8] c"NOT A Fail!\0A\00"
@.str.4 = [13 x i8] c"NOT B Fail!\0A\00"
@.str.5 = [9 x i8] c"<< Fail!\00"
@.str.6 = [9 x i8] c">> Fail!\00"
@.str.7 = [60 x i8] c"Bitshift right on a signed type keeps the most left bit...\0A\00"
@.str.8 = [16 x i8] c"...set to one.\0A\00"
@.str.9 = [17 x i8] c"...set to zero.\0A\00"
@.str.10 = [6 x i8] c"huh?\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca i8
%4 = alloca i8
%5 = alloca i8
%6 = alloca i8
%7 = alloca i8
%8 = alloca i8
%9 = alloca i8
%10 = alloca i8
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %1
store i8 51, i8* %2
store i8 15, i8* %3
store i8 3, i8* %4
store i8 63, i8* %5
store i8 60, i8* %6
store i8 -52, i8* %7
store i8 -16, i8* %8
%14 = load i8, i8* %2
%15 = zext i8 %14 to i32
%16 = load i8, i8* %3
%17 = zext i8 %16 to i32
%18 = and i32 %15, %17
%19 = trunc i32 %18 to i8
%20 = zext i8 %19 to i32
%21 = load i8, i8* %4
%22 = zext i8 %21 to i32
%23 = icmp ne i32 %20, %22
br i1 %23, label %24, label %26
24: ; preds = %0
%25 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %26
26: ; preds = %24, %0
%27 = load i8, i8* %2
%28 = zext i8 %27 to i32
%29 = load i8, i8* %3
%30 = zext i8 %29 to i32
%31 = or i32 %28, %30
%32 = trunc i32 %31 to i8
%33 = zext i8 %32 to i32
%34 = load i8, i8* %5
%35 = zext i8 %34 to i32
%36 = icmp ne i32 %33, %35
br i1 %36, label %37, label %39
37: ; preds = %26
%38 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
br label %39
39: ; preds = %37, %26
%40 = load i8, i8* %2
%41 = zext i8 %40 to i32
%42 = load i8, i8* %3
%43 = zext i8 %42 to i32
%44 = xor i32 %41, %43
%45 = trunc i32 %44 to i8
%46 = zext i8 %45 to i32
%47 = load i8, i8* %6
%48 = zext i8 %47 to i32
%49 = icmp ne i32 %46, %48
br i1 %49, label %50, label %52
50: ; preds = %39
%51 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %52
52: ; preds = %50, %39
%53 = load i8, i8* %2
%54 = zext i8 %53 to i32
%55 = xor i32 %54, -1
%56 = trunc i32 %55 to i8
%57 = zext i8 %56 to i32
%58 = load i8, i8* %7
%59 = zext i8 %58 to i32
%60 = icmp ne i32 %57, %59
br i1 %60, label %61, label %63
61: ; preds = %52
%62 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br label %63
63: ; preds = %61, %52
%64 = load i8, i8* %3
%65 = zext i8 %64 to i32
%66 = xor i32 %65, -1
%67 = trunc i32 %66 to i8
%68 = zext i8 %67 to i32
%69 = load i8, i8* %8
%70 = zext i8 %69 to i32
%71 = icmp ne i32 %68, %70
br i1 %71, label %72, label %74
72: ; preds = %63
%73 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
br label %74
74: ; preds = %72, %63
store i8 -1, i8* %9
%75 = load i8, i8* %9
%76 = zext i8 %75 to i32
%77 = shl i32 %76, 1
%78 = trunc i32 %77 to i8
%79 = zext i8 %78 to i32
%80 = icmp ne i32 %79, 254
br i1 %80, label %81, label %83
81: ; preds = %74
%82 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
br label %83
83: ; preds = %81, %74
%84 = load i8, i8* %9
%85 = zext i8 %84 to i32
%86 = ashr i32 %85, 4
%87 = trunc i32 %86 to i8
%88 = zext i8 %87 to i32
%89 = icmp ne i32 %88, 15
br i1 %89, label %90, label %92
90: ; preds = %83
%91 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
br label %92
92: ; preds = %90, %83
store i8 -1, i8* %10
%93 = load i8, i8* %10
%94 = zext i8 %93 to i32
%95 = shl i32 %94, 1
%96 = trunc i32 %95 to i8
store i8 %96, i8* %10
%97 = load i8, i8* %10
%98 = zext i8 %97 to i32
%99 = shl i32 %98, -1
%100 = trunc i32 %99 to i8
store i8 %100, i8* %10
store i32 -1, i32* %11
%101 = load i8, i8* %10
%102 = zext i8 %101 to i32
%103 = load i32, i32* %11
%104 = shl i32 %102, %103
%105 = trunc i32 %104 to i8
store i8 %105, i8* %10
store i32 123, i32* %12
%106 = load i32, i32* %12
%107 = shl i32 %106, 32
store i32 %107, i32* %12
%108 = load i8, i8* %10
%109 = zext i8 %108 to i32
%110 = shl i32 %109, 8
%111 = trunc i32 %110 to i8
store i8 %111, i8* %10
store i32 -1, i32* %13
%112 = call i32 @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.7, i64 0, i64 0))
%113 = load i32, i32* %13
%114 = ashr i32 %113, 1
%115 = icmp eq i32 %114, -1
br i1 %115, label %116, label %118
116: ; preds = %92
%117 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0))
br label %127
118: ; preds = %92
%119 = load i32, i32* %13
%120 = ashr i32 %119, 1
%121 = icmp eq i32 %120, 127
br i1 %121, label %122, label %124
122: ; preds = %118
%123 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.9, i64 0, i64 0))
br label %126
124: ; preds = %118
%125 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0))
br label %126
126: ; preds = %124, %122
br label %127
127: ; preds = %126, %116
%128 = load i32, i32* %1
ret i32 %128
}

LLVM IR (-O2):
@str = [59 x i8] c"Bitshift right on a signed type keeps the most left bit...\00"
@str.11 = [15 x i8] c"...set to one.\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @str, i64 0, i64 0))
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.11, i64 0, i64 0))
ret i32 0
}