#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 Data {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ appendData(struct Data **, struct Data *);
char *calloc(int, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int const, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ freeData(struct Data *);
scalar_t__ isLoopback(struct Data *);
int /*<<< orphan*/ logMsg(int, char *);
struct Data *parseProcNetDevLine(char *, char *);
char *strchr(char *, char);
int /*<<< orphan*/ strncpy(char *, char *, int);
struct Data *getData() {
  FILE *fProcNetDev = fopen("/proc/net/dev", "r");
  if (fProcNetDev == NULL) {
    logMsg(4, "Unable to open "
              "/proc/net/dev");
    return NULL;
  }
  const int MAX_LINE_SIZE = 256;
  char line[MAX_LINE_SIZE];
  char *colonPos;
  struct Data *firstData = NULL;
  struct Data *thisData = NULL;
  while (fgets(line, MAX_LINE_SIZE, fProcNetDev) != NULL) {
    if ((colonPos = strchr(line, ':')) != NULL) {
      char *ifName = calloc(32, 1);
      strncpy(ifName, line, colonPos - line);
      thisData = parseProcNetDevLine(ifName, colonPos + 1);
      free(ifName);
      if (isLoopback(thisData) == 0) {
        appendData(&firstData, thisData);
      } else {
        freeData(thisData);
      }
    }
  }
  fclose(fProcNetDev);
  return firstData;
}


x86 assembly (clang, -O0):
<getData>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
lea    0xe42(%rip),%rdi
lea    0xe2a(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1208 <getData+0x48>
mov    $0x4,%edi
lea    0xe0c(%rip),%rsi
call   10c0 <logMsg@plt>
movq   $0x0,-0x8(%rbp)
jmp    1305 <getData+0x145>
movl   $0x100,-0x14(%rbp)
mov    %rsp,%rax
mov    %rax,-0x20(%rbp)
mov    %rsp,%rax
add    $0xffffffffffffff00,%rax
mov    %rax,-0x48(%rbp)
mov    %rax,%rsp
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x100,%esi
call   10a0 <fgets@plt>
cmp    $0x0,%rax
je     12ed <getData+0x12d>
mov    -0x48(%rbp),%rdi
mov    $0x3a,%esi
call   1080 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     12e8 <getData+0x128>
mov    $0x20,%edi
mov    $0x1,%esi
call   10b0 <calloc@plt>
mov    -0x48(%rbp),%rsi
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x28(%rbp),%rax
sub    %rsi,%rax
mov    %eax,%edx
call   1040 <strncpy@plt>
mov    -0x40(%rbp),%rdi
mov    -0x28(%rbp),%rsi
add    $0x1,%rsi
call   1090 <parseProcNetDevLine@plt>
mov    %rax,-0x38(%rbp)
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1060 <isLoopback@plt>
cmp    $0x0,%rax
jne    12da <getData+0x11a>
mov    -0x38(%rbp),%rsi
lea    -0x30(%rbp),%rdi
call   10d0 <appendData@plt>
jmp    12e3 <getData+0x123>
mov    -0x38(%rbp),%rdi
call   1050 <freeData@plt>
jmp    12e8 <getData+0x128>
jmp    1236 <getData+0x76>
mov    -0x10(%rbp),%rdi
call   1070 <fclose@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x8(%rbp),%rax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getData>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xe39(%rip),%rdi
lea    0xe21(%rip),%rsi
call   10e0 <fopen@plt>
test   %rax,%rax
je     12ca <getData+0x10a>
mov    %rax,%r14
mov    %rsp,-0x38(%rbp)
mov    %rsp,%r12
add    $0xffffffffffffff00,%r12
mov    %r12,%rsp
movq   $0x0,-0x30(%rbp)
mov    %r12,%rdi
mov    $0x100,%esi
mov    %rax,%rdx
call   10a0 <fgets@plt>
test   %rax,%rax
je     12b8 <getData+0xf8>
lea    -0x30(%rbp),%r15
jmp    124d <getData+0x8d>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1050 <freeData@plt>
mov    %r12,%rdi
mov    $0x100,%esi
mov    %r14,%rdx
call   10a0 <fgets@plt>
test   %rax,%rax
je     12b8 <getData+0xf8>
mov    %r12,%rdi
mov    $0x3a,%esi
call   1080 <strchr@plt>
test   %rax,%rax
je     1238 <getData+0x78>
mov    %rax,%rbx
mov    $0x20,%edi
mov    $0x1,%esi
call   10b0 <calloc@plt>
mov    %rax,%r13
mov    %ebx,%edx
sub    %r12d,%edx
mov    %rax,%rdi
mov    %r12,%rsi
call   1040 <strncpy@plt>
add    $0x1,%rbx
mov    %r13,%rdi
mov    %rbx,%rsi
call   1090 <parseProcNetDevLine@plt>
mov    %rax,%rbx
mov    %r13,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1060 <isLoopback@plt>
test   %rax,%rax
jne    1230 <getData+0x70>
mov    %r15,%rdi
mov    %rbx,%rsi
call   10d0 <appendData@plt>
jmp    1238 <getData+0x78>
mov    %r14,%rdi
call   1070 <fclose@plt>
mov    -0x30(%rbp),%rax
mov    -0x38(%rbp),%rsp
jmp    12dd <getData+0x11d>
lea    0xd31(%rip),%rsi
mov    $0x4,%edi
call   10c0 <logMsg@plt>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.Data = type { i32 }
@.str = [14 x i8] c"/proc/net/dev\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [29 x i8] c"Unable to open /proc/net/dev\00"
define %struct.Data* @getData() {
%1 = alloca %struct.Data*
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca %struct.Data*
%7 = alloca %struct.Data*
%8 = alloca i8*
%9 = 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* %9, i32** %2
%10 = load i32*, i32** %2
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %14
12: ; preds = %0
%13 = call i32 @logMsg(i32 4, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
store %struct.Data* null, %struct.Data** %1
br label %55
14: ; preds = %0
store i32 256, i32* %3
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %4
%16 = alloca i8, i64 256
store %struct.Data* null, %struct.Data** %6
store %struct.Data* null, %struct.Data** %7
br label %17
17: ; preds = %49, %14
%18 = load i32*, i32** %2
%19 = call i32* @fgets(i8* %16, i32 256, i32* %18)
%20 = icmp ne i32* %19, null
br i1 %20, label %21, label %50
21: ; preds = %17
%22 = call i8* @strchr(i8* %16, i8 signext 58)
store i8* %22, i8** %5
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %49
24: ; preds = %21
%25 = call i8* @calloc(i32 32, i32 1)
store i8* %25, i8** %8
%26 = load i8*, i8** %8
%27 = load i8*, i8** %5
%28 = ptrtoint i8* %27 to i64
%29 = ptrtoint i8* %16 to i64
%30 = sub i64 %28, %29
%31 = trunc i64 %30 to i32
%32 = call i32 @strncpy(i8* %26, i8* %16, i32 %31)
%33 = load i8*, i8** %8
%34 = load i8*, i8** %5
%35 = getelementptr inbounds i8, i8* %34, i64 1
%36 = call %struct.Data* @parseProcNetDevLine(i8* %33, i8* %35)
store %struct.Data* %36, %struct.Data** %7
%37 = load i8*, i8** %8
%38 = call i32 @free(i8* %37)
%39 = load %struct.Data*, %struct.Data** %7
%40 = call i64 @isLoopback(%struct.Data* %39)
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %24
%43 = load %struct.Data*, %struct.Data** %7
%44 = call i32 @appendData(%struct.Data** %6, %struct.Data* %43)
br label %48
45: ; preds = %24
%46 = load %struct.Data*, %struct.Data** %7
%47 = call i32 @freeData(%struct.Data* %46)
br label %48
48: ; preds = %45, %42
br label %49
49: ; preds = %48, %21
br label %17
50: ; preds = %17
%51 = load i32*, i32** %2
%52 = call i32 @fclose(i32* %51)
%53 = load %struct.Data*, %struct.Data** %6
store %struct.Data* %53, %struct.Data** %1
%54 = load i8*, i8** %4
br label %55
55: ; preds = %50, %12
%56 = load %struct.Data*, %struct.Data** %1
ret %struct.Data* %56
}

LLVM IR (-O2):
%struct.Data = type { i32 }
@.str = [14 x i8] c"/proc/net/dev\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [29 x i8] c"Unable to open /proc/net/dev\00"
define %struct.Data* @getData() {
%1 = alloca %struct.Data*
%2 = tail 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))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %6
4: ; preds = %0
%5 = tail call i32 @logMsg(i32 4, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
br label %39
6: ; preds = %0
%7 = tail call i8* @llvm.stacksave()
%8 = alloca [256 x i8]
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%10 = bitcast %struct.Data** %1 to i8*
store %struct.Data* null, %struct.Data** %1
%11 = call i32* @fgets(i8* %9, i32 256, i32* %2)
%12 = icmp eq i32* %11, null
br i1 %12, label %36, label %13
13: ; preds = %6
%14 = ptrtoint [256 x i8]* %8 to i64
br label %15
15: ; preds = %13, %33
%16 = call i8* @strchr(i8* %9, i8 signext 58)
%17 = icmp eq i8* %16, null
br i1 %17, label %33, label %18
18: ; preds = %15
%19 = call dereferenceable_or_null(32) i8* @calloc(i32 32, i32 1)
%20 = ptrtoint i8* %16 to i64
%21 = sub i64 %20, %14
%22 = trunc i64 %21 to i32
%23 = call i32 @strncpy(i8* %19, i8* %9, i32 %22)
%24 = getelementptr inbounds i8, i8* %16, i64 1
%25 = call %struct.Data* @parseProcNetDevLine(i8* %19, i8* %24)
%26 = call i32 @free(i8* %19)
%27 = call i64 @isLoopback(%struct.Data* %25)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %18
%30 = call i32 @appendData(%struct.Data** %1, %struct.Data* %25)
br label %33
31: ; preds = %18
%32 = call i32 @freeData(%struct.Data* %25)
br label %33
33: ; preds = %29, %31, %15
%34 = call i32* @fgets(i8* %9, i32 256, i32* %2)
%35 = icmp eq i32* %34, null
br i1 %35, label %36, label %15
36: ; preds = %33, %6
%37 = call i32 @fclose(i32* %2)
%38 = load %struct.Data*, %struct.Data** %1
br label %39
39: ; preds = %36, %4
%40 = phi %struct.Data* [ null, %4 ], [ %38, %36 ]
ret %struct.Data* %40
}