#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 */
int /*<<< orphan*/ fb_hDateDecodeSerial(double, int *, int /*<<< orphan*/,
                                        int /*<<< orphan*/);
double fb_hGetFirstWeekOfYear(int, int, int);
double floor(double);
int fb_hGetWeekOfYear(int ref_year, double serial, int first_day_of_year,
                      int first_day_of_week) {
  int sign;
  int year, week;
  double serial_first_week;
  fb_hDateDecodeSerial(serial, &year, 0, 0);
  serial_first_week =
      fb_hGetFirstWeekOfYear(ref_year, first_day_of_year, first_day_of_week);
  serial = floor(serial - serial_first_week);
  sign = (((serial) < 0) ? -1 : 1);
  serial /= 7.0l;
  week = (int)(serial + sign);
  return week;
}


x86 assembly (clang, -O0):
<fb_hGetWeekOfYear>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
movsd  %xmm0,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
lea    -0x20(%rbp),%rdi
xor    %edx,%edx
mov    %edx,%esi
call   1040 <fb_hDateDecodeSerial@plt>
mov    -0x4(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1030 <fb_hGetFirstWeekOfYear@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
subsd  %xmm1,%xmm0
call   1050 <floor@plt>
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm1
xorps  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
setbe  %al
movzbl %al,%ecx
mov    %ecx,%eax
lea    -0x1(%rax,%rax,1),%eax
mov    %eax,-0x1c(%rbp)
fldl   -0x10(%rbp)
flds   0xe59(%rip)
fdivrp %st,%st(1)
fstpl  -0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
cvtsi2sdl -0x1c(%rbp),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fb_hGetWeekOfYear>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %edx,%r14d
mov    %esi,%ebp
movsd  %xmm0,(%rsp)
mov    %edi,%ebx
lea    0x1c(%rsp),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1040 <fb_hDateDecodeSerial@plt>
mov    %ebx,%edi
mov    %ebp,%esi
mov    %r14d,%edx
call   1030 <fb_hGetFirstWeekOfYear@plt>
movsd  (%rsp),%xmm1
subsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
call   1050 <floor@plt>
xorpd  %xmm1,%xmm1
xor    %eax,%eax
ucomisd %xmm0,%xmm1
seta   %al
movsd  %xmm0,0x10(%rsp)
fldl   0x10(%rsp)
fdivs  0xe73(%rip)
fstpl  0x8(%rsp)
lea    0xe70(%rip),%rcx
movsd  (%rcx,%rax,8),%xmm0
addsd  0x8(%rsp),%xmm0
cvttsd2si %xmm0,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @fb_hGetWeekOfYear(i32 %0, double %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca double
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca double
store i32 %0, i32* %5
store double %1, double* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%13 = load double, double* %6
%14 = call i32 @fb_hDateDecodeSerial(double %13, i32* %10, i32 0, i32 0)
%15 = load i32, i32* %5
%16 = load i32, i32* %7
%17 = load i32, i32* %8
%18 = call double @fb_hGetFirstWeekOfYear(i32 %15, i32 %16, i32 %17)
store double %18, double* %12
%19 = load double, double* %6
%20 = load double, double* %12
%21 = fsub double %19, %20
%22 = call double @llvm.floor.f64(double %21)
store double %22, double* %6
%23 = load double, double* %6
%24 = fcmp olt double %23, 0.000000e+00
%25 = zext i1 %24 to i64
%26 = select i1 %24, i32 -1, i32 1
store i32 %26, i32* %9
%27 = load double, double* %6
%28 = fpext double %27 to x86_fp80
%29 = fdiv x86_fp80 %28, 0xK4001E000000000000000
%30 = fptrunc x86_fp80 %29 to double
store double %30, double* %6
%31 = load double, double* %6
%32 = load i32, i32* %9
%33 = sitofp i32 %32 to double
%34 = fadd double %31, %33
%35 = fptosi double %34 to i32
store i32 %35, i32* %11
%36 = load i32, i32* %11
ret i32 %36
}

LLVM IR (-O2):
define i32 @fb_hGetWeekOfYear(i32 %0, double %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = bitcast i32* %5 to i8*
%7 = call i32 @fb_hDateDecodeSerial(double %1, i32* %5, i32 0, i32 0)
%8 = call double @fb_hGetFirstWeekOfYear(i32 %0, i32 %2, i32 %3)
%9 = fsub double %1, %8
%10 = call double @llvm.floor.f64(double %9)
%11 = fcmp olt double %10, 0.000000e+00
%12 = fpext double %10 to x86_fp80
%13 = fdiv x86_fp80 %12, 0xK4001E000000000000000
%14 = fptrunc x86_fp80 %13 to double
%15 = select i1 %11, double -1.000000e+00, double 1.000000e+00
%16 = fadd double %15, %14
%17 = fptosi double %16 to i32
ret i32 %17
}