#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 long time_t;
struct tm {
  int /*<<< orphan*/ tm_wday;
  scalar_t__ tm_sec;
  scalar_t__ tm_min;
  scalar_t__ tm_hour;
};

/* Variables and functions */
long getRelativeSecondsOfDayofweek(int /*<<< orphan*/, int /*<<< orphan*/);
long getSeconds(struct tm *);
struct tm *localtime(long *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memcpy(struct tm *, struct tm *, int);
long mktime(struct tm *);
int /*<<< orphan*/ time(long *);
long int getRelativeIntervalOfWeek(struct tm *tp) {
  time_t current_time;
  struct tm *current, *midnight;
  time_t delayed_time = 0;
  time(&current_time);
  current = localtime(&current_time);
  midnight = (struct tm *)malloc(sizeof(struct tm));
  memcpy(midnight, current, sizeof(struct tm));
  midnight->tm_hour = 0;
  midnight->tm_min = 0;
  midnight->tm_sec = 0;
  delayed_time = current_time - mktime(midnight);
  delayed_time = getRelativeSecondsOfDayofweek(current->tm_wday, tp->tm_wday) -
                 delayed_time;
  delayed_time = delayed_time + getSeconds(tp);
  return delayed_time;
}


x86 assembly (clang, -O0):
<getRelativeIntervalOfWeek>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x28(%rbp)
lea    -0x10(%rbp),%rdi
call   1070 <time@plt>
lea    -0x10(%rbp),%rdi
call   1040 <localtime@plt>
mov    %rax,-0x18(%rbp)
mov    $0x20,%edi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x20,%edx
call   1060 <memcpy@plt>
mov    -0x20(%rbp),%rax
movq   $0x0,0x18(%rax)
mov    -0x20(%rbp),%rax
movq   $0x0,0x10(%rax)
mov    -0x20(%rbp),%rax
movq   $0x0,0x8(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
call   1090 <mktime@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rax
mov    (%rax),%esi
call   1030 <getRelativeSecondsOfDayofweek@plt>
sub    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <getSeconds@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getRelativeIntervalOfWeek>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1070 <time@plt>
mov    %rbx,%rdi
call   1040 <localtime@plt>
mov    %rax,%r15
mov    $0x20,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
mov    $0x20,%edx
call   1060 <memcpy@plt>
xorps  %xmm0,%xmm0
movups %xmm0,0x8(%rbx)
movq   $0x0,0x18(%rbx)
mov    0x8(%rsp),%r13
mov    %rbx,%rdi
call   1090 <mktime@plt>
mov    %rax,%r12
sub    %r13,%r12
mov    (%r15),%edi
mov    (%r14),%esi
call   1030 <getRelativeSecondsOfDayofweek@plt>
mov    %rax,%rbx
add    %r12,%rbx
mov    %r14,%rdi
call   1050 <getSeconds@plt>
add    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.tm = type { i32, i64, i64, i64 }
define i64 @getRelativeIntervalOfWeek(%struct.tm* %0) {
%2 = alloca %struct.tm*
%3 = alloca i64
%4 = alloca %struct.tm*
%5 = alloca %struct.tm*
%6 = alloca i64
store %struct.tm* %0, %struct.tm** %2
store i64 0, i64* %6
%7 = call i32 @time(i64* %3)
%8 = call %struct.tm* @localtime(i64* %3)
store %struct.tm* %8, %struct.tm** %4
%9 = call i64 @malloc(i32 32)
%10 = inttoptr i64 %9 to %struct.tm*
store %struct.tm* %10, %struct.tm** %5
%11 = load %struct.tm*, %struct.tm** %5
%12 = load %struct.tm*, %struct.tm** %4
%13 = call i32 @memcpy(%struct.tm* %11, %struct.tm* %12, i32 32)
%14 = load %struct.tm*, %struct.tm** %5
%15 = getelementptr inbounds %struct.tm, %struct.tm* %14, i32 0, i32 3
store i64 0, i64* %15
%16 = load %struct.tm*, %struct.tm** %5
%17 = getelementptr inbounds %struct.tm, %struct.tm* %16, i32 0, i32 2
store i64 0, i64* %17
%18 = load %struct.tm*, %struct.tm** %5
%19 = getelementptr inbounds %struct.tm, %struct.tm* %18, i32 0, i32 1
store i64 0, i64* %19
%20 = load i64, i64* %3
%21 = load %struct.tm*, %struct.tm** %5
%22 = call i64 @mktime(%struct.tm* %21)
%23 = sub nsw i64 %20, %22
store i64 %23, i64* %6
%24 = load %struct.tm*, %struct.tm** %4
%25 = getelementptr inbounds %struct.tm, %struct.tm* %24, i32 0, i32 0
%26 = load i32, i32* %25
%27 = load %struct.tm*, %struct.tm** %2
%28 = getelementptr inbounds %struct.tm, %struct.tm* %27, i32 0, i32 0
%29 = load i32, i32* %28
%30 = call i64 @getRelativeSecondsOfDayofweek(i32 %26, i32 %29)
%31 = load i64, i64* %6
%32 = sub nsw i64 %30, %31
store i64 %32, i64* %6
%33 = load i64, i64* %6
%34 = load %struct.tm*, %struct.tm** %2
%35 = call i64 @getSeconds(%struct.tm* %34)
%36 = add nsw i64 %33, %35
store i64 %36, i64* %6
%37 = load i64, i64* %6
ret i64 %37
}

LLVM IR (-O2):
%struct.tm = type { i32, i64, i64, i64 }
define i64 @getRelativeIntervalOfWeek(%struct.tm* %0) {
%2 = alloca i64
%3 = bitcast i64* %2 to i8*
%4 = call i32 @time(i64* %2)
%5 = call %struct.tm* @localtime(i64* %2)
%6 = call i64 @malloc(i32 32)
%7 = inttoptr i64 %6 to %struct.tm*
%8 = call i32 @memcpy(%struct.tm* %7, %struct.tm* %5, i32 32)
%9 = getelementptr inbounds %struct.tm, %struct.tm* %7, i64 0, i32 1
%10 = bitcast i64* %9 to i8*
%11 = load i64, i64* %2
%12 = call i64 @mktime(%struct.tm* %7)
%13 = sub i64 %12, %11
%14 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 0
%15 = load i32, i32* %14
%16 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 0
%17 = load i32, i32* %16
%18 = call i64 @getRelativeSecondsOfDayofweek(i32 %15, i32 %17)
%19 = add i64 %13, %18
%20 = call i64 @getSeconds(%struct.tm* %0)
%21 = add nsw i64 %19, %20
ret i64 %21
}