#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 /*<<< orphan*/ rhost;
typedef int /*<<< orphan*/ iaddr;
typedef int /*<<< orphan*/ desc;

/* Variables and functions */
scalar_t__ get_redirect_rule_by_index(int /*<<< orphan*/, char *,
                                      unsigned short *, char *, int,
                                      unsigned short *, int *, char *, int,
                                      char *, int, unsigned int *,
                                      int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
void test_index(void) {
  char ifname[16];
  char iaddr[32];
  char desc[64];
  char rhost[32];
  unsigned short iport = 0;
  unsigned short eport = 0;
  int proto = 0;
  unsigned int timestamp;
  ifname[0] = '\0';
  iaddr[0] = '\0';
  rhost[0] = '\0';
  if (get_redirect_rule_by_index(0, ifname, &eport, iaddr, sizeof(iaddr),
                                 &iport, &proto, desc, sizeof(desc), rhost,
                                 sizeof(rhost), &timestamp, 0, 0) < 0) {
    printf("get.._by_index : no rule\n");
  } else {
    printf("%s %u -> %s:%u proto %d\n", ifname, (unsigned int)eport, iaddr,
           (unsigned int)iport, proto);
    printf("description: \"%s\"\n", desc);
  }
}


x86 assembly (clang, -O0):
<test_index>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
sub    $0xe8,%rsp
movw   $0x0,-0xa2(%rbp)
movw   $0x0,-0xa4(%rbp)
movl   $0x0,-0xa8(%rbp)
movb   $0x0,-0x20(%rbp)
movb   $0x0,-0x40(%rbp)
movb   $0x0,-0xa0(%rbp)
lea    -0x20(%rbp),%rsi
lea    -0x40(%rbp),%rcx
lea    -0x80(%rbp),%r11
lea    -0xa0(%rbp),%r10
xor    %edi,%edi
lea    -0xa4(%rbp),%rdx
mov    $0x20,%r8d
lea    -0xa2(%rbp),%r9
lea    -0xa8(%rbp),%rbx
lea    -0xac(%rbp),%rax
mov    %rbx,(%rsp)
mov    %r11,0x8(%rsp)
movl   $0x40,0x10(%rsp)
mov    %r10,0x18(%rsp)
movl   $0x20,0x20(%rsp)
mov    %rax,0x28(%rsp)
movl   $0x0,0x30(%rsp)
movl   $0x0,0x38(%rsp)
call   1040 <get_redirect_rule_by_index@plt>
cmp    $0x0,%rax
jge    11e3 <test_index+0xc3>
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1221 <test_index+0x101>
lea    -0x20(%rbp),%rsi
movzwl -0xa4(%rbp),%edx
lea    -0x40(%rbp),%rcx
movzwl -0xa2(%rbp),%r8d
ff
mov    -0xa8(%rbp),%r9d
lea    0xe12(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x80(%rbp),%rsi
lea    0xe19(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0xe8,%rsp
pop    %rbx
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_index>:
push   %rbx
sub    $0xa0,%rsp
movw   $0x0,0x6(%rsp)
movw   $0x0,0x4(%rsp)
movl   $0x0,0x8(%rsp)
movb   $0x0,0x10(%rsp)
movb   $0x0,0x20(%rsp)
movb   $0x0,0x40(%rsp)
lea    0xc(%rsp),%rax
lea    0x40(%rsp),%r10
lea    0x60(%rsp),%r11
lea    0x8(%rsp),%rbx
lea    0x10(%rsp),%rsi
lea    0x4(%rsp),%rdx
lea    0x20(%rsp),%rcx
lea    0x6(%rsp),%r9
xor    %edi,%edi
mov    $0x20,%r8d
push   $0x0
push   $0x0
push   %rax
push   $0x20
push   %r10
push   $0x40
push   %r11
push   %rbx
call   1050 <get_redirect_rule_by_index@plt>
add    $0x40,%rsp
test   %rax,%rax
js     11e6 <test_index+0xb6>
movzwl 0x4(%rsp),%edx
movzwl 0x6(%rsp),%r8d
mov    0x8(%rsp),%r9d
lea    0xe40(%rip),%rdi
lea    0x10(%rsp),%rsi
lea    0x20(%rsp),%rcx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe41(%rip),%rdi
lea    0x60(%rsp),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11f2 <test_index+0xc2>
lea    0xe3f(%rip),%rdi
call   1030 <puts@plt>
add    $0xa0,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [26 x i8] c"get.._by_index : no rule\0A\00"
@.str.1 = [25 x i8] c"%s %u -> %s:%u proto %d\0A\00"
@.str.2 = [19 x i8] c"description: \22%s\22\0A\00"
define void @test_index() {
%1 = alloca [16 x i8]
%2 = alloca [32 x i8]
%3 = alloca [64 x i8]
%4 = alloca [32 x i8]
%5 = alloca i16
%6 = alloca i16
%7 = alloca i32
%8 = alloca i32
store i16 0, i16* %5
store i16 0, i16* %6
store i32 0, i32* %7
%9 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 0
store i8 0, i8* %9
%10 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
store i8 0, i8* %10
%11 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
store i8 0, i8* %11
%12 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 0
%13 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%14 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%15 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%16 = call i64 @get_redirect_rule_by_index(i32 0, i8* %12, i16* %6, i8* %13, i32 32, i16* %5, i32* %7, i8* %14, i32 64, i8* %15, i32 32, i32* %8, i32 0, i32 0)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %0
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %31
20: ; preds = %0
%21 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 0
%22 = load i16, i16* %6
%23 = zext i16 %22 to i32
%24 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%25 = load i16, i16* %5
%26 = zext i16 %25 to i32
%27 = load i32, i32* %7
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %21, i32 %23, i8* %24, i32 %26, i32 %27)
%29 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %29)
br label %31
31: ; preds = %20, %18
ret void
}

LLVM IR (-O2):
@.str.1 = [25 x i8] c"%s %u -> %s:%u proto %d\0A\00"
@.str.2 = [19 x i8] c"description: \22%s\22\0A\00"
@str = [25 x i8] c"get.._by_index : no rule\00"
define void @test_index() {
%1 = alloca [16 x i8]
%2 = alloca [32 x i8]
%3 = alloca [64 x i8]
%4 = alloca [32 x i8]
%5 = alloca i16
%6 = alloca i16
%7 = alloca i32
%8 = alloca i32
%9 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 0
%10 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%11 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%12 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%13 = bitcast i16* %5 to i8*
store i16 0, i16* %5
%14 = bitcast i16* %6 to i8*
store i16 0, i16* %6
%15 = bitcast i32* %7 to i8*
store i32 0, i32* %7
%16 = bitcast i32* %8 to i8*
store i8 0, i8* %9
store i8 0, i8* %10
store i8 0, i8* %12
%17 = call i64 @get_redirect_rule_by_index(i32 0, i8* %9, i16* %6, i8* %10, i32 32, i16* %5, i32* %7, i8* %11, i32 64, i8* %12, i32 32, i32* %8, i32 0, i32 0)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %0
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
br label %29
21: ; preds = %0
%22 = load i16, i16* %6
%23 = zext i16 %22 to i32
%24 = load i16, i16* %5
%25 = zext i16 %24 to i32
%26 = load i32, i32* %7
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %9, i32 %23, i8* %10, i32 %25, i32 %26)
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %11)
br label %29
29: ; preds = %21, %19
ret void
}