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

/* Variables and functions */
uint32_t riva128_pfifo_cache1_lin(uint32_t ptr) {
  int bits = 5;
  uint32_t res = 0;
  uint32_t tmp = ptr >> 2;
  for (int bit = bits = 1; bit > 0; bit--) {
    if (tmp & (1 << bit)) {
      tmp ^= 3 << (bit - 1);
      res ^= 4 << bit;
    }
  }
  if (tmp & 1)
    res ^= 4;
  return res;
}


x86 assembly (clang, -O0):
<riva128_pfifo_cache1_lin>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
movl   $0x5,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x4(%rbp),%eax
sar    $0x2,%eax
mov    %eax,-0x10(%rbp)
movl   $0x1,-0x8(%rbp)
movl   $0x1,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    1186 <riva128_pfifo_cache1_lin+0x86>
mov    -0x10(%rbp),%eax
mov    -0x14(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     1173 <riva128_pfifo_cache1_lin+0x73>
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
mov    $0x3,%eax
shl    %cl,%eax
xor    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%ecx
mov    $0x4,%eax
shl    %cl,%eax
xor    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    1178 <riva128_pfifo_cache1_lin+0x78>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    112c <riva128_pfifo_cache1_lin+0x2c>
mov    -0x10(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     119e <riva128_pfifo_cache1_lin+0x9e>
mov    -0xc(%rbp),%eax
xor    $0x4,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<riva128_pfifo_cache1_lin>:
mov    %edi,%ecx
shr    $0x2,%ecx
and    $0x8,%edi
mov    %edi,%edx
shr    $0x3,%edx
and    $0x1,%ecx
lea    0x4(%rdi),%eax
cmp    %edx,%ecx
cmove  %edi,%eax
ret

LLVM IR (-O0):
define i32 @riva128_pfifo_cache1_lin(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %2
store i32 5, i32* %3
store i32 0, i32* %4
%7 = load i32, i32* %2
%8 = ashr i32 %7, 2
store i32 %8, i32* %5
store i32 1, i32* %3
store i32 1, i32* %6
br label %9
9: ; preds = %29, %1
%10 = load i32, i32* %6
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %32
12: ; preds = %9
%13 = load i32, i32* %5
%14 = load i32, i32* %6
%15 = shl i32 1, %14
%16 = and i32 %13, %15
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %28
18: ; preds = %12
%19 = load i32, i32* %6
%20 = sub nsw i32 %19, 1
%21 = shl i32 3, %20
%22 = load i32, i32* %5
%23 = xor i32 %22, %21
store i32 %23, i32* %5
%24 = load i32, i32* %6
%25 = shl i32 4, %24
%26 = load i32, i32* %4
%27 = xor i32 %26, %25
store i32 %27, i32* %4
br label %28
28: ; preds = %18, %12
br label %29
29: ; preds = %28
%30 = load i32, i32* %6
%31 = add nsw i32 %30, -1
store i32 %31, i32* %6
br label %9
32: ; preds = %9
%33 = load i32, i32* %5
%34 = and i32 %33, 1
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %32
%37 = load i32, i32* %4
%38 = xor i32 %37, 4
store i32 %38, i32* %4
br label %39
39: ; preds = %36, %32
%40 = load i32, i32* %4
ret i32 %40
}

LLVM IR (-O2):
define i32 @riva128_pfifo_cache1_lin(i32 %0) {
%2 = lshr i32 %0, 2
%3 = and i32 %0, 8
%4 = lshr exact i32 %3, 3
%5 = and i32 %2, 1
%6 = icmp eq i32 %5, %4
%7 = or i32 %3, 4
%8 = select i1 %6, i32 %3, i32 %7
ret i32 %8
}