#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 dstEndDayOfYear(int year) {
  int daysToOctober = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30;
  int dayOfOctober;
  for (dayOfOctober = 20;
       !isDst(dayOfOctober, 10, dayOfWeek(dayOfOctober, 9, year));
       dayOfOctober++)
    ;
  ;
  if (dayOfWeek(dayOfOctober, 9, year) != 0)
    printf("!!! GMT START SHOULD BE A SUNDAY (%d) !!!\n", year);
  dayOfOctober--;
  if (year % 4 == 0)
    daysToOctober++;
  return daysToOctober + dayOfOctober - 1;
}


x86 assembly (clang, -O0):
<dstEndDayOfYear>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x111,-0x8(%rbp)
movl   $0x14,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x4(%rbp),%edx
mov    $0x9,%esi
call   1030 <dayOfWeek@plt>
mov    -0x10(%rbp),%edi
mov    %rax,%rdx
mov    $0xa,%esi
call   1050 <isDst@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1184 <dstEndDayOfYear+0x54>
jmp    1197 <dstEndDayOfYear+0x67>
jmp    1189 <dstEndDayOfYear+0x59>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1149 <dstEndDayOfYear+0x19>
mov    -0xc(%rbp),%edi
mov    -0x4(%rbp),%edx
mov    $0x9,%esi
call   1030 <dayOfWeek@plt>
cmp    $0x0,%rax
je     11c0 <dstEndDayOfYear+0x90>
mov    -0x4(%rbp),%esi
lea    0xe45(%rip),%rdi
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11e6 <dstEndDayOfYear+0xb6>
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):
<dstEndDayOfYear>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
mov    $0x13,%ebx
nopw   0x0(%rax,%rax,1)
add    $0x1,%ebx
mov    %ebx,%edi
mov    $0x9,%esi
mov    %ebp,%edx
call   1030 <dayOfWeek@plt>
mov    %ebx,%edi
mov    $0xa,%esi
mov    %rax,%rdx
call   1050 <isDst@plt>
test   %eax,%eax
je     1140 <dstEndDayOfYear+0x10>
mov    %ebx,%edi
mov    $0x9,%esi
mov    %ebp,%edx
call   1030 <dayOfWeek@plt>
test   %rax,%rax
je     1185 <dstEndDayOfYear+0x55>
lea    0xe82(%rip),%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
and    $0x3,%ebp
cmp    $0x1,%ebp
adc    $0x0,%ebx
add    $0x10f,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [43 x i8] c"!!! GMT START SHOULD BE A SUNDAY (%d) !!!\0A\00"
define i32 @dstEndDayOfYear(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
store i32 273, 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 9, i32 %8)
%10 = call i32 @isDst(i32 %6, i32 10, 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 9, 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* %4
%27 = add nsw i32 %26, -1
store i32 %27, i32* %4
%28 = load i32, i32* %2
%29 = srem i32 %28, 4
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %25
%32 = load i32, i32* %3
%33 = add nsw i32 %32, 1
store i32 %33, i32* %3
br label %34
34: ; preds = %31, %25
%35 = load i32, i32* %3
%36 = load i32, i32* %4
%37 = add nsw i32 %35, %36
%38 = sub nsw i32 %37, 1
ret i32 %38
}

LLVM IR (-O2):
@.str = [43 x i8] c"!!! GMT START SHOULD BE A SUNDAY (%d) !!!\0A\00"
define i32 @dstEndDayOfYear(i32 %0) {
br label %2
2: ; preds = %2, %1
%3 = phi i32 [ 20, %1 ], [ %7, %2 ]
%4 = tail call i64 @dayOfWeek(i32 %3, i32 9, i32 %0)
%5 = tail call i32 @isDst(i32 %3, i32 10, 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 9, 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 272, i32 271
%17 = add nuw i32 %16, %3
ret i32 %17
}