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

/* Variables and functions */
scalar_t__ EOF;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
size_t fread(char *, int, size_t, int /*<<< orphan*/ *);
scalar_t__ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ ftell(int /*<<< orphan*/ *);
char *gethome();
scalar_t__ sstrncat(char *, size_t *, int, char const *, int);
int /*<<< orphan*/ stdout;
int strlen(char const *);
int strtol(char *, int /*<<< orphan*/ *, int);
int time(int /*<<< orphan*/ *);
long check_localdate(void) {
  FILE *fp;
  char const *homedir;
  char outdir[512], buffer[512];
  size_t curlen, read, len;
  time_t oldtime, curtime, difftime;
  homedir = gethome();
  if (homedir == NULL)
    return -1;
  curlen = 0;
  if (sstrncat(outdir, &curlen, 512, homedir, strlen(homedir)))
    return -1;
  if (sstrncat(outdir, &curlen, 512, "/.tldrc/date",
               (sizeof("/.tldrc/date") - 1)))
    return -1;
  fp = fopen(outdir, "rb");
  if (!fp)
    return -1;
  if (fseek(fp, 0, SEEK_END))
    goto error;
  if ((len = (size_t)ftell(fp)) == (size_t)EOF)
    goto error;
  if (fseek(fp, 0, SEEK_SET))
    goto error;
  read = fread(buffer, 1, len, fp);
  if (read != len)
    goto error;
  curtime = time(NULL);
  oldtime = strtol(buffer, NULL, 10);
  difftime = curtime - oldtime;
  if (difftime > (60 * 60 * 24 * 7 * 2)) {
    fprintf(stdout, "%s", "\x1b[1m");
    fprintf(stdout, "%s", "\x1b[31m");
    fprintf(
        stdout,
        "Local data is older than two weeks, use --update to update it.\n\n");
    fprintf(stdout, "%s", "\x1b[39m");
    fprintf(stdout, "%s", "\x1b[22m");
  }
  fclose(fp);
  return difftime;
error:
  fclose(fp);
  return -1;
}


