#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 */
struct tm {
  scalar_t__ tm_isdst;
};
struct timezone {
  int tz_minuteswest;
};
struct timeval {
  long tv_sec;
  int tv_usec;
};

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int gettimeofday(struct timeval *, struct timezone *);
int /*<<< orphan*/ perror(char *);
void gs_get_clock(long *pdt) {
  long secs_since_1980;
  struct timeval tp;
  struct timezone tzp;
  struct tm *tm, *localtime();
  if (gettimeofday(&tp, &tzp) == -1) {
    perror("Ghostscript: gettimeofday failed:");
    exit(-1);
  }
  secs_since_1980 = tp.tv_sec - (long)(60 * 60 * 24 * 365.25 * 10);
  secs_since_1980 -= (tzp.tz_minuteswest * 60);
  tm = localtime(&(tp.tv_sec));
  if (tm->tm_isdst)
    secs_since_1980 += (60 * 60);
  pdt[0] = secs_since_1980 / (60 * 60 * 24);
  pdt[1] = (secs_since_1980 % (60 * 60 * 24)) * 1000 + tp.tv_usec / 1000;
}


x86 assembly (clang, -O0):
<gs_get_clock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1040 <gettimeofday@plt>
cmp    $0xffffffff,%eax
jne    1178 <gs_get_clock+0x38>
lea    0xe97(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
mov    -0x20(%rbp),%rax
sub    $0x12cf4ec0,%rax
mov    %rax,-0x10(%rbp)
imul   $0x3c,-0x28(%rbp),%eax
movslq %eax,%rcx
mov    -0x10(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
mov    $0x0,%al
call   1030 <localtime@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmpq   $0x0,(%rax)
je     11c3 <gs_get_clock+0x83>
mov    -0x10(%rbp),%rax
add    $0xe10,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    $0x15180,%ecx
cqto
idiv   %rcx
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    $0x15180,%ecx
cqto
idiv   %rcx
imul   $0x3e8,%rdx,%rcx
mov    -0x18(%rbp),%eax
mov    $0x3e8,%esi
cltd
idiv   %esi
cltq
add    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,0x8(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gs_get_clock>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r14
lea    0x8(%rsp),%rdi
mov    %rsp,%rsi
call   1040 <gettimeofday@plt>
cmp    $0xffffffff,%eax
je     11fe <gs_get_clock+0xbe>
mov    0x8(%rsp),%r15
movslq (%rsp),%rax
imul   $0x3c,%rax,%r12
mov    %r15,%rbx
sub    %r12,%rbx
lea    0x8(%rsp),%rdi
xor    %eax,%eax
call   1030 <localtime@plt>
add    $0xffffffffed30b140,%rbx
neg    %r12
cmpq   $0x0,(%rax)
lea    -0x12cf40b0(%r15,%r12,1),%rcx
ed
cmove  %rbx,%rcx
movabs $0x1845c8a0ce512957,%rdx
c8 45 18
mov    %rcx,%rax
imul   %rdx
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0xd,%rdx
add    %rax,%rdx
mov    %rdx,(%r14)
imul   $0x15180,%rdx,%rax
sub    %rax,%rcx
imul   $0x3e8,%rcx,%rax
movslq 0x10(%rsp),%rcx
imul   $0x10624dd3,%rcx,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
movslq %ecx,%rcx
add    %rax,%rcx
mov    %rcx,0x8(%r14)
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xdfb(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.timeval = type { i64, i32 }
%struct.timezone = type { i32 }
%struct.tm = type { i64 }
@.str = [34 x i8] c"Ghostscript: gettimeofday failed:\00"
define void @gs_get_clock(i64* %0) {
%2 = alloca i64*
%3 = alloca i64
%4 = alloca %struct.timeval
%5 = alloca %struct.timezone
%6 = alloca %struct.tm*
store i64* %0, i64** %2
%7 = call i32 @gettimeofday(%struct.timeval* %4, %struct.timezone* %5)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @exit(i32 -1)
unreachable
12: ; preds = %1
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
%14 = load i64, i64* %13
%15 = sub nsw i64 %14, 315576000
store i64 %15, i64* %3
%16 = getelementptr inbounds %struct.timezone, %struct.timezone* %5, i32 0, i32 0
%17 = load i32, i32* %16
%18 = mul nsw i32 %17, 60
%19 = sext i32 %18 to i64
%20 = load i64, i64* %3
%21 = sub nsw i64 %20, %19
store i64 %21, i64* %3
%22 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
%23 = call %struct.tm* (i64*, ...) bitcast (%struct.tm* (...)* @localtime to %struct.tm* (i64*, ...)*)(i64* %22)
store %struct.tm* %23, %struct.tm** %6
%24 = load %struct.tm*, %struct.tm** %6
%25 = getelementptr inbounds %struct.tm, %struct.tm* %24, i32 0, i32 0
%26 = load i64, i64* %25
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %12
%29 = load i64, i64* %3
%30 = add nsw i64 %29, 3600
store i64 %30, i64* %3
br label %31
31: ; preds = %28, %12
%32 = load i64, i64* %3
%33 = sdiv i64 %32, 86400
%34 = load i64*, i64** %2
%35 = getelementptr inbounds i64, i64* %34, i64 0
store i64 %33, i64* %35
%36 = load i64, i64* %3
%37 = srem i64 %36, 86400
%38 = mul nsw i64 %37, 1000
%39 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 1
%40 = load i32, i32* %39
%41 = sdiv i32 %40, 1000
%42 = sext i32 %41 to i64
%43 = add nsw i64 %38, %42
%44 = load i64*, i64** %2
%45 = getelementptr inbounds i64, i64* %44, i64 1
store i64 %43, i64* %45
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i64, i32 }
%struct.timezone = type { i32 }
%struct.tm = type { i64 }
@.str = [34 x i8] c"Ghostscript: gettimeofday failed:\00"
define void @gs_get_clock(i64* nocapture writeonly %0) {
%2 = alloca %struct.timeval
%3 = alloca %struct.timezone
%4 = bitcast %struct.timeval* %2 to i8*
%5 = bitcast %struct.timezone* %3 to i8*
%6 = call i32 @gettimeofday(%struct.timeval* %2, %struct.timezone* %3)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = tail call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @exit(i32 -1)
unreachable
11: ; preds = %1
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%13 = load i64, i64* %12
%14 = add nsw i64 %13, -315576000
%15 = getelementptr inbounds %struct.timezone, %struct.timezone* %3, i64 0, i32 0
%16 = load i32, i32* %15
%17 = mul nsw i32 %16, 60
%18 = sext i32 %17 to i64
%19 = sub i64 %14, %18
%20 = call %struct.tm* (i64*, ...) bitcast (%struct.tm* (...)* @localtime to %struct.tm* (i64*, ...)*)(i64* %12)
%21 = getelementptr inbounds %struct.tm, %struct.tm* %20, i64 0, i32 0
%22 = load i64, i64* %21
%23 = icmp eq i64 %22, 0
%24 = add nsw i64 %19, 3600
%25 = select i1 %23, i64 %19, i64 %24
%26 = sdiv i64 %25, 86400
store i64 %26, i64* %0
%27 = srem i64 %25, 86400
%28 = mul nsw i64 %27, 1000
%29 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%30 = load i32, i32* %29
%31 = sdiv i32 %30, 1000
%32 = sext i32 %31 to i64
%33 = add nsw i64 %28, %32
%34 = getelementptr inbounds i64, i64* %0, i64 1
store i64 %33, i64* %34
ret void
}