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

/* Variables and functions */
scalar_t__ calloc(int, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(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 *netdevice) {
  char *buf;
  char *netstart;
  int netdevlength;
  static int bufsize;
  FILE *devfd;
  buf = (char *)calloc(255, 1);
  bufsize = 255;
  devfd = fopen("/proc/net/dev", "r");
  fgets(buf, bufsize, devfd);
  fgets(buf, bufsize, devfd);
  while (fgets(buf, bufsize, devfd)) {
    if ((netstart = strstr(buf, netdevice)) != NULL) {
      netdevlength = sizeof(netdevice) / sizeof(char);
      sscanf(netstart + netdevlength,
             "%llu  %*d     %*d  %*d  %*d  %*d   %*d        %*d       %llu",
             receivedabs, sentabs);
      fclose(devfd);
      free(buf);
      return 0;
    }
  }
  fclose(devfd);
  free(buf);
  return 1;
}


x86 assembly (clang, -O0):
<parse_netdev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    $0xff,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0xff,0x2ebb(%rip)
lea    0xe58(%rip),%rdi
lea    0xe5f(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rdi
mov    0x2e9a(%rip),%esi
mov    -0x40(%rbp),%rdx
call   1050 <fgets@plt>
mov    -0x28(%rbp),%rdi
mov    0x2e87(%rip),%esi
mov    -0x40(%rbp),%rdx
call   1050 <fgets@plt>
mov    -0x28(%rbp),%rdi
mov    0x2e74(%rip),%esi
mov    -0x40(%rbp),%rdx
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     125f <parse_netdev+0xef>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1090 <strstr@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     125a <parse_netdev+0xea>
movl   $0x8,-0x34(%rbp)
mov    -0x30(%rbp),%rdi
movslq -0x34(%rbp),%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xdd9(%rip),%rsi
call   1070 <sscanf@plt>
mov    -0x40(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    1278 <parse_netdev+0x108>
jmp    11de <parse_netdev+0x6e>
mov    -0x40(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_netdev>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r12
mov    %rsi,(%rsp)
mov    %rdi,%r15
mov    $0xff,%r14d
mov    $0xff,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,%rbx
movb   $0x1,0x2eb8(%rip)
lea    0xe55(%rip),%rdi
lea    0xe5c(%rip),%rsi
call   1080 <fopen@plt>
xor    %ebp,%ebp
cmpb   $0x0,0x2e9c(%rip)
mov    %rax,%r13
mov    $0x0,%esi
cmovne %r14d,%esi
mov    %rbx,%rdi
mov    %rax,%rdx
call   1050 <fgets@plt>
cmpb   $0x0,0x2e7e(%rip)
cmovne %r14d,%ebp
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r13,%rdx
call   1050 <fgets@plt>
nop
cmpb   $0x0,0x2e65(%rip)
mov    $0xff,%esi
jne    1200 <parse_netdev+0x90>
xor    %esi,%esi
mov    %rbx,%rdi
mov    %r13,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     123e <parse_netdev+0xce>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1090 <strstr@plt>
test   %rax,%rax
je     11f0 <parse_netdev+0x80>
add    $0x8,%rax
lea    0xde5(%rip),%rsi
mov    %rax,%rdi
mov    %r15,%rdx
mov    (%rsp),%rcx
call   1070 <sscanf@plt>
xor    %ebp,%ebp
jmp    1243 <parse_netdev+0xd3>
mov    $0x1,%ebp
mov    %r13,%rdi
call   1040 <fclose@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x8,%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 = [61 x i8] c"%llu %*d %*d %*d %*d %*d %*d %*d %llu\00"
define i32 @parse_netdev(i64* %0, i64* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i64*
%6 = alloca i64*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32*
store i64* %0, i64** %5
store i64* %1, i64** %6
store i8* %2, i8** %7
%12 = call i64 @calloc(i32 255, i32 1)
%13 = inttoptr i64 %12 to i8*
store i8* %13, i8** %8
store i32 255, i32* @parse_netdev.bufsize
%14 = 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* %14, i32** %11
%15 = load i8*, i8** %8
%16 = load i32, i32* @parse_netdev.bufsize
%17 = load i32*, i32** %11
%18 = call i64 @fgets(i8* %15, i32 %16, i32* %17)
%19 = load i8*, i8** %8
%20 = load i32, i32* @parse_netdev.bufsize
%21 = load i32*, i32** %11
%22 = call i64 @fgets(i8* %19, i32 %20, i32* %21)
br label %23
23: ; preds = %46, %3
%24 = load i8*, i8** %8
%25 = load i32, i32* @parse_netdev.bufsize
%26 = load i32*, i32** %11
%27 = call i64 @fgets(i8* %24, i32 %25, i32* %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %47
29: ; preds = %23
%30 = load i8*, i8** %8
%31 = load i8*, i8** %7
%32 = call i8* @strstr(i8* %30, i8* %31)
store i8* %32, i8** %9
%33 = icmp ne i8* %32, null
br i1 %33, label %34, label %46
34: ; preds = %29
store i32 8, i32* %10
%35 = load i8*, i8** %9
%36 = load i32, i32* %10
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
%39 = load i64*, i64** %5
%40 = load i64*, i64** %6
%41 = call i32 @sscanf(i8* %38, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.2, i64 0, i64 0), i64* %39, i64* %40)
%42 = load i32*, i32** %11
%43 = call i32 @fclose(i32* %42)
%44 = load i8*, i8** %8
%45 = call i32 @free(i8* %44)
store i32 0, i32* %4
br label %52
46: ; preds = %29
br label %23
47: ; preds = %23
%48 = load i32*, i32** %11
%49 = call i32 @fclose(i32* %48)
%50 = load i8*, i8** %8
%51 = call i32 @free(i8* %50)
store i32 1, i32* %4
br label %52
52: ; preds = %47, %34
%53 = load i32, i32* %4
ret i32 %53
}

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 = [61 x i8] c"%llu %*d %*d %*d %*d %*d %*d %*d %llu\00"
define i32 @parse_netdev(i64* %0, i64* %1, i8* nocapture %2) {
%4 = tail call i64 @calloc(i32 255, i32 1)
%5 = inttoptr i64 %4 to i8*
store i1 true, i1* @parse_netdev.bufsize
%6 = 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))
%7 = load i1, i1* @parse_netdev.bufsize
%8 = select i1 %7, i32 255, i32 0
%9 = tail call i64 @fgets(i8* %5, i32 %8, i32* %6)
%10 = load i1, i1* @parse_netdev.bufsize
%11 = select i1 %10, i32 255, i32 0
%12 = tail call i64 @fgets(i8* %5, i32 %11, i32* %6)
br label %13
13: ; preds = %18, %3
%14 = load i1, i1* @parse_netdev.bufsize
%15 = select i1 %14, i32 255, i32 0
%16 = tail call i64 @fgets(i8* %5, i32 %15, i32* %6)
%17 = icmp eq i64 %16, 0
br i1 %17, label %24, label %18
18: ; preds = %13
%19 = tail call i8* @strstr(i8* dereferenceable(1) %5, i8* dereferenceable(1) %2)
%20 = icmp eq i8* %19, null
br i1 %20, label %13, label %21
21: ; preds = %18
%22 = getelementptr inbounds i8, i8* %19, i64 8
%23 = tail call i32 @sscanf(i8* %22, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.2, i64 0, i64 0), i64* %0, i64* %1)
br label %24
24: ; preds = %13, %21
%25 = phi i32 [ 0, %21 ], [ 1, %13 ]
%26 = tail call i32 @fclose(i32* %6)
%27 = tail call i32 @free(i8* %5)
ret i32 %25
}