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

/* Variables and functions */
int /*<<< orphan*/ ig_table_cmd_set(unsigned int, union ig_table_cmd_u *);
int /*<<< orphan*/ ingress_reg_tbl_get(unsigned int, int, unsigned int *, int);
int ig_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 < 12; i++) {
    cmd = (0x1 << 30) | (6 << 12) | ((index * 12) + i);
    ig_table_cmd_set(dev_id, (union ig_table_cmd_u *)&cmd);
    ingress_reg_tbl_get(dev_id, 0x140, (pentry + entry_offset), 2);
    entry_offset += 2;
  }
  return 0;
}


x86 assembly (clang, -O0):
<ig_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 <ig_smib_table_sc_sa_get+0x34>
cmpl   $0x1f,-0xc(%rbp)
jbe    1160 <ig_smib_table_sc_sa_get+0x40>
movl   $0xffffffff,-0x4(%rbp)
jmp    11cb <ig_smib_table_sc_sa_get+0xab>
movl   $0x0,-0x1c(%rbp)
cmpl   $0xc,-0x1c(%rbp)
jge    11c4 <ig_smib_table_sc_sa_get+0xa4>
imul   $0xc,-0xc(%rbp),%eax
add    -0x1c(%rbp),%eax
or     $0x40006000,%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x24(%rbp),%rsi
call   1030 <ig_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 <ingress_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 <ig_smib_table_sc_sa_get+0x47>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ig_smib_table_sc_sa_get>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0xffffffff,%r14d
cmp    $0x1f,%esi
ja     1189 <ig_smib_table_sc_sa_get+0x69>
mov    %rdx,%rbx
mov    %edi,%r13d
shl    $0x2,%esi
lea    (%rsi,%rsi,2),%r12d
xor    %r14d,%r14d
lea    0x4(%rsp),%r15
xor    %ebp,%ebp
nopl   (%rax)
lea    (%r12,%rbp,1),%eax
or     $0x40006000,%eax
mov    %eax,0x4(%rsp)
mov    %r13d,%edi
mov    %r15,%rsi
call   1030 <ig_table_cmd_set@plt>
mov    %r13d,%edi
mov    $0x140,%esi
mov    %rbx,%rdx
mov    $0x2,%ecx
call   1040 <ingress_reg_tbl_get@plt>
add    $0x1,%ebp
add    $0x8,%rbx
cmp    $0xc,%ebp
jne    1150 <ig_smib_table_sc_sa_get+0x30>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%union.ig_table_cmd_u = type { i32 }
define i32 @ig_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, 12
br i1 %20, label %21, label %41
21: ; preds = %18
%22 = load i32, i32* %6
%23 = mul i32 %22, 12
%24 = load i32, i32* %8
%25 = add i32 %23, %24
%26 = or i32 1073766400, %25
store i32 %26, i32* %10
%27 = load i32, i32* %5
%28 = bitcast i32* %10 to %union.ig_table_cmd_u*
%29 = call i32 @ig_table_cmd_set(i32 %27, %union.ig_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 @ingress_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.ig_table_cmd_u = type { i32 }
define i32 @ig_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 %21, label %7
7: ; preds = %3
%8 = mul nuw nsw i32 %1, 12
%9 = bitcast i32* %4 to %union.ig_table_cmd_u*
br label %10
10: ; preds = %7, %10
%11 = phi i64 [ 0, %7 ], [ %18, %10 ]
%12 = phi i32 [ 0, %7 ], [ %19, %10 ]
%13 = add i32 %12, %8
%14 = or i32 %13, 1073766400
store i32 %14, i32* %4
%15 = call i32 @ig_table_cmd_set(i32 %0, %union.ig_table_cmd_u* %9)
%16 = getelementptr inbounds i32, i32* %2, i64 %11
%17 = call i32 @ingress_reg_tbl_get(i32 %0, i32 320, i32* %16, i32 2)
%18 = add nuw nsw i64 %11, 2
%19 = add nuw nsw i32 %12, 1
%20 = icmp eq i32 %19, 12
br i1 %20, label %21, label %10
21: ; preds = %10, %3
%22 = phi i32 [ -1, %3 ], [ 0, %10 ]
ret i32 %22
}