#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 */
scalar_t__ dt_leap_year(int);
int dt_weeks_in_year(int year) {
  unsigned int y, d;
  if (year < 1)
    year += 400 * (1 - year / 400);
  y = year - 1;
  d = (y + y / 4 - y / 100 + y / 400) % 7;
  return (d == 3 || (d == 2 && dt_leap_year(year))) ? 53 : 52;
}


x86 assembly (clang, -O0):
<dt_weeks_in_year>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x1,-0x4(%rbp)
jge    1145 <dt_weeks_in_year+0x35>
mov    -0x4(%rbp),%eax
mov    $0x190,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    $0x1,%eax
sub    %ecx,%eax
imul   $0x190,%eax,%eax
add    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    -0x8(%rbp),%ecx
shr    $0x2,%ecx
add    %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x64,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x190,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
add    %ecx,%eax
mov    $0x7,%ecx
xor    %edx,%edx
div    %ecx
mov    %edx,-0xc(%rbp)
mov    $0x1,%al
cmpl   $0x3,-0xc(%rbp)
mov    %al,-0xd(%rbp)
je     11c7 <dt_weeks_in_year+0xb7>
xor    %eax,%eax
cmpl   $0x2,-0xc(%rbp)
mov    %al,-0x19(%rbp)
jne    11c1 <dt_weeks_in_year+0xb1>
mov    -0x4(%rbp),%edi
call   1030 <dt_leap_year@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%dl
mov    $0x34,%eax
mov    $0x35,%ecx
test   $0x1,%dl
cmovne %ecx,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dt_weeks_in_year>:
test   %edi,%edi
jg     1131 <dt_weeks_in_year+0x21>
mov    %edi,%eax
neg    %eax
imul   $0x51eb851f,%rax,%rax
shr    $0x27,%rax
imul   $0x190,%eax,%eax
add    %eax,%edi
add    $0x190,%edi
lea    -0x1(%rdi),%eax
imul   $0x51eb851f,%rax,%rcx
shr    $0x2,%eax
add    %edi,%eax
add    $0xffffffff,%eax
mov    %rcx,%rdx
shr    $0x25,%rdx
sub    %edx,%eax
shr    $0x27,%rcx
add    %eax,%ecx
imul   $0x24924925,%rcx,%rdx
shr    $0x20,%rdx
mov    %ecx,%eax
sub    %edx,%eax
shr    %eax
add    %edx,%eax
shr    $0x2,%eax
lea    0x0(,%rax,8),%edx
sub    %edx,%eax
add    %ecx,%eax
cmp    $0x3,%eax
je     1194 <dt_weeks_in_year+0x84>
cmp    $0x2,%eax
jne    119a <dt_weeks_in_year+0x8a>
push   %rax
call   1030 <dt_leap_year@plt>
cmp    $0x1,%rax
mov    $0x35,%eax
sbb    $0x0,%eax
add    $0x8,%rsp
ret
mov    $0x35,%eax
ret
mov    $0x34,%eax
ret

LLVM IR (-O0):
define i32 @dt_weeks_in_year(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = icmp slt i32 %5, 1
br i1 %6, label %7, label %14
7: ; preds = %1
%8 = load i32, i32* %2
%9 = sdiv i32 %8, 400
%10 = sub nsw i32 1, %9
%11 = mul nsw i32 400, %10
%12 = load i32, i32* %2
%13 = add nsw i32 %12, %11
store i32 %13, i32* %2
br label %14
14: ; preds = %7, %1
%15 = load i32, i32* %2
%16 = sub nsw i32 %15, 1
store i32 %16, i32* %3
%17 = load i32, i32* %3
%18 = load i32, i32* %3
%19 = udiv i32 %18, 4
%20 = add i32 %17, %19
%21 = load i32, i32* %3
%22 = udiv i32 %21, 100
%23 = sub i32 %20, %22
%24 = load i32, i32* %3
%25 = udiv i32 %24, 400
%26 = add i32 %23, %25
%27 = urem i32 %26, 7
store i32 %27, i32* %4
%28 = load i32, i32* %4
%29 = icmp eq i32 %28, 3
br i1 %29, label %39, label %30
30: ; preds = %14
%31 = load i32, i32* %4
%32 = icmp eq i32 %31, 2
br i1 %32, label %33, label %37
33: ; preds = %30
%34 = load i32, i32* %2
%35 = call i64 @dt_leap_year(i32 %34)
%36 = icmp ne i64 %35, 0
br label %37
37: ; preds = %33, %30
%38 = phi i1 [ false, %30 ], [ %36, %33 ]
br label %39
39: ; preds = %37, %14
%40 = phi i1 [ true, %14 ], [ %38, %37 ]
%41 = zext i1 %40 to i64
%42 = select i1 %40, i32 53, i32 52
ret i32 %42
}

LLVM IR (-O2):
define i32 @dt_weeks_in_year(i32 %0) {
%2 = icmp slt i32 %0, 1
br i1 %2, label %3, label %7
3: ; preds = %1
%4 = sub i32 0, %0
%5 = urem i32 %4, 400
%6 = sub nuw nsw i32 400, %5
br label %7
7: ; preds = %3, %1
%8 = phi i32 [ %6, %3 ], [ %0, %1 ]
%9 = add nsw i32 %8, -1
%10 = lshr i32 %9, 2
%11 = add nuw i32 %10, %9
%12 = udiv i32 %9, 100
%13 = sub i32 %11, %12
%14 = udiv i32 %9, 400
%15 = add i32 %13, %14
%16 = urem i32 %15, 7
switch i32 %16, label %21 [
i32 3, label %22
i32 2, label %17
]
17: ; preds = %7
%18 = tail call i64 @dt_leap_year(i32 %8)
%19 = icmp eq i64 %18, 0
%20 = select i1 %19, i32 52, i32 53
br label %22
21: ; preds = %7
br label %22
22: ; preds = %7, %21, %17
%23 = phi i32 [ 53, %7 ], [ %20, %17 ], [ 52, %21 ]
ret i32 %23
}