#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 */
struct tm {
  int tm_yday;
  int tm_wday;
  int tm_year;
};

/* Variables and functions */
int tm_isleapyear(int);
int tm_getisoyear(struct tm date) {
  int week = (date.tm_yday - (date.tm_wday + 6) % 7 + 10) / 7;
  if (week == 0)
    return date.tm_year + 1900 - 1;
  else if (week > 52 &&
           ((date.tm_yday - 365 - tm_isleapyear(date.tm_year + 1900) -
             (date.tm_wday + 6) % 7 + 10) /
            7) > 0)
    return date.tm_year + 1900 + 1;
  else
    return date.tm_year + 1900;
}


x86 assembly (clang, -O0):
<tm_getisoyear>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x20(%rbp)
mov    %esi,-0x18(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0xc(%rbp),%eax
add    $0x6,%eax
mov    $0x7,%ecx
cltd
idiv   %ecx
mov    -0x28(%rbp),%eax
sub    %edx,%eax
add    $0xa,%eax
mov    $0x7,%ecx
cltd
idiv   %ecx
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    1171 <tm_getisoyear+0x61>
mov    -0x8(%rbp),%eax
add    $0x76c,%eax
sub    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11e3 <tm_getisoyear+0xd3>
cmpl   $0x34,-0x24(%rbp)
jle    11d8 <tm_getisoyear+0xc8>
mov    -0x10(%rbp),%eax
sub    $0x16d,%eax
mov    %eax,-0x30(%rbp)
mov    -0x8(%rbp),%edi
add    $0x76c,%edi
call   1030 <tm_isleapyear@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x2c(%rbp)
mov    -0xc(%rbp),%eax
add    $0x6,%eax
mov    $0x7,%ecx
cltd
idiv   %ecx
mov    -0x2c(%rbp),%eax
sub    %edx,%eax
add    $0xa,%eax
mov    $0x7,%ecx
cltd
idiv   %ecx
cmp    $0x0,%eax
jle    11d8 <tm_getisoyear+0xc8>
mov    -0x8(%rbp),%eax
add    $0x76c,%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11e3 <tm_getisoyear+0xd3>
mov    -0x8(%rbp),%eax
add    $0x76c,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tm_getisoyear>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%rbx
mov    %rdi,%rax
shr    $0x20,%rax
mov    %eax,%ecx
add    $0x6,%ecx
movslq %ecx,%rcx
imul   $0xffffffff92492493,%rcx,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
add    $0x6,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0x2,%ecx
add    %edx,%ecx
lea    0x0(,%rcx,8),%edx
sub    %edx,%ecx
lea    (%rax,%rcx,1),%ebp
add    $0x6,%ebp
mov    %ebx,%eax
sub    %ebp,%eax
lea    0x10(%rax),%ecx
cmp    $0xc,%ecx
ja     116a <tm_getisoyear+0x5a>
add    $0x76b,%r14d
jmp    1198 <tm_getisoyear+0x88>
lea    0x76c(%r14),%r15d
cmp    $0x169,%eax
jl     119b <tm_getisoyear+0x8b>
mov    %r15d,%edi
call   1030 <tm_isleapyear@plt>
add    %eax,%ebp
sub    %ebp,%ebx
add    $0xfffffe93,%ebx
add    $0x76d,%r14d
cmp    $0xfffffffd,%ebx
cmovl  %r15d,%r14d
mov    %r14d,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32 }
define i32 @tm_getisoyear(i64 %0, i32 %1) {
%3 = alloca i32
%4 = alloca %struct.tm
%5 = alloca { i64, i32 }
%6 = alloca i32
%7 = getelementptr inbounds { i64, i32 }, { i64, i32 }* %5, i32 0, i32 0
store i64 %0, i64* %7
%8 = getelementptr inbounds { i64, i32 }, { i64, i32 }* %5, i32 0, i32 1
store i32 %1, i32* %8
%9 = bitcast %struct.tm* %4 to i8*
%10 = bitcast { i64, i32 }* %5 to i8*
%11 = getelementptr inbounds %struct.tm, %struct.tm* %4, i32 0, i32 0
%12 = load i32, i32* %11
%13 = getelementptr inbounds %struct.tm, %struct.tm* %4, i32 0, i32 1
%14 = load i32, i32* %13
%15 = add nsw i32 %14, 6
%16 = srem i32 %15, 7
%17 = sub nsw i32 %12, %16
%18 = add nsw i32 %17, 10
%19 = sdiv i32 %18, 7
store i32 %19, i32* %6
%20 = load i32, i32* %6
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %27
22: ; preds = %2
%23 = getelementptr inbounds %struct.tm, %struct.tm* %4, i32 0, i32 2
%24 = load i32, i32* %23
%25 = add nsw i32 %24, 1900
%26 = sub nsw i32 %25, 1
store i32 %26, i32* %3
br label %56
27: ; preds = %2
%28 = load i32, i32* %6
%29 = icmp sgt i32 %28, 52
br i1 %29, label %30, label %52
30: ; preds = %27
%31 = getelementptr inbounds %struct.tm, %struct.tm* %4, i32 0, i32 0
%32 = load i32, i32* %31
%33 = sub nsw i32 %32, 365
%34 = getelementptr inbounds %struct.tm, %struct.tm* %4, i32 0, i32 2
%35 = load i32, i32* %34
%36 = add nsw i32 %35, 1900
%37 = call i32 @tm_isleapyear(i32 %36)
%38 = sub nsw i32 %33, %37
%39 = getelementptr inbounds %struct.tm, %struct.tm* %4, i32 0, i32 1
%40 = load i32, i32* %39
%41 = add nsw i32 %40, 6
%42 = srem i32 %41, 7
%43 = sub nsw i32 %38, %42
%44 = add nsw i32 %43, 10
%45 = sdiv i32 %44, 7
%46 = icmp sgt i32 %45, 0
br i1 %46, label %47, label %52
47: ; preds = %30
%48 = getelementptr inbounds %struct.tm, %struct.tm* %4, i32 0, i32 2
%49 = load i32, i32* %48
%50 = add nsw i32 %49, 1900
%51 = add nsw i32 %50, 1
store i32 %51, i32* %3
br label %56
52: ; preds = %30, %27
%53 = getelementptr inbounds %struct.tm, %struct.tm* %4, i32 0, i32 2
%54 = load i32, i32* %53
%55 = add nsw i32 %54, 1900
store i32 %55, i32* %3
br label %56
56: ; preds = %52, %47, %22
%57 = load i32, i32* %3
ret i32 %57
}

LLVM IR (-O2):
define i32 @tm_getisoyear(i64 %0, i32 %1) {
%3 = trunc i64 %0 to i32
%4 = lshr i64 %0, 32
%5 = trunc i64 %4 to i32
%6 = add nsw i32 %5, 6
%7 = srem i32 %6, 7
%8 = sub nsw i32 %3, %7
%9 = add i32 %8, 16
%10 = icmp ult i32 %9, 13
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = add nsw i32 %1, 1899
br label %24
13: ; preds = %2
%14 = icmp sgt i32 %8, 360
%15 = add nsw i32 %1, 1900
br i1 %14, label %16, label %24
16: ; preds = %13
%17 = tail call i32 @tm_isleapyear(i32 %15)
%18 = add i32 %3, -365
%19 = add i32 %7, %17
%20 = sub i32 %18, %19
%21 = icmp sgt i32 %20, -4
%22 = add nsw i32 %1, 1901
%23 = select i1 %21, i32 %22, i32 %15
br label %24
24: ; preds = %16, %13, %11
%25 = phi i32 [ %12, %11 ], [ %15, %13 ], [ %23, %16 ]
ret i32 %25
}