#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 */
struct pid_lookup_t {
  int dummy;
};
typedef struct pid_lookup_t conn_t;

/* Variables and functions */
scalar_t__ get_net(int, int, struct pid_lookup_t **, size_t *,
                   struct pid_lookup_t *, size_t);
scalar_t__ get_pids(struct pid_lookup_t **, size_t *);
int /*<<< orphan*/ mem_free(struct pid_lookup_t *);
int /*<<< orphan*/ print_net(struct pid_lookup_t *, size_t);
int /*<<< orphan*/ print_title();
int /*<<< orphan*/ printf(char *);
int main() {
  int options[4][2] = {{1, 0}, {0, 0}, {1, 1}, {0, 1}};
  size_t pid_count = 0;
  size_t count = 0;
  int ii = 0;
  struct pid_lookup_t *pids = NULL;
  struct conn_t *conns = NULL;
  if (get_pids(&pids, &pid_count) != 0) {
    printf("ERROR!\n");
    return 1;
  }
  print_title();
  for (ii = 0; ii < 4; ++ii) {
    if (get_net(options[ii][0], options[ii][1], &conns, &count, pids,
                pid_count) != 0) {
      printf("Error getting ");
      if (options[ii][0] != 0)
        printf("tcp");
      else
        printf("udp");
      if (options[ii][1] != 0)
        printf("6");
      else
        printf("4");
      printf(" connections!\n");
      return 1;
    }
    print_net(conns, count);
    mem_free(conns);
    count = 0;
    conns = NULL;
  }
  pid_count = 0;
  mem_free(pids);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe8a(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xe87(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xe84(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xe81(%rip),%rax
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
movq   $0x0,-0x50(%rbp)
movq   $0x0,-0x58(%rbp)
lea    -0x50(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   1060 <get_pids@plt>
cmp    $0x0,%rax
je     11f1 <main+0x91>
lea    0xe40(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1300 <main+0x1a0>
mov    $0x0,%al
call   1080 <print_title@plt>
movl   $0x0,-0x44(%rbp)
cmpl   $0x4,-0x44(%rbp)
jge    12e8 <main+0x188>
movslq -0x44(%rbp),%rax
mov    -0x30(%rbp,%rax,8),%edi
movslq -0x44(%rbp),%rax
mov    -0x2c(%rbp,%rax,8),%esi
lea    -0x58(%rbp),%rdx
mov    -0x50(%rbp),%r8
mov    -0x38(%rbp),%r9
lea    -0x40(%rbp),%rcx
call   1070 <get_net@plt>
cmp    $0x0,%rax
je     12b4 <main+0x154>
lea    0xde9(%rip),%rdi
call   1040 <printf@plt>
movslq -0x44(%rbp),%rax
cmpl   $0x0,-0x30(%rbp,%rax,8)
je     1264 <main+0x104>
lea    0xddd(%rip),%rdi
call   1040 <printf@plt>
jmp    1270 <main+0x110>
lea    0xdd0(%rip),%rdi
call   1040 <printf@plt>
movslq -0x44(%rbp),%rax
cmpl   $0x0,-0x2c(%rbp,%rax,8)
je     1290 <main+0x130>
lea    0xdb9(%rip),%rdi
call   1040 <printf@plt>
jmp    129c <main+0x13c>
lea    0xdaa(%rip),%rdi
call   1040 <printf@plt>
lea    0xda0(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1300 <main+0x1a0>
mov    -0x58(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1050 <print_net@plt>
mov    -0x58(%rbp),%rdi
call   1030 <mem_free@plt>
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x58(%rbp)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    11ff <main+0x9f>
movq   $0x0,-0x38(%rbp)
mov    -0x50(%rbp),%rdi
call   1030 <mem_free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
movq   $0x0,0x20(%rsp)
movq   $0x0,0x10(%rsp)
movq   $0x0,0x18(%rsp)
movq   $0x0,0x8(%rsp)
lea    0x18(%rsp),%rdi
lea    0x20(%rsp),%rsi
call   1080 <get_pids@plt>
test   %rax,%rax
je     11d8 <main+0x58>
lea    0xe5c(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%ebx
jmp    1297 <main+0x117>
xor    %eax,%eax
call   10a0 <print_title@plt>
mov    0x18(%rsp),%r8
mov    0x20(%rsp),%r9
mov    $0x1,%ebx
lea    0x8(%rsp),%rdx
lea    0x10(%rsp),%rcx
mov    $0x1,%edi
xor    %esi,%esi
call   1090 <get_net@plt>
mov    $0x34,%r14d
lea    0xdfe(%rip),%r15
test   %rax,%rax
je     121b <main+0x9b>
mov    %r15,%rbp
jmp    126f <main+0xef>
mov    0x8(%rsp),%rdi
mov    0x10(%rsp),%rsi
call   1070 <print_net@plt>
mov    0x8(%rsp),%rdi
call   1050 <mem_free@plt>
movq   $0x0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
mov    0x18(%rsp),%r8
mov    0x20(%rsp),%r9
lea    0x8(%rsp),%rdx
lea    0x10(%rsp),%rcx
xor    %edi,%edi
xor    %esi,%esi
call   1090 <get_net@plt>
lea    0xda9(%rip),%rbp
test   %rax,%rax
je     12a4 <main+0x124>
lea    0xd8a(%rip),%rdi
call   1060 <printf@plt>
mov    %rbp,%rdi
call   1060 <printf@plt>
mov    %r14d,%edi
call   1030 <putchar@plt>
lea    0xd85(%rip),%rdi
call   1040 <puts@plt>
mov    %ebx,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x8(%rsp),%rdi
mov    0x10(%rsp),%rsi
call   1070 <print_net@plt>
mov    0x8(%rsp),%rdi
call   1050 <mem_free@plt>
movq   $0x0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
mov    0x18(%rsp),%r8
mov    0x20(%rsp),%r9
lea    0x8(%rsp),%rdx
lea    0x10(%rsp),%rcx
mov    $0x1,%edi
mov    $0x1,%esi
call   1090 <get_net@plt>
mov    $0x36,%r14d
test   %rax,%rax
jne    1216 <main+0x96>
mov    0x8(%rsp),%rdi
mov    0x10(%rsp),%rsi
call   1070 <print_net@plt>
mov    0x8(%rsp),%rdi
call   1050 <mem_free@plt>
movq   $0x0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
mov    0x18(%rsp),%r8
mov    0x20(%rsp),%r9
lea    0x8(%rsp),%rdx
lea    0x10(%rsp),%rcx
xor    %edi,%edi
mov    $0x1,%esi
call   1090 <get_net@plt>
test   %rax,%rax
jne    126f <main+0xef>
mov    0x8(%rsp),%rdi
mov    0x10(%rsp),%rsi
call   1070 <print_net@plt>
mov    0x8(%rsp),%rdi
call   1050 <mem_free@plt>
movq   $0x0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
movq   $0x0,0x20(%rsp)
mov    0x18(%rsp),%rdi
call   1050 <mem_free@plt>
xor    %ebx,%ebx
jmp    1297 <main+0x117>

LLVM IR (-O0):
%struct.pid_lookup_t = type { i32 }
%struct.conn_t = type opaque
@__const.main.options = [4 x [2 x i32]] [[2 x i32] [i32 1, i32 0], [2 x i32] zeroinitializer, [2 x i32] [i32 1, i32 1], [2 x i32] [i32 0, i32 1]]
@.str = [8 x i8] c"ERROR!\0A\00"
@.str.1 = [15 x i8] c"Error getting \00"
@.str.2 = [4 x i8] c"tcp\00"
@.str.3 = [4 x i8] c"udp\00"
@.str.4 = [2 x i8] c"6\00"
@.str.5 = [2 x i8] c"4\00"
@.str.6 = [15 x i8] c" connections!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [4 x [2 x i32]]
%3 = alloca i64
%4 = alloca i64
%5 = alloca i32
%6 = alloca %struct.pid_lookup_t*
%7 = alloca %struct.conn_t*
store i32 0, i32* %1
%8 = bitcast [4 x [2 x i32]]* %2 to i8*
store i64 0, i64* %3
store i64 0, i64* %4
store i32 0, i32* %5
store %struct.pid_lookup_t* null, %struct.pid_lookup_t** %6
store %struct.conn_t* null, %struct.conn_t** %7
%9 = call i64 @get_pids(%struct.pid_lookup_t** %6, i64* %3)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %1
br label %73
13: ; preds = %0
%14 = call i32 (...) @print_title()
store i32 0, i32* %5
br label %15
15: ; preds = %67, %13
%16 = load i32, i32* %5
%17 = icmp slt i32 %16, 4
br i1 %17, label %18, label %70
18: ; preds = %15
%19 = load i32, i32* %5
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %2, i64 0, i64 %20
%22 = getelementptr inbounds [2 x i32], [2 x i32]* %21, i64 0, i64 0
%23 = load i32, i32* %22
%24 = load i32, i32* %5
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %2, i64 0, i64 %25
%27 = getelementptr inbounds [2 x i32], [2 x i32]* %26, i64 0, i64 1
%28 = load i32, i32* %27
%29 = bitcast %struct.conn_t** %7 to %struct.pid_lookup_t**
%30 = load %struct.pid_lookup_t*, %struct.pid_lookup_t** %6
%31 = load i64, i64* %3
%32 = call i64 @get_net(i32 %23, i32 %28, %struct.pid_lookup_t** %29, i64* %4, %struct.pid_lookup_t* %30, i64 %31)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %59
34: ; preds = %18
%35 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%36 = load i32, i32* %5
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %2, i64 0, i64 %37
%39 = getelementptr inbounds [2 x i32], [2 x i32]* %38, i64 0, i64 0
%40 = load i32, i32* %39
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %34
%43 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br label %46
44: ; preds = %34
%45 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
br label %46
46: ; preds = %44, %42
%47 = load i32, i32* %5
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %2, i64 0, i64 %48
%50 = getelementptr inbounds [2 x i32], [2 x i32]* %49, i64 0, i64 1
%51 = load i32, i32* %50
%52 = icmp ne i32 %51, 0
br i1 %52, label %53, label %55
53: ; preds = %46
%54 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %57
55: ; preds = %46
%56 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %57
57: ; preds = %55, %53
%58 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %1
br label %73
59: ; preds = %18
%60 = load %struct.conn_t*, %struct.conn_t** %7
%61 = bitcast %struct.conn_t* %60 to %struct.pid_lookup_t*
%62 = load i64, i64* %4
%63 = call i32 @print_net(%struct.pid_lookup_t* %61, i64 %62)
%64 = load %struct.conn_t*, %struct.conn_t** %7
%65 = bitcast %struct.conn_t* %64 to %struct.pid_lookup_t*
%66 = call i32 @mem_free(%struct.pid_lookup_t* %65)
store i64 0, i64* %4
store %struct.conn_t* null, %struct.conn_t** %7
br label %67
67: ; preds = %59
%68 = load i32, i32* %5
%69 = add nsw i32 %68, 1
store i32 %69, i32* %5
br label %15
70: ; preds = %15
store i64 0, i64* %3
%71 = load %struct.pid_lookup_t*, %struct.pid_lookup_t** %6
%72 = call i32 @mem_free(%struct.pid_lookup_t* %71)
store i32 0, i32* %1
br label %73
73: ; preds = %70, %57, %11
%74 = load i32, i32* %1
ret i32 %74
}

LLVM IR (-O2):
%struct.pid_lookup_t = type { i32 }
%struct.conn_t = type opaque
@.str.1 = [15 x i8] c"Error getting \00"
@.str.2 = [4 x i8] c"tcp\00"
@.str.3 = [4 x i8] c"udp\00"
@str = [14 x i8] c" connections!\00"
@str.7 = [7 x i8] c"ERROR!\00"
define i32 @main() {
%1 = alloca i64
%2 = alloca i64
%3 = alloca %struct.pid_lookup_t*
%4 = alloca %struct.conn_t*
%5 = bitcast i64* %1 to i8*
store i64 0, i64* %1
%6 = bitcast i64* %2 to i8*
store i64 0, i64* %2
%7 = bitcast %struct.pid_lookup_t** %3 to i8*
store %struct.pid_lookup_t* null, %struct.pid_lookup_t** %3
%8 = bitcast %struct.conn_t** %4 to i8*
store %struct.conn_t* null, %struct.conn_t** %4
%9 = call i64 @get_pids(%struct.pid_lookup_t** %3, i64* %1)
%10 = icmp eq i64 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %0
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.7, i64 0, i64 0))
br label %65
13: ; preds = %0
%14 = call i32 (...) @print_title()
%15 = bitcast %struct.conn_t** %4 to %struct.pid_lookup_t**
%16 = load %struct.pid_lookup_t*, %struct.pid_lookup_t** %3
%17 = load i64, i64* %1
%18 = call i64 @get_net(i32 1, i32 0, %struct.pid_lookup_t** %15, i64* %2, %struct.pid_lookup_t* %16, i64 %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %27, label %20
20: ; preds = %27, %13, %37, %47
%21 = phi i8* [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), %37 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), %47 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), %27 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), %13 ]
%22 = phi i32 [ 54, %37 ], [ 54, %47 ], [ 52, %27 ], [ 52, %13 ]
%23 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%24 = call i32 @printf(i8* dereferenceable(1) %21)
%25 = call i32 @putchar(i32 %22)
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
br label %65
27: ; preds = %13
%28 = load %struct.pid_lookup_t*, %struct.pid_lookup_t** %15
%29 = load i64, i64* %2
%30 = call i32 @print_net(%struct.pid_lookup_t* %28, i64 %29)
%31 = load %struct.pid_lookup_t*, %struct.pid_lookup_t** %15
%32 = call i32 @mem_free(%struct.pid_lookup_t* %31)
store i64 0, i64* %2
store %struct.conn_t* null, %struct.conn_t** %4
%33 = load %struct.pid_lookup_t*, %struct.pid_lookup_t** %3
%34 = load i64, i64* %1
%35 = call i64 @get_net(i32 0, i32 0, %struct.pid_lookup_t** %15, i64* %2, %struct.pid_lookup_t* %33, i64 %34)
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %20
37: ; preds = %27
%38 = load %struct.pid_lookup_t*, %struct.pid_lookup_t** %15
%39 = load i64, i64* %2
%40 = call i32 @print_net(%struct.pid_lookup_t* %38, i64 %39)
%41 = load %struct.pid_lookup_t*, %struct.pid_lookup_t** %15
%42 = call i32 @mem_free(%struct.pid_lookup_t* %41)
store i64 0, i64* %2
store %struct.conn_t* null, %struct.conn_t** %4
%43 = load %struct.pid_lookup_t*, %struct.pid_lookup_t** %3
%44 = load i64, i64* %1
%45 = call i64 @get_net(i32 1, i32 1, %struct.pid_lookup_t** %15, i64* %2, %struct.pid_lookup_t* %43, i64 %44)
%46 = icmp eq i64 %45, 0
br i1 %46, label %47, label %20
47: ; preds = %37
%48 = load %struct.pid_lookup_t*, %struct.pid_lookup_t** %15
%49 = load i64, i64* %2
%50 = call i32 @print_net(%struct.pid_lookup_t* %48, i64 %49)
%51 = load %struct.pid_lookup_t*, %struct.pid_lookup_t** %15
%52 = call i32 @mem_free(%struct.pid_lookup_t* %51)
store i64 0, i64* %2
store %struct.conn_t* null, %struct.conn_t** %4
%53 = load %struct.pid_lookup_t*, %struct.pid_lookup_t** %3
%54 = load i64, i64* %1
%55 = call i64 @get_net(i32 0, i32 1, %struct.pid_lookup_t** %15, i64* %2, %struct.pid_lookup_t* %53, i64 %54)
%56 = icmp eq i64 %55, 0
br i1 %56, label %57, label %20
57: ; preds = %47
%58 = load %struct.pid_lookup_t*, %struct.pid_lookup_t** %15
%59 = load i64, i64* %2
%60 = call i32 @print_net(%struct.pid_lookup_t* %58, i64 %59)
%61 = load %struct.pid_lookup_t*, %struct.pid_lookup_t** %15
%62 = call i32 @mem_free(%struct.pid_lookup_t* %61)
store i64 0, i64* %2
store %struct.conn_t* null, %struct.conn_t** %4
store i64 0, i64* %1
%63 = load %struct.pid_lookup_t*, %struct.pid_lookup_t** %3
%64 = call i32 @mem_free(%struct.pid_lookup_t* %63)
br label %65
65: ; preds = %57, %20, %11
%66 = phi i32 [ 1, %11 ], [ 1, %20 ], [ 0, %57 ]
ret i32 %66
}