#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 /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ free(unsigned short *);
unsigned short *get_portmappings_in_range(int /*<<< orphan*/, int,
                                          int /*<<< orphan*/, unsigned int *);
int /*<<< orphan*/ printf(char *, ...);
void list_eports_tcp(void) {
  unsigned short *port_list;
  unsigned int number = 0;
  unsigned int i;
  port_list = get_portmappings_in_range(0, 65535, IPPROTO_TCP, &number);
  printf("%u ports redirected (TCP) :", number);
  for (i = 0; i < number; i++) {
    printf(" %hu", port_list[i]);
  }
  printf("\n");
  free(port_list);
}


x86 assembly (clang, -O0):
<list_eports_tcp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0xc(%rbp)
mov    0x2ea2(%rip),%rax
mov    (%rax),%edx
xor    %edi,%edi
mov    $0xffff,%esi
lea    -0xc(%rbp),%rcx
call   1050 <get_portmappings_in_range@plt>
mov    %rax,-0x8(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    11a7 <list_eports_tcp+0x77>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
movzwl (%rax,%rcx,2),%esi
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1174 <list_eports_tcp+0x44>
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<list_eports_tcp>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
movl   $0x0,0xc(%rsp)
mov    0x2e90(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
xor    %edi,%edi
mov    $0xffff,%esi
call   1060 <get_portmappings_in_range@plt>
mov    %rax,%r15
mov    0xc(%rsp),%esi
lea    0xe87(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
cmpl   $0x0,0xc(%rsp)
je     11ac <list_eports_tcp+0x6c>
lea    0xe8e(%rip),%r14
xor    %ebx,%ebx
movzwl (%r15,%rbx,2),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
mov    0xc(%rsp),%eax
cmp    %rax,%rbx
jb     1190 <list_eports_tcp+0x50>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    %r15,%rdi
call   1030 <free@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@IPPROTO_TCP = global i32 0
@.str = [28 x i8] c"%u ports redirected (TCP) :\00"
@.str.1 = [5 x i8] c" %hu\00"
@.str.2 = [2 x i8] c"\0A\00"
define void @list_eports_tcp() {
%1 = alloca i16*
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %2
%4 = load i32, i32* @IPPROTO_TCP
%5 = call i16* @get_portmappings_in_range(i32 0, i32 65535, i32 %4, i32* %2)
store i16* %5, i16** %1
%6 = load i32, i32* %2
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %6)
store i32 0, i32* %3
br label %8
8: ; preds = %20, %0
%9 = load i32, i32* %3
%10 = load i32, i32* %2
%11 = icmp ult i32 %9, %10
br i1 %11, label %12, label %23
12: ; preds = %8
%13 = load i16*, i16** %1
%14 = load i32, i32* %3
%15 = zext i32 %14 to i64
%16 = getelementptr inbounds i16, i16* %13, i64 %15
%17 = load i16, i16* %16
%18 = zext i16 %17 to i32
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %18)
br label %20
20: ; preds = %12
%21 = load i32, i32* %3
%22 = add i32 %21, 1
store i32 %22, i32* %3
br label %8
23: ; preds = %8
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%25 = load i16*, i16** %1
%26 = call i32 @free(i16* %25)
ret void
}

LLVM IR (-O2):
@IPPROTO_TCP = global i32 0
@.str = [28 x i8] c"%u ports redirected (TCP) :\00"
@.str.1 = [5 x i8] c" %hu\00"
define void @list_eports_tcp() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%3 = load i32, i32* @IPPROTO_TCP
%4 = call i16* @get_portmappings_in_range(i32 0, i32 65535, i32 %3, i32* %1)
%5 = load i32, i32* %1
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = load i32, i32* %1
%8 = icmp eq i32 %7, 0
br i1 %8, label %19, label %9
9: ; preds = %0, %9
%10 = phi i64 [ %15, %9 ], [ 0, %0 ]
%11 = getelementptr inbounds i16, i16* %4, i64 %10
%12 = load i16, i16* %11
%13 = zext i16 %12 to i32
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = add nuw nsw i64 %10, 1
%16 = load i32, i32* %1
%17 = zext i32 %16 to i64
%18 = icmp ult i64 %15, %17
br i1 %18, label %9, label %19
19: ; preds = %9, %0
%20 = call i32 @putchar(i32 10)
%21 = call i32 @free(i16* %4)
ret void
}