#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*/ 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,
                                      int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
void test_index(void) {
  char ifname[16];
  char iaddr[32];
  char desc[64];
  unsigned short iport = 0;
  unsigned short eport = 0;
  int proto = 0;
  ifname[0] = '\0';
  iaddr[0] = '\0';
  if (get_redirect_rule_by_index(0, ifname, &eport, iaddr, sizeof(iaddr),
                                 &iport, &proto, desc, sizeof(desc), 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
sub    $0xa0,%rsp
movw   $0x0,-0x72(%rbp)
movw   $0x0,-0x74(%rbp)
movl   $0x0,-0x78(%rbp)
movb   $0x0,-0x10(%rbp)
movb   $0x0,-0x30(%rbp)
lea    -0x10(%rbp),%rsi
lea    -0x30(%rbp),%rcx
lea    -0x70(%rbp),%rax
xor    %edi,%edi
lea    -0x74(%rbp),%rdx
mov    $0x20,%r8d
lea    -0x72(%rbp),%r9
lea    -0x78(%rbp),%r10
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
movl   $0x40,0x10(%rsp)
movl   $0x0,0x18(%rsp)
movl   $0x0,0x20(%rsp)
call   1040 <get_redirect_rule_by_index@plt>
cmp    $0x0,%rax
jge    11a9 <test_index+0x89>
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11de <test_index+0xbe>
lea    -0x10(%rbp),%rsi
movzwl -0x74(%rbp),%edx
lea    -0x30(%rbp),%rcx
movzwl -0x72(%rbp),%r8d
mov    -0x78(%rbp),%r9d
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x70(%rbp),%rsi
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_index>:
sub    $0x88,%rsp
movw   $0x0,0xa(%rsp)
movw   $0x0,0x8(%rsp)
movl   $0x0,0xc(%rsp)
movb   $0x0,0x10(%rsp)
movb   $0x0,0x20(%rsp)
sub    $0x8,%rsp
lea    0x48(%rsp),%rax
lea    0x14(%rsp),%r10
lea    0x18(%rsp),%rsi
lea    0x10(%rsp),%rdx
lea    0x28(%rsp),%rcx
lea    0x12(%rsp),%r9
xor    %edi,%edi
mov    $0x20,%r8d
push   $0x0
push   $0x0
push   $0x40
push   %rax
push   %r10
call   1050 <get_redirect_rule_by_index@plt>
add    $0x30,%rsp
test   %rax,%rax
js     11db <test_index+0xab>
movzwl 0x8(%rsp),%edx
movzwl 0xa(%rsp),%r8d
mov    0xc(%rsp),%r9d
lea    0xe51(%rip),%rdi
lea    0x10(%rsp),%rsi
lea    0x20(%rsp),%rcx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe52(%rip),%rdi
lea    0x40(%rsp),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x88,%rsp
ret
lea    0xe4a(%rip),%rdi
call   1030 <puts@plt>
add    $0x88,%rsp
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 i16
%5 = alloca i16
%6 = alloca i32
store i16 0, i16* %4
store i16 0, i16* %5
store i32 0, i32* %6
%7 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 0
store i8 0, i8* %7
%8 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
store i8 0, i8* %8
%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 = call i64 @get_redirect_rule_by_index(i32 0, i8* %9, i16* %5, i8* %10, i32 32, i16* %4, i32* %6, i8* %11, i32 64, i32 0, i32 0)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %0
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %27
16: ; preds = %0
%17 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 0
%18 = load i16, i16* %5
%19 = zext i16 %18 to i32
%20 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%21 = load i16, i16* %4
%22 = zext i16 %21 to i32
%23 = load i32, i32* %6
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %17, i32 %19, i8* %20, i32 %22, i32 %23)
%25 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %25)
br label %27
27: ; preds = %16, %14
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 i16
%5 = alloca i16
%6 = alloca i32
%7 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 0
%8 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%9 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%10 = bitcast i16* %4 to i8*
store i16 0, i16* %4
%11 = bitcast i16* %5 to i8*
store i16 0, i16* %5
%12 = bitcast i32* %6 to i8*
store i32 0, i32* %6
store i8 0, i8* %7
store i8 0, i8* %8
%13 = call i64 @get_redirect_rule_by_index(i32 0, i8* %7, i16* %5, i8* %8, i32 32, i16* %4, i32* %6, i8* %9, i32 64, i32 0, i32 0)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %0
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
br label %25
17: ; preds = %0
%18 = load i16, i16* %5
%19 = zext i16 %18 to i32
%20 = load i16, i16* %4
%21 = zext i16 %20 to i32
%22 = load i32, i32* %6
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %7, i32 %19, i8* %8, i32 %21, i32 %22)
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %9)
br label %25
25: ; preds = %17, %15
ret void
}