#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*/ time_t;
struct stat {
  int /*<<< orphan*/ st_mtime;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, unsigned long long,
                           unsigned long long);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, unsigned long long *,
                          unsigned long long *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
scalar_t__ stat(char const *, struct stat *);
int cache_netdev(unsigned long long int *newrec,
                 unsigned long long int *newsent,
                 unsigned long long int *oldrec,
                 unsigned long long int *oldsent, time_t *mtime) {
  FILE *cache;
  struct stat statbuf;
  const char *path = "/tmp/status";
  if (stat(path, &statbuf) == 0) {
    *mtime = statbuf.st_mtime;
    cache = fopen(path, "r+");
    fscanf(cache, "%llu %llu", oldrec, oldsent);
    rewind(cache);
  } else {
    oldrec = newrec;
    oldsent = newsent;
    cache = fopen(path, "w");
  }
  fprintf(cache, "%llu %llu", *newrec, *newsent);
  fclose(cache);
  return 0;
}


x86 assembly (clang, -O0):
<cache_netdev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
lea    0xe7d(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   1070 <stat@plt>
cmp    $0x0,%rax
jne    11e1 <cache_netdev+0x81>
mov    -0x38(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x40(%rbp),%rdi
lea    0xe5a(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xe41(%rip),%rsi
call   1050 <fscanf@plt>
mov    -0x30(%rbp),%rdi
call   1040 <rewind@plt>
jmp    1205 <cache_netdev+0xa5>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x40(%rbp),%rdi
lea    0xe1d(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
lea    0xdf1(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cache_netdev>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %r8,%rbx
mov    %rcx,%r15
mov    %rdx,%r13
mov    %rsi,%r14
mov    %rdi,%r12
lea    0xe7d(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1070 <stat@plt>
test   %rax,%rax
je     11aa <cache_netdev+0x4a>
lea    0xe67(%rip),%rdi
lea    0xe79(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
jmp    11e3 <cache_netdev+0x83>
mov    0x8(%rsp),%eax
mov    %eax,(%rbx)
lea    0xe49(%rip),%rdi
lea    0xe4e(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
lea    0xe42(%rip),%rsi
mov    %rax,%rdi
mov    %r13,%rdx
mov    %r15,%rcx
call   1050 <fscanf@plt>
mov    %rbx,%rdi
call   1040 <rewind@plt>
mov    (%r12),%rdx
mov    (%r14),%rcx
lea    0xe1e(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [12 x i8] c"/tmp/status\00"
@.str.1 = [3 x i8] c"r+\00"
@.str.2 = [10 x i8] c"%llu %llu\00"
@.str.3 = [2 x i8] c"w\00"
define i32 @cache_netdev(i64* %0, i64* %1, i64* %2, i64* %3, i32* %4) {
%6 = alloca i64*
%7 = alloca i64*
%8 = alloca i64*
%9 = alloca i64*
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca %struct.stat
%13 = alloca i8*
store i64* %0, i64** %6
store i64* %1, i64** %7
store i64* %2, i64** %8
store i64* %3, i64** %9
store i32* %4, i32** %10
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8** %13
%14 = load i8*, i8** %13
%15 = call i64 @stat(i8* %14, %struct.stat* %12)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %29
17: ; preds = %5
%18 = getelementptr inbounds %struct.stat, %struct.stat* %12, i32 0, i32 0
%19 = load i32, i32* %18
%20 = load i32*, i32** %10
store i32 %19, i32* %20
%21 = load i8*, i8** %13
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %22, i32** %11
%23 = load i32*, i32** %11
%24 = load i64*, i64** %8
%25 = load i64*, i64** %9
%26 = call i32 @fscanf(i32* %23, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i64* %24, i64* %25)
%27 = load i32*, i32** %11
%28 = call i32 @rewind(i32* %27)
br label %34
29: ; preds = %5
%30 = load i64*, i64** %6
store i64* %30, i64** %8
%31 = load i64*, i64** %7
store i64* %31, i64** %9
%32 = load i8*, i8** %13
%33 = call i32* @fopen(i8* %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %33, i32** %11
br label %34
34: ; preds = %29, %17
%35 = load i32*, i32** %11
%36 = load i64*, i64** %6
%37 = load i64, i64* %36
%38 = load i64*, i64** %7
%39 = load i64, i64* %38
%40 = call i32 @fprintf(i32* %35, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i64 %37, i64 %39)
%41 = load i32*, i32** %11
%42 = call i32 @fclose(i32* %41)
ret i32 0
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [12 x i8] c"/tmp/status\00"
@.str.1 = [3 x i8] c"r+\00"
@.str.2 = [10 x i8] c"%llu %llu\00"
@.str.3 = [2 x i8] c"w\00"
define i32 @cache_netdev(i64* nocapture %0, i64* nocapture %1, i64* %2, i64* %3, i32* nocapture writeonly %4) {
%6 = alloca %struct.stat
%7 = bitcast %struct.stat* %6 to i8*
%8 = call i64 @stat(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), %struct.stat* %6)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %16
10: ; preds = %5
%11 = getelementptr inbounds %struct.stat, %struct.stat* %6, i64 0, i32 0
%12 = load i32, i32* %11
store i32 %12, i32* %4
%13 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @fscanf(i32* %13, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i64* %2, i64* %3)
%15 = call i32 @rewind(i32* %13)
br label %18
16: ; preds = %5
%17 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %18
18: ; preds = %16, %10
%19 = phi i32* [ %13, %10 ], [ %17, %16 ]
%20 = load i64, i64* %0
%21 = load i64, i64* %1
%22 = call i32 @fprintf(i32* %19, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i64 %20, i64 %21)
%23 = call i32 @fclose(i32* %19)
ret i32 0
}