#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 uint8_t;
typedef int /*<<< orphan*/ ingress_up;

/* Variables and functions */
int *get_current_hof(int *);
int *get_current_iof(int *);
int *get_hof_ver_normal(int *);
int /*<<< orphan*/ memset(int **, int /*<<< orphan*/, int);
uint8_t *get_hof_ver(uint8_t *buf, int ingress) {
  uint8_t *iof = get_current_iof(buf);
  uint8_t *hof = get_current_hof(buf);
  if (!((*hof) & 0x01) || (((*iof) & 0x02) && !((*iof) & 0x04)))
    return get_hof_ver_normal(buf);
  uint8_t ingress_up[2][2];
  memset(ingress_up, 0, sizeof(ingress_up));
  if (((*iof) & 0x04)) {
    ingress_up[1][1] = 2;
    ingress_up[1][0] = 1;
    ingress_up[0][1] = -1;
    ingress_up[0][0] = -2;
  } else {
    ingress_up[1][1] = 0;
    ingress_up[1][0] = -1;
    ingress_up[0][1] = 1;
    ingress_up[0][0] = 0;
  }
  int offset = ingress_up[ingress][((*iof) & 0x01)];
  if (offset == 0)
    return NULL;
  return hof + offset * 8;
}


x86 assembly (clang, -O0):
<get_hof_ver>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <get_current_iof@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <get_current_hof@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     119f <get_hof_ver+0x5f>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     11b1 <get_hof_ver+0x71>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
and    $0x4,%eax
cmp    $0x0,%eax
jne    11b1 <get_hof_ver+0x71>
mov    -0x10(%rbp),%rdi
call   1050 <get_hof_ver_normal@plt>
mov    %rax,-0x8(%rbp)
jmp    1260 <get_hof_ver+0x120>
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1030 <memset@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
and    $0x4,%eax
cmp    $0x0,%eax
je     11f4 <get_hof_ver+0xb4>
movl   $0x2,-0x34(%rbp)
movl   $0x1,-0x38(%rbp)
movl   $0xffffffff,-0x3c(%rbp)
movl   $0xfffffffe,-0x40(%rbp)
jmp    1210 <get_hof_ver+0xd0>
movl   $0x0,-0x34(%rbp)
movl   $0xffffffff,-0x38(%rbp)
movl   $0x1,-0x3c(%rbp)
movl   $0x0,-0x40(%rbp)
movslq -0x14(%rbp),%rcx
lea    -0x40(%rbp),%rax
shl    $0x3,%rcx
add    %rcx,%rax
mov    -0x20(%rbp),%rcx
mov    (%rcx),%ecx
and    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jne    1248 <get_hof_ver+0x108>
movq   $0x0,-0x8(%rbp)
jmp    1260 <get_hof_ver+0x120>
mov    -0x28(%rbp),%rax
mov    -0x44(%rbp),%ecx
shl    $0x3,%ecx
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_hof_ver>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %esi,%r14d
mov    %rdi,%rbp
call   1060 <get_current_iof@plt>
mov    %rax,%r15
mov    %rbp,%rdi
call   1040 <get_current_hof@plt>
testb  $0x1,(%rax)
je     1173 <get_hof_ver+0x33>
mov    %rax,%rbx
mov    (%r15),%eax
and    $0x6,%eax
cmp    $0x2,%eax
jne    1185 <get_hof_ver+0x45>
mov    %rbp,%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <get_hof_ver_normal@plt>
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1030 <memset@plt>
testb  $0x4,(%r15)
je     11a3 <get_hof_ver+0x63>
movaps 0xe6f(%rip),%xmm0
jmp    11aa <get_hof_ver+0x6a>
movaps 0xe56(%rip),%xmm0
movaps %xmm0,(%rsp)
movslq %r14d,%rax
mov    (%r15),%ecx
and    $0x1,%ecx
lea    (%rsp,%rax,8),%rax
movslq (%rax,%rcx,4),%rax
mov    %rax,%rcx
shl    $0x5,%rcx
add    %rcx,%rbx
test   %rax,%rax
cmove  %rax,%rbx
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32* @get_hof_ver(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca [2 x [2 x i32]]
%9 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
%10 = load i32*, i32** %4
%11 = call i32* @get_current_iof(i32* %10)
store i32* %11, i32** %6
%12 = load i32*, i32** %4
%13 = call i32* @get_current_hof(i32* %12)
store i32* %13, i32** %7
%14 = load i32*, i32** %7
%15 = load i32, i32* %14
%16 = and i32 %15, 1
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %28
18: ; preds = %2
%19 = load i32*, i32** %6
%20 = load i32, i32* %19
%21 = and i32 %20, 2
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %31
23: ; preds = %18
%24 = load i32*, i32** %6
%25 = load i32, i32* %24
%26 = and i32 %25, 4
%27 = icmp ne i32 %26, 0
br i1 %27, label %31, label %28
28: ; preds = %23, %2
%29 = load i32*, i32** %4
%30 = call i32* @get_hof_ver_normal(i32* %29)
store i32* %30, i32** %3
br label %76
31: ; preds = %23, %18
%32 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %8, i64 0, i64 0
%33 = bitcast [2 x i32]* %32 to i32**
%34 = call i32 @memset(i32** %33, i32 0, i32 16)
%35 = load i32*, i32** %6
%36 = load i32, i32* %35
%37 = and i32 %36, 4
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %48
39: ; preds = %31
%40 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %8, i64 0, i64 1
%41 = getelementptr inbounds [2 x i32], [2 x i32]* %40, i64 0, i64 1
store i32 2, i32* %41
%42 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %8, i64 0, i64 1
%43 = getelementptr inbounds [2 x i32], [2 x i32]* %42, i64 0, i64 0
store i32 1, i32* %43
%44 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %8, i64 0, i64 0
%45 = getelementptr inbounds [2 x i32], [2 x i32]* %44, i64 0, i64 1
store i32 -1, i32* %45
%46 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %8, i64 0, i64 0
%47 = getelementptr inbounds [2 x i32], [2 x i32]* %46, i64 0, i64 0
store i32 -2, i32* %47
br label %57
48: ; preds = %31
%49 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %8, i64 0, i64 1
%50 = getelementptr inbounds [2 x i32], [2 x i32]* %49, i64 0, i64 1
store i32 0, i32* %50
%51 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %8, i64 0, i64 1
%52 = getelementptr inbounds [2 x i32], [2 x i32]* %51, i64 0, i64 0
store i32 -1, i32* %52
%53 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %8, i64 0, i64 0
%54 = getelementptr inbounds [2 x i32], [2 x i32]* %53, i64 0, i64 1
store i32 1, i32* %54
%55 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %8, i64 0, i64 0
%56 = getelementptr inbounds [2 x i32], [2 x i32]* %55, i64 0, i64 0
store i32 0, i32* %56
br label %57
57: ; preds = %48, %39
%58 = load i32, i32* %5
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %8, i64 0, i64 %59
%61 = load i32*, i32** %6
%62 = load i32, i32* %61
%63 = and i32 %62, 1
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds [2 x i32], [2 x i32]* %60, i64 0, i64 %64
%66 = load i32, i32* %65
store i32 %66, i32* %9
%67 = load i32, i32* %9
%68 = icmp eq i32 %67, 0
br i1 %68, label %69, label %70
69: ; preds = %57
store i32* null, i32** %3
br label %76
70: ; preds = %57
%71 = load i32*, i32** %7
%72 = load i32, i32* %9
%73 = mul nsw i32 %72, 8
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds i32, i32* %71, i64 %74
store i32* %75, i32** %3
br label %76
76: ; preds = %70, %69, %28
%77 = load i32*, i32** %3
ret i32* %77
}

