#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;
struct tm {
  int tm_year;
  int tm_hour;
  int tm_min;
  int /*<<< orphan*/ tm_mon;
  int /*<<< orphan*/ tm_mday;
};

/* Variables and functions */
int /*<<< orphan*/ abrt(char *);
int /*<<< orphan*/ asctime(struct tm *);
int /*<<< orphan*/ assert(int);
int atol(char const *);
int /*<<< orphan*/ bail(char *, int);
int /*<<< orphan*/ dbug(char *, int /*<<< orphan*/);
char *getenv(char *);
int /*<<< orphan*/ info(char *, int);
struct tm *localtime(int *);
int /*<<< orphan*/ memset(struct tm *, int /*<<< orphan*/, int);
int time(int /*<<< orphan*/ *);
int timegm(struct tm *);
void get_current_time(unsigned *const restrict days,
                      unsigned *const restrict mins) {
  const char *override;
  struct tm tm, *lt;
  time_t t;
  if ((override = getenv("RAIDCHECK_TIME_OVERRIDE")) == NULL) {
    t = time(NULL);
  } else {
    t = atol(override);
    info("Time set via RAIDCHECK_TIME_OVERRIDE (%ld)\n", t);
  }
  if ((lt = localtime(&t)) == NULL)
    abrt("localtime: %m\n");
  dbug("Current time is %s", asctime(lt));
  if (lt->tm_year >= 1100)
    bail("Current year (%d) out of range (1970-3000)\n", lt->tm_year + 1900);
  assert(lt->tm_hour >= 0 && lt->tm_hour < 24 && lt->tm_min >= 0 &&
         lt->tm_min < 60);
  *mins = lt->tm_hour * 60 + lt->tm_min;
  memset(&tm, 0, sizeof tm);
  tm.tm_mday = lt->tm_mday;
  tm.tm_mon = lt->tm_mon;
  tm.tm_year = lt->tm_year;
  if ((t = timegm(&tm)) == -1)
    abrt("timegm: %m\n");
  assert(t >= 0 && t % 86400 == 0);
  *days = t / 86400;
}


