#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 */
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 *face) {
  char *buf;
  char *eth0start;
  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 ((eth0start = strstr(buf, face)) != NULL) {
      sscanf(eth0start + 6,
             "%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,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
mov    0x2e9a(%rip),%esi
mov    -0x38(%rbp),%rdx
call   1050 <fgets@plt>
mov    -0x28(%rbp),%rdi
mov    0x2e87(%rip),%esi
mov    -0x38(%rbp),%rdx
call   1050 <fgets@plt>
mov    -0x28(%rbp),%rdi
mov    0x2e74(%rip),%esi
mov    -0x38(%rbp),%rdx
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1255 <parse_netdev+0xe5>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1090 <strstr@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     1250 <parse_netdev+0xe0>
mov    -0x30(%rbp),%rdi
add    $0x6,%rdi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xde3(%rip),%rsi
call   1070 <sscanf@plt>
mov    -0x38(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    126e <parse_netdev+0xfe>
jmp    11de <parse_netdev+0x6e>
mov    -0x38(%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    $0x6,%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*
store i64* %0, i64** %5
store i64* %1, i64** %6
store i8* %2, i8** %7
%11 = call i64 @calloc(i32 255, i32 1)
%12 = inttoptr i64 %11 to i8*
store i8* %12, i8** %8
store i32 255, i32* @parse_netdev.bufsize
%13 = 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* %13, i32** %10
%14 = load i8*, i8** %8
%15 = load i32, i32* @parse_netdev.bufsize
%16 = load i32*, i32** %10
%17 = call i64 @fgets(i8* %14, i32 %15, i32* %16)
%18 = load i8*, i8** %8
%19 = load i32, i32* @parse_netdev.bufsize
%20 = load i32*, i32** %10
%21 = call i64 @fgets(i8* %18, i32 %19, i32* %20)
br label %22
22: ; preds = %43, %3
%23 = load i8*, i8** %8
%24 = load i32, i32* @parse_netdev.bufsize
%25 = load i32*, i32** %10
%26 = call i64 @fgets(i8* %23, i32 %24, i32* %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %44
28: ; preds = %22
%29 = load i8*, i8** %8
%30 = load i8*, i8** %7
%31 = call i8* @strstr(i8* %29, i8* %30)
store i8* %31, i8** %9
%32 = icmp ne i8* %31, null
br i1 %32, label %33, label %43
33: ; preds = %28
%34 = load i8*, i8** %9
%35 = getelementptr inbounds i8, i8* %34, i64 6
%36 = load i64*, i64** %5
%37 = load i64*, i64** %6
%38 = call i32 @sscanf(i8* %35, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.2, i64 0, i64 0), i64* %36, i64* %37)
%39 = load i32*, i32** %10
%40 = call i32 @fclose(i32* %39)
%41 = load i8*, i8** %8
%42 = call i32 @free(i8* %41)
store i32 0, i32* %4
br label %49
43: ; preds = %28
br label %22
44: ; preds = %22
%45 = load i32*, i32** %10
%46 = call i32 @fclose(i32* %45)
%47 = load i8*, i8** %8
%48 = call i32 @free(i8* %47)
store i32 1, i32* %4
br label %49
49: ; preds = %44, %33
%50 = load i32, i32* %4
ret i32 %50
}

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 6
%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
}