#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 scalar_t__ time_t;
typedef int /*<<< orphan*/ cmd;

/* Variables and functions */
int config_get_eepromcounter_address();
int config_get_eepromcounter_page();
char *config_get_runoneepromcounterincrease();
scalar_t__ config_get_runoneepromcounterincreaseminimumdelayinsecbetweenruns();
int /*<<< orphan*/ config_set_eepromcounter_address(int);
int /*<<< orphan*/ config_set_eepromcounter_page(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, int, int, int, int);
int /*<<< orphan*/ stderr;
scalar_t__ system(char *);
scalar_t__ time(int /*<<< orphan*/ *);
void nai_eepromcounterhasincreased(int newpage, int newaddress) {
  static time_t lastrunoneepromcounterincrease = 0;
  char *runoneepromcounterincrease = NULL;
  char cmd[255] = {0};
  printf("nai: eeprom counter has increased.\n");
  if (time(NULL) - lastrunoneepromcounterincrease >
      config_get_runoneepromcounterincreaseminimumdelayinsecbetweenruns()) {
    runoneepromcounterincrease = config_get_runoneepromcounterincrease();
    snprintf(cmd, sizeof(cmd), "%s %d %d %d %d", runoneepromcounterincrease,
             newpage, newaddress, config_get_eepromcounter_page(),
             config_get_eepromcounter_address());
    printf("nai: executing: %s\n", cmd);
    if (system(cmd) < 0)
      fprintf(stderr, "nai error: error on exec.\n");
    free(runoneepromcounterincrease);
  } else
    fprintf(stderr, "nai: minimum delay between on eeprom counter increase "
                    "runs not spent, not running command.\n");
  config_set_eepromcounter_page(newpage);
  config_set_eepromcounter_address(newaddress);
}


