#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 union eg_table_cmd_u {
  int dummy;
} eg_table_cmd_u;

/* Variables and functions */
int /*<<< orphan*/ eg_table_cmd_set(unsigned int, union eg_table_cmd_u *);
int /*<<< orphan*/ egress_reg_tbl_get(unsigned int, int, unsigned int *, int);
int eg_smib_table_sc_sa_get(unsigned int dev_id, unsigned int index,
                            unsigned int *pentry) {
  int i;
  int entry_offset = 0;
  unsigned int cmd = 0;
  if ((index < 0) || (index > 31)) {
    return -1;
  }
  for (i = 0; i < 8; i++) {
    cmd = (0x1 << 30) | (3 << 12) | ((index * 8) + i);
    eg_table_cmd_set(dev_id, (union eg_table_cmd_u *)&cmd);
    egress_reg_tbl_get(dev_id, 0x140, (pentry + entry_offset), 2);
    entry_offset += 2;
  }
  return 0;
}


x86 assembly (clang, -O0):
<eg_smib_table_sc_sa_get>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x0,-0xc(%rbp)
jb     1154 <eg_smib_table_sc_sa_get+0x34>
cmpl   $0x1f,-0xc(%rbp)
jbe    1160 <eg_smib_table_sc_sa_get+0x40>
movl   $0xffffffff,-0x4(%rbp)
jmp    11cd <eg_smib_table_sc_sa_get+0xad>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x8,-0x1c(%rbp)
jge    11c6 <eg_smib_table_sc_sa_get+0xa6>
mov    -0xc(%rbp),%eax
shl    $0x3,%eax
add    -0x1c(%rbp),%eax
or     $0x40003000,%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x24(%rbp),%rsi
call   1030 <eg_table_cmd_set@plt>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rdx
movslq -0x20(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdx
mov    $0x140,%esi
mov    $0x2,%ecx
call   1040 <egress_reg_tbl_get@plt>
mov    -0x20(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1167 <eg_smib_table_sc_sa_get+0x47>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<eg_smib_table_sc_sa_get>:
mov    $0xffffffff,%eax
cmp    $0x1f,%esi
ja     129f <eg_smib_table_sc_sa_get+0x17f>
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %esi,%ebx
mov    %edi,%ebp
shl    $0x3,%ebx
mov    %ebx,%eax
or     $0x40003000,%eax
mov    %eax,0x4(%rsp)
lea    0x4(%rsp),%r15
mov    %r15,%rsi
call   1030 <eg_table_cmd_set@plt>
mov    %ebp,%edi
mov    $0x140,%esi
mov    %r14,%rdx
mov    $0x2,%ecx
call   1040 <egress_reg_tbl_get@plt>
mov    %ebx,%eax
or     $0x40003001,%eax
mov    %eax,0x4(%rsp)
mov    %ebp,%edi
mov    %r15,%rsi
call   1030 <eg_table_cmd_set@plt>
lea    0x8(%r14),%rdx
mov    %ebp,%edi
mov    $0x140,%esi
mov    $0x2,%ecx
call   1040 <egress_reg_tbl_get@plt>
mov    %ebx,%eax
or     $0x40003002,%eax
mov    %eax,0x4(%rsp)
mov    %ebp,%edi
mov    %r15,%rsi
call   1030 <eg_table_cmd_set@plt>
lea    0x10(%r14),%rdx
mov    %ebp,%edi
mov    $0x140,%esi
mov    $0x2,%ecx
call   1040 <egress_reg_tbl_get@plt>
mov    %ebx,%eax
or     $0x40003003,%eax
mov    %eax,0x4(%rsp)
mov    %ebp,%edi
mov    %r15,%rsi
call   1030 <eg_table_cmd_set@plt>
lea    0x18(%r14),%rdx
mov    %ebp,%edi
mov    $0x140,%esi
mov    $0x2,%ecx
call   1040 <egress_reg_tbl_get@plt>
mov    %ebx,%eax
or     $0x40003004,%eax
mov    %eax,0x4(%rsp)
mov    %ebp,%edi
mov    %r15,%rsi
call   1030 <eg_table_cmd_set@plt>
lea    0x20(%r14),%rdx
mov    %ebp,%edi
mov    $0x140,%esi
mov    $0x2,%ecx
call   1040 <egress_reg_tbl_get@plt>
mov    %ebx,%eax
or     $0x40003005,%eax
mov    %eax,0x4(%rsp)
mov    %ebp,%edi
mov    %r15,%rsi
call   1030 <eg_table_cmd_set@plt>
lea    0x28(%r14),%rdx
mov    %ebp,%edi
mov    $0x140,%esi
mov    $0x2,%ecx
call   1040 <egress_reg_tbl_get@plt>
mov    %ebx,%eax
or     $0x40003006,%eax
mov    %eax,0x4(%rsp)
mov    %ebp,%edi
mov    %r15,%rsi
call   1030 <eg_table_cmd_set@plt>
lea    0x30(%r14),%rdx
mov    %ebp,%edi
mov    $0x140,%esi
mov    $0x2,%ecx
call   1040 <egress_reg_tbl_get@plt>
or     $0x40003007,%ebx
mov    %ebx,0x4(%rsp)
mov    %ebp,%edi
mov    %r15,%rsi
call   1030 <eg_table_cmd_set@plt>
add    $0x38,%r14
mov    %ebp,%edi
mov    $0x140,%esi
mov    %r14,%rdx
mov    $0x2,%ecx
call   1040 <egress_reg_tbl_get@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%union.eg_table_cmd_u = type { i32 }
define i32 @eg_smib_table_sc_sa_get(i32 %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32* %2, i32** %7
store i32 0, i32* %9
store i32 0, i32* %10
%11 = load i32, i32* %6
%12 = icmp ult i32 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %3
%14 = load i32, i32* %6
%15 = icmp ugt i32 %14, 31
br i1 %15, label %16, label %17
16: ; preds = %13, %3
store i32 -1, i32* %4
br label %42
17: ; preds = %13
store i32 0, i32* %8
br label %18
18: ; preds = %38, %17
%19 = load i32, i32* %8
%20 = icmp slt i32 %19, 8
br i1 %20, label %21, label %41
21: ; preds = %18
%22 = load i32, i32* %6
%23 = mul i32 %22, 8
%24 = load i32, i32* %8
%25 = add i32 %23, %24
%26 = or i32 1073754112, %25
store i32 %26, i32* %10
%27 = load i32, i32* %5
%28 = bitcast i32* %10 to %union.eg_table_cmd_u*
%29 = call i32 @eg_table_cmd_set(i32 %27, %union.eg_table_cmd_u* %28)
%30 = load i32, i32* %5
%31 = load i32*, i32** %7
%32 = load i32, i32* %9
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i32, i32* %31, i64 %33
%35 = call i32 @egress_reg_tbl_get(i32 %30, i32 320, i32* %34, i32 2)
%36 = load i32, i32* %9
%37 = add nsw i32 %36, 2
store i32 %37, i32* %9
br label %38
38: ; preds = %21
%39 = load i32, i32* %8
%40 = add nsw i32 %39, 1
store i32 %40, i32* %8
br label %18
41: ; preds = %18
store i32 0, i32* %4
br label %42
42: ; preds = %41, %16
%43 = load i32, i32* %4
ret i32 %43
}

LLVM IR (-O2):
%union.eg_table_cmd_u = type { i32 }
define i32 @eg_smib_table_sc_sa_get(i32 %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = icmp ugt i32 %1, 31
br i1 %6, label %41, label %7
7: ; preds = %3
%8 = shl nuw nsw i32 %1, 3
%9 = bitcast i32* %4 to %union.eg_table_cmd_u*
%10 = or i32 %8, 1073754112
store i32 %10, i32* %4
%11 = call i32 @eg_table_cmd_set(i32 %0, %union.eg_table_cmd_u* %9)
%12 = call i32 @egress_reg_tbl_get(i32 %0, i32 320, i32* %2, i32 2)
%13 = or i32 %8, 1073754113
store i32 %13, i32* %4
%14 = call i32 @eg_table_cmd_set(i32 %0, %union.eg_table_cmd_u* %9)
%15 = getelementptr inbounds i32, i32* %2, i64 2
%16 = call i32 @egress_reg_tbl_get(i32 %0, i32 320, i32* %15, i32 2)
%17 = or i32 %8, 1073754114
store i32 %17, i32* %4
%18 = call i32 @eg_table_cmd_set(i32 %0, %union.eg_table_cmd_u* %9)
%19 = getelementptr inbounds i32, i32* %2, i64 4
%20 = call i32 @egress_reg_tbl_get(i32 %0, i32 320, i32* %19, i32 2)
%21 = or i32 %8, 1073754115
store i32 %21, i32* %4
%22 = call i32 @eg_table_cmd_set(i32 %0, %union.eg_table_cmd_u* %9)
%23 = getelementptr inbounds i32, i32* %2, i64 6
%24 = call i32 @egress_reg_tbl_get(i32 %0, i32 320, i32* %23, i32 2)
%25 = or i32 %8, 1073754116
store i32 %25, i32* %4
%26 = call i32 @eg_table_cmd_set(i32 %0, %union.eg_table_cmd_u* %9)
%27 = getelementptr inbounds i32, i32* %2, i64 8
%28 = call i32 @egress_reg_tbl_get(i32 %0, i32 320, i32* %27, i32 2)
%29 = or i32 %8, 1073754117
store i32 %29, i32* %4
%30 = call i32 @eg_table_cmd_set(i32 %0, %union.eg_table_cmd_u* %9)
%31 = getelementptr inbounds i32, i32* %2, i64 10
%32 = call i32 @egress_reg_tbl_get(i32 %0, i32 320, i32* %31, i32 2)
%33 = or i32 %8, 1073754118
store i32 %33, i32* %4
%34 = call i32 @eg_table_cmd_set(i32 %0, %union.eg_table_cmd_u* %9)
%35 = getelementptr inbounds i32, i32* %2, i64 12
%36 = call i32 @egress_reg_tbl_get(i32 %0, i32 320, i32* %35, i32 2)
%37 = or i32 %8, 1073754119
store i32 %37, i32* %4
%38 = call i32 @eg_table_cmd_set(i32 %0, %union.eg_table_cmd_u* %9)
%39 = getelementptr inbounds i32, i32* %2, i64 14
%40 = call i32 @egress_reg_tbl_get(i32 %0, i32 320, i32* %39, i32 2)
br label %41
41: ; preds = %7, %3
%42 = phi i32 [ -1, %3 ], [ 0, %7 ]
ret i32 %42
}