#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*/ assert(int);
unsigned char UnRandomize255State(unsigned char value, int idx) {
  int pseudoRandom;
  int tmp;
  pseudoRandom = ((149 * idx) % 255) + 1;
  tmp = value - pseudoRandom;
  if (tmp < 0)
    tmp += 256;
  assert(tmp >= 0 && tmp < 256);
  return (unsigned char)tmp;
}


x86 assembly (clang, -O0):
<UnRandomize255State>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
mov    %esi,-0x8(%rbp)
imul   $0x95,-0x8(%rbp),%eax
mov    $0xff,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
mov    %edx,-0xc(%rbp)
movzbl -0x1(%rbp),%eax
sub    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    1155 <UnRandomize255State+0x45>
mov    -0x10(%rbp),%eax
add    $0x100,%eax
mov    %eax,-0x10(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x10(%rbp)
mov    %al,-0x11(%rbp)
jl     1171 <UnRandomize255State+0x61>
cmpl   $0x100,-0x10(%rbp)
setl   %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x10(%rbp),%eax
movzbl %al,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<UnRandomize255State>:
push   %rbx
imul   $0x95,%esi,%eax
cltq
imul   $0xffffffff80808081,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0x7,%ecx
add    %edx,%ecx
mov    %ecx,%edx
shl    $0x8,%edx
sub    %edx,%ecx
add    %eax,%ecx
not    %ecx
lea    (%rcx,%rdi,1),%ebx
add    $0x100,%ebx
mov    %ecx,%eax
add    %edi,%eax
cmovns %eax,%ebx
xor    %edi,%edi
cmp    $0x100,%ebx
setl   %dil
call   1030 <assert@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
define zeroext i8 @UnRandomize255State(i8 zeroext %0, i32 %1) {
%3 = alloca i8
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8 %0, i8* %3
store i32 %1, i32* %4
%7 = load i32, i32* %4
%8 = mul nsw i32 149, %7
%9 = srem i32 %8, 255
%10 = add nsw i32 %9, 1
store i32 %10, i32* %5
%11 = load i8, i8* %3
%12 = zext i8 %11 to i32
%13 = load i32, i32* %5
%14 = sub nsw i32 %12, %13
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %2
%18 = load i32, i32* %6
%19 = add nsw i32 %18, 256
store i32 %19, i32* %6
br label %20
20: ; preds = %17, %2
%21 = load i32, i32* %6
%22 = icmp sge i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = load i32, i32* %6
%25 = icmp slt i32 %24, 256
br label %26
26: ; preds = %23, %20
%27 = phi i1 [ false, %20 ], [ %25, %23 ]
%28 = zext i1 %27 to i32
%29 = call i32 @assert(i32 %28)
%30 = load i32, i32* %6
%31 = trunc i32 %30 to i8
ret i8 %31
}

LLVM IR (-O2):
define zeroext i8 @UnRandomize255State(i8 zeroext %0, i32 %1) {
%3 = mul nsw i32 %1, 149
%4 = srem i32 %3, 255
%5 = xor i32 %4, -1
%6 = zext i8 %0 to i32
%7 = add nsw i32 %5, %6
%8 = icmp slt i32 %7, 0
%9 = add nsw i32 %7, 256
%10 = select i1 %8, i32 %9, i32 %7
%11 = icmp slt i32 %10, 256
%12 = zext i1 %11 to i32
%13 = tail call i32 @assert(i32 %12)
%14 = trunc i32 %10 to i8
ret i8 %14
}