x86 assembly (clang, -O0):
<check_localdate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x460,%rsp
mov    $0x0,%al
call   10d0 <gethome@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11de <check_localdate+0x2e>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    145b <check_localdate+0x2ab>
movq   $0x0,-0x428(%rbp)
lea    -0x220(%rbp),%rax
mov    %rax,-0x458(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x450(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x458(%rbp),%rdi
mov    -0x450(%rbp),%rcx
mov    %eax,%r8d
lea    -0x428(%rbp),%rsi
mov    $0x200,%edx
call   1060 <sstrncat@plt>
cmp    $0x0,%rax
je     1244 <check_localdate+0x94>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    145b <check_localdate+0x2ab>
lea    -0x220(%rbp),%rdi
lea    -0x428(%rbp),%rsi
mov    $0x200,%edx
lea    0xda2(%rip),%rcx
mov    $0xc,%r8d
call   1060 <sstrncat@plt>
cmp    $0x0,%rax
je     1280 <check_localdate+0xd0>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    145b <check_localdate+0x2ab>
lea    -0x220(%rbp),%rdi
lea    0xd7f(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    12af <check_localdate+0xff>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    145b <check_localdate+0x2ab>
mov    -0x10(%rbp),%rdi
mov    0x2d2e(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10b0 <fseek@plt>
cmp    $0x0,%rax
je     12d2 <check_localdate+0x122>
jmp    144a <check_localdate+0x29a>
mov    -0x10(%rbp),%rdi
call   1080 <ftell@plt>
mov    %rax,-0x438(%rbp)
mov    0x2cf7(%rip),%rcx
cmp    (%rcx),%rax
jne    12f7 <check_localdate+0x147>
jmp    144a <check_localdate+0x29a>
mov    -0x10(%rbp),%rdi
mov    0x2cce(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10b0 <fseek@plt>
cmp    $0x0,%rax
je     131a <check_localdate+0x16a>
jmp    144a <check_localdate+0x29a>
lea    -0x420(%rbp),%rdi
mov    -0x438(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %rax,-0x430(%rbp)
mov    -0x430(%rbp),%rax
cmp    -0x438(%rbp),%rax
je     1356 <check_localdate+0x1a6>
jmp    144a <check_localdate+0x29a>
xor    %eax,%eax
mov    %eax,%edi
call   10a0 <time@plt>
mov    %eax,-0x440(%rbp)
lea    -0x420(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1090 <strtol@plt>
mov    %eax,-0x43c(%rbp)
mov    -0x440(%rbp),%eax
sub    -0x43c(%rbp),%eax
mov    %eax,-0x444(%rbp)
cmpl   $0x127500,-0x444(%rbp)
jle    1431 <check_localdate+0x281>
mov    0x2c1f(%rip),%rax
mov    (%rax),%edi
lea    0xc5e(%rip),%rsi
lea    0xc5a(%rip),%rdx
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2c01(%rip),%rax
mov    (%rax),%edi
lea    0xc40(%rip),%rsi
lea    0xc41(%rip),%rdx
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2be3(%rip),%rax
mov    (%rax),%edi
lea    0xc30(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2bcc(%rip),%rax
mov    (%rax),%edi
lea    0xc0b(%rip),%rsi
lea    0xc53(%rip),%rdx
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2bae(%rip),%rax
mov    (%rax),%edi
lea    0xbed(%rip),%rsi
lea    0xc3b(%rip),%rdx
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
movslq -0x444(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    145b <check_localdate+0x2ab>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
mov    -0x8(%rbp),%rax
add    $0x460,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_localdate>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x418,%rsp
xor    %eax,%eax
call   10d0 <gethome@plt>
mov    $0xffffffffffffffff,%r12
test   %rax,%rax
je     1377 <check_localdate+0x1c7>
mov    %rax,%rbx
movq   $0x0,0x8(%rsp)
mov    %rax,%rdi
call   1050 <strlen@plt>
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
mov    $0x200,%edx
mov    %rbx,%rcx
mov    %eax,%r8d
call   1060 <sstrncat@plt>
test   %rax,%rax
jne    1377 <check_localdate+0x1c7>
lea    0xded(%rip),%rcx
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
mov    $0x200,%edx
mov    $0xc,%r8d
call   1060 <sstrncat@plt>
test   %rax,%rax
jne    1377 <check_localdate+0x1c7>
lea    0xdd0(%rip),%rsi
lea    0x10(%rsp),%rdi
call   10c0 <fopen@plt>
test   %rax,%rax
je     1377 <check_localdate+0x1c7>
mov    %rax,%r14
mov    0x2d8e(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   10b0 <fseek@plt>
test   %rax,%rax
jne    136f <check_localdate+0x1bf>
mov    %r14,%rdi
call   1080 <ftell@plt>
mov    %rax,%r15
mov    0x2d5f(%rip),%rax
cmp    (%rax),%r15
je     136f <check_localdate+0x1bf>
mov    0x2d3f(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   10b0 <fseek@plt>
test   %rax,%rax
jne    136f <check_localdate+0x1bf>
lea    0x210(%rsp),%rdi
mov    $0x1,%esi
mov    %r15,%rdx
mov    %r14,%rcx
call   1030 <fread@plt>
cmp    %r15,%rax
jne    136f <check_localdate+0x1bf>
xor    %edi,%edi
call   10a0 <time@plt>
mov    %eax,%ebx
lea    0x210(%rsp),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1090 <strtol@plt>
sub    %eax,%ebx
cmp    $0x127501,%ebx
jl     1362 <check_localdate+0x1b2>
mov    0x2cd3(%rip),%r12
mov    (%r12),%edi
lea    0xd10(%rip),%r15
lea    0xd0c(%rip),%rdx
mov    %r15,%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    (%r12),%edi
lea    0xcfc(%rip),%rdx
mov    %r15,%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    (%r12),%edi
lea    0xced(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    (%r12),%edi
lea    0xd1c(%rip),%rdx
mov    %r15,%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    (%r12),%edi
lea    0xd0d(%rip),%rdx
mov    %r15,%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
movslq %ebx,%r12
jmp    1377 <check_localdate+0x1c7>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %r12,%rax
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [13 x i8] c"/.tldrc/date\00"
@.str.1 = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@EOF = global i64 0
@SEEK_SET = global i32 0
@stdout = global i32 0
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [5 x i8] c"\1B[1m\00"
@.str.4 = [6 x i8] c"\1B[31m\00"
@.str.5 = [65 x i8] c"Local data is older than two weeks, use --update to update it.\0A\0A\00"
@.str.6 = [6 x i8] c"\1B[39m\00"
@.str.7 = [6 x i8] c"\1B[22m\00"
define i64 @check_localdate() {
%1 = alloca i64
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca [512 x i8]
%5 = alloca [512 x i8]
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = call i8* (...) @gethome()
store i8* %12, i8** %3
%13 = load i8*, i8** %3
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %16
15: ; preds = %0
store i64 -1, i64* %1
br label %90
16: ; preds = %0
store i64 0, i64* %6
%17 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%18 = load i8*, i8** %3
%19 = load i8*, i8** %3
%20 = call i32 @strlen(i8* %19)
%21 = call i64 @sstrncat(i8* %17, i64* %6, i32 512, i8* %18, i32 %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %16
store i64 -1, i64* %1
br label %90
24: ; preds = %16
%25 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%26 = call i64 @sstrncat(i8* %25, i64* %6, i32 512, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 12)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %24
store i64 -1, i64* %1
br label %90
29: ; preds = %24
%30 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%31 = call i32* @fopen(i8* %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %31, i32** %2
%32 = load i32*, i32** %2
%33 = icmp ne i32* %32, null
br i1 %33, label %35, label %34
34: ; preds = %29
store i64 -1, i64* %1
br label %90
35: ; preds = %29
%36 = load i32*, i32** %2
%37 = load i32, i32* @SEEK_END
%38 = call i64 @fseek(i32* %36, i32 0, i32 %37)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %35
br label %87
41: ; preds = %35
%42 = load i32*, i32** %2
%43 = call i64 @ftell(i32* %42)
store i64 %43, i64* %8
%44 = load i64, i64* @EOF
%45 = icmp eq i64 %43, %44
br i1 %45, label %46, label %47
46: ; preds = %41
br label %87
47: ; preds = %41
%48 = load i32*, i32** %2
%49 = load i32, i32* @SEEK_SET
%50 = call i64 @fseek(i32* %48, i32 0, i32 %49)
%51 = icmp ne i64 %50, 0
br i1 %51, label %52, label %53
52: ; preds = %47
br label %87
53: ; preds = %47
%54 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%55 = load i64, i64* %8
%56 = load i32*, i32** %2
%57 = call i64 @fread(i8* %54, i32 1, i64 %55, i32* %56)
store i64 %57, i64* %7
%58 = load i64, i64* %7
%59 = load i64, i64* %8
%60 = icmp ne i64 %58, %59
br i1 %60, label %61, label %62
61: ; preds = %53
br label %87
62: ; preds = %53
%63 = call i32 @time(i32* null)
store i32 %63, i32* %10
%64 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%65 = call i32 @strtol(i8* %64, i32* null, i32 10)
store i32 %65, i32* %9
%66 = load i32, i32* %10
%67 = load i32, i32* %9
%68 = sub nsw i32 %66, %67
store i32 %68, i32* %11
%69 = load i32, i32* %11
%70 = icmp sgt i32 %69, 1209600
br i1 %70, label %71, label %82
71: ; preds = %62
%72 = load i32, i32* @stdout
%73 = call i32 (i32, i8*, ...) @fprintf(i32 %72, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%74 = load i32, i32* @stdout
%75 = call i32 (i32, i8*, ...) @fprintf(i32 %74, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%76 = load i32, i32* @stdout
%77 = call i32 (i32, i8*, ...) @fprintf(i32 %76, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.5, i64 0, i64 0))
%78 = load i32, i32* @stdout
%79 = call i32 (i32, i8*, ...) @fprintf(i32 %78, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%80 = load i32, i32* @stdout
%81 = call i32 (i32, i8*, ...) @fprintf(i32 %80, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
br label %82
82: ; preds = %71, %62
%83 = load i32*, i32** %2
%84 = call i32 @fclose(i32* %83)
%85 = load i32, i32* %11
%86 = sext i32 %85 to i64
store i64 %86, i64* %1
br label %90
87: ; preds = %61, %52, %46, %40
%88 = load i32*, i32** %2
%89 = call i32 @fclose(i32* %88)
store i64 -1, i64* %1
br label %90
90: ; preds = %87, %82, %34, %28, %23, %15
%91 = load i64, i64* %1
ret i64 %91
}

LLVM IR (-O2):
@.str = [13 x i8] c"/.tldrc/date\00"
@.str.1 = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@EOF = global i64 0
@SEEK_SET = global i32 0
@stdout = global i32 0
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [5 x i8] c"\1B[1m\00"
@.str.4 = [6 x i8] c"\1B[31m\00"
@.str.5 = [65 x i8] c"Local data is older than two weeks, use --update to update it.\0A\0A\00"
@.str.6 = [6 x i8] c"\1B[39m\00"
@.str.7 = [6 x i8] c"\1B[22m\00"
define i64 @check_localdate() {
%1 = alloca [512 x i8]
%2 = alloca [512 x i8]
%3 = alloca i64
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%6 = bitcast i64* %3 to i8*
%7 = tail call i8* (...) @gethome()
%8 = icmp eq i8* %7, null
br i1 %8, label %55, label %9
9: ; preds = %0
store i64 0, i64* %3
%10 = tail call i32 @strlen(i8* %7)
%11 = call i64 @sstrncat(i8* %4, i64* %3, i32 512, i8* %7, i32 %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %55
13: ; preds = %9
%14 = call i64 @sstrncat(i8* %4, i64* %3, i32 512, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 12)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %55
16: ; preds = %13
%17 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp eq i32* %17, null
br i1 %18, label %55, label %19
19: ; preds = %16
%20 = load i32, i32* @SEEK_END
%21 = call i64 @fseek(i32* %17, i32 0, i32 %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %53
23: ; preds = %19
%24 = call i64 @ftell(i32* %17)
%25 = load i64, i64* @EOF
%26 = icmp eq i64 %24, %25
br i1 %26, label %53, label %27
27: ; preds = %23
%28 = load i32, i32* @SEEK_SET
%29 = call i64 @fseek(i32* %17, i32 0, i32 %28)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %53
31: ; preds = %27
%32 = call i64 @fread(i8* %5, i32 1, i64 %24, i32* %17)
%33 = icmp eq i64 %32, %24
br i1 %33, label %34, label %53
34: ; preds = %31
%35 = call i32 @time(i32* null)
%36 = call i32 @strtol(i8* nocapture %5, i32* null, i32 10)
%37 = sub nsw i32 %35, %36
%38 = icmp sgt i32 %37, 1209600
br i1 %38, label %39, label %50
39: ; preds = %34
%40 = load i32, i32* @stdout
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%42 = load i32, i32* @stdout
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%44 = load i32, i32* @stdout
%45 = call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.5, i64 0, i64 0))
%46 = load i32, i32* @stdout
%47 = call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%48 = load i32, i32* @stdout
%49 = call i32 (i32, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
br label %50
50: ; preds = %39, %34
%51 = call i32 @fclose(i32* %17)
%52 = sext i32 %37 to i64
br label %55
53: ; preds = %31, %27, %23, %19
%54 = call i32 @fclose(i32* %17)
br label %55
55: ; preds = %16, %13, %9, %0, %53, %50
%56 = phi i64 [ -1, %53 ], [ %52, %50 ], [ -1, %0 ], [ -1, %9 ], [ -1, %13 ], [ -1, %16 ]
ret i64 %56
}