int ecma_DaysInYear(int y) {
  if (y % 4 != 0) {
    return 365;
  } else if (y % 4 == 0 && y % 100 != 0) {
    return 366;
  } else if (y % 100 == 0 && y % 400 != 0) {
    return 365;
  } else if (y % 400 == 0) {
    return 366;
  } else {
    return 365;
  }
}


x86 assembly (clang, -O0):
<ecma_DaysInYear>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     1127 <ecma_DaysInYear+0x27>
movl   $0x16d,-0x4(%rbp)
jmp    11b6 <ecma_DaysInYear+0xb6>
mov    -0x8(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    115b <ecma_DaysInYear+0x5b>
mov    -0x8(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     115b <ecma_DaysInYear+0x5b>
movl   $0x16e,-0x4(%rbp)
jmp    11b6 <ecma_DaysInYear+0xb6>
mov    -0x8(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    118f <ecma_DaysInYear+0x8f>
mov    -0x8(%rbp),%eax
mov    $0x190,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     118f <ecma_DaysInYear+0x8f>
movl   $0x16d,-0x4(%rbp)
jmp    11b6 <ecma_DaysInYear+0xb6>
mov    -0x8(%rbp),%eax
mov    $0x190,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11af <ecma_DaysInYear+0xaf>
movl   $0x16e,-0x4(%rbp)
jmp    11b6 <ecma_DaysInYear+0xb6>
movl   $0x16d,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<ecma_DaysInYear>:
mov    $0x16d,%eax
test   $0x3,%dil
je     110c <ecma_DaysInYear+0xc>
ret
imul   $0xc28f5c29,%edi,%ecx
add    $0x51eb850,%ecx
mov    %ecx,%edx
ror    $0x2,%edx
mov    $0x16e,%eax
cmp    $0x28f5c28,%edx
ja     110b <ecma_DaysInYear+0xb>
ror    $0x4,%ecx
cmp    $0xa3d70b,%ecx
mov    $0x16d,%eax
adc    $0x0,%eax
ret

LLVM IR (-O0):
define i32 @ecma_DaysInYear(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = srem i32 %4, 4
%6 = icmp ne i32 %5, 0
br i1 %6, label %7, label %8
7: ; preds = %1
store i32 365, i32* %2
br label %32
8: ; preds = %1
%9 = load i32, i32* %3
%10 = srem i32 %9, 4
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %8
%13 = load i32, i32* %3
%14 = srem i32 %13, 100
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %12
store i32 366, i32* %2
br label %32
17: ; preds = %12, %8
%18 = load i32, i32* %3
%19 = srem i32 %18, 100
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %17
%22 = load i32, i32* %3
%23 = srem i32 %22, 400
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %21
store i32 365, i32* %2
br label %32
26: ; preds = %21, %17
%27 = load i32, i32* %3
%28 = srem i32 %27, 400
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %26
store i32 366, i32* %2
br label %32
31: ; preds = %26
store i32 365, i32* %2
br label %32
32: ; preds = %31, %30, %25, %16, %7
%33 = load i32, i32* %2
ret i32 %33
}

LLVM IR (-O2):
define i32 @ecma_DaysInYear(i32 %0) {
%2 = and i32 %0, 3
%3 = icmp eq i32 %2, 0
br i1 %3, label %4, label %11
4: ; preds = %1
%5 = srem i32 %0, 100
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %4
%8 = srem i32 %0, 400
%9 = icmp eq i32 %8, 0
%10 = select i1 %9, i32 366, i32 365
br label %11
11: ; preds = %7, %4, %1
%12 = phi i32 [ 365, %1 ], [ 366, %4 ], [ %10, %7 ]
ret i32 %12
}