#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 tm {
  scalar_t__ tm_mday;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, char *, int);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void check_for_new_date(void) {
  FILE *date = fopen("/var/info/systemmonitor/stats/datecode", "r");
  char buffer[4];
  time_t rawtime;
  time(&rawtime);
  struct tm *timen;
  timen = localtime(&rawtime);
  int day = (int)timen->tm_mday;
  fgets(buffer, 4, date);
  int x = 0;
  char fn[100];
  if (day != atoi(buffer))
    while (x <= 24) {
      sprintf(fn, "%s%d", "/var/info/systemmonitor/stats/", x);
      FILE *buff = fopen(fn, "w");
      fprintf(buff, " ");
      fclose(buff);
      x++;
    }
  fclose(date);
  date = fopen("/var/info/systemmonitor/stats/datecode", "w");
  fprintf(date, "%d", day);
}


x86 assembly (clang, -O0):
<check_for_new_date>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
lea    0xe6e(%rip),%rdi
lea    0xe8e(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x8(%rbp)
lea    -0x10(%rbp),%rdi
call   1070 <time@plt>
lea    -0x10(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %eax,-0x1c(%rbp)
lea    -0xc(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x4,%esi
call   1050 <fgets@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x9c(%rbp)
lea    -0xc(%rbp),%rdi
call   1090 <atoi@plt>
mov    %eax,%ecx
mov    -0x9c(%rbp),%eax
cmp    %ecx,%eax
je     1277 <check_for_new_date+0xf7>
jmp    1202 <check_for_new_date+0x82>
cmpl   $0x18,-0x20(%rbp)
jg     1272 <check_for_new_date+0xf2>
lea    -0x90(%rbp),%rdi
mov    -0x20(%rbp),%ecx
lea    0xe0c(%rip),%rsi
lea    0xe0a(%rip),%rdx
call   10a0 <sprintf@plt>
lea    -0x90(%rbp),%rdi
lea    0xe16(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x98(%rbp)
mov    -0x98(%rbp),%rdi
lea    0xdfe(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x98(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1202 <check_for_new_date+0x82>
jmp    1277 <check_for_new_date+0xf7>
mov    -0x8(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xd79(%rip),%rdi
lea    0xdbf(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    0xd86(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_for_new_date>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
lea    0xe58(%rip),%rdi
lea    0xe78(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%rbx
lea    0x18(%rsp),%rbp
mov    %rbp,%rdi
call   1080 <time@plt>
mov    %rbp,%rdi
call   1030 <localtime@plt>
mov    (%rax),%ebp
lea    0x1c(%rsp),%r14
mov    %r14,%rdi
mov    $0x4,%esi
mov    %rbx,0x10(%rsp)
mov    %rbx,%rdx
call   1060 <fgets@plt>
mov    %r14,%rdi
call   10a0 <atoi@plt>
mov    %ebp,0xc(%rsp)
cmp    %ebp,%eax
je     125b <check_for_new_date+0xcb>
xor    %ebp,%ebp
lea    0xe28(%rip),%r12
lea    0xe26(%rip),%r13
lea    0x20(%rsp),%rbx
lea    0xe39(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
mov    %ebp,%ecx
call   10b0 <sprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1090 <fopen@plt>
mov    %rax,%r15
mov    $0x20,%edi
mov    %rax,%rsi
call   1050 <fputc@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
add    $0x1,%ebp
cmp    $0x19,%ebp
jne    1220 <check_for_new_date+0x90>
mov    0x10(%rsp),%rdi
call   1040 <fclose@plt>
lea    0xd94(%rip),%rdi
lea    0xdda(%rip),%rsi
call   1090 <fopen@plt>
lea    0xdac(%rip),%rsi
mov    %rax,%rdi
mov    0xc(%rsp),%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i64 }
@.str = [39 x i8] c"/var/info/systemmonitor/stats/datecode\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [5 x i8] c"%s%d\00"
@.str.3 = [31 x i8] c"/var/info/systemmonitor/stats/\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [2 x i8] c" \00"
@.str.6 = [3 x i8] c"%d\00"
define void @check_for_new_date() {
%1 = alloca i32*
%2 = alloca [4 x i8]
%3 = alloca i32
%4 = alloca %struct.tm*
%5 = alloca i32
%6 = alloca i32
%7 = alloca [100 x i8]
%8 = alloca i32*
%9 = call i32* @fopen(i8* getelementptr inbounds ([39 x i8], [39 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** %1
%10 = call i32 @time(i32* %3)
%11 = call %struct.tm* @localtime(i32* %3)
store %struct.tm* %11, %struct.tm** %4
%12 = load %struct.tm*, %struct.tm** %4
%13 = getelementptr inbounds %struct.tm, %struct.tm* %12, i32 0, i32 0
%14 = load i64, i64* %13
%15 = trunc i64 %14 to i32
store i32 %15, i32* %5
%16 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%17 = load i32*, i32** %1
%18 = call i32 @fgets(i8* %16, i32 4, i32* %17)
store i32 0, i32* %6
%19 = load i32, i32* %5
%20 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%21 = call i32 @atoi(i8* %20)
%22 = icmp ne i32 %19, %21
br i1 %22, label %23, label %40
23: ; preds = %0
br label %24
24: ; preds = %27, %23
%25 = load i32, i32* %6
%26 = icmp sle i32 %25, 24
br i1 %26, label %27, label %39
27: ; preds = %24
%28 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%29 = load i32, i32* %6
%30 = call i32 @sprintf(i8* %28, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i32 %29)
%31 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%32 = call i32* @fopen(i8* %31, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %32, i32** %8
%33 = load i32*, i32** %8
%34 = call i32 (i32*, i8*, ...) @fprintf(i32* %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%35 = load i32*, i32** %8
%36 = call i32 @fclose(i32* %35)
%37 = load i32, i32* %6
%38 = add nsw i32 %37, 1
store i32 %38, i32* %6
br label %24
39: ; preds = %24
br label %40
40: ; preds = %39, %0
%41 = load i32*, i32** %1
%42 = call i32 @fclose(i32* %41)
%43 = call i32* @fopen(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %43, i32** %1
%44 = load i32*, i32** %1
%45 = load i32, i32* %5
%46 = call i32 (i32*, i8*, ...) @fprintf(i32* %44, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 %45)
ret void
}

LLVM IR (-O2):
%struct.tm = type { i64 }
@.str = [39 x i8] c"/var/info/systemmonitor/stats/datecode\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [5 x i8] c"%s%d\00"
@.str.3 = [31 x i8] c"/var/info/systemmonitor/stats/\00"
@.str.4 = [2 x i8] c"w\00"
@.str.6 = [3 x i8] c"%d\00"
define void @check_for_new_date() {
%1 = alloca [4 x i8]
%2 = alloca i32
%3 = alloca [100 x i8]
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = getelementptr inbounds [4 x i8], [4 x i8]* %1, i64 0, i64 0
%6 = bitcast i32* %2 to i8*
%7 = call i32 @time(i32* %2)
%8 = call %struct.tm* @localtime(i32* %2)
%9 = getelementptr inbounds %struct.tm, %struct.tm* %8, i64 0, i32 0
%10 = load i64, i64* %9
%11 = trunc i64 %10 to i32
%12 = call i32 @fgets(i8* %5, i32 4, i32* %4)
%13 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%14 = call i32 @atoi(i8* %5)
%15 = icmp eq i32 %14, %11
br i1 %15, label %24, label %16
16: ; preds = %0, %16
%17 = phi i32 [ %22, %16 ], [ 0, %0 ]
%18 = call i32 @sprintf(i8* %13, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i32 %17)
%19 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%20 = call i32 @fputc(i32 32, i32* %19)
%21 = call i32 @fclose(i32* %19)
%22 = add nuw nsw i32 %17, 1
%23 = icmp eq i32 %22, 25
br i1 %23, label %24, label %16
24: ; preds = %16, %0
%25 = call i32 @fclose(i32* %4)
%26 = call i32* @fopen(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%27 = call i32 (i32*, i8*, ...) @fprintf(i32* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 %11)
ret void
}