x86 assembly (clang, -O0):
<get_current_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe29(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11fb <get_current_time+0x3b>
xor    %eax,%eax
mov    %eax,%edi
call   1090 <time@plt>
mov    %eax,-0x3c(%rbp)
jmp    1216 <get_current_time+0x56>
mov    -0x18(%rbp),%rdi
call   10b0 <atol@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%esi
lea    0xe07(%rip),%rdi
call   10e0 <info@plt>
lea    -0x3c(%rbp),%rdi
call   1040 <localtime@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    1239 <get_current_time+0x79>
lea    0xe10(%rip),%rdi
call   1050 <abrt@plt>
mov    -0x38(%rbp),%rdi
call   1060 <asctime@plt>
mov    %eax,%esi
lea    0xe08(%rip),%rdi
call   10d0 <dbug@plt>
mov    -0x38(%rbp),%rax
cmpl   $0x44c,(%rax)
jl     1278 <get_current_time+0xb8>
mov    -0x38(%rbp),%rax
mov    (%rax),%esi
add    $0x76c,%esi
lea    0xdf3(%rip),%rdi
call   10c0 <bail@plt>
mov    -0x38(%rbp),%rcx
xor    %eax,%eax
cmpl   $0x0,0x4(%rcx)
mov    %al,-0x3d(%rbp)
jl     12bf <get_current_time+0xff>
mov    -0x38(%rbp),%rcx
xor    %eax,%eax
cmpl   $0x18,0x4(%rcx)
mov    %al,-0x3d(%rbp)
jge    12bf <get_current_time+0xff>
mov    -0x38(%rbp),%rcx
xor    %eax,%eax
cmpl   $0x0,0x8(%rcx)
mov    %al,-0x3d(%rbp)
jl     12bf <get_current_time+0xff>
mov    -0x38(%rbp),%rax
cmpl   $0x3c,0x8(%rax)
setl   %al
mov    %al,-0x3d(%rbp)
mov    -0x3d(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x38(%rbp),%rax
imul   $0x3c,0x4(%rax),%ecx
mov    -0x38(%rbp),%rax
add    0x8(%rax),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1070 <memset@plt>
mov    -0x38(%rbp),%rax
mov    0x10(%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x38(%rbp),%rax
mov    0xc(%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x38(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
lea    -0x30(%rbp),%rdi
call   10a0 <timegm@plt>
mov    %eax,-0x3c(%rbp)
cmp    $0xffffffff,%eax
jne    132f <get_current_time+0x16f>
lea    0xd68(%rip),%rdi
call   1050 <abrt@plt>
xor    %eax,%eax
cmpl   $0x0,-0x3c(%rbp)
mov    %al,-0x3e(%rbp)
jl     1352 <get_current_time+0x192>
mov    -0x3c(%rbp),%eax
mov    $0x15180,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
sete   %al
mov    %al,-0x3e(%rbp)
mov    -0x3e(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x3c(%rbp),%eax
mov    $0x15180,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_current_time>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r15
mov    %rdi,%r14
lea    0xe29(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11fd <get_current_time+0x3d>
mov    %rax,%rdi
call   10b0 <atol@plt>
mov    %eax,0xc(%rsp)
lea    0xe24(%rip),%rdi
mov    %eax,%esi
call   10e0 <info@plt>
jmp    1208 <get_current_time+0x48>
xor    %edi,%edi
call   1090 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1040 <localtime@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1226 <get_current_time+0x66>
lea    0xe23(%rip),%rdi
call   1050 <abrt@plt>
mov    %rbx,%rdi
call   1060 <asctime@plt>
lea    0xe1e(%rip),%rdi
mov    %eax,%esi
call   10d0 <dbug@plt>
mov    (%rbx),%esi
cmp    $0x44c,%esi
jl     1258 <get_current_time+0x98>
add    $0x76c,%esi
lea    0xe13(%rip),%rdi
call   10c0 <bail@plt>
xor    %edi,%edi
cmpl   $0x17,0x4(%rbx)
ja     1270 <get_current_time+0xb0>
mov    0x8(%rbx),%eax
test   %eax,%eax
js     1270 <get_current_time+0xb0>
xor    %edi,%edi
cmp    $0x3c,%eax
setb   %dil
call   1080 <assert@plt>
imul   $0x3c,0x4(%rbx),%eax
add    0x8(%rbx),%eax
mov    %eax,(%r15)
lea    0x10(%rsp),%r15
xor    %ebp,%ebp
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1070 <memset@plt>
mov    0x10(%rbx),%eax
mov    %eax,0x20(%rsp)
mov    0xc(%rbx),%eax
mov    %eax,0x1c(%rsp)
mov    (%rbx),%eax
mov    %eax,0x10(%rsp)
mov    %r15,%rdi
call   10a0 <timegm@plt>
mov    %eax,0xc(%rsp)
cmp    $0xffffffff,%eax
jne    12ca <get_current_time+0x10a>
lea    0xdd1(%rip),%rdi
call   1050 <abrt@plt>
mov    0xc(%rsp),%eax
test   %eax,%eax
js     12e2 <get_current_time+0x122>
imul   $0x2d21c10b,%eax,%eax
ror    $0x7,%eax
xor    %ebp,%ebp
cmp    $0xc22f,%eax
setb   %bpl
mov    %ebp,%edi
call   1080 <assert@plt>
movslq 0xc(%rsp),%rax
imul   $0xffffffffc22e4507,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%eax
shr    $0x1f,%eax
sar    $0x10,%ecx
add    %eax,%ecx
mov    %ecx,(%r14)
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32, i32, i32 }
@.str = [24 x i8] c"RAIDCHECK_TIME_OVERRIDE\00"
@.str.1 = [44 x i8] c"Time set via RAIDCHECK_TIME_OVERRIDE (%ld)\0A\00"
@.str.2 = [15 x i8] c"localtime: %m\0A\00"
@.str.3 = [19 x i8] c"Current time is %s\00"
@.str.4 = [44 x i8] c"Current year (%d) out of range (1970-3000)\0A\00"
@.str.5 = [12 x i8] c"timegm: %m\0A\00"
define void @get_current_time(i32* noalias %0, i32* noalias %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca %struct.tm
%7 = alloca %struct.tm*
%8 = alloca i32
store i32* %0, i32** %3
store i32* %1, i32** %4
%9 = call i8* @getenv(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
store i8* %9, i8** %5
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @time(i32* null)
store i32 %12, i32* %8
br label %18
13: ; preds = %2
%14 = load i8*, i8** %5
%15 = call i32 @atol(i8* %14)
store i32 %15, i32* %8
%16 = load i32, i32* %8
%17 = call i32 @info(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i32 %16)
br label %18
18: ; preds = %13, %11
%19 = call %struct.tm* @localtime(i32* %8)
store %struct.tm* %19, %struct.tm** %7
%20 = icmp eq %struct.tm* %19, null
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = call i32 @abrt(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
br label %23
23: ; preds = %21, %18
%24 = load %struct.tm*, %struct.tm** %7
%25 = call i32 @asctime(%struct.tm* %24)
%26 = call i32 @dbug(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %25)
%27 = load %struct.tm*, %struct.tm** %7
%28 = getelementptr inbounds %struct.tm, %struct.tm* %27, i32 0, i32 0
%29 = load i32, i32* %28
%30 = icmp sge i32 %29, 1100
br i1 %30, label %31, label %37
31: ; preds = %23
%32 = load %struct.tm*, %struct.tm** %7
%33 = getelementptr inbounds %struct.tm, %struct.tm* %32, i32 0, i32 0
%34 = load i32, i32* %33
%35 = add nsw i32 %34, 1900
%36 = call i32 @bail(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0), i32 %35)
br label %37
37: ; preds = %31, %23
%38 = load %struct.tm*, %struct.tm** %7
%39 = getelementptr inbounds %struct.tm, %struct.tm* %38, i32 0, i32 1
%40 = load i32, i32* %39
%41 = icmp sge i32 %40, 0
br i1 %41, label %42, label %57
42: ; preds = %37
%43 = load %struct.tm*, %struct.tm** %7
%44 = getelementptr inbounds %struct.tm, %struct.tm* %43, i32 0, i32 1
%45 = load i32, i32* %44
%46 = icmp slt i32 %45, 24
br i1 %46, label %47, label %57
47: ; preds = %42
%48 = load %struct.tm*, %struct.tm** %7
%49 = getelementptr inbounds %struct.tm, %struct.tm* %48, i32 0, i32 2
%50 = load i32, i32* %49
%51 = icmp sge i32 %50, 0
br i1 %51, label %52, label %57
52: ; preds = %47
%53 = load %struct.tm*, %struct.tm** %7
%54 = getelementptr inbounds %struct.tm, %struct.tm* %53, i32 0, i32 2
%55 = load i32, i32* %54
%56 = icmp slt i32 %55, 60
br label %57
57: ; preds = %52, %47, %42, %37
%58 = phi i1 [ false, %47 ], [ false, %42 ], [ false, %37 ], [ %56, %52 ]
%59 = zext i1 %58 to i32
%60 = call i32 @assert(i32 %59)
%61 = load %struct.tm*, %struct.tm** %7
%62 = getelementptr inbounds %struct.tm, %struct.tm* %61, i32 0, i32 1
%63 = load i32, i32* %62
%64 = mul nsw i32 %63, 60
%65 = load %struct.tm*, %struct.tm** %7
%66 = getelementptr inbounds %struct.tm, %struct.tm* %65, i32 0, i32 2
%67 = load i32, i32* %66
%68 = add nsw i32 %64, %67
%69 = load i32*, i32** %4
store i32 %68, i32* %69
%70 = call i32 @memset(%struct.tm* %6, i32 0, i32 20)
%71 = load %struct.tm*, %struct.tm** %7
%72 = getelementptr inbounds %struct.tm, %struct.tm* %71, i32 0, i32 4
%73 = load i32, i32* %72
%74 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 4
store i32 %73, i32* %74
%75 = load %struct.tm*, %struct.tm** %7
%76 = getelementptr inbounds %struct.tm, %struct.tm* %75, i32 0, i32 3
%77 = load i32, i32* %76
%78 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 3
store i32 %77, i32* %78
%79 = load %struct.tm*, %struct.tm** %7
%80 = getelementptr inbounds %struct.tm, %struct.tm* %79, i32 0, i32 0
%81 = load i32, i32* %80
%82 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 0
store i32 %81, i32* %82
%83 = call i32 @timegm(%struct.tm* %6)
store i32 %83, i32* %8
%84 = icmp eq i32 %83, -1
br i1 %84, label %85, label %87
85: ; preds = %57
%86 = call i32 @abrt(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
br label %87
87: ; preds = %85, %57
%88 = load i32, i32* %8
%89 = icmp sge i32 %88, 0
br i1 %89, label %90, label %94
90: ; preds = %87
%91 = load i32, i32* %8
%92 = srem i32 %91, 86400
%93 = icmp eq i32 %92, 0
br label %94
94: ; preds = %90, %87
%95 = phi i1 [ false, %87 ], [ %93, %90 ]
%96 = zext i1 %95 to i32
%97 = call i32 @assert(i32 %96)
%98 = load i32, i32* %8
%99 = sdiv i32 %98, 86400
%100 = load i32*, i32** %3
store i32 %99, i32* %100
ret void
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32, i32, i32 }
@.str = [24 x i8] c"RAIDCHECK_TIME_OVERRIDE\00"
@.str.1 = [44 x i8] c"Time set via RAIDCHECK_TIME_OVERRIDE (%ld)\0A\00"
@.str.2 = [15 x i8] c"localtime: %m\0A\00"
@.str.3 = [19 x i8] c"Current time is %s\00"
@.str.4 = [44 x i8] c"Current year (%d) out of range (1970-3000)\0A\00"
@.str.5 = [12 x i8] c"timegm: %m\0A\00"
define void @get_current_time(i32* noalias nocapture writeonly %0, i32* noalias nocapture writeonly %1) {
%3 = alloca %struct.tm
%4 = alloca i32
%5 = bitcast %struct.tm* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = tail call i8* @getenv(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = tail call i32 @time(i32* null)
store i32 %10, i32* %4
br label %14
11: ; preds = %2
%12 = tail call i32 @atol(i8* %7)
store i32 %12, i32* %4
%13 = tail call i32 @info(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i32 %12)
br label %14
14: ; preds = %11, %9
%15 = call %struct.tm* @localtime(i32* %4)
%16 = icmp eq %struct.tm* %15, null
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = call i32 @abrt(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
br label %19
19: ; preds = %17, %14
%20 = call i32 @asctime(%struct.tm* %15)
%21 = call i32 @dbug(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %20)
%22 = getelementptr inbounds %struct.tm, %struct.tm* %15, i64 0, i32 0
%23 = load i32, i32* %22
%24 = icmp sgt i32 %23, 1099
br i1 %24, label %25, label %28
25: ; preds = %19
%26 = add nuw nsw i32 %23, 1900
%27 = call i32 @bail(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0), i32 %26)
br label %28
28: ; preds = %25, %19
%29 = getelementptr inbounds %struct.tm, %struct.tm* %15, i64 0, i32 1
%30 = load i32, i32* %29
%31 = icmp ult i32 %30, 24
br i1 %31, label %32, label %39
32: ; preds = %28
%33 = getelementptr inbounds %struct.tm, %struct.tm* %15, i64 0, i32 2
%34 = load i32, i32* %33
%35 = icmp sgt i32 %34, -1
br i1 %35, label %36, label %39
36: ; preds = %32
%37 = icmp ult i32 %34, 60
%38 = zext i1 %37 to i32
br label %39
39: ; preds = %36, %32, %28
%40 = phi i32 [ 0, %32 ], [ 0, %28 ], [ %38, %36 ]
%41 = call i32 @assert(i32 %40)
%42 = load i32, i32* %29
%43 = mul nsw i32 %42, 60
%44 = getelementptr inbounds %struct.tm, %struct.tm* %15, i64 0, i32 2
%45 = load i32, i32* %44
%46 = add nsw i32 %43, %45
store i32 %46, i32* %1
%47 = call i32 @memset(%struct.tm* %3, i32 0, i32 20)
%48 = getelementptr inbounds %struct.tm, %struct.tm* %15, i64 0, i32 4
%49 = load i32, i32* %48
%50 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 4
store i32 %49, i32* %50
%51 = getelementptr inbounds %struct.tm, %struct.tm* %15, i64 0, i32 3
%52 = load i32, i32* %51
%53 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 3
store i32 %52, i32* %53
%54 = load i32, i32* %22
%55 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 0
store i32 %54, i32* %55
%56 = call i32 @timegm(%struct.tm* %3)
store i32 %56, i32* %4
%57 = icmp eq i32 %56, -1
br i1 %57, label %58, label %61
58: ; preds = %39
%59 = call i32 @abrt(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
%60 = load i32, i32* %4
br label %61
61: ; preds = %58, %39
%62 = phi i32 [ %60, %58 ], [ %56, %39 ]
%63 = icmp sgt i32 %62, -1
br i1 %63, label %64, label %68
64: ; preds = %61
%65 = urem i32 %62, 86400
%66 = icmp eq i32 %65, 0
%67 = zext i1 %66 to i32
br label %68
68: ; preds = %64, %61
%69 = phi i32 [ 0, %61 ], [ %67, %64 ]
%70 = call i32 @assert(i32 %69)
%71 = load i32, i32* %4
%72 = sdiv i32 %71, 86400
store i32 %72, i32* %0
ret void
}