#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__ dayOfWeek(int, int, int);
int /*<<< orphan*/ isDst(int, int, scalar_t__);
int /*<<< orphan*/ printf(char *, int);
int dstStartDayOfYear(int year) {
  int daysToMarch = 31 + 28;
  int dayOfMarch;
  for (dayOfMarch = 20; !isDst(dayOfMarch, 3, dayOfWeek(dayOfMarch, 2, year));
       dayOfMarch++)
    ;
  ;
  if (dayOfWeek(dayOfMarch, 2, year) != 0)
    printf("!!! BST START SHOULD BE A SUNDAY (%d) !!!\n", year);
  if (year % 4 == 0)
    daysToMarch++;
  return daysToMarch + dayOfMarch - 1;
}


x86 assembly (clang, -O0):
<dstStartDayOfYear>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x3b,-0x8(%rbp)
movl   $0x14,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x4(%rbp),%edx
mov    $0x2,%esi
call   1030 <dayOfWeek@plt>
mov    -0x10(%rbp),%edi
mov    %rax,%rdx
mov    $0x3,%esi
call   1050 <isDst@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1184 <dstStartDayOfYear+0x54>
jmp    1197 <dstStartDayOfYear+0x67>
jmp    1189 <dstStartDayOfYear+0x59>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1149 <dstStartDayOfYear+0x19>
mov    -0xc(%rbp),%edi
mov    -0x4(%rbp),%edx
mov    $0x2,%esi
call   1030 <dayOfWeek@plt>
cmp    $0x0,%rax
je     11c0 <dstStartDayOfYear+0x90>
mov    -0x4(%rbp),%esi
lea    0xe45(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11dd <dstStartDayOfYear+0xad>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
add    -0xc(%rbp),%eax
sub    $0x1,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dstStartDayOfYear>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
mov    $0x13,%ebx
nopw   0x0(%rax,%rax,1)
add    $0x1,%ebx
mov    %ebx,%edi
mov    $0x2,%esi
mov    %ebp,%edx
call   1030 <dayOfWeek@plt>
mov    %ebx,%edi
mov    $0x3,%esi
mov    %rax,%rdx
call   1050 <isDst@plt>
test   %eax,%eax
je     1140 <dstStartDayOfYear+0x10>
mov    %ebx,%edi
mov    $0x2,%esi
mov    %ebp,%edx
call   1030 <dayOfWeek@plt>
test   %rax,%rax
je     1185 <dstStartDayOfYear+0x55>
lea    0xe82(%rip),%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
and    $0x3,%ebp
cmp    $0x1,%ebp
adc    $0x0,%ebx
add    $0x3a,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [43 x i8] c"!!! BST START SHOULD BE A SUNDAY (%d) !!!\0A\00"
define i32 @dstStartDayOfYear(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
store i32 59, i32* %3
store i32 20, i32* %4
br label %5
5: ; preds = %14, %1
%6 = load i32, i32* %4
%7 = load i32, i32* %4
%8 = load i32, i32* %2
%9 = call i64 @dayOfWeek(i32 %7, i32 2, i32 %8)
%10 = call i32 @isDst(i32 %6, i32 3, i64 %9)
%11 = icmp ne i32 %10, 0
%12 = xor i1 %11, true
br i1 %12, label %13, label %17
13: ; preds = %5
br label %14
14: ; preds = %13
%15 = load i32, i32* %4
%16 = add nsw i32 %15, 1
store i32 %16, i32* %4
br label %5
17: ; preds = %5
%18 = load i32, i32* %4
%19 = load i32, i32* %2
%20 = call i64 @dayOfWeek(i32 %18, i32 2, i32 %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %17
%23 = load i32, i32* %2
%24 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %23)
br label %25
25: ; preds = %22, %17
%26 = load i32, i32* %2
%27 = srem i32 %26, 4
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %25
%30 = load i32, i32* %3
%31 = add nsw i32 %30, 1
store i32 %31, i32* %3
br label %32
32: ; preds = %29, %25
%33 = load i32, i32* %3
%34 = load i32, i32* %4
%35 = add nsw i32 %33, %34
%36 = sub nsw i32 %35, 1
ret i32 %36
}

LLVM IR (-O2):
@.str = [43 x i8] c"!!! BST START SHOULD BE A SUNDAY (%d) !!!\0A\00"
define i32 @dstStartDayOfYear(i32 %0) {
br label %2
2: ; preds = %2, %1
%3 = phi i32 [ 20, %1 ], [ %7, %2 ]
%4 = tail call i64 @dayOfWeek(i32 %3, i32 2, i32 %0)
%5 = tail call i32 @isDst(i32 %3, i32 3, i64 %4)
%6 = icmp eq i32 %5, 0
%7 = add nuw nsw i32 %3, 1
br i1 %6, label %2, label %8
8: ; preds = %2
%9 = tail call i64 @dayOfWeek(i32 %3, i32 2, i32 %0)
%10 = icmp eq i64 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %8
%12 = tail call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %13
13: ; preds = %11, %8
%14 = and i32 %0, 3
%15 = icmp eq i32 %14, 0
%16 = select i1 %15, i32 59, i32 58
%17 = add nuw i32 %16, %3
ret i32 %17
}