#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_year;
  int tm_yday;
  int tm_wday;
};

/* Variables and functions */
int iso_year_adjust(const struct tm *tim_p) {
  int leap =
      ((((tim_p->tm_year + (1900 - (tim_p->tm_year < 0 ? 0 : 2000))) % 4) ==
            0 &&
        ((tim_p->tm_year + (1900 - (tim_p->tm_year < 0 ? 0 : 2000))) % 100) !=
            0) ||
       ((tim_p->tm_year + (1900 - (tim_p->tm_year < 0 ? 0 : 2000))) % 400) ==
           0);
  switch ((((tim_p->tm_yday) << 4) + (tim_p->tm_wday << 1) + (leap))) {
  case (((0) << 4) + (5 << 1) + (0)):
  case (((0) << 4) + (6 << 1) + (0)):
  case (((0) << 4) + (0 << 1) + (0)):
  case (((0) << 4) + (5 << 1) + (1)):
  case (((0) << 4) + (6 << 1) + (1)):
  case (((0) << 4) + (0 << 1) + (1)):
  case (((1) << 4) + (6 << 1) + (0)):
  case (((1) << 4) + (0 << 1) + (0)):
  case (((1) << 4) + (6 << 1) + (1)):
  case (((1) << 4) + (0 << 1) + (1)):
  case (((2) << 4) + (0 << 1) + (0)):
  case (((2) << 4) + (0 << 1) + (1)):
    return -1;
  case (((362) << 4) + (1 << 1) + (0)):
  case (((363) << 4) + (1 << 1) + (1)):
  case (((363) << 4) + (1 << 1) + (0)):
  case (((363) << 4) + (2 << 1) + (0)):
  case (((364) << 4) + (1 << 1) + (1)):
  case (((364) << 4) + (2 << 1) + (1)):
  case (((364) << 4) + (1 << 1) + (0)):
  case (((364) << 4) + (2 << 1) + (0)):
  case (((364) << 4) + (3 << 1) + (0)):
  case (((365) << 4) + (1 << 1) + (1)):
  case (((365) << 4) + (2 << 1) + (1)):
  case (((365) << 4) + (3 << 1) + (1)):
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<iso_year_adjust>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%esi
mov    $0x7d0,%edx
xor    %ecx,%ecx
cmp    $0x0,%esi
cmovl  %ecx,%edx
mov    $0x76c,%ecx
sub    %edx,%ecx
add    %ecx,%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1173 <iso_year_adjust+0x73>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%esi
mov    $0x7d0,%edx
xor    %ecx,%ecx
cmp    $0x0,%esi
cmovl  %ecx,%edx
mov    $0x76c,%ecx
sub    %edx,%ecx
add    %ecx,%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    $0x1,%al
cmp    $0x0,%edx
mov    %al,-0x15(%rbp)
jne    11a6 <iso_year_adjust+0xa6>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%esi
mov    $0x7d0,%edx
xor    %ecx,%ecx
cmp    $0x0,%esi
cmovl  %ecx,%edx
mov    $0x76c,%ecx
sub    %edx,%ecx
add    %ecx,%eax
mov    $0x190,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
sete   %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
movzbl %al,%eax
and    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edx
mov    0x8(%rax),%eax
shl    $0x4,%edx
mov    %eax,%ecx
mov    %edx,%eax
lea    (%rax,%rcx,2),%eax
mov    -0x14(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0x1c(%rbp)
sub    $0x2,%eax
jb     12a4 <iso_year_adjust+0x1a4>
jmp    11dc <iso_year_adjust+0xdc>
mov    -0x1c(%rbp),%eax
add    $0xfffffff6,%eax
sub    $0x4,%eax
jb     12a4 <iso_year_adjust+0x1a4>
jmp    11f0 <iso_year_adjust+0xf0>
mov    -0x1c(%rbp),%eax
add    $0xfffffff0,%eax
sub    $0x2,%eax
jb     12a4 <iso_year_adjust+0x1a4>
jmp    1204 <iso_year_adjust+0x104>
mov    -0x1c(%rbp),%eax
add    $0xffffffe4,%eax
sub    $0x2,%eax
jb     12a4 <iso_year_adjust+0x1a4>
jmp    1218 <iso_year_adjust+0x118>
mov    -0x1c(%rbp),%eax
add    $0xffffffe0,%eax
sub    $0x2,%eax
jb     12a4 <iso_year_adjust+0x1a4>
jmp    122c <iso_year_adjust+0x12c>
mov    -0x1c(%rbp),%eax
sub    $0x16a2,%eax
je     12b0 <iso_year_adjust+0x1b0>
jmp    123f <iso_year_adjust+0x13f>
mov    -0x1c(%rbp),%eax
add    $0xffffe94e,%eax
sub    $0x3,%eax
jb     12b0 <iso_year_adjust+0x1b0>
jmp    1255 <iso_year_adjust+0x155>
mov    -0x1c(%rbp),%eax
add    $0xffffe93e,%eax
sub    $0x5,%eax
jb     12b0 <iso_year_adjust+0x1b0>
jmp    126b <iso_year_adjust+0x16b>
mov    -0x1c(%rbp),%eax
sub    $0x16d3,%eax
je     12b0 <iso_year_adjust+0x1b0>
jmp    127e <iso_year_adjust+0x17e>
mov    -0x1c(%rbp),%eax
sub    $0x16d5,%eax
je     12b0 <iso_year_adjust+0x1b0>
jmp    1291 <iso_year_adjust+0x191>
mov    -0x1c(%rbp),%eax
sub    $0x16d7,%eax
je     12b0 <iso_year_adjust+0x1b0>
jmp    12bc <iso_year_adjust+0x1bc>
movl   $0xffffffff,-0x4(%rbp)
jmp    12c3 <iso_year_adjust+0x1c3>
movl   $0x1,-0x4(%rbp)
jmp    12c3 <iso_year_adjust+0x1c3>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<iso_year_adjust>:
mov    (%rdi),%ecx
lea    -0x64(%rcx),%edx
lea    0x76c(%rcx),%eax
test   %ecx,%ecx
cmovns %edx,%eax
test   $0x3,%al
jne    1139 <iso_year_adjust+0x39>
movslq %eax,%rcx
imul   $0x51eb851f,%rcx,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x25,%rcx
add    %edx,%ecx
imul   $0x64,%ecx,%ecx
mov    %eax,%esi
mov    $0x1,%edx
sub    %ecx,%esi
jne    1151 <iso_year_adjust+0x51>
imul   $0xc28f5c29,%eax,%eax
add    $0x51eb850,%eax
ror    $0x4,%eax
xor    %edx,%edx
cmp    $0xa3d70b,%eax
setb   %dl
mov    0x4(%rdi),%eax
mov    0x8(%rdi),%ecx
shl    $0x4,%eax
lea    (%rax,%rcx,2),%ecx
or     %edx,%ecx
cmp    $0x21,%ecx
ja     117a <iso_year_adjust+0x7a>
mov    $0xffffffff,%eax
movabs $0x330033c03,%rdx
bt     %rcx,%rdx
jae    117a <iso_year_adjust+0x7a>
ret
add    $0xffffe95e,%ecx
cmp    $0x35,%ecx
ja     119b <iso_year_adjust+0x9b>
movabs $0x2a001f00070001,%rax
bt     %rcx,%rax
jae    119b <iso_year_adjust+0x9b>
mov    $0x1,%eax
ret
xor    %eax,%eax
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32 }
define i32 @iso_year_adjust(%struct.tm* %0) {
%2 = alloca i32
%3 = alloca %struct.tm*
%4 = alloca i32
store %struct.tm* %0, %struct.tm** %3
%5 = load %struct.tm*, %struct.tm** %3
%6 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 0
%7 = load i32, i32* %6
%8 = load %struct.tm*, %struct.tm** %3
%9 = getelementptr inbounds %struct.tm, %struct.tm* %8, i32 0, i32 0
%10 = load i32, i32* %9
%11 = icmp slt i32 %10, 0
%12 = zext i1 %11 to i64
%13 = select i1 %11, i32 0, i32 2000
%14 = sub nsw i32 1900, %13
%15 = add nsw i32 %7, %14
%16 = srem i32 %15, 4
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %32
18: ; preds = %1
%19 = load %struct.tm*, %struct.tm** %3
%20 = getelementptr inbounds %struct.tm, %struct.tm* %19, i32 0, i32 0
%21 = load i32, i32* %20
%22 = load %struct.tm*, %struct.tm** %3
%23 = getelementptr inbounds %struct.tm, %struct.tm* %22, i32 0, i32 0
%24 = load i32, i32* %23
%25 = icmp slt i32 %24, 0
%26 = zext i1 %25 to i64
%27 = select i1 %25, i32 0, i32 2000
%28 = sub nsw i32 1900, %27
%29 = add nsw i32 %21, %28
%30 = srem i32 %29, 100
%31 = icmp ne i32 %30, 0
br i1 %31, label %46, label %32
32: ; preds = %18, %1
%33 = load %struct.tm*, %struct.tm** %3
%34 = getelementptr inbounds %struct.tm, %struct.tm* %33, i32 0, i32 0
%35 = load i32, i32* %34
%36 = load %struct.tm*, %struct.tm** %3
%37 = getelementptr inbounds %struct.tm, %struct.tm* %36, i32 0, i32 0
%38 = load i32, i32* %37
%39 = icmp slt i32 %38, 0
%40 = zext i1 %39 to i64
%41 = select i1 %39, i32 0, i32 2000
%42 = sub nsw i32 1900, %41
%43 = add nsw i32 %35, %42
%44 = srem i32 %43, 400
%45 = icmp eq i32 %44, 0
br label %46
46: ; preds = %32, %18
%47 = phi i1 [ true, %18 ], [ %45, %32 ]
%48 = zext i1 %47 to i32
store i32 %48, i32* %4
%49 = load %struct.tm*, %struct.tm** %3
%50 = getelementptr inbounds %struct.tm, %struct.tm* %49, i32 0, i32 1
%51 = load i32, i32* %50
%52 = shl i32 %51, 4
%53 = load %struct.tm*, %struct.tm** %3
%54 = getelementptr inbounds %struct.tm, %struct.tm* %53, i32 0, i32 2
%55 = load i32, i32* %54
%56 = shl i32 %55, 1
%57 = add nsw i32 %52, %56
%58 = load i32, i32* %4
%59 = add nsw i32 %57, %58
switch i32 %59, label %62 [
i32 10, label %60
i32 12, label %60
i32 0, label %60
i32 11, label %60
i32 13, label %60
i32 1, label %60
i32 28, label %60
i32 16, label %60
i32 29, label %60
i32 17, label %60
i32 32, label %60
i32 33, label %60
i32 5794, label %61
i32 5811, label %61
i32 5810, label %61
i32 5812, label %61
i32 5827, label %61
i32 5829, label %61
i32 5826, label %61
i32 5828, label %61
i32 5830, label %61
i32 5843, label %61
i32 5845, label %61
i32 5847, label %61
]
60: ; preds = %46, %46, %46, %46, %46, %46, %46, %46, %46, %46, %46, %46
store i32 -1, i32* %2
br label %63
61: ; preds = %46, %46, %46, %46, %46, %46, %46, %46, %46, %46, %46, %46
store i32 1, i32* %2
br label %63
62: ; preds = %46
store i32 0, i32* %2
br label %63
63: ; preds = %62, %61, %60
%64 = load i32, i32* %2
ret i32 %64
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32 }
define i32 @iso_year_adjust(%struct.tm* nocapture %0) {
%2 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 0
%3 = load i32, i32* %2
%4 = icmp slt i32 %3, 0
%5 = select i1 %4, i32 1900, i32 -100
%6 = add nsw i32 %5, %3
%7 = and i32 %6, 3
%8 = icmp ne i32 %7, 0
%9 = srem i32 %6, 100
%10 = icmp eq i32 %9, 0
%11 = or i1 %8, %10
br i1 %11, label %12, label %16
12: ; preds = %1
%13 = srem i32 %6, 400
%14 = icmp eq i32 %13, 0
%15 = zext i1 %14 to i32
br label %16
16: ; preds = %1, %12
%17 = phi i32 [ %15, %12 ], [ 1, %1 ]
%18 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 1
%19 = load i32, i32* %18
%20 = shl i32 %19, 4
%21 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 2
%22 = load i32, i32* %21
%23 = shl i32 %22, 1
%24 = add nsw i32 %23, %20
%25 = or i32 %24, %17
switch i32 %25, label %27 [
i32 10, label %28
i32 12, label %28
i32 0, label %28
i32 11, label %28
i32 13, label %28
i32 1, label %28
i32 28, label %28
i32 16, label %28
i32 29, label %28
i32 17, label %28
i32 32, label %28
i32 33, label %28
i32 5794, label %26
i32 5811, label %26
i32 5810, label %26
i32 5812, label %26
i32 5827, label %26
i32 5829, label %26
i32 5826, label %26
i32 5828, label %26
i32 5830, label %26
i32 5843, label %26
i32 5845, label %26
i32 5847, label %26
]
26: ; preds = %16, %16, %16, %16, %16, %16, %16, %16, %16, %16, %16, %16
br label %28
27: ; preds = %16
br label %28
28: ; preds = %16, %16, %16, %16, %16, %16, %16, %16, %16, %16, %16, %16, %27, %26
%29 = phi i32 [ 0, %27 ], [ 1, %26 ], [ -1, %16 ], [ -1, %16 ], [ -1, %16 ], [ -1, %16 ], [ -1, %16 ], [ -1, %16 ], [ -1, %16 ], [ -1, %16 ], [ -1, %16 ], [ -1, %16 ], [ -1, %16 ], [ -1, %16 ]
ret i32 %29
}