#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 */
int upnp_get_redirection_infos_by_index(int, unsigned short *, char *,
                                        unsigned short *, char *, int, char *,
                                        int);
int upnp_get_portmapping_number_of_entries() {
  int n = 0, r = 0;
  unsigned short eport, iport;
  char protocol[4], iaddr[32], desc[64];
  do {
    protocol[0] = '\0';
    iaddr[0] = '\0';
    desc[0] = '\0';
    r = upnp_get_redirection_infos_by_index(n, &eport, protocol, &iport, iaddr,
                                            sizeof(iaddr), desc, sizeof(desc));
    n++;
  } while (r == 0);
  return (n - 1);
}


x86 assembly (clang, -O0):
<upnp_get_portmapping_number_of_entries>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movb   $0x0,-0x10(%rbp)
movb   $0x0,-0x30(%rbp)
movb   $0x0,-0x70(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x10(%rbp),%rdx
lea    -0x30(%rbp),%r8
lea    -0x70(%rbp),%rax
lea    -0xa(%rbp),%rsi
lea    -0xc(%rbp),%rcx
mov    $0x20,%r9d
mov    %rax,(%rsp)
movl   $0x40,0x8(%rsp)
call   1030 <upnp_get_redirection_infos_by_index@plt>
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1129 <upnp_get_portmapping_number_of_entries+0x19>
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<upnp_get_portmapping_number_of_entries>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    $0xffffffff,%ebx
lea    0x30(%rsp),%rbp
lea    0xa(%rsp),%r14
lea    0xc(%rsp),%r15
lea    0x8(%rsp),%r12
lea    0x10(%rsp),%r13
nopl   0x0(%rax)
add    $0x1,%ebx
movb   $0x0,0xc(%rsp)
movb   $0x0,0x10(%rsp)
movb   $0x0,0x30(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %r12,%rcx
mov    %r13,%r8
mov    $0x20,%r9d
push   $0x40
push   %rbp
call   1030 <upnp_get_redirection_infos_by_index@plt>
add    $0x10,%rsp
test   %eax,%eax
je     1140 <upnp_get_portmapping_number_of_entries+0x30>
mov    %ebx,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @upnp_get_portmapping_number_of_entries() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i16
%4 = alloca i16
%5 = alloca [4 x i8]
%6 = alloca [32 x i8]
%7 = alloca [64 x i8]
store i32 0, i32* %1
store i32 0, i32* %2
br label %8
8: ; preds = %19, %0
%9 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
store i8 0, i8* %9
%10 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
store i8 0, i8* %10
%11 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
store i8 0, i8* %11
%12 = load i32, i32* %1
%13 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
%14 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%15 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%16 = call i32 @upnp_get_redirection_infos_by_index(i32 %12, i16* %3, i8* %13, i16* %4, i8* %14, i32 32, i8* %15, i32 64)
store i32 %16, i32* %2
%17 = load i32, i32* %1
%18 = add nsw i32 %17, 1
store i32 %18, i32* %1
br label %19
19: ; preds = %8
%20 = load i32, i32* %2
%21 = icmp eq i32 %20, 0
br i1 %21, label %8, label %22
22: ; preds = %19
%23 = load i32, i32* %1
%24 = sub nsw i32 %23, 1
ret i32 %24
}

LLVM IR (-O2):
define i32 @upnp_get_portmapping_number_of_entries() {
%1 = alloca i16
%2 = alloca i16
%3 = alloca [4 x i8]
%4 = alloca [32 x i8]
%5 = alloca [64 x i8]
%6 = bitcast i16* %1 to i8*
%7 = bitcast i16* %2 to i8*
%8 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%9 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%10 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
br label %11
11: ; preds = %11, %0
%12 = phi i32 [ 0, %0 ], [ %14, %11 ]
store i8 0, i8* %8
store i8 0, i8* %9
store i8 0, i8* %10
%13 = call i32 @upnp_get_redirection_infos_by_index(i32 %12, i16* %1, i8* %8, i16* %2, i8* %9, i32 32, i8* %10, i32 64)
%14 = add nuw nsw i32 %12, 1
%15 = icmp eq i32 %13, 0
br i1 %15, label %11, label %16
16: ; preds = %11
ret i32 %12
}