#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 uint8_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, int);
void print_state_change(uint8_t cur_state, uint8_t last_state) {
  uint8_t changed = cur_state ^ last_state;
  int i;
  for (i = 0; i < 4; i++) {
    if (!((changed >> i) & 1))
      continue;
    if ((cur_state >> i) & 1)
      printf("switch %d flipped up\n", i);
    else
      printf("switch %d flipped down\n", i);
  }
  for (i = 0; i < 4; i++) {
    int shift = 4 + i;
    if (!((changed >> shift) & 1))
      continue;
    if ((cur_state >> shift) & 1)
      printf("key %d released\n", i);
    else
      printf("key %d pushed\n", i);
  }
}


x86 assembly (clang, -O0):
<print_state_change>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%eax
xor    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x4,-0x10(%rbp)
jge    119b <print_state_change+0x8b>
mov    -0xc(%rbp),%eax
mov    -0x10(%rbp),%ecx
sar    %cl,%eax
and    $0x1,%eax
cmp    $0x0,%eax
jne    1151 <print_state_change+0x41>
jmp    118d <print_state_change+0x7d>
mov    -0x4(%rbp),%eax
mov    -0x10(%rbp),%ecx
sar    %cl,%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1179 <print_state_change+0x69>
mov    -0x10(%rbp),%esi
lea    0xe91(%rip),%rdi
call   1030 <printf@plt>
jmp    1188 <print_state_change+0x78>
mov    -0x10(%rbp),%esi
lea    0xe93(%rip),%rdi
call   1030 <printf@plt>
jmp    118d <print_state_change+0x7d>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    112e <print_state_change+0x1e>
movl   $0x0,-0x10(%rbp)
cmpl   $0x4,-0x10(%rbp)
jge    1218 <print_state_change+0x108>
mov    -0x10(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
mov    -0x14(%rbp),%ecx
sar    %cl,%eax
and    $0x1,%eax
cmp    $0x0,%eax
jne    11ce <print_state_change+0xbe>
jmp    120a <print_state_change+0xfa>
mov    -0x4(%rbp),%eax
mov    -0x14(%rbp),%ecx
sar    %cl,%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     11f6 <print_state_change+0xe6>
mov    -0x10(%rbp),%esi
lea    0xe42(%rip),%rdi
call   1030 <printf@plt>
jmp    1205 <print_state_change+0xf5>
mov    -0x10(%rbp),%esi
lea    0xe3f(%rip),%rdi
call   1030 <printf@plt>
jmp    120a <print_state_change+0xfa>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11a2 <print_state_change+0x92>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_state_change>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %edi,%ebx
xor    %edi,%ebp
test   $0x1,%bpl
jne    1168 <print_state_change+0x58>
test   $0x2,%bpl
jne    118a <print_state_change+0x7a>
test   $0x4,%bpl
jne    11af <print_state_change+0x9f>
test   $0x8,%bpl
jne    11d8 <print_state_change+0xc8>
test   $0x10,%bpl
jne    1201 <print_state_change+0xf1>
test   $0x20,%bpl
jne    1227 <print_state_change+0x117>
test   $0x40,%bpl
jne    1250 <print_state_change+0x140>
test   $0x80,%bpl
jne    1279 <print_state_change+0x169>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
test   $0x1,%bl
lea    0xea4(%rip),%rax
lea    0xe87(%rip),%rdi
cmove  %rax,%rdi
xor    %esi,%esi
call   1030 <printf@plt>
test   $0x2,%bpl
je     1125 <print_state_change+0x15>
test   $0x2,%bl
lea    0xe82(%rip),%rax
lea    0xe65(%rip),%rdi
cmove  %rax,%rdi
mov    $0x1,%esi
call   1030 <printf@plt>
test   $0x4,%bpl
je     112f <print_state_change+0x1f>
test   $0x4,%bl
lea    0xe5d(%rip),%rax
lea    0xe40(%rip),%rdi
cmove  %rax,%rdi
mov    $0x2,%esi
call   1030 <printf@plt>
test   $0x8,%bpl
je     1139 <print_state_change+0x29>
test   $0x8,%bl
lea    0xe34(%rip),%rax
lea    0xe17(%rip),%rdi
cmove  %rax,%rdi
mov    $0x3,%esi
call   1030 <printf@plt>
test   $0x10,%bpl
je     1143 <print_state_change+0x33>
test   $0x10,%bl
lea    0xe34(%rip),%rax
lea    0xe1c(%rip),%rdi
cmove  %rax,%rdi
xor    %esi,%esi
call   1030 <printf@plt>
test   $0x20,%bpl
je     114d <print_state_change+0x3d>
test   $0x20,%bl
lea    0xe0e(%rip),%rax
lea    0xdf6(%rip),%rdi
cmove  %rax,%rdi
mov    $0x1,%esi
call   1030 <printf@plt>
test   $0x40,%bpl
je     1157 <print_state_change+0x47>
test   $0x40,%bl
lea    0xde5(%rip),%rax
lea    0xdcd(%rip),%rdi
cmove  %rax,%rdi
mov    $0x2,%esi
call   1030 <printf@plt>
test   $0x80,%bpl
je     1161 <print_state_change+0x51>
test   $0x80,%bl
lea    0xdbc(%rip),%rax
lea    0xda4(%rip),%rdi
cmove  %rax,%rdi
mov    $0x3,%esi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [22 x i8] c"switch %d flipped up\0A\00"
@.str.1 = [24 x i8] c"switch %d flipped down\0A\00"
@.str.2 = [17 x i8] c"key %d released\0A\00"
@.str.3 = [15 x i8] c"key %d pushed\0A\00"
define void @print_state_change(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%8 = load i32, i32* %3
%9 = load i32, i32* %4
%10 = xor i32 %8, %9
store i32 %10, i32* %5
store i32 0, i32* %6
br label %11
11: ; preds = %34, %2
%12 = load i32, i32* %6
%13 = icmp slt i32 %12, 4
br i1 %13, label %14, label %37
14: ; preds = %11
%15 = load i32, i32* %5
%16 = load i32, i32* %6
%17 = ashr i32 %15, %16
%18 = and i32 %17, 1
%19 = icmp ne i32 %18, 0
br i1 %19, label %21, label %20
20: ; preds = %14
br label %34
21: ; preds = %14
%22 = load i32, i32* %3
%23 = load i32, i32* %6
%24 = ashr i32 %22, %23
%25 = and i32 %24, 1
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %21
%28 = load i32, i32* %6
%29 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %28)
br label %33
30: ; preds = %21
%31 = load i32, i32* %6
%32 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %31)
br label %33
33: ; preds = %30, %27
br label %34
34: ; preds = %33, %20
%35 = load i32, i32* %6
%36 = add nsw i32 %35, 1
store i32 %36, i32* %6
br label %11
37: ; preds = %11
store i32 0, i32* %6
br label %38
38: ; preds = %63, %37
%39 = load i32, i32* %6
%40 = icmp slt i32 %39, 4
br i1 %40, label %41, label %66
41: ; preds = %38
%42 = load i32, i32* %6
%43 = add nsw i32 4, %42
store i32 %43, i32* %7
%44 = load i32, i32* %5
%45 = load i32, i32* %7
%46 = ashr i32 %44, %45
%47 = and i32 %46, 1
%48 = icmp ne i32 %47, 0
br i1 %48, label %50, label %49
49: ; preds = %41
br label %63
50: ; preds = %41
%51 = load i32, i32* %3
%52 = load i32, i32* %7
%53 = ashr i32 %51, %52
%54 = and i32 %53, 1
%55 = icmp ne i32 %54, 0
br i1 %55, label %56, label %59
56: ; preds = %50
%57 = load i32, i32* %6
%58 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %57)
br label %62
59: ; preds = %50
%60 = load i32, i32* %6
%61 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %60)
br label %62
62: ; preds = %59, %56
br label %63
63: ; preds = %62, %49
%64 = load i32, i32* %6
%65 = add nsw i32 %64, 1
store i32 %65, i32* %6
br label %38
66: ; preds = %38
ret void
}