LLVM IR (-O2):
define i32* @get_hof_ver(i32* %0, i32 %1) {
%3 = alloca <4 x i32>
%4 = bitcast <4 x i32>* %3 to [2 x [2 x i32]]*
%5 = tail call i32* @get_current_iof(i32* %0)
%6 = tail call i32* @get_current_hof(i32* %0)
%7 = load i32, i32* %6
%8 = and i32 %7, 1
%9 = icmp eq i32 %8, 0
br i1 %9, label %14, label %10
10: ; preds = %2
%11 = load i32, i32* %5
%12 = and i32 %11, 6
%13 = icmp eq i32 %12, 2
br i1 %13, label %14, label %16
14: ; preds = %10, %2
%15 = tail call i32* @get_hof_ver_normal(i32* %0)
br label %35
16: ; preds = %10
%17 = bitcast <4 x i32>* %3 to i8*
%18 = bitcast <4 x i32>* %3 to i32**
%19 = call i32 @memset(i32** %18, i32 0, i32 16)
%20 = load i32, i32* %5
%21 = and i32 %20, 4
%22 = icmp eq i32 %21, 0
%23 = select i1 %22, <4 x i32> <i32 0, i32 1, i32 -1, i32 0>, <4 x i32> <i32 -2, i32 -1, i32 1, i32 2>
store <4 x i32> %23, <4 x i32>* %3
%24 = sext i32 %1 to i64
%25 = load i32, i32* %5
%26 = and i32 %25, 1
%27 = zext i32 %26 to i64
%28 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %4, i64 0, i64 %24, i64 %27
%29 = load i32, i32* %28
%30 = icmp eq i32 %29, 0
%31 = shl nsw i32 %29, 3
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i32, i32* %6, i64 %32
%34 = select i1 %30, i32* null, i32* %33
br label %35
35: ; preds = %16, %14
%36 = phi i32* [ %34, %16 ], [ %15, %14 ]
ret i32* %36
}