#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 */

/* Variables and functions */
int IPPROTO_TCP;
scalar_t__ get_redirect_rule_by_index(int, int /*<<< orphan*/, unsigned short *,
                                      char *, int, unsigned short *, int *,
                                      char *, int, int /*<<< orphan*/,
                                      int /*<<< orphan*/);
int /*<<< orphan*/ memcpy(char *, char *, int);
int upnp_get_redirection_infos_by_index(int index, unsigned short *eport,
                                        char *protocol, unsigned short *iport,
                                        char *iaddr, int iaddrlen, char *desc,
                                        int desclen) {
  int proto = 0;
  if (desc && (desclen > 0))
    desc[0] = '\0';
  if (get_redirect_rule_by_index(index, 0, eport, iaddr, iaddrlen, iport,
                                 &proto, desc, desclen, 0, 0) < 0)
    return -1;
  else {
    if (proto == IPPROTO_TCP)
      memcpy(protocol, "TCP", 4);
    else
      memcpy(protocol, "UDP", 4);
    return 0;
  }
}


x86 assembly (clang, -O0):
<upnp_get_redirection_infos_by_index>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%rax
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
cmpq   $0x0,0x10(%rbp)
je     1169 <upnp_get_redirection_infos_by_index+0x49>
cmpl   $0x0,0x18(%rbp)
jle    1169 <upnp_get_redirection_infos_by_index+0x49>
mov    0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x2c(%rbp),%r8d
mov    -0x20(%rbp),%r9
mov    0x10(%rbp),%r10
mov    0x18(%rbp),%eax
xor    %esi,%esi
lea    -0x30(%rbp),%r11
mov    %r11,(%rsp)
mov    %r10,0x8(%rsp)
mov    %eax,0x10(%rsp)
movl   $0x0,0x18(%rsp)
movl   $0x0,0x20(%rsp)
call   1040 <get_redirect_rule_by_index@plt>
cmp    $0x0,%rax
jge    11c1 <upnp_get_redirection_infos_by_index+0xa1>
movl   $0xffffffff,-0x4(%rbp)
jmp    1209 <upnp_get_redirection_infos_by_index+0xe9>
mov    -0x30(%rbp),%eax
mov    0x2e1d(%rip),%rcx
cmp    (%rcx),%eax
jne    11ed <upnp_get_redirection_infos_by_index+0xcd>
mov    -0x18(%rbp),%rdi
lea    0xe22(%rip),%rsi
mov    $0x4,%edx
call   1030 <memcpy@plt>
jmp    1202 <upnp_get_redirection_infos_by_index+0xe2>
mov    -0x18(%rbp),%rdi
lea    0xe0c(%rip),%rsi
mov    $0x4,%edx
call   1030 <memcpy@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<upnp_get_redirection_infos_by_index>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rcx,%rax
mov    %rdx,%r14
mov    %rsi,%rdx
mov    0x38(%rsp),%r10d
mov    0x30(%rsp),%rbx
movl   $0x0,0xc(%rsp)
test   %rbx,%rbx
je     1150 <upnp_get_redirection_infos_by_index+0x30>
test   %r10d,%r10d
jle    1150 <upnp_get_redirection_infos_by_index+0x30>
movb   $0x0,(%rbx)
sub    $0x8,%rsp
lea    0x14(%rsp),%r11
xor    %ebp,%ebp
xor    %esi,%esi
mov    %r8,%rcx
mov    %r9d,%r8d
mov    %rax,%r9
push   $0x0
push   $0x0
push   %r10
push   %rbx
push   %r11
call   1040 <get_redirect_rule_by_index@plt>
add    $0x30,%rsp
test   %rax,%rax
js     11ab <upnp_get_redirection_infos_by_index+0x8b>
mov    0xc(%rsp),%eax
mov    0x2e60(%rip),%rcx
cmp    (%rcx),%eax
lea    0xe6f(%rip),%rax
lea    0xe6c(%rip),%rsi
cmove  %rax,%rsi
mov    %r14,%rdi
mov    $0x4,%edx
call   1030 <memcpy@plt>
jmp    11b0 <upnp_get_redirection_infos_by_index+0x90>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@IPPROTO_TCP = global i32 0
@.str = [4 x i8] c"TCP\00"
@.str.1 = [4 x i8] c"UDP\00"
define i32 @upnp_get_redirection_infos_by_index(i32 %0, i16* %1, i8* %2, i16* %3, i8* %4, i32 %5, i8* %6, i32 %7) {
%9 = alloca i32
%10 = alloca i32
%11 = alloca i16*
%12 = alloca i8*
%13 = alloca i16*
%14 = alloca i8*
%15 = alloca i32
%16 = alloca i8*
%17 = alloca i32
%18 = alloca i32
store i32 %0, i32* %10
store i16* %1, i16** %11
store i8* %2, i8** %12
store i16* %3, i16** %13
store i8* %4, i8** %14
store i32 %5, i32* %15
store i8* %6, i8** %16
store i32 %7, i32* %17
store i32 0, i32* %18
%19 = load i8*, i8** %16
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %27
21: ; preds = %8
%22 = load i32, i32* %17
%23 = icmp sgt i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = load i8*, i8** %16
%26 = getelementptr inbounds i8, i8* %25, i64 0
store i8 0, i8* %26
br label %27
27: ; preds = %24, %21, %8
%28 = load i32, i32* %10
%29 = load i16*, i16** %11
%30 = load i8*, i8** %14
%31 = load i32, i32* %15
%32 = load i16*, i16** %13
%33 = load i8*, i8** %16
%34 = load i32, i32* %17
%35 = call i64 @get_redirect_rule_by_index(i32 %28, i32 0, i16* %29, i8* %30, i32 %31, i16* %32, i32* %18, i8* %33, i32 %34, i32 0, i32 0)
%36 = icmp slt i64 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %27
store i32 -1, i32* %9
br label %49
38: ; preds = %27
%39 = load i32, i32* %18
%40 = load i32, i32* @IPPROTO_TCP
%41 = icmp eq i32 %39, %40
br i1 %41, label %42, label %45
42: ; preds = %38
%43 = load i8*, i8** %12
%44 = call i32 @memcpy(i8* %43, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 4)
br label %48
45: ; preds = %38
%46 = load i8*, i8** %12
%47 = call i32 @memcpy(i8* %46, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 4)
br label %48
48: ; preds = %45, %42
store i32 0, i32* %9
br label %49
49: ; preds = %48, %37
%50 = load i32, i32* %9
ret i32 %50
}

