#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 uint32_t;
typedef int time_t;

/* Variables and functions */
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
char *getenv(char *);
int /*<<< orphan*/ stderr;
int strtoull(char *, char **, int);
int /*<<< orphan*/ time(int *);
uint32_t jboot_timestamp(void) {
  char *env = getenv("SOURCE_DATE_EPOCH");
  char *endptr = env;
  time_t fixed_timestamp = -1;
  errno = 0;
  if (env && *env) {
    fixed_timestamp = strtoull(env, &endptr, 10);
    if (errno || (endptr && *endptr != '\0')) {
      fprintf(stderr, "Invalid SOURCE_DATE_EPOCH");
      fixed_timestamp = -1;
    }
  }
  if (fixed_timestamp == -1)
    time(&fixed_timestamp);
  return (((uint32_t)fixed_timestamp) - 0x35016f00L) >> 2;
}


x86 assembly (clang, -O0):
<jboot_timestamp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xeb9(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
mov    0x2e6a(%rip),%rax
movq   $0x0,(%rax)
cmpq   $0x0,-0x8(%rbp)
je     11f2 <jboot_timestamp+0xb2>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11f2 <jboot_timestamp+0xb2>
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtoull@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e2c(%rip),%rax
cmpq   $0x0,(%rax)
jne    11d1 <jboot_timestamp+0x91>
cmpq   $0x0,-0x10(%rbp)
je     11ed <jboot_timestamp+0xad>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11ed <jboot_timestamp+0xad>
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
lea    0xe1f(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x14(%rbp)
jmp    11f2 <jboot_timestamp+0xb2>
cmpl   $0xffffffff,-0x14(%rbp)
jne    1205 <jboot_timestamp+0xc5>
lea    -0x14(%rbp),%rdi
call   1060 <time@plt>
movslq -0x14(%rbp),%rax
sub    $0x35016f00,%rax
sar    $0x2,%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<jboot_timestamp>:
push   %rbx
sub    $0x10,%rsp
lea    0xebc(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,0x8(%rsp)
movl   $0xffffffff,0x4(%rsp)
ff
mov    0x2e73(%rip),%rbx
movq   $0x0,(%rbx)
test   %rax,%rax
je     11af <jboot_timestamp+0x6f>
cmpb   $0x0,(%rax)
je     11af <jboot_timestamp+0x6f>
lea    0x8(%rsp),%rsi
mov    %rax,%rdi
mov    $0xa,%edx
call   1040 <strtoull@plt>
mov    %eax,0x4(%rsp)
cmpq   $0x0,(%rbx)
je     11d7 <jboot_timestamp+0x97>
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
lea    0xe5e(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,0x4(%rsp)
ff
lea    0x4(%rsp),%rdi
call   1060 <time@plt>
mov    0x4(%rsp),%eax
movslq %eax,%rcx
movabs $0x3cafe9100,%rax
add    %rcx,%rax
shr    $0x2,%rax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x8(%rsp),%rcx
test   %rcx,%rcx
je     11e6 <jboot_timestamp+0xa6>
cmpb   $0x0,(%rcx)
jne    1192 <jboot_timestamp+0x52>
cmp    $0xffffffff,%eax
jne    11bd <jboot_timestamp+0x7d>
jmp    11af <jboot_timestamp+0x6f>

LLVM IR (-O0):
@.str = [18 x i8] c"SOURCE_DATE_EPOCH\00"
@errno = global i64 0
@stderr = global i32 0
@.str.1 = [26 x i8] c"Invalid SOURCE_DATE_EPOCH\00"
define i32 @jboot_timestamp() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i32
%4 = call i8* @getenv(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
store i8* %4, i8** %1
%5 = load i8*, i8** %1
store i8* %5, i8** %2
store i32 -1, i32* %3
store i64 0, i64* @errno
%6 = load i8*, i8** %1
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %30
8: ; preds = %0
%9 = load i8*, i8** %1
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %30
13: ; preds = %8
%14 = load i8*, i8** %1
%15 = call i32 @strtoull(i8* %14, i8** %2, i32 10)
store i32 %15, i32* %3
%16 = load i64, i64* @errno
%17 = icmp ne i64 %16, 0
br i1 %17, label %26, label %18
18: ; preds = %13
%19 = load i8*, i8** %2
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %29
21: ; preds = %18
%22 = load i8*, i8** %2
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %21, %13
%27 = load i32, i32* @stderr
%28 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %29
29: ; preds = %26, %21, %18
br label %30
30: ; preds = %29, %8, %0
%31 = load i32, i32* %3
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %35
33: ; preds = %30
%34 = call i32 @time(i32* %3)
br label %35
35: ; preds = %33, %30
%36 = load i32, i32* %3
%37 = sext i32 %36 to i64
%38 = sub nsw i64 %37, 889286400
%39 = ashr i64 %38, 2
%40 = trunc i64 %39 to i32
ret i32 %40
}

LLVM IR (-O2):
@.str = [18 x i8] c"SOURCE_DATE_EPOCH\00"
@errno = global i64 0
@stderr = global i32 0
@.str.1 = [26 x i8] c"Invalid SOURCE_DATE_EPOCH\00"
define i32 @jboot_timestamp() {
%1 = alloca i8*
%2 = alloca i32
%3 = tail call i8* @getenv(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%4 = bitcast i8** %1 to i8*
store i8* %3, i8** %1
%5 = bitcast i32* %2 to i8*
store i32 -1, i32* %2
store i64 0, i64* @errno
%6 = icmp eq i8* %3, null
br i1 %6, label %25, label %7
7: ; preds = %0
%8 = load i8, i8* %3
%9 = icmp eq i8 %8, 0
br i1 %9, label %25, label %10
10: ; preds = %7
%11 = call i32 @strtoull(i8* %3, i8** %1, i32 10)
store i32 %11, i32* %2
%12 = load i64, i64* @errno
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %20
14: ; preds = %10
%15 = load i8*, i8** %1
%16 = icmp eq i8* %15, null
br i1 %16, label %23, label %17
17: ; preds = %14
%18 = load i8, i8* %15
%19 = icmp eq i8 %18, 0
br i1 %19, label %23, label %20
20: ; preds = %17, %10
%21 = load i32, i32* @stderr
%22 = tail call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %2
br label %25
23: ; preds = %14, %17
%24 = icmp eq i32 %11, -1
br i1 %24, label %25, label %28
25: ; preds = %7, %0, %20, %23
%26 = call i32 @time(i32* %2)
%27 = load i32, i32* %2
br label %28
28: ; preds = %25, %23
%29 = phi i32 [ %27, %25 ], [ %11, %23 ]
%30 = sext i32 %29 to i64
%31 = add nsw i64 %30, 16290582784
%32 = lshr i64 %31, 2
%33 = trunc i64 %32 to i32
ret i32 %33
}