#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 timeval {
  long const tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
long get_tow(void) {
  int day_of_week;
  long days_from_1970;
  long today_seconds;
  const long SECS_PER_DAY = (3600 * 24);
  const long leap_seconds = 13;
  struct timeval tv;
  gettimeofday(&tv, NULL);
  days_from_1970 = (tv.tv_sec / SECS_PER_DAY);
  today_seconds = tv.tv_sec - days_from_1970 * SECS_PER_DAY;
  day_of_week = (days_from_1970 + 4) % 7;
  return day_of_week * SECS_PER_DAY + today_seconds + leap_seconds;
}


x86 assembly (clang, -O0):
<get_tow>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movq   $0x15180,-0x20(%rbp)
movq   $0xd,-0x28(%rbp)
lea    -0x30(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
mov    -0x30(%rbp),%rax
mov    $0x15180,%ecx
cqto
idiv   %rcx
mov    %rax,-0x10(%rbp)
mov    -0x30(%rbp),%rax
imul   $0x15180,-0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
add    $0x4,%rax
mov    $0x7,%ecx
cqto
idiv   %rcx
mov    %edx,%eax
mov    %eax,-0x4(%rbp)
movslq -0x4(%rbp),%rax
imul   $0x15180,%rax,%rax
add    -0x18(%rbp),%rax
add    $0xd,%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_tow>:
push   %rax
mov    %rsp,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    (%rsp),%rcx
movabs $0x1845c8a0ce512957,%rdx
c8 45 18
mov    %rcx,%rax
imul   %rdx
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0xd,%rdx
lea    (%rdx,%rax,1),%rsi
add    %rdx,%rax
add    $0x4,%rax
movabs $0x4924924924924925,%rdx
92 24 49
imul   %rdx
mov    %rdx,%rax
shr    $0x3f,%rax
sar    %rdx
add    %rax,%rdx
lea    0x0(,%rdx,8),%rax
sub    %rax,%rdx
lea    (%rdx,%rsi,1),%rax
add    $0x4,%rax
sub    %rsi,%rax
imul   $0x15180,%rax,%rax
add    %rcx,%rax
add    $0xd,%rax
pop    %rcx
ret

LLVM IR (-O0):
%struct.timeval = type { i64 }
define i64 @get_tow() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca %struct.timeval
store i64 86400, i64* %4
store i64 13, i64* %5
%7 = call i32 @gettimeofday(%struct.timeval* %6, i32* null)
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
%9 = load i64, i64* %8
%10 = sdiv i64 %9, 86400
store i64 %10, i64* %2
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
%12 = load i64, i64* %11
%13 = load i64, i64* %2
%14 = mul nsw i64 %13, 86400
%15 = sub nsw i64 %12, %14
store i64 %15, i64* %3
%16 = load i64, i64* %2
%17 = add nsw i64 %16, 4
%18 = srem i64 %17, 7
%19 = trunc i64 %18 to i32
store i32 %19, i32* %1
%20 = load i32, i32* %1
%21 = sext i32 %20 to i64
%22 = mul nsw i64 %21, 86400
%23 = load i64, i64* %3
%24 = add nsw i64 %22, %23
%25 = add nsw i64 %24, 13
ret i64 %25
}

LLVM IR (-O2):
%struct.timeval = type { i64 }
define i64 @get_tow() {
%1 = alloca %struct.timeval
%2 = bitcast %struct.timeval* %1 to i8*
%3 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%4 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%5 = load i64, i64* %4
%6 = sdiv i64 %5, 86400
%7 = add nsw i64 %6, 4
%8 = srem i64 %7, 7
%9 = sub nsw i64 %8, %6
%10 = mul i64 %9, 86400
%11 = add i64 %5, 13
%12 = add i64 %11, %10
ret i64 %12
}