LLVM IR (-O2):
@.str = [22 x i8] c"switch %d flipped up\0A\00"
@.str.1 = [24 x i8] c"switch %d flipped down\0A\00"
@.str.2 = [17 x i8] c"key %d released\0A\00"
@.str.3 = [15 x i8] c"key %d pushed\0A\00"
define void @print_state_change(i32 %0, i32 %1) {
%3 = xor i32 %1, %0
%4 = and i32 %3, 1
%5 = icmp eq i32 %4, 0
br i1 %5, label %11, label %6
6: ; preds = %2
%7 = and i32 %0, 1
%8 = icmp eq i32 %7, 0
%9 = select i1 %8, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0)
%10 = tail call i32 @printf(i8* %9, i32 0)
br label %11
11: ; preds = %6, %2
%12 = and i32 %3, 2
%13 = icmp eq i32 %12, 0
br i1 %13, label %19, label %14
14: ; preds = %11
%15 = and i32 %0, 2
%16 = icmp eq i32 %15, 0
%17 = select i1 %16, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0)
%18 = tail call i32 @printf(i8* %17, i32 1)
br label %19
19: ; preds = %14, %11
%20 = and i32 %3, 4
%21 = icmp eq i32 %20, 0
br i1 %21, label %27, label %22
22: ; preds = %19
%23 = and i32 %0, 4
%24 = icmp eq i32 %23, 0
%25 = select i1 %24, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0)
%26 = tail call i32 @printf(i8* %25, i32 2)
br label %27
27: ; preds = %22, %19
%28 = and i32 %3, 8
%29 = icmp eq i32 %28, 0
br i1 %29, label %35, label %30
30: ; preds = %27
%31 = and i32 %0, 8
%32 = icmp eq i32 %31, 0
%33 = select i1 %32, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0)
%34 = tail call i32 @printf(i8* %33, i32 3)
br label %35
35: ; preds = %30, %27
%36 = and i32 %3, 16
%37 = icmp eq i32 %36, 0
br i1 %37, label %43, label %38
38: ; preds = %35
%39 = and i32 %0, 16
%40 = icmp eq i32 %39, 0
%41 = select i1 %40, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0)
%42 = tail call i32 @printf(i8* %41, i32 0)
br label %43
43: ; preds = %38, %35
%44 = and i32 %3, 32
%45 = icmp eq i32 %44, 0
br i1 %45, label %51, label %46
46: ; preds = %43
%47 = and i32 %0, 32
%48 = icmp eq i32 %47, 0
%49 = select i1 %48, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0)
%50 = tail call i32 @printf(i8* %49, i32 1)
br label %51
51: ; preds = %46, %43
%52 = and i32 %3, 64
%53 = icmp eq i32 %52, 0
br i1 %53, label %59, label %54
54: ; preds = %51
%55 = and i32 %0, 64
%56 = icmp eq i32 %55, 0
%57 = select i1 %56, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0)
%58 = tail call i32 @printf(i8* %57, i32 2)
br label %59
59: ; preds = %54, %51
%60 = and i32 %3, 128
%61 = icmp eq i32 %60, 0
br i1 %61, label %67, label %62
62: ; preds = %59
%63 = and i32 %0, 128
%64 = icmp eq i32 %63, 0
%65 = select i1 %64, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0)
%66 = tail call i32 @printf(i8* %65, i32 3)
br label %67
67: ; preds = %62, %59
ret void
}