#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*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ sscanf(char *, char *, unsigned long long *,
                          unsigned long long *);
char *strstr(char *, char *);
int parse_netdev(unsigned long long int *receivedabs,
                 unsigned long long int *sentabs) {
  char buf[255];
  char *datastart;
  static int bufsize;
  int rval;
  FILE *devfd;
  unsigned long long int receivedacc, sentacc;
  bufsize = 255;
  devfd = fopen("/proc/net/dev", "r");
  rval = 1;
  fgets(buf, bufsize, devfd);
  fgets(buf, bufsize, devfd);
  while (fgets(buf, bufsize, devfd)) {
    if ((datastart = strstr(buf, "lo:")) == NULL) {
      datastart = strstr(buf, ":");
      sscanf(datastart + 1,
             "%llu  %*d     %*d  %*d  %*d  %*d   %*d        %*d       %llu",
             &receivedacc, &sentacc);
      *receivedabs += receivedacc;
      *sentabs += sentacc;
      rval = 0;
    }
  }
  fclose(devfd);
  return rval;
}


x86 assembly (clang, -O0):
<parse_netdev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xff,0x2edf(%rip)
lea    0xe8c(%rip),%rdi
lea    0xe93(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x128(%rbp)
movl   $0x1,-0x11c(%rbp)
lea    -0x110(%rbp),%rdi
mov    0x2eae(%rip),%esi
mov    -0x128(%rbp),%rdx
call   1040 <fgets@plt>
lea    -0x110(%rbp),%rdi
mov    0x2e95(%rip),%esi
mov    -0x128(%rbp),%rdx
call   1040 <fgets@plt>
lea    -0x110(%rbp),%rdi
mov    0x2e7c(%rip),%esi
mov    -0x128(%rbp),%rdx
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     127a <parse_netdev+0x12a>
lea    -0x110(%rbp),%rdi
lea    0xe1c(%rip),%rsi
call   1070 <strstr@plt>
mov    %rax,-0x118(%rbp)
cmp    $0x0,%rax
jne    1275 <parse_netdev+0x125>
lea    -0x110(%rbp),%rdi
lea    0xdfa(%rip),%rsi
call   1070 <strstr@plt>
mov    %rax,-0x118(%rbp)
mov    -0x118(%rbp),%rdi
add    $0x1,%rdi
lea    0xdde(%rip),%rsi
lea    -0x130(%rbp),%rdx
lea    -0x138(%rbp),%rcx
call   1050 <sscanf@plt>
mov    -0x130(%rbp),%rcx
mov    -0x8(%rbp),%rax
add    (%rax),%rcx
mov    %rcx,(%rax)
mov    -0x138(%rbp),%rcx
mov    -0x10(%rbp),%rax
add    (%rax),%rcx
mov    %rcx,(%rax)
movl   $0x0,-0x11c(%rbp)
jmp    11c3 <parse_netdev+0x73>
mov    -0x128(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x11c(%rbp),%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_netdev>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x128,%rsp
mov    %rsi,0x8(%rsp)
mov    %rdi,%r15
movb   $0x1,0x2ed4(%rip)
lea    0xe79(%rip),%rdi
lea    0xe80(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r13
xor    %ebx,%ebx
cmpb   $0x0,0x2eb5(%rip)
mov    $0xff,%r14d
mov    $0x0,%esi
cmovne %r14d,%esi
lea    0x20(%rsp),%rbp
mov    %rbp,%rdi
mov    %rax,%rdx
call   1050 <fgets@plt>
cmpb   $0x0,0x2e8f(%rip)
mov    $0x0,%esi
cmovne %r14d,%esi
mov    %rbp,%rdi
mov    %r13,%rdx
call   1050 <fgets@plt>
cmpb   $0x0,0x2e74(%rip)
cmovne %r14d,%ebx
mov    %rbp,%rdi
mov    %ebx,%esi
mov    %r13,%rdx
call   1050 <fgets@plt>
mov    $0x1,%ebp
test   %rax,%rax
je     1280 <parse_netdev+0x120>
lea    0xe0a(%rip),%r12
lea    0x20(%rsp),%rbx
jmp    1230 <parse_netdev+0xd0>
nopl   (%rax)
cmpb   $0x0,0x2e3d(%rip)
mov    $0x0,%esi
cmovne %r14d,%esi
mov    %rbx,%rdi
mov    %r13,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1280 <parse_netdev+0x120>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1080 <strstr@plt>
test   %rax,%rax
jne    1210 <parse_netdev+0xb0>
mov    %rbx,%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
lea    0x1(%rax),%rdi
lea    0xdbc(%rip),%rsi
lea    0x18(%rsp),%rdx
lea    0x10(%rsp),%rcx
call   1060 <sscanf@plt>
mov    0x18(%rsp),%rax
add    %rax,(%r15)
mov    0x10(%rsp),%rax
mov    0x8(%rsp),%rcx
add    %rax,(%rcx)
xor    %ebp,%ebp
jmp    1210 <parse_netdev+0xb0>
mov    %r13,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
add    $0x128,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@parse_netdev.bufsize = internal global i32 0
@.str = [14 x i8] c"/proc/net/dev\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [4 x i8] c"lo:\00"
@.str.3 = [2 x i8] c":\00"
@.str.4 = [61 x i8] c"%llu %*d %*d %*d %*d %*d %*d %*d %llu\00"
define i32 @parse_netdev(i64* %0, i64* %1) {
%3 = alloca i64*
%4 = alloca i64*
%5 = alloca [255 x i8]
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i64
%10 = alloca i64
store i64* %0, i64** %3
store i64* %1, i64** %4
store i32 255, i32* @parse_netdev.bufsize
%11 = 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* %11, i32** %8
store i32 1, i32* %7
%12 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
%13 = load i32, i32* @parse_netdev.bufsize
%14 = load i32*, i32** %8
%15 = call i64 @fgets(i8* %12, i32 %13, i32* %14)
%16 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
%17 = load i32, i32* @parse_netdev.bufsize
%18 = load i32*, i32** %8
%19 = call i64 @fgets(i8* %16, i32 %17, i32* %18)
br label %20
20: ; preds = %44, %2
%21 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
%22 = load i32, i32* @parse_netdev.bufsize
%23 = load i32*, i32** %8
%24 = call i64 @fgets(i8* %21, i32 %22, i32* %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %45
26: ; preds = %20
%27 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
%28 = call i8* @strstr(i8* %27, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
store i8* %28, i8** %6
%29 = icmp eq i8* %28, null
br i1 %29, label %30, label %44
30: ; preds = %26
%31 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
%32 = call i8* @strstr(i8* %31, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i8* %32, i8** %6
%33 = load i8*, i8** %6
%34 = getelementptr inbounds i8, i8* %33, i64 1
%35 = call i32 @sscanf(i8* %34, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.4, i64 0, i64 0), i64* %9, i64* %10)
%36 = load i64, i64* %9
%37 = load i64*, i64** %3
%38 = load i64, i64* %37
%39 = add i64 %38, %36
store i64 %39, i64* %37
%40 = load i64, i64* %10
%41 = load i64*, i64** %4
%42 = load i64, i64* %41
%43 = add i64 %42, %40
store i64 %43, i64* %41
store i32 0, i32* %7
br label %44
44: ; preds = %30, %26
br label %20
45: ; preds = %20
%46 = load i32*, i32** %8
%47 = call i32 @fclose(i32* %46)
%48 = load i32, i32* %7
ret i32 %48
}

LLVM IR (-O2):
@parse_netdev.bufsize = internal unnamed_addr global i1 false
@.str = [14 x i8] c"/proc/net/dev\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [4 x i8] c"lo:\00"
@.str.4 = [61 x i8] c"%llu %*d %*d %*d %*d %*d %*d %*d %llu\00"
define i32 @parse_netdev(i64* nocapture %0, i64* nocapture %1) {
%3 = alloca [255 x i8]
%4 = alloca i64
%5 = alloca i64
%6 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%7 = bitcast i64* %4 to i8*
%8 = bitcast i64* %5 to i8*
store i1 true, i1* @parse_netdev.bufsize
%9 = 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))
%10 = load i1, i1* @parse_netdev.bufsize
%11 = select i1 %10, i32 255, i32 0
%12 = call i64 @fgets(i8* %6, i32 %11, i32* %9)
%13 = load i1, i1* @parse_netdev.bufsize
%14 = select i1 %13, i32 255, i32 0
%15 = call i64 @fgets(i8* %6, i32 %14, i32* %9)
%16 = load i1, i1* @parse_netdev.bufsize
%17 = select i1 %16, i32 255, i32 0
%18 = call i64 @fgets(i8* %6, i32 %17, i32* %9)
%19 = icmp eq i64 %18, 0
br i1 %19, label %40, label %20
20: ; preds = %2, %34
%21 = phi i32 [ %35, %34 ], [ 1, %2 ]
%22 = call i8* @strstr(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%23 = icmp eq i8* %22, null
br i1 %23, label %24, label %34
24: ; preds = %20
%25 = call i8* @strchr(i8* %6, i32 58)
%26 = getelementptr inbounds i8, i8* %25, i64 1
%27 = call i32 @sscanf(i8* %26, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.4, i64 0, i64 0), i64* %4, i64* %5)
%28 = load i64, i64* %4
%29 = load i64, i64* %0
%30 = add i64 %29, %28
store i64 %30, i64* %0
%31 = load i64, i64* %5
%32 = load i64, i64* %1
%33 = add i64 %32, %31
store i64 %33, i64* %1
br label %34
34: ; preds = %24, %20
%35 = phi i32 [ 0, %24 ], [ %21, %20 ]
%36 = load i1, i1* @parse_netdev.bufsize
%37 = select i1 %36, i32 255, i32 0
%38 = call i64 @fgets(i8* %6, i32 %37, i32* %9)
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %20
40: ; preds = %34, %2
%41 = phi i32 [ 1, %2 ], [ %35, %34 ]
%42 = call i32 @fclose(i32* %9)
ret i32 %41
}