int calc_days_in_month(int iYear, int iMonth) {
  int days = 0;
  int daysInMonth[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  if ((iMonth == 2) &&
      ((iYear % 4) ? 0 : ((iYear % 100) ? 1 : ((iYear % 400) ? 0 : 1)))) {
    days = 29;
  } else if ((iMonth >= 1) && (iMonth <= 12)) {
    days = daysInMonth[iMonth - 1];
  }
  return days;
}


x86 assembly (clang, -O0):
<calc_days_in_month>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xed0(%rip),%rsi
mov    $0x30,%edx
call   1030 <memcpy@plt>
cmpl   $0x2,-0x8(%rbp)
jne    11c8 <calc_days_in_month+0xb8>
mov    -0x4(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     1167 <calc_days_in_month+0x57>
xor    %eax,%eax
test   $0x1,%al
jne    11bc <calc_days_in_month+0xac>
jmp    11c8 <calc_days_in_month+0xb8>
mov    -0x4(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     118a <calc_days_in_month+0x7a>
mov    $0x1,%al
test   $0x1,%al
jne    11bc <calc_days_in_month+0xac>
jmp    11c8 <calc_days_in_month+0xb8>
mov    -0x4(%rbp),%eax
mov    $0x190,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     11ad <calc_days_in_month+0x9d>
xor    %eax,%eax
test   $0x1,%al
jne    11bc <calc_days_in_month+0xac>
jmp    11c8 <calc_days_in_month+0xb8>
mov    $0x1,%al
test   $0x1,%al
jne    11bc <calc_days_in_month+0xac>
jmp    11c8 <calc_days_in_month+0xb8>
movl   $0x1d,-0xc(%rbp)
jmp    11f0 <calc_days_in_month+0xe0>
cmpl   $0x1,-0x8(%rbp)
jl     11eb <calc_days_in_month+0xdb>
cmpl   $0xc,-0x8(%rbp)
jg     11eb <calc_days_in_month+0xdb>
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
cltq
mov    -0x40(%rbp,%rax,4),%eax
mov    %eax,-0xc(%rbp)
jmp    11f0 <calc_days_in_month+0xe0>
mov    -0xc(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calc_days_in_month>:
cmp    $0x2,%esi
jne    1150 <calc_days_in_month+0x50>
mov    %edi,%eax
and    $0x3,%eax
jne    1150 <calc_days_in_month+0x50>
imul   $0xc28f5c29,%edi,%ecx
add    $0x51eb850,%ecx
ror    $0x2,%ecx
mov    $0x1d,%eax
cmp    $0x28f5c28,%ecx
ja     1166 <calc_days_in_month+0x66>
movslq %edi,%rcx
imul   $0x51eb851f,%rcx,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x27,%rcx
add    %edx,%ecx
imul   $0x190,%ecx,%ecx
mov    $0x1,%esi
sub    %ecx,%edi
jne    115a <calc_days_in_month+0x5a>
jmp    1166 <calc_days_in_month+0x66>
add    $0xffffffff,%esi
xor    %eax,%eax
cmp    $0xb,%esi
ja     1166 <calc_days_in_month+0x66>
mov    %esi,%eax
lea    0xe9d(%rip),%rcx
mov    (%rcx,%rax,4),%eax
ret

LLVM IR (-O0):
@__const.calc_days_in_month.daysInMonth = [12 x i32] [i32 31, i32 28, i32 31, i32 30, i32 31, i32 30, i32 31, i32 31, i32 30, i32 31, i32 30, i32 31]
define i32 @calc_days_in_month(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [12 x i32]
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 0, i32* %5
%7 = bitcast [12 x i32]* %6 to i8*
%8 = load i32, i32* %4
%9 = icmp eq i32 %8, 2
br i1 %9, label %10, label %27
10: ; preds = %2
%11 = load i32, i32* %3
%12 = srem i32 %11, 4
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %10
br i1 false, label %26, label %27
15: ; preds = %10
%16 = load i32, i32* %3
%17 = srem i32 %16, 100
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %15
br i1 true, label %26, label %27
20: ; preds = %15
%21 = load i32, i32* %3
%22 = srem i32 %21, 400
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %20
br i1 false, label %26, label %27
25: ; preds = %20
br i1 true, label %26, label %27
26: ; preds = %25, %24, %19, %14
store i32 29, i32* %5
br label %40
27: ; preds = %25, %24, %19, %14, %2
%28 = load i32, i32* %4
%29 = icmp sge i32 %28, 1
br i1 %29, label %30, label %39
30: ; preds = %27
%31 = load i32, i32* %4
%32 = icmp sle i32 %31, 12
br i1 %32, label %33, label %39
33: ; preds = %30
%34 = load i32, i32* %4
%35 = sub nsw i32 %34, 1
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [12 x i32], [12 x i32]* %6, i64 0, i64 %36
%38 = load i32, i32* %37
store i32 %38, i32* %5
br label %39
39: ; preds = %33, %30, %27
br label %40
40: ; preds = %39, %26
%41 = load i32, i32* %5
ret i32 %41
}

LLVM IR (-O2):
@__const.calc_days_in_month.daysInMonth = [12 x i32] [i32 31, i32 28, i32 31, i32 30, i32 31, i32 30, i32 31, i32 31, i32 30, i32 31, i32 30, i32 31]
define i32 @calc_days_in_month(i32 %0, i32 %1) {
%3 = icmp eq i32 %1, 2
%4 = and i32 %0, 3
%5 = icmp eq i32 %4, 0
%6 = and i1 %3, %5
br i1 %6, label %7, label %13
7: ; preds = %2
%8 = srem i32 %0, 100
%9 = icmp ne i32 %8, 0
%10 = srem i32 %0, 400
%11 = icmp eq i32 %10, 0
%12 = or i1 %9, %11
br i1 %12, label %21, label %16
13: ; preds = %2
%14 = add i32 %1, -1
%15 = icmp ult i32 %14, 12
br i1 %15, label %16, label %21
16: ; preds = %7, %13
%17 = phi i32 [ %14, %13 ], [ 1, %7 ]
%18 = zext i32 %17 to i64
%19 = getelementptr inbounds [12 x i32], [12 x i32]* @__const.calc_days_in_month.daysInMonth, i64 0, i64 %18
%20 = load i32, i32* %19
br label %21
21: ; preds = %7, %13, %16
%22 = phi i32 [ %20, %16 ], [ 0, %13 ], [ 29, %7 ]
ret i32 %22
}