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

/* Variables and functions */
int lv1_insert_htab_entry(int /*<<< orphan*/, int, int, int, int,
                          int /*<<< orphan*/, int *, int *, int *);
int mm_insert_htab_entry(uint64_t va_addr, uint64_t lpar_addr, uint64_t prot,
                         uint64_t *index) {
  uint64_t hpte_group, hpte_index = 0, hpte_v, hpte_r, hpte_evicted_v,
                       hpte_evicted_r;
  hpte_group = (((va_addr >> 28) ^ ((va_addr & 0xFFFFFFFULL) >> 12)) & 0x7FF)
               << 3;
  hpte_v = ((va_addr >> 23) << 7) | 0x0000000000000001ULL;
  hpte_r = lpar_addr | 0x38 | (prot & 0x0000000000000003ULL);
  int result = lv1_insert_htab_entry(0, hpte_group, hpte_v, hpte_r,
                                     0x0000000000000010ULL, 0, &hpte_index,
                                     &hpte_evicted_v, &hpte_evicted_r);
  if ((result == 0) && (index != 0))
    *index = hpte_index;
  return (int)result;
}


x86 assembly (clang, -O0):
<mm_insert_htab_entry>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x4(%rbp),%eax
sar    $0x1c,%eax
cltq
movslq -0x4(%rbp),%rcx
and    $0xfffffff,%rcx
shr    $0xc,%rcx
xor    %rcx,%rax
and    $0x7ff,%rax
shl    $0x3,%rax
mov    %eax,-0x1c(%rbp)
mov    -0x4(%rbp),%eax
sar    $0x17,%eax
shl    $0x7,%eax
cltq
or     $0x1,%rax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%eax
or     $0x38,%eax
cltq
movslq -0xc(%rbp),%rcx
and    $0x3,%rcx
or     %rcx,%rax
mov    %eax,-0x28(%rbp)
mov    -0x1c(%rbp),%esi
mov    -0x24(%rbp),%edx
mov    -0x28(%rbp),%ecx
xor    %r9d,%r9d
mov    $0x10,%r8d
lea    -0x20(%rbp),%r11
lea    -0x2c(%rbp),%r10
lea    -0x30(%rbp),%rax
mov    %r9d,%edi
mov    %r11,(%rsp)
mov    %r10,0x8(%rsp)
mov    %rax,0x10(%rsp)
call   1030 <lv1_insert_htab_entry@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jne    11d0 <mm_insert_htab_entry+0xc0>
cmpq   $0x0,-0x18(%rbp)
je     11d0 <mm_insert_htab_entry+0xc0>
mov    -0x20(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x34(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mm_insert_htab_entry>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%rbx
mov    %edx,%ecx
movl   $0x0,0xc(%rsp)
mov    %edi,%edx
sar    $0x1c,%edx
mov    %edi,%eax
shr    $0xc,%eax
xor    %edx,%eax
shl    $0x3,%eax
and    $0x3ff8,%eax
sar    $0x10,%edi
and    $0xffffff80,%edi
lea    0x1(%rdi),%edx
and    $0x3,%ecx
or     %esi,%ecx
or     $0x38,%ecx
sub    $0x8,%rsp
lea    0x18(%rsp),%r10
lea    0x1c(%rsp),%r11
lea    0x14(%rsp),%r14
xor    %edi,%edi
mov    %eax,%esi
mov    $0x10,%r8d
xor    %r9d,%r9d
push   %r10
push   %r11
push   %r14
call   1030 <lv1_insert_htab_entry@plt>
add    $0x20,%rsp
test   %rbx,%rbx
je     1187 <mm_insert_htab_entry+0x77>
test   %eax,%eax
jne    1187 <mm_insert_htab_entry+0x77>
mov    0xc(%rsp),%ecx
mov    %ecx,(%rbx)
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @mm_insert_htab_entry(i32 %0, i32 %1, i32 %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32* %3, i32** %8
store i32 0, i32* %10
%16 = load i32, i32* %5
%17 = ashr i32 %16, 28
%18 = sext i32 %17 to i64
%19 = load i32, i32* %5
%20 = sext i32 %19 to i64
%21 = and i64 %20, 268435455
%22 = lshr i64 %21, 12
%23 = xor i64 %18, %22
%24 = and i64 %23, 2047
%25 = shl i64 %24, 3
%26 = trunc i64 %25 to i32
store i32 %26, i32* %9
%27 = load i32, i32* %5
%28 = ashr i32 %27, 23
%29 = shl i32 %28, 7
%30 = sext i32 %29 to i64
%31 = or i64 %30, 1
%32 = trunc i64 %31 to i32
store i32 %32, i32* %11
%33 = load i32, i32* %6
%34 = or i32 %33, 56
%35 = sext i32 %34 to i64
%36 = load i32, i32* %7
%37 = sext i32 %36 to i64
%38 = and i64 %37, 3
%39 = or i64 %35, %38
%40 = trunc i64 %39 to i32
store i32 %40, i32* %12
%41 = load i32, i32* %9
%42 = load i32, i32* %11
%43 = load i32, i32* %12
%44 = call i32 @lv1_insert_htab_entry(i32 0, i32 %41, i32 %42, i32 %43, i32 16, i32 0, i32* %10, i32* %13, i32* %14)
store i32 %44, i32* %15
%45 = load i32, i32* %15
%46 = icmp eq i32 %45, 0
br i1 %46, label %47, label %53
47: ; preds = %4
%48 = load i32*, i32** %8
%49 = icmp ne i32* %48, null
br i1 %49, label %50, label %53
50: ; preds = %47
%51 = load i32, i32* %10
%52 = load i32*, i32** %8
store i32 %51, i32* %52
br label %53
53: ; preds = %50, %47, %4
%54 = load i32, i32* %15
ret i32 %54
}

LLVM IR (-O2):
define i32 @mm_insert_htab_entry(i32 %0, i32 %1, i32 %2, i32* writeonly %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = bitcast i32* %5 to i8*
store i32 0, i32* %5
%9 = bitcast i32* %6 to i8*
%10 = bitcast i32* %7 to i8*
%11 = ashr i32 %0, 28
%12 = lshr i32 %0, 12
%13 = xor i32 %11, %12
%14 = shl nsw i32 %13, 3
%15 = and i32 %14, 16376
%16 = ashr i32 %0, 16
%17 = and i32 %16, -128
%18 = or i32 %17, 1
%19 = and i32 %2, 3
%20 = or i32 %19, %1
%21 = or i32 %20, 56
%22 = call i32 @lv1_insert_htab_entry(i32 0, i32 %15, i32 %18, i32 %21, i32 16, i32 0, i32* %5, i32* %6, i32* %7)
%23 = icmp eq i32 %22, 0
%24 = icmp ne i32* %3, null
%25 = and i1 %24, %23
br i1 %25, label %26, label %28
26: ; preds = %4
%27 = load i32, i32* %5
store i32 %27, i32* %3
br label %28
28: ; preds = %26, %4
ret i32 %22
}