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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
unsigned short *get_ports(int, int *);
unsigned short htons(unsigned short);
unsigned short *malloc(int);
int /*<<< orphan*/ memcpy(unsigned short *, unsigned short *, int);
int sscanf(char *, char *, unsigned short *);
char *strchr(char *, char);
scalar_t__ strncmp(char *, char *, int);
unsigned short *tcp_listen_ports(int *SIZE) {
  unsigned short *p, *ports, *q;
  char buf[512];
  FILE *fp;
  int size;
  char *s;
  ports = get_ports(1, &size);
  fp = fopen("/proc/net/tcp6", "r");
  if (fp == NULL) {
    *SIZE = size;
    return ports;
  }
  p = ports + size / sizeof(unsigned short);
  if (size < 32)
    size = 32;
  while (fgets(buf, 512, fp) != NULL) {
    s = strchr(buf, ':');
    if (s++ == NULL)
      continue;
    while (*s == ' ' || *s == '\t')
      s++;
    if (strncmp(s, "00000000000000000000000001000000", 32) == 0)
      continue;
    s = strchr(s, ':');
    if (s++ == NULL)
      continue;
    if (sscanf(s, "%hx", p) != 1)
      continue;
    *p = htons(*p);
    s = strchr(s, ' ');
    if (s++ == NULL)
      continue;
    while (*s == ' ' || *s == '\t')
      s++;
    if (strncmp(s, "00000000000000000000000000000000:0000", 37))
      continue;
    for (q = ports; q < p; q++)
      if (*q == *p)
        break;
    if (q != p)
      continue;
    if (p++ - ports > size / sizeof(short)) {
      p = malloc(size * 2 + sizeof(short));
      memcpy(p, ports, size);
      p = ports + size;
      size *= 2;
      if (size > 128)
        break;
    }
  }
  *p++ = 0;
  *SIZE = (char *)p - (char *)ports;
  fclose(fp);
  return ports;
}