x86 assembly (clang, -O0):
<nai_eepromcounterhasincreased>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
mov    $0xff,%edx
call   10b0 <memset@plt>
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10e0 <time@plt>
sub    0x2e76(%rip),%rax
mov    %rax,-0x118(%rbp)
mov    $0x0,%al
call   1050 <config_get_runoneepromcounterincreaseminimumdelayinsecbetweenruns@plt>
mov    %rax,%rcx
mov    -0x118(%rbp),%rax
cmp    %rcx,%rax
jle    130f <nai_eepromcounterhasincreased+0x13f>
mov    $0x0,%al
call   1040 <config_get_runoneepromcounterincrease@plt>
mov    %rax,-0x10(%rbp)
lea    -0x110(%rbp),%rax
mov    %rax,-0x138(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x130(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x124(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x120(%rbp)
mov    $0x0,%al
call   10c0 <config_get_eepromcounter_page@plt>
mov    %eax,-0x11c(%rbp)
mov    $0x0,%al
call   10f0 <config_get_eepromcounter_address@plt>
mov    -0x138(%rbp),%rdi
mov    -0x130(%rbp),%rcx
mov    -0x124(%rbp),%r8d
mov    -0x120(%rbp),%r9d
mov    -0x11c(%rbp),%r10d
mov    $0xff,%esi
lea    0xd70(%rip),%rdx
mov    %r10d,(%rsp)
mov    %eax,0x8(%rsp)
call   1080 <snprintf@plt>
lea    -0x110(%rbp),%rsi
lea    0xd64(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x110(%rbp),%rdi
call   1060 <system@plt>
cmp    $0x0,%rax
jge    1301 <nai_eepromcounterhasincreased+0x131>
mov    0x2ced(%rip),%rax
mov    (%rax),%edi
lea    0xd4b(%rip),%rsi
call   10d0 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
jmp    1324 <nai_eepromcounterhasincreased+0x154>
mov    0x2cca(%rip),%rax
mov    (%rax),%edi
lea    0xd43(%rip),%rsi
call   10d0 <fprintf@plt>
mov    -0x4(%rbp),%edi
call   10a0 <config_set_eepromcounter_page@plt>
mov    -0x8(%rbp),%edi
call   1090 <config_set_eepromcounter_address@plt>
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nai_eepromcounterhasincreased>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x100,%rsp
mov    %esi,%r14d
mov    %edi,%r15d
xorps  %xmm0,%xmm0
movups %xmm0,0xef(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
lea    0xe44(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   10e0 <time@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1060 <config_get_runoneepromcounterincreaseminimumdelayinsecbetweenruns@plt>
cmp    %rax,%rbx
jle    12ee <nai_eepromcounterhasincreased+0x11e>
xor    %eax,%eax
call   1050 <config_get_runoneepromcounterincrease@plt>
mov    %rax,%r12
xor    %eax,%eax
call   10c0 <config_get_eepromcounter_page@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   10f0 <config_get_eepromcounter_address@plt>
lea    0xd6e(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0xff,%esi
mov    %r12,%rcx
mov    %r15d,%r8d
mov    %r14d,%r9d
push   %rax
push   %rbp
call   1090 <snprintf@plt>
add    $0x10,%rsp
lea    0xd57(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %rbx,%rdi
call   1070 <system@plt>
test   %rax,%rax
jns    12e4 <nai_eepromcounterhasincreased+0x114>
mov    0x2d0a(%rip),%rax
mov    (%rax),%edi
lea    0xd44(%rip),%rsi
call   10d0 <fprintf@plt>
mov    %r12,%rdi
call   1030 <free@plt>
jmp    1303 <nai_eepromcounterhasincreased+0x133>
mov    0x2ceb(%rip),%rax
mov    (%rax),%edi
lea    0xd40(%rip),%rsi
call   10d0 <fprintf@plt>
mov    %r15d,%edi
call   10b0 <config_set_eepromcounter_page@plt>
mov    %r14d,%edi
call   10a0 <config_set_eepromcounter_address@plt>
add    $0x100,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@nai_eepromcounterhasincreased.lastrunoneepromcounterincrease = internal global i64 0
@.str = [36 x i8] c"nai: eeprom counter has increased.\0A\00"
@.str.1 = [15 x i8] c"%s %d %d %d %d\00"
@.str.2 = [20 x i8] c"nai: executing: %s\0A\00"
@stderr = global i32 0
@.str.3 = [27 x i8] c"nai error: error on exec.\0A\00"
@.str.4 = [92 x i8] c"nai: minimum delay between on eeprom counter increase runs not spent, not running command.\0A\00"
define void @nai_eepromcounterhasincreased(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca [255 x i8]
store i32 %0, i32* %3
store i32 %1, i32* %4
store i8* null, i8** %5
%7 = bitcast [255 x i8]* %6 to i8*
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%9 = call i64 @time(i32* null)
%10 = load i64, i64* @nai_eepromcounterhasincreased.lastrunoneepromcounterincrease
%11 = sub nsw i64 %9, %10
%12 = call i64 (...) @config_get_runoneepromcounterincreaseminimumdelayinsecbetweenruns()
%13 = icmp sgt i64 %11, %12
br i1 %13, label %14, label %34
14: ; preds = %2
%15 = call i8* (...) @config_get_runoneepromcounterincrease()
store i8* %15, i8** %5
%16 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%17 = load i8*, i8** %5
%18 = load i32, i32* %3
%19 = load i32, i32* %4
%20 = call i32 (...) @config_get_eepromcounter_page()
%21 = call i32 (...) @config_get_eepromcounter_address()
%22 = call i32 @snprintf(i8* %16, i32 255, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %17, i32 %18, i32 %19, i32 %20, i32 %21)
%23 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %23)
%25 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%26 = call i64 @system(i8* %25)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %14
%29 = load i32, i32* @stderr
%30 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
br label %31
31: ; preds = %28, %14
%32 = load i8*, i8** %5
%33 = call i32 @free(i8* %32)
br label %37
34: ; preds = %2
%35 = load i32, i32* @stderr
%36 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([92 x i8], [92 x i8]* @.str.4, i64 0, i64 0))
br label %37
37: ; preds = %34, %31
%38 = load i32, i32* %3
%39 = call i32 @config_set_eepromcounter_page(i32 %38)
%40 = load i32, i32* %4
%41 = call i32 @config_set_eepromcounter_address(i32 %40)
ret void
}

LLVM IR (-O2):
@.str.1 = [15 x i8] c"%s %d %d %d %d\00"
@.str.2 = [20 x i8] c"nai: executing: %s\0A\00"
@stderr = global i32 0
@.str.3 = [27 x i8] c"nai error: error on exec.\0A\00"
@.str.4 = [92 x i8] c"nai: minimum delay between on eeprom counter increase runs not spent, not running command.\0A\00"
@str = [35 x i8] c"nai: eeprom counter has increased.\00"
define void @nai_eepromcounterhasincreased(i32 %0, i32 %1) {
%3 = alloca [255 x i8]
%4 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str, i64 0, i64 0))
%6 = tail call i64 @time(i32* null)
%7 = tail call i64 (...) @config_get_runoneepromcounterincreaseminimumdelayinsecbetweenruns()
%8 = icmp sgt i64 %6, %7
br i1 %8, label %9, label %22
9: ; preds = %2
%10 = tail call i8* (...) @config_get_runoneepromcounterincrease()
%11 = tail call i32 (...) @config_get_eepromcounter_page()
%12 = tail call i32 (...) @config_get_eepromcounter_address()
%13 = call i32 @snprintf(i8* %4, i32 255, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %10, i32 %0, i32 %1, i32 %11, i32 %12)
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%15 = call i64 @system(i8* %4)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %9
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
br label %20
20: ; preds = %17, %9
%21 = call i32 @free(i8* %10)
br label %25
22: ; preds = %2
%23 = load i32, i32* @stderr
%24 = tail call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([92 x i8], [92 x i8]* @.str.4, i64 0, i64 0))
br label %25
25: ; preds = %22, %20
%26 = call i32 @config_set_eepromcounter_page(i32 %0)
%27 = call i32 @config_set_eepromcounter_address(i32 %1)
ret void
}