#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*/ resetFlag(int);
int /*<<< orphan*/ setFlag(int);
scalar_t__ testFlag(int);
unsigned char rr(unsigned char value) {
  int carry = value & 0x01;
  value >>= 1;
  if (testFlag(4))
    value |= 0x80;
  resetFlag(6);
  resetFlag(5);
  if (value)
    resetFlag(7);
  else
    setFlag(7);
  if (carry)
    setFlag(4);
  else
    resetFlag(4);
  return value;
}


x86 assembly (clang, -O0):
<rr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
movzbl -0x1(%rbp),%eax
and    $0x1,%eax
mov    %eax,-0x8(%rbp)
movzbl -0x1(%rbp),%eax
sar    $0x1,%eax
mov    %al,-0x1(%rbp)
mov    $0x4,%edi
call   1030 <testFlag@plt>
cmp    $0x0,%rax
je     1172 <rr+0x42>
movzbl -0x1(%rbp),%eax
or     $0x80,%eax
mov    %al,-0x1(%rbp)
mov    $0x6,%edi
call   1050 <resetFlag@plt>
mov    $0x5,%edi
call   1050 <resetFlag@plt>
cmpb   $0x0,-0x1(%rbp)
je     119f <rr+0x6f>
mov    $0x7,%edi
call   1050 <resetFlag@plt>
jmp    11a9 <rr+0x79>
mov    $0x7,%edi
call   1040 <setFlag@plt>
cmpl   $0x0,-0x8(%rbp)
je     11c2 <rr+0x92>
mov    $0x4,%edi
call   1040 <setFlag@plt>
jmp    11cc <rr+0x9c>
mov    $0x4,%edi
call   1050 <resetFlag@plt>
movzbl -0x1(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rr>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
mov    %ebp,%ebx
shr    %bl
mov    $0x4,%edi
call   1030 <testFlag@plt>
lea    -0x80(%rbx),%ecx
test   %rax,%rax
movzbl %bl,%eax
movzbl %cl,%ebx
cmove  %eax,%ebx
mov    $0x6,%edi
call   1050 <resetFlag@plt>
mov    $0x5,%edi
call   1050 <resetFlag@plt>
mov    $0x7,%edi
test   %bl,%bl
je     1176 <rr+0x46>
call   1050 <resetFlag@plt>
jmp    117b <rr+0x4b>
call   1040 <setFlag@plt>
mov    $0x4,%edi
test   $0x1,%bpl
jne    118d <rr+0x5d>
call   1050 <resetFlag@plt>
jmp    1192 <rr+0x62>
call   1040 <setFlag@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define zeroext i8 @rr(i8 zeroext %0) {
%2 = alloca i8
%3 = alloca i32
store i8 %0, i8* %2
%4 = load i8, i8* %2
%5 = zext i8 %4 to i32
%6 = and i32 %5, 1
store i32 %6, i32* %3
%7 = load i8, i8* %2
%8 = zext i8 %7 to i32
%9 = ashr i32 %8, 1
%10 = trunc i32 %9 to i8
store i8 %10, i8* %2
%11 = call i64 @testFlag(i32 4)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %1
%14 = load i8, i8* %2
%15 = zext i8 %14 to i32
%16 = or i32 %15, 128
%17 = trunc i32 %16 to i8
store i8 %17, i8* %2
br label %18
18: ; preds = %13, %1
%19 = call i32 @resetFlag(i32 6)
%20 = call i32 @resetFlag(i32 5)
%21 = load i8, i8* %2
%22 = icmp ne i8 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %18
%24 = call i32 @resetFlag(i32 7)
br label %27
25: ; preds = %18
%26 = call i32 @setFlag(i32 7)
br label %27
27: ; preds = %25, %23
%28 = load i32, i32* %3
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %27
%31 = call i32 @setFlag(i32 4)
br label %34
32: ; preds = %27
%33 = call i32 @resetFlag(i32 4)
br label %34
34: ; preds = %32, %30
%35 = load i8, i8* %2
ret i8 %35
}

LLVM IR (-O2):
define zeroext i8 @rr(i8 zeroext %0) {
%2 = and i8 %0, 1
%3 = lshr i8 %0, 1
%4 = tail call i64 @testFlag(i32 4)
%5 = icmp eq i64 %4, 0
%6 = or i8 %3, -128
%7 = select i1 %5, i8 %3, i8 %6
%8 = tail call i32 @resetFlag(i32 6)
%9 = tail call i32 @resetFlag(i32 5)
%10 = icmp eq i8 %7, 0
br i1 %10, label %13, label %11
11: ; preds = %1
%12 = tail call i32 @resetFlag(i32 7)
br label %15
13: ; preds = %1
%14 = tail call i32 @setFlag(i32 7)
br label %15
15: ; preds = %13, %11
%16 = icmp eq i8 %2, 0
br i1 %16, label %19, label %17
17: ; preds = %15
%18 = tail call i32 @setFlag(i32 4)
br label %21
19: ; preds = %15
%20 = tail call i32 @resetFlag(i32 4)
br label %21
21: ; preds = %19, %17
ret i8 %7
}