x86 assembly (clang, -O0):
<tcp_listen_ports>:
push   %rbp
mov    %rsp,%rbp
sub    $0x250,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x1,%edi
lea    -0x23c(%rbp),%rsi
call   1070 <get_ports@plt>
mov    %rax,-0x20(%rbp)
lea    0xe35(%rip),%rdi
lea    0xe3d(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x238(%rbp)
cmpq   $0x0,-0x238(%rbp)
jne    1205 <tcp_listen_ports+0x65>
mov    -0x23c(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    158e <tcp_listen_ports+0x3ee>
mov    -0x20(%rbp),%rax
movslq -0x23c(%rbp),%rcx
shr    $0x1,%rcx
shl    $0x1,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x20,-0x23c(%rbp)
jge    1236 <tcp_listen_ports+0x96>
movl   $0x20,-0x23c(%rbp)
jmp    123b <tcp_listen_ports+0x9b>
lea    -0x230(%rbp),%rdi
mov    -0x238(%rbp),%rdx
mov    $0x200,%esi
call   1080 <fgets@plt>
cmp    $0x0,%rax
je     1553 <tcp_listen_ports+0x3b3>
lea    -0x230(%rbp),%rdi
mov    $0x3a,%esi
call   1060 <strchr@plt>
mov    %rax,-0x248(%rbp)
mov    -0x248(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x248(%rbp)
cmp    $0x0,%rax
jne    1299 <tcp_listen_ports+0xf9>
jmp    123b <tcp_listen_ports+0x9b>
jmp    129e <tcp_listen_ports+0xfe>
mov    -0x248(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0x20,%ecx
mov    %al,-0x249(%rbp)
je     12cf <tcp_listen_ports+0x12f>
mov    -0x248(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x9,%eax
sete   %al
mov    %al,-0x249(%rbp)
mov    -0x249(%rbp),%al
test   $0x1,%al
jne    12e2 <tcp_listen_ports+0x142>
jmp    12f9 <tcp_listen_ports+0x159>
mov    -0x248(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x248(%rbp)
jmp    129e <tcp_listen_ports+0xfe>
mov    -0x248(%rbp),%rdi
lea    0xd0a(%rip),%rsi
mov    $0x20,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1320 <tcp_listen_ports+0x180>
jmp    123b <tcp_listen_ports+0x9b>
mov    -0x248(%rbp),%rdi
mov    $0x3a,%esi
call   1060 <strchr@plt>
mov    %rax,-0x248(%rbp)
mov    -0x248(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x248(%rbp)
cmp    $0x0,%rax
jne    135c <tcp_listen_ports+0x1bc>
jmp    123b <tcp_listen_ports+0x9b>
mov    -0x248(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xcc4(%rip),%rsi
call   10b0 <sscanf@plt>
cmp    $0x1,%eax
je     1381 <tcp_listen_ports+0x1e1>
jmp    123b <tcp_listen_ports+0x9b>
mov    -0x18(%rbp),%rax
movzwl (%rax),%edi
call   1050 <htons@plt>
mov    %ax,%cx
mov    -0x18(%rbp),%rax
mov    %cx,(%rax)
mov    -0x248(%rbp),%rdi
mov    $0x20,%esi
call   1060 <strchr@plt>
mov    %rax,-0x248(%rbp)
mov    -0x248(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x248(%rbp)
cmp    $0x0,%rax
jne    13d3 <tcp_listen_ports+0x233>
jmp    123b <tcp_listen_ports+0x9b>
jmp    13d8 <tcp_listen_ports+0x238>
mov    -0x248(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0x20,%ecx
mov    %al,-0x24a(%rbp)
je     1409 <tcp_listen_ports+0x269>
mov    -0x248(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x9,%eax
sete   %al
mov    %al,-0x24a(%rbp)
mov    -0x24a(%rbp),%al
test   $0x1,%al
jne    141c <tcp_listen_ports+0x27c>
jmp    1433 <tcp_listen_ports+0x293>
mov    -0x248(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x248(%rbp)
jmp    13d8 <tcp_listen_ports+0x238>
mov    -0x248(%rbp),%rdi
lea    0xbf5(%rip),%rsi
mov    $0x25,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     145a <tcp_listen_ports+0x2ba>
jmp    123b <tcp_listen_ports+0x9b>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    14a1 <tcp_listen_ports+0x301>
mov    -0x28(%rbp),%rax
movzwl (%rax),%eax
mov    -0x18(%rbp),%rcx
movzwl (%rcx),%ecx
cmp    %ecx,%eax
jne    148b <tcp_listen_ports+0x2eb>
jmp    14a1 <tcp_listen_ports+0x301>
jmp    1490 <tcp_listen_ports+0x2f0>
mov    -0x28(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x28(%rbp)
jmp    1462 <tcp_listen_ports+0x2c2>
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
je     14b4 <tcp_listen_ports+0x314>
jmp    123b <tcp_listen_ports+0x9b>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x2,%rcx
mov    %rcx,-0x18(%rbp)
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
sar    $0x1,%rax
movslq -0x23c(%rbp),%rcx
shr    $0x1,%rcx
cmp    %rcx,%rax
jbe    154e <tcp_listen_ports+0x3ae>
mov    -0x23c(%rbp),%eax
shl    $0x1,%eax
cltq
add    $0x2,%rax
mov    %eax,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x23c(%rbp),%edx
call   1090 <memcpy@plt>
mov    -0x20(%rbp),%rax
movslq -0x23c(%rbp),%rcx
shl    $0x1,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x23c(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x23c(%rbp)
cmpl   $0x80,-0x23c(%rbp)
jle    1549 <tcp_listen_ports+0x3a9>
jmp    1553 <tcp_listen_ports+0x3b3>
jmp    154e <tcp_listen_ports+0x3ae>
jmp    123b <tcp_listen_ports+0x9b>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x2,%rcx
mov    %rcx,-0x18(%rbp)
movw   $0x0,(%rax)
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x238(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x250,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tcp_listen_ports>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x228,%rsp
mov    %rdi,%rbx
lea    0xc(%rsp),%rsi
mov    $0x1,%edi
call   1070 <get_ports@plt>
mov    %rax,%rbp
lea    0xe33(%rip),%rdi
lea    0xe3b(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,%r12
mov    0xc(%rsp),%eax
test   %r12,%r12
je     1231 <tcp_listen_ports+0x91>
mov    %rbx,0x18(%rsp)
cltq
mov    %rax,%rbx
and    $0xfffffffffffffffe,%rbx
cmp    $0x1f,%eax
jg     1200 <tcp_listen_ports+0x60>
movl   $0x20,0xc(%rsp)
mov    %rbp,0x10(%rsp)
add    %rbp,%rbx
lea    0x20(%rsp),%rdi
mov    $0x200,%esi
mov    %r12,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     13c0 <tcp_listen_ports+0x220>
lea    0x20(%rsp),%r13
lea    0xde2(%rip),%r15
jmp    1269 <tcp_listen_ports+0xc9>
mov    %eax,(%rbx)
jmp    13de <tcp_listen_ports+0x23e>
cmp    %rbx,%rax
je     1367 <tcp_listen_ports+0x1c7>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    $0x200,%esi
mov    %r12,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     13c0 <tcp_listen_ports+0x220>
mov    %r13,%rdi
mov    $0x3a,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     1250 <tcp_listen_ports+0xb0>
mov    %rax,%r14
xchg   %ax,%ax
add    $0x1,%r14
movzbl (%r14),%eax
cmp    $0x20,%al
je     1280 <tcp_listen_ports+0xe0>
cmp    $0x9,%al
je     1280 <tcp_listen_ports+0xe0>
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0x20,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1250 <tcp_listen_ports+0xb0>
mov    %r14,%rdi
mov    $0x3a,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     1250 <tcp_listen_ports+0xb0>
mov    %rax,%rbp
add    $0x1,%rbp
mov    %rbp,%rdi
lea    0xd6a(%rip),%rsi
mov    %rbx,%rdx
call   10b0 <sscanf@plt>
cmp    $0x1,%eax
jne    1250 <tcp_listen_ports+0xb0>
movzwl (%rbx),%edi
call   1050 <htons@plt>
mov    %ax,(%rbx)
mov    %rbp,%rdi
mov    $0x20,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     1250 <tcp_listen_ports+0xb0>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rax
movzbl (%rax),%ecx
cmp    $0x20,%cl
je     1300 <tcp_listen_ports+0x160>
cmp    $0x9,%cl
je     1300 <tcp_listen_ports+0x160>
mov    %rax,%rdi
lea    0xd1b(%rip),%rsi
mov    $0x25,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    1250 <tcp_listen_ports+0xb0>
mov    0x10(%rsp),%rcx
mov    %rcx,%rax
cmp    %rbx,%rcx
jae    1238 <tcp_listen_ports+0x98>
movzwl (%rbx),%ecx
mov    0x10(%rsp),%rax
nopw   0x0(%rax,%rax,1)
cmp    %cx,(%rax)
je     1238 <tcp_listen_ports+0x98>
add    $0x2,%rax
cmp    %rbx,%rax
jb     1350 <tcp_listen_ports+0x1b0>
jmp    1238 <tcp_listen_ports+0x98>
mov    %rbx,%rax
mov    0x10(%rsp),%r14
sub    %r14,%rax
sar    %rax
movslq 0xc(%rsp),%rbp
mov    %rbp,%rcx
shr    %rcx
cmp    %rcx,%rax
jbe    13b7 <tcp_listen_ports+0x217>
lea    0x2(%rbp,%rbp,1),%edi
call   10a0 <malloc@plt>
mov    %rax,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1090 <memcpy@plt>
movslq 0xc(%rsp),%rax
lea    (%rax,%rax,1),%ecx
lea    (%r14,%rax,2),%rbx
mov    %ecx,0xc(%rsp)
cmp    $0x40,%rax
jle    1250 <tcp_listen_ports+0xb0>
jmp    13c0 <tcp_listen_ports+0x220>
add    $0x2,%rbx
jmp    1250 <tcp_listen_ports+0xb0>
movw   $0x0,(%rbx)
mov    0x10(%rsp),%rbp
sub    %ebp,%ebx
add    $0x2,%ebx
mov    0x18(%rsp),%rax
mov    %ebx,(%rax)
mov    %r12,%rdi
call   1040 <fclose@plt>
mov    %rbp,%rax
add    $0x228,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"/proc/net/tcp6\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [33 x i8] c"00000000000000000000000001000000\00"
@.str.3 = [4 x i8] c"%hx\00"
@.str.4 = [38 x i8] c"00000000000000000000000000000000:0000\00"
define i16* @tcp_listen_ports(i32* %0) {
%2 = alloca i16*
%3 = alloca i32*
%4 = alloca i16*
%5 = alloca i16*
%6 = alloca i16*
%7 = alloca [512 x i8]
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i8*
store i32* %0, i32** %3
%11 = call i16* @get_ports(i32 1, i32* %9)
store i16* %11, i16** %5
%12 = call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %12, i32** %8
%13 = load i32*, i32** %8
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %19
15: ; preds = %1
%16 = load i32, i32* %9
%17 = load i32*, i32** %3
store i32 %16, i32* %17
%18 = load i16*, i16** %5
store i16* %18, i16** %2
br label %180
19: ; preds = %1
%20 = load i16*, i16** %5
%21 = load i32, i32* %9
%22 = sext i32 %21 to i64
%23 = udiv i64 %22, 2
%24 = getelementptr inbounds i16, i16* %20, i64 %23
store i16* %24, i16** %4
%25 = load i32, i32* %9
%26 = icmp slt i32 %25, 32
br i1 %26, label %27, label %28
27: ; preds = %19
store i32 32, i32* %9
br label %28
28: ; preds = %27, %19
br label %29
29: ; preds = %164, %130, %106, %85, %74, %68, %61, %40, %28
%30 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%31 = load i32*, i32** %8
%32 = call i32* @fgets(i8* %30, i32 512, i32* %31)
%33 = icmp ne i32* %32, null
br i1 %33, label %34, label %165
34: ; preds = %29
%35 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%36 = call i8* @strchr(i8* %35, i8 signext 58)
store i8* %36, i8** %10
%37 = load i8*, i8** %10
%38 = getelementptr inbounds i8, i8* %37, i32 1
store i8* %38, i8** %10
%39 = icmp eq i8* %37, null
br i1 %39, label %40, label %41
40: ; preds = %34
br label %29
41: ; preds = %34
br label %42
42: ; preds = %54, %41
%43 = load i8*, i8** %10
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = icmp eq i32 %45, 32
br i1 %46, label %52, label %47
47: ; preds = %42
%48 = load i8*, i8** %10
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = icmp eq i32 %50, 9
br label %52
52: ; preds = %47, %42
%53 = phi i1 [ true, %42 ], [ %51, %47 ]
br i1 %53, label %54, label %57
54: ; preds = %52
%55 = load i8*, i8** %10
%56 = getelementptr inbounds i8, i8* %55, i32 1
store i8* %56, i8** %10
br label %42
57: ; preds = %52
%58 = load i8*, i8** %10
%59 = call i64 @strncmp(i8* %58, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 32)
%60 = icmp eq i64 %59, 0
br i1 %60, label %61, label %62
61: ; preds = %57
br label %29
62: ; preds = %57
%63 = load i8*, i8** %10
%64 = call i8* @strchr(i8* %63, i8 signext 58)
store i8* %64, i8** %10
%65 = load i8*, i8** %10
%66 = getelementptr inbounds i8, i8* %65, i32 1
store i8* %66, i8** %10
%67 = icmp eq i8* %65, null
br i1 %67, label %68, label %69
68: ; preds = %62
br label %29
69: ; preds = %62
%70 = load i8*, i8** %10
%71 = load i16*, i16** %4
%72 = call i32 @sscanf(i8* %70, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i16* %71)
%73 = icmp ne i32 %72, 1
br i1 %73, label %74, label %75
74: ; preds = %69
br label %29
75: ; preds = %69
%76 = load i16*, i16** %4
%77 = load i16, i16* %76
%78 = call zeroext i16 @htons(i16 zeroext %77)
%79 = load i16*, i16** %4
store i16 %78, i16* %79
%80 = load i8*, i8** %10
%81 = call i8* @strchr(i8* %80, i8 signext 32)
store i8* %81, i8** %10
%82 = load i8*, i8** %10
%83 = getelementptr inbounds i8, i8* %82, i32 1
store i8* %83, i8** %10
%84 = icmp eq i8* %82, null
br i1 %84, label %85, label %86
85: ; preds = %75
br label %29
86: ; preds = %75
br label %87
87: ; preds = %99, %86
%88 = load i8*, i8** %10
%89 = load i8, i8* %88
%90 = sext i8 %89 to i32
%91 = icmp eq i32 %90, 32
br i1 %91, label %97, label %92
92: ; preds = %87
%93 = load i8*, i8** %10
%94 = load i8, i8* %93
%95 = sext i8 %94 to i32
%96 = icmp eq i32 %95, 9
br label %97
97: ; preds = %92, %87
%98 = phi i1 [ true, %87 ], [ %96, %92 ]
br i1 %98, label %99, label %102
99: ; preds = %97
%100 = load i8*, i8** %10
%101 = getelementptr inbounds i8, i8* %100, i32 1
store i8* %101, i8** %10
br label %87
102: ; preds = %97
%103 = load i8*, i8** %10
%104 = call i64 @strncmp(i8* %103, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i32 37)
%105 = icmp ne i64 %104, 0
br i1 %105, label %106, label %107
106: ; preds = %102
br label %29
107: ; preds = %102
%108 = load i16*, i16** %5
store i16* %108, i16** %6
br label %109
109: ; preds = %123, %107
%110 = load i16*, i16** %6
%111 = load i16*, i16** %4
%112 = icmp ult i16* %110, %111
br i1 %112, label %113, label %126
113: ; preds = %109
%114 = load i16*, i16** %6
%115 = load i16, i16* %114
%116 = zext i16 %115 to i32
%117 = load i16*, i16** %4
%118 = load i16, i16* %117
%119 = zext i16 %118 to i32
%120 = icmp eq i32 %116, %119
br i1 %120, label %121, label %122
121: ; preds = %113
br label %126
122: ; preds = %113
br label %123
123: ; preds = %122
%124 = load i16*, i16** %6
%125 = getelementptr inbounds i16, i16* %124, i32 1
store i16* %125, i16** %6
br label %109
126: ; preds = %121, %109
%127 = load i16*, i16** %6
%128 = load i16*, i16** %4
%129 = icmp ne i16* %127, %128
br i1 %129, label %130, label %131
130: ; preds = %126
br label %29
131: ; preds = %126
%132 = load i16*, i16** %4
%133 = getelementptr inbounds i16, i16* %132, i32 1
store i16* %133, i16** %4
%134 = load i16*, i16** %5
%135 = ptrtoint i16* %132 to i64
%136 = ptrtoint i16* %134 to i64
%137 = sub i64 %135, %136
%138 = sdiv exact i64 %137, 2
%139 = load i32, i32* %9
%140 = sext i32 %139 to i64
%141 = udiv i64 %140, 2
%142 = icmp ugt i64 %138, %141
br i1 %142, label %143, label %164
143: ; preds = %131
%144 = load i32, i32* %9
%145 = mul nsw i32 %144, 2
%146 = sext i32 %145 to i64
%147 = add i64 %146, 2
%148 = trunc i64 %147 to i32
%149 = call i16* @malloc(i32 %148)
store i16* %149, i16** %4
%150 = load i16*, i16** %4
%151 = load i16*, i16** %5
%152 = load i32, i32* %9
%153 = call i32 @memcpy(i16* %150, i16* %151, i32 %152)
%154 = load i16*, i16** %5
%155 = load i32, i32* %9
%156 = sext i32 %155 to i64
%157 = getelementptr inbounds i16, i16* %154, i64 %156
store i16* %157, i16** %4
%158 = load i32, i32* %9
%159 = mul nsw i32 %158, 2
store i32 %159, i32* %9
%160 = load i32, i32* %9
%161 = icmp sgt i32 %160, 128
br i1 %161, label %162, label %163
162: ; preds = %143
br label %165
163: ; preds = %143
br label %164
164: ; preds = %163, %131
br label %29
165: ; preds = %162, %29
%166 = load i16*, i16** %4
%167 = getelementptr inbounds i16, i16* %166, i32 1
store i16* %167, i16** %4
store i16 0, i16* %166
%168 = load i16*, i16** %4
%169 = bitcast i16* %168 to i8*
%170 = load i16*, i16** %5
%171 = bitcast i16* %170 to i8*
%172 = ptrtoint i8* %169 to i64
%173 = ptrtoint i8* %171 to i64
%174 = sub i64 %172, %173
%175 = trunc i64 %174 to i32
%176 = load i32*, i32** %3
store i32 %175, i32* %176
%177 = load i32*, i32** %8
%178 = call i32 @fclose(i32* %177)
%179 = load i16*, i16** %5
store i16* %179, i16** %2
br label %180
180: ; preds = %165, %15
%181 = load i16*, i16** %2
ret i16* %181
}

LLVM IR (-O2):
@.str = [15 x i8] c"/proc/net/tcp6\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [33 x i8] c"00000000000000000000000001000000\00"
@.str.3 = [4 x i8] c"%hx\00"
@.str.4 = [38 x i8] c"00000000000000000000000000000000:0000\00"
define i16* @tcp_listen_ports(i32* nocapture writeonly %0) {
%2 = alloca [512 x i8]
%3 = alloca i32
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%5 = bitcast i32* %3 to i8*
%6 = call i16* @get_ports(i32 1, i32* %3)
%7 = call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32* %7, null
%9 = load i32, i32* %3
br i1 %8, label %10, label %11
10: ; preds = %1
store i32 %9, i32* %0
br label %97
11: ; preds = %1
%12 = sext i32 %9 to i64
%13 = lshr i64 %12, 1
%14 = getelementptr inbounds i16, i16* %6, i64 %13
%15 = icmp slt i32 %9, 32
br i1 %15, label %16, label %17
16: ; preds = %11
store i32 32, i32* %3
br label %17
17: ; preds = %16, %11
%18 = call i32* @fgets(i8* %4, i32 512, i32* %7)
%19 = icmp eq i32* %18, null
%20 = ptrtoint i16* %6 to i64
br i1 %19, label %90, label %21
21: ; preds = %17, %86
%22 = phi i16* [ %87, %86 ], [ %14, %17 ]
%23 = call i8* @strchr(i8* %4, i8 signext 58)
%24 = icmp eq i8* %23, null
br i1 %24, label %86, label %25
25: ; preds = %21, %29
%26 = phi i8* [ %27, %29 ], [ %23, %21 ]
%27 = getelementptr inbounds i8, i8* %26, i64 1
%28 = load i8, i8* %27
switch i8 %28, label %30 [
i8 32, label %29
i8 9, label %29
]
29: ; preds = %25, %25
br label %25
30: ; preds = %25
%31 = call i64 @strncmp(i8* %27, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 32)
%32 = icmp eq i64 %31, 0
br i1 %32, label %86, label %33
33: ; preds = %30
%34 = call i8* @strchr(i8* %27, i8 signext 58)
%35 = getelementptr inbounds i8, i8* %34, i64 1
%36 = icmp eq i8* %34, null
br i1 %36, label %86, label %37
37: ; preds = %33
%38 = call i32 @sscanf(i8* %35, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i16* %22)
%39 = icmp eq i32 %38, 1
br i1 %39, label %40, label %86
40: ; preds = %37
%41 = load i16, i16* %22
%42 = call zeroext i16 @htons(i16 zeroext %41)
store i16 %42, i16* %22
%43 = call i8* @strchr(i8* %35, i8 signext 32)
%44 = icmp eq i8* %43, null
br i1 %44, label %86, label %45
45: ; preds = %40, %49
%46 = phi i8* [ %47, %49 ], [ %43, %40 ]
%47 = getelementptr inbounds i8, i8* %46, i64 1
%48 = load i8, i8* %47
switch i8 %48, label %50 [
i8 32, label %49
i8 9, label %49
]
49: ; preds = %45, %45
br label %45
50: ; preds = %45
%51 = call i64 @strncmp(i8* %47, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i32 37)
%52 = icmp eq i64 %51, 0
br i1 %52, label %53, label %86
53: ; preds = %50
%54 = icmp ult i16* %6, %22
br i1 %54, label %55, label %64
55: ; preds = %53
%56 = load i16, i16* %22
br label %57
57: ; preds = %55, %61
%58 = phi i16* [ %6, %55 ], [ %62, %61 ]
%59 = load i16, i16* %58
%60 = icmp eq i16 %59, %56
br i1 %60, label %64, label %61
61: ; preds = %57
%62 = getelementptr inbounds i16, i16* %58, i64 1
%63 = icmp ult i16* %62, %22
br i1 %63, label %57, label %64
64: ; preds = %61, %57, %53
%65 = phi i16* [ %6, %53 ], [ %58, %57 ], [ %62, %61 ]
%66 = icmp eq i16* %65, %22
br i1 %66, label %67, label %86
67: ; preds = %64
%68 = getelementptr inbounds i16, i16* %22, i64 1
%69 = ptrtoint i16* %22 to i64
%70 = sub i64 %69, %20
%71 = ashr exact i64 %70, 1
%72 = load i32, i32* %3
%73 = sext i32 %72 to i64
%74 = lshr i64 %73, 1
%75 = icmp ugt i64 %71, %74
br i1 %75, label %76, label %86
76: ; preds = %67
%77 = shl nsw i32 %72, 1
%78 = add i32 %77, 2
%79 = call i16* @malloc(i32 %78)
%80 = call i32 @memcpy(i16* %79, i16* %6, i32 %72)
%81 = load i32, i32* %3
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds i16, i16* %6, i64 %82
%84 = shl nsw i32 %81, 1
store i32 %84, i32* %3
%85 = icmp sgt i32 %81, 64
br i1 %85, label %90, label %86
86: ; preds = %67, %76, %21, %30, %33, %37, %40, %50, %64
%87 = phi i16* [ %22, %21 ], [ %22, %30 ], [ %22, %33 ], [ %22, %37 ], [ %22, %40 ], [ %22, %50 ], [ %22, %64 ], [ %83, %76 ], [ %68, %67 ]
%88 = call i32* @fgets(i8* %4, i32 512, i32* %7)
%89 = icmp eq i32* %88, null
br i1 %89, label %90, label %21
90: ; preds = %86, %76, %17
%91 = phi i16* [ %14, %17 ], [ %83, %76 ], [ %87, %86 ]
%92 = getelementptr inbounds i16, i16* %91, i64 1
store i16 0, i16* %91
%93 = ptrtoint i16* %92 to i64
%94 = sub i64 %93, %20
%95 = trunc i64 %94 to i32
store i32 %95, i32* %0
%96 = call i32 @fclose(i32* %7)
br label %97
97: ; preds = %90, %10
ret i16* %6
}