#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_wday;
};

/* Variables and functions */
int DSTcorrect(int, int);
struct tm *localtime(int *);
time_t RelativeDate(time_t Start, time_t DayOrdinal, time_t DayNumber) {
  struct tm *tm;
  time_t now;
  now = Start;
  tm = localtime(&now);
  now += (24L * 60L * 60L) * ((DayNumber - tm->tm_wday + 7) % 7);
  now +=
      7 * (24L * 60L * 60L) * (DayOrdinal <= 0 ? DayOrdinal : DayOrdinal - 1);
  return DSTcorrect(Start, now);
}


x86 assembly (clang, -O0):
<RelativeDate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x1c(%rbp)
lea    -0x1c(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    -0x18(%rbp),%rcx
sub    (%rcx),%eax
add    $0x7,%eax
mov    $0x7,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
imul   $0x15180,%rax,%rcx
movslq -0x1c(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x8(%rbp)
jg     1181 <RelativeDate+0x61>
mov    -0x8(%rbp),%eax
mov    %eax,-0x20(%rbp)
jmp    118a <RelativeDate+0x6a>
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cltq
imul   $0x93a80,%rax,%rcx
movslq -0x1c(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x1c(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1040 <DSTcorrect@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<RelativeDate>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edx,%ebx
mov    %esi,%ebp
mov    %edi,%r14d
mov    %edi,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1030 <localtime@plt>
sub    (%rax),%ebx
mov    %ebx,%eax
add    $0x7,%eax
cltq
imul   $0xffffffff92492493,%rax,%rax
shr    $0x20,%rax
add    %ebx,%eax
add    $0x7,%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
sar    $0x2,%eax
add    %ecx,%eax
lea    0x0(,%rax,8),%ecx
sub    %ecx,%eax
add    %ebx,%eax
add    $0x7,%eax
imul   $0x15180,%eax,%eax
xor    %ecx,%ecx
test   %ebp,%ebp
setg   %cl
sub    %ecx,%ebp
imul   $0x93a80,%ebp,%esi
add    0xc(%rsp),%esi
add    %eax,%esi
mov    %esi,0xc(%rsp)
mov    %r14d,%edi
call   1040 <DSTcorrect@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
define i32 @RelativeDate(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.tm*
%8 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = load i32, i32* %4
store i32 %9, i32* %8
%10 = call %struct.tm* @localtime(i32* %8)
store %struct.tm* %10, %struct.tm** %7
%11 = load i32, i32* %6
%12 = load %struct.tm*, %struct.tm** %7
%13 = getelementptr inbounds %struct.tm, %struct.tm* %12, i32 0, i32 0
%14 = load i32, i32* %13
%15 = sub nsw i32 %11, %14
%16 = add nsw i32 %15, 7
%17 = srem i32 %16, 7
%18 = sext i32 %17 to i64
%19 = mul nsw i64 86400, %18
%20 = load i32, i32* %8
%21 = sext i32 %20 to i64
%22 = add nsw i64 %21, %19
%23 = trunc i64 %22 to i32
store i32 %23, i32* %8
%24 = load i32, i32* %5
%25 = icmp sle i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %3
%27 = load i32, i32* %5
br label %31
28: ; preds = %3
%29 = load i32, i32* %5
%30 = sub nsw i32 %29, 1
br label %31
31: ; preds = %28, %26
%32 = phi i32 [ %27, %26 ], [ %30, %28 ]
%33 = sext i32 %32 to i64
%34 = mul nsw i64 604800, %33
%35 = load i32, i32* %8
%36 = sext i32 %35 to i64
%37 = add nsw i64 %36, %34
%38 = trunc i64 %37 to i32
store i32 %38, i32* %8
%39 = load i32, i32* %4
%40 = load i32, i32* %8
%41 = call i32 @DSTcorrect(i32 %39, i32 %40)
ret i32 %41
}

LLVM IR (-O2):
%struct.tm = type { i32 }
define i32 @RelativeDate(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
store i32 %0, i32* %4
%6 = call %struct.tm* @localtime(i32* %4)
%7 = getelementptr inbounds %struct.tm, %struct.tm* %6, i64 0, i32 0
%8 = load i32, i32* %7
%9 = add i32 %2, 7
%10 = sub i32 %9, %8
%11 = srem i32 %10, 7
%12 = mul nsw i32 %11, 86400
%13 = load i32, i32* %4
%14 = icmp sgt i32 %1, 0
%15 = sext i1 %14 to i32
%16 = add nsw i32 %15, %1
%17 = mul i32 %16, 604800
%18 = add i32 %13, %17
%19 = add i32 %18, %12
store i32 %19, i32* %4
%20 = call i32 @DSTcorrect(i32 %0, i32 %19)
ret i32 %20
}