#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 uint64_t;
typedef int /*<<< orphan*/ int64_t;

/* Variables and functions */
int UINT64_C(int);
int /*<<< orphan*/ assert(int);
int bitreverse(int);
int64_t scramble(int64_t v0, int lgN, uint64_t val0, uint64_t val1) {
  uint64_t v = (uint64_t)v0;
  v += val0 + val1;
  v *= (val0 | UINT64_C(0x4519840211493211));
  v = (bitreverse(v) >> (64 - lgN));
  assert((v >> lgN) == 0);
  v *= (val1 | UINT64_C(0x3050852102C843A5));
  v = (bitreverse(v) >> (64 - lgN));
  assert((v >> lgN) == 0);
  return (int64_t)v;
}


x86 assembly (clang, -O0):
<scramble>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    $0x11493211,%edi
call   1030 <UINT64_C@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
or     %ecx,%eax
imul   -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1050 <bitreverse@plt>
mov    $0x40,%ecx
sub    -0x8(%rbp),%ecx
sar    %cl,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x8(%rbp),%ecx
sar    %cl,%eax
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    $0x2c843a5,%edi
call   1030 <UINT64_C@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
or     %ecx,%eax
imul   -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1050 <bitreverse@plt>
mov    $0x40,%ecx
sub    -0x8(%rbp),%ecx
sar    %cl,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x8(%rbp),%ecx
sar    %cl,%eax
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scramble>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%r15d
mov    %edx,%ebx
mov    %esi,%r14d
mov    %edi,%ebp
add    %edx,%ebp
add    %ecx,%ebp
mov    $0x11493211,%edi
call   1030 <UINT64_C@plt>
or     %eax,%ebx
imul   %ebp,%ebx
mov    %ebx,%edi
call   1050 <bitreverse@plt>
mov    %eax,%ebp
mov    %r14d,%ebx
neg    %bl
mov    %ebx,%ecx
sar    %cl,%ebp
mov    %ebp,%eax
mov    %r14d,%ecx
sar    %cl,%eax
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1040 <assert@plt>
mov    $0x2c843a5,%edi
call   1030 <UINT64_C@plt>
or     %eax,%r15d
imul   %ebp,%r15d
mov    %r15d,%edi
call   1050 <bitreverse@plt>
mov    %eax,%ebp
mov    %ebx,%ecx
sar    %cl,%ebp
mov    %ebp,%eax
mov    %r14d,%ecx
sar    %cl,%eax
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1040 <assert@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @scramble(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%10 = load i32, i32* %5
store i32 %10, i32* %9
%11 = load i32, i32* %7
%12 = load i32, i32* %8
%13 = add nsw i32 %11, %12
%14 = load i32, i32* %9
%15 = add nsw i32 %14, %13
store i32 %15, i32* %9
%16 = load i32, i32* %7
%17 = call i32 @UINT64_C(i32 290009617)
%18 = or i32 %16, %17
%19 = load i32, i32* %9
%20 = mul nsw i32 %19, %18
store i32 %20, i32* %9
%21 = load i32, i32* %9
%22 = call i32 @bitreverse(i32 %21)
%23 = load i32, i32* %6
%24 = sub nsw i32 64, %23
%25 = ashr i32 %22, %24
store i32 %25, i32* %9
%26 = load i32, i32* %9
%27 = load i32, i32* %6
%28 = ashr i32 %26, %27
%29 = icmp eq i32 %28, 0
%30 = zext i1 %29 to i32
%31 = call i32 @assert(i32 %30)
%32 = load i32, i32* %8
%33 = call i32 @UINT64_C(i32 46678949)
%34 = or i32 %32, %33
%35 = load i32, i32* %9
%36 = mul nsw i32 %35, %34
store i32 %36, i32* %9
%37 = load i32, i32* %9
%38 = call i32 @bitreverse(i32 %37)
%39 = load i32, i32* %6
%40 = sub nsw i32 64, %39
%41 = ashr i32 %38, %40
store i32 %41, i32* %9
%42 = load i32, i32* %9
%43 = load i32, i32* %6
%44 = ashr i32 %42, %43
%45 = icmp eq i32 %44, 0
%46 = zext i1 %45 to i32
%47 = call i32 @assert(i32 %46)
%48 = load i32, i32* %9
ret i32 %48
}

LLVM IR (-O2):
define i32 @scramble(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = add i32 %2, %0
%6 = add i32 %5, %3
%7 = tail call i32 @UINT64_C(i32 290009617)
%8 = or i32 %7, %2
%9 = mul nsw i32 %8, %6
%10 = tail call i32 @bitreverse(i32 %9)
%11 = sub nsw i32 64, %1
%12 = ashr i32 %10, %11
%13 = ashr i32 %12, %1
%14 = icmp eq i32 %13, 0
%15 = zext i1 %14 to i32
%16 = tail call i32 @assert(i32 %15)
%17 = tail call i32 @UINT64_C(i32 46678949)
%18 = or i32 %17, %3
%19 = mul nsw i32 %18, %12
%20 = tail call i32 @bitreverse(i32 %19)
%21 = ashr i32 %20, %11
%22 = ashr i32 %21, %1
%23 = icmp eq i32 %22, 0
%24 = zext i1 %23 to i32
%25 = tail call i32 @assert(i32 %24)
ret i32 %21
}