LLVM IR (-O2):
@IPPROTO_TCP = global i32 0
@.str = [4 x i8] c"TCP\00"
@.str.1 = [4 x i8] c"UDP\00"
define i32 @upnp_get_redirection_infos_by_index(i32 %0, i16* %1, i8* %2, i16* %3, i8* %4, i32 %5, i8* %6, i32 %7) {
%9 = alloca i32
%10 = bitcast i32* %9 to i8*
store i32 0, i32* %9
%11 = icmp ne i8* %6, null
%12 = icmp sgt i32 %7, 0
%13 = and i1 %11, %12
br i1 %13, label %14, label %15
14: ; preds = %8
store i8 0, i8* %6
br label %15
15: ; preds = %14, %8
%16 = call i64 @get_redirect_rule_by_index(i32 %0, i32 0, i16* %1, i8* %4, i32 %5, i16* %3, i32* %9, i8* %6, i32 %7, i32 0, i32 0)
%17 = icmp slt i64 %16, 0
br i1 %17, label %24, label %18
18: ; preds = %15
%19 = load i32, i32* %9
%20 = load i32, i32* @IPPROTO_TCP
%21 = icmp eq i32 %19, %20
%22 = select i1 %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0)
%23 = call i32 @memcpy(i8* %2, i8* %22, i32 4)
br label %24
24: ; preds = %18, %15
%25 = phi i32 [ -1, %15 ], [ 0, %18 ]
ret i32 %25
}