#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 */

/* Variables and functions */
double fb_DateSerial(int, int, int);
int fb_Weekday(double, int);
int /*<<< orphan*/ fb_hDateDecodeSerial(double, int *, int *, int *);
void fb_hGetBeginOfWeek(int *pYear, int *pMonth, int *pDay,
                        int first_day_of_week) {
  double serial;
  int weekday;
  serial = fb_DateSerial(*pYear, *pMonth, *pDay);
  weekday = fb_Weekday(serial, first_day_of_week);
  serial -= weekday - 1;
  fb_hDateDecodeSerial(serial, pYear, pMonth, pDay);
}


x86 assembly (clang, -O0):
<fb_hGetBeginOfWeek>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
call   1040 <fb_DateSerial@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
mov    -0x1c(%rbp),%edi
call   1030 <fb_Weekday@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
sub    $0x1,%eax
cvtsi2sd %eax,%xmm1
movsd  -0x28(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <fb_hDateDecodeSerial@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fb_hGetBeginOfWeek>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %rsi,%rbp
mov    %rdi,%rbx
mov    (%rdi),%edi
mov    (%rsi),%esi
mov    (%rdx),%edx
call   1040 <fb_DateSerial@plt>
movsd  %xmm0,(%rsp)
mov    %r14d,%edi
call   1030 <fb_Weekday@plt>
add    $0xffffffff,%eax
cvtsi2sd %eax,%xmm1
movsd  (%rsp),%xmm0
subsd  %xmm1,%xmm0
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r15,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <fb_hDateDecodeSerial@plt>

LLVM IR (-O0):
define void @fb_hGetBeginOfWeek(i32* %0, i32* %1, i32* %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca double
%10 = alloca i32
store i32* %0, i32** %5
store i32* %1, i32** %6
store i32* %2, i32** %7
store i32 %3, i32* %8
%11 = load i32*, i32** %5
%12 = load i32, i32* %11
%13 = load i32*, i32** %6
%14 = load i32, i32* %13
%15 = load i32*, i32** %7
%16 = load i32, i32* %15
%17 = call double @fb_DateSerial(i32 %12, i32 %14, i32 %16)
store double %17, double* %9
%18 = load double, double* %9
%19 = load i32, i32* %8
%20 = call i32 @fb_Weekday(double %18, i32 %19)
store i32 %20, i32* %10
%21 = load i32, i32* %10
%22 = sub nsw i32 %21, 1
%23 = sitofp i32 %22 to double
%24 = load double, double* %9
%25 = fsub double %24, %23
store double %25, double* %9
%26 = load double, double* %9
%27 = load i32*, i32** %5
%28 = load i32*, i32** %6
%29 = load i32*, i32** %7
%30 = call i32 @fb_hDateDecodeSerial(double %26, i32* %27, i32* %28, i32* %29)
ret void
}

LLVM IR (-O2):
define void @fb_hGetBeginOfWeek(i32* %0, i32* %1, i32* %2, i32 %3) {
%5 = load i32, i32* %0
%6 = load i32, i32* %1
%7 = load i32, i32* %2
%8 = tail call double @fb_DateSerial(i32 %5, i32 %6, i32 %7)
%9 = tail call i32 @fb_Weekday(double %8, i32 %3)
%10 = add nsw i32 %9, -1
%11 = sitofp i32 %10 to double
%12 = fsub double %8, %11
%13 = tail call i32 @fb_hDateDecodeSerial(double %12, i32* %0, i32* %1, i32* %2)
ret void
}