#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*/ buffer;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(unsigned long *);
int get_socket_inodes_list(int, unsigned long **);
int /*<<< orphan*/ printf(char *);
scalar_t__ tcp_do_one(int /*<<< orphan*/, char *, unsigned long **, int);
int get_tcp_activity(int pid) {
  unsigned long int *inodes_numbers;
  int inodes_count = get_socket_inodes_list(pid, &inodes_numbers);
  FILE *procinfo = fopen("/proc/net/tcp", "r");
  int has_activity = 0;
  if (procinfo != NULL) {
    char buffer[512];
    int lnr = 0;
    do {
      if (fgets(buffer, (int)sizeof(buffer), procinfo))
        if (tcp_do_one(lnr++, buffer, &inodes_numbers, inodes_count))
          has_activity++;
    } while (!feof(procinfo));
    (void)fclose(procinfo);
    free(inodes_numbers);
  }
  if (has_activity > 0) {
    printf("Got activity!\n");
    return (!((0)));
  } else
    return (0);
}


x86 assembly (clang, -O0):
<get_tcp_activity>:
push   %rbp
mov    %rsp,%rbp
sub    $0x240,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   1030 <get_socket_inodes_list@plt>
mov    %eax,-0x14(%rbp)
lea    0xe5c(%rip),%rdi
lea    0xe63(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     125b <get_tcp_activity+0xdb>
movl   $0x0,-0x234(%rbp)
lea    -0x230(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x200,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     122b <get_tcp_activity+0xab>
mov    -0x234(%rbp),%edi
mov    %edi,%eax
add    $0x1,%eax
mov    %eax,-0x234(%rbp)
lea    -0x230(%rbp),%rsi
mov    -0x14(%rbp),%ecx
lea    -0x10(%rbp),%rdx
call   10a0 <tcp_do_one@plt>
cmp    $0x0,%rax
je     1226 <get_tcp_activity+0xa6>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    122b <get_tcp_activity+0xab>
jmp    1230 <get_tcp_activity+0xb0>
mov    -0x20(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11d0 <get_tcp_activity+0x50>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x10(%rbp),%rdi
call   1040 <free@plt>
cmpl   $0x0,-0x24(%rbp)
jle    127d <get_tcp_activity+0xfd>
lea    0xda4(%rip),%rdi
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1284 <get_tcp_activity+0x104>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x240,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_tcp_activity>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x218,%rsp
lea    0x8(%rsp),%rsi
call   1030 <get_socket_inodes_list@plt>
mov    %eax,%r14d
lea    0xe5b(%rip),%rdi
lea    0xe62(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     123e <get_tcp_activity+0xbe>
mov    %rax,%rbx
xor    %r13d,%r13d
lea    0x10(%rsp),%r12
xor    %ebp,%ebp
jmp    11dc <get_tcp_activity+0x5c>
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1080 <feof@plt>
test   %eax,%eax
jne    1214 <get_tcp_activity+0x94>
mov    %r12,%rdi
mov    $0x200,%esi
mov    %rbx,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     11d0 <get_tcp_activity+0x50>
lea    0x1(%rbp),%r15d
mov    %ebp,%edi
mov    %r12,%rsi
lea    0x8(%rsp),%rdx
mov    %r14d,%ecx
call   10a0 <tcp_do_one@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%r13d
mov    %r15d,%ebp
jmp    11d0 <get_tcp_activity+0x50>
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    0x8(%rsp),%rdi
call   1040 <free@plt>
test   %r13d,%r13d
jle    123e <get_tcp_activity+0xbe>
lea    0xdde(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%eax
jmp    1240 <get_tcp_activity+0xc0>
xor    %eax,%eax
add    $0x218,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"/proc/net/tcp\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [15 x i8] c"Got activity!\0A\00"
define i32 @get_tcp_activity(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i64*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca [512 x i8]
%9 = alloca i32
store i32 %0, i32* %3
%10 = load i32, i32* %3
%11 = call i32 @get_socket_inodes_list(i32 %10, i64** %4)
store i32 %11, i32* %5
%12 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 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** %6
store i32 0, i32* %7
%13 = load i32*, i32** %6
%14 = icmp ne i32* %13, null
br i1 %14, label %15, label %43
15: ; preds = %1
store i32 0, i32* %9
br label %16
16: ; preds = %33, %15
%17 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%18 = load i32*, i32** %6
%19 = call i64 @fgets(i8* %17, i32 512, i32* %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %32
21: ; preds = %16
%22 = load i32, i32* %9
%23 = add nsw i32 %22, 1
store i32 %23, i32* %9
%24 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%25 = load i32, i32* %5
%26 = call i64 @tcp_do_one(i32 %22, i8* %24, i64** %4, i32 %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %21
%29 = load i32, i32* %7
%30 = add nsw i32 %29, 1
store i32 %30, i32* %7
br label %31
31: ; preds = %28, %21
br label %32
32: ; preds = %31, %16
br label %33
33: ; preds = %32
%34 = load i32*, i32** %6
%35 = call i32 @feof(i32* %34)
%36 = icmp ne i32 %35, 0
%37 = xor i1 %36, true
br i1 %37, label %16, label %38
38: ; preds = %33
%39 = load i32*, i32** %6
%40 = call i32 @fclose(i32* %39)
%41 = load i64*, i64** %4
%42 = call i32 @free(i64* %41)
br label %43
43: ; preds = %38, %1
%44 = load i32, i32* %7
%45 = icmp sgt i32 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %43
%47 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %2
br label %49
48: ; preds = %43
store i32 0, i32* %2
br label %49
49: ; preds = %48, %46
%50 = load i32, i32* %2
ret i32 %50
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/net/tcp\00"
@.str.1 = [2 x i8] c"r\00"
@str = [14 x i8] c"Got activity!\00"
define i32 @get_tcp_activity(i32 %0) {
%2 = alloca i64*
%3 = alloca [512 x i8]
%4 = bitcast i64** %2 to i8*
%5 = call i32 @get_socket_inodes_list(i32 %0, i64** %2)
%6 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %33, label %8
8: ; preds = %1
%9 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
br label %10
10: ; preds = %21, %8
%11 = phi i32 [ 0, %8 ], [ %22, %21 ]
%12 = phi i32 [ 0, %8 ], [ %23, %21 ]
%13 = call i64 @fgets(i8* %9, i32 512, i32* %6)
%14 = icmp eq i64 %13, 0
br i1 %14, label %21, label %15
15: ; preds = %10
%16 = add nsw i32 %12, 1
%17 = call i64 @tcp_do_one(i32 %12, i8* %9, i64** %2, i32 %5)
%18 = icmp ne i64 %17, 0
%19 = zext i1 %18 to i32
%20 = add nsw i32 %11, %19
br label %21
21: ; preds = %15, %10
%22 = phi i32 [ %11, %10 ], [ %20, %15 ]
%23 = phi i32 [ %12, %10 ], [ %16, %15 ]
%24 = call i32 @feof(i32* %6)
%25 = icmp eq i32 %24, 0
br i1 %25, label %10, label %26
26: ; preds = %21
%27 = call i32 @fclose(i32* %6)
%28 = load i64*, i64** %2
%29 = call i32 @free(i64* %28)
%30 = icmp sgt i32 %22, 0
br i1 %30, label %31, label %33
31: ; preds = %26
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
br label %33
33: ; preds = %1, %26, %31
%34 = phi i32 [ 1, %31 ], [ 0, %26 ], [ 0, %1 ]
ret i32 %34
}