int caldays(year, month)
int year;
int month;
{
  if (month < 1) {
    month = month + 12;
    year = year + 1;
  }
  if (month > 12) {
    month = month - 12;
    year = year + 1;
  }
  switch (month) {
  case 1:
    return (31);
  case 2:
    if (year % 400 == 0)
      return (29);
    else if (year % 100 == 0)
      return (28);
    else if (year % 4 == 0)
      return (29);
    else
      return (28);
  case 3:
    return (31);
  case 4:
    return (30);
  case 5:
    return (31);
  case 6:
    return (30);
  case 7:
    return (31);
  case 8:
    return (31);
  case 9:
    return (30);
  case 10:
    return (31);
  case 11:
    return (30);
  case 12:
    return (31);
  default:
    return (0);
  }
}


x86 assembly (clang, -O0):
<caldays>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x1,-0xc(%rbp)
jge    1126 <caldays+0x26>
mov    -0xc(%rbp),%eax
add    $0xc,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
cmpl   $0xc,-0xc(%rbp)
jle    1142 <caldays+0x42>
mov    -0xc(%rbp),%eax
sub    $0xc,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0xb,%eax
ja     125b <caldays+0x15b>
mov    -0x18(%rbp),%rax
lea    0xe9e(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x1f,-0x4(%rbp)
jmp    1262 <caldays+0x162>
mov    -0x8(%rbp),%eax
mov    $0x190,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1197 <caldays+0x97>
movl   $0x1d,-0x4(%rbp)
jmp    1262 <caldays+0x162>
mov    -0x8(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11b7 <caldays+0xb7>
movl   $0x1c,-0x4(%rbp)
jmp    1262 <caldays+0x162>
mov    -0x8(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11d7 <caldays+0xd7>
movl   $0x1d,-0x4(%rbp)
jmp    1262 <caldays+0x162>
movl   $0x1c,-0x4(%rbp)
jmp    1262 <caldays+0x162>
movl   $0x1f,-0x4(%rbp)
jmp    1262 <caldays+0x162>
movl   $0x1e,-0x4(%rbp)
jmp    1262 <caldays+0x162>
movl   $0x1f,-0x4(%rbp)
jmp    1262 <caldays+0x162>
movl   $0x1e,-0x4(%rbp)
jmp    1262 <caldays+0x162>
movl   $0x1f,-0x4(%rbp)
jmp    1262 <caldays+0x162>
movl   $0x1f,-0x4(%rbp)
jmp    1262 <caldays+0x162>
movl   $0x1e,-0x4(%rbp)
jmp    1262 <caldays+0x162>
movl   $0x1f,-0x4(%rbp)
jmp    1262 <caldays+0x162>
movl   $0x1e,-0x4(%rbp)
jmp    1262 <caldays+0x162>
movl   $0x1f,-0x4(%rbp)
jmp    1262 <caldays+0x162>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<caldays>:
lea    0xc(%rsi),%eax
xor    %edx,%edx
test   %esi,%esi
setle  %r8b
cmovg  %esi,%eax
lea    -0xc(%rax),%esi
xor    %r9d,%r9d
cmp    $0xd,%eax
setge  %r10b
cmovl  %eax,%esi
add    $0xffffffff,%esi
cmp    $0xb,%esi
ja     1142 <caldays+0x42>
mov    $0x1f,%eax
lea    0xece(%rip),%rcx
movslq (%rcx,%rsi,4),%rsi
add    %rcx,%rsi
jmp    *%rsi
ret
mov    $0x1e,%eax
ret
xor    %eax,%eax
ret
mov    %r8b,%dl
add    %edi,%edx
mov    %r10b,%r9b
add    %edx,%r9d
imul   $0xc28f5c29,%r9d,%eax
add    $0x51eb850,%eax
mov    %eax,%ecx
ror    $0x4,%ecx
cmp    $0xa3d70b,%ecx
jb     1180 <caldays+0x80>
ror    $0x2,%eax
cmp    $0x28f5c29,%eax
jb     1186 <caldays+0x86>
xor    %eax,%eax
test   $0x3,%r9b
sete   %al
or     $0x1c,%eax
ret
mov    $0x1d,%eax
ret
mov    $0x1c,%eax
ret

LLVM IR (-O0):
define i32 @caldays(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%6 = load i32, i32* %5
%7 = icmp slt i32 %6, 1
br i1 %7, label %8, label %13
8: ; preds = %2
%9 = load i32, i32* %5
%10 = add nsw i32 %9, 12
store i32 %10, i32* %5
%11 = load i32, i32* %4
%12 = add nsw i32 %11, 1
store i32 %12, i32* %4
br label %13
13: ; preds = %8, %2
%14 = load i32, i32* %5
%15 = icmp sgt i32 %14, 12
br i1 %15, label %16, label %21
16: ; preds = %13
%17 = load i32, i32* %5
%18 = sub nsw i32 %17, 12
store i32 %18, i32* %5
%19 = load i32, i32* %4
%20 = add nsw i32 %19, 1
store i32 %20, i32* %4
br label %21
21: ; preds = %16, %13
%22 = load i32, i32* %5
switch i32 %22, label %50 [
i32 1, label %23
i32 2, label %24
i32 3, label %40
i32 4, label %41
i32 5, label %42
i32 6, label %43
i32 7, label %44
i32 8, label %45
i32 9, label %46
i32 10, label %47
i32 11, label %48
i32 12, label %49
]
23: ; preds = %21
store i32 31, i32* %3
br label %51
24: ; preds = %21
%25 = load i32, i32* %4
%26 = srem i32 %25, 400
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %24
store i32 29, i32* %3
br label %51
29: ; preds = %24
%30 = load i32, i32* %4
%31 = srem i32 %30, 100
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %29
store i32 28, i32* %3
br label %51
34: ; preds = %29
%35 = load i32, i32* %4
%36 = srem i32 %35, 4
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %34
store i32 29, i32* %3
br label %51
39: ; preds = %34
store i32 28, i32* %3
br label %51
40: ; preds = %21
store i32 31, i32* %3
br label %51
41: ; preds = %21
store i32 30, i32* %3
br label %51
42: ; preds = %21
store i32 31, i32* %3
br label %51
43: ; preds = %21
store i32 30, i32* %3
br label %51
44: ; preds = %21
store i32 31, i32* %3
br label %51
45: ; preds = %21
store i32 31, i32* %3
br label %51
46: ; preds = %21
store i32 30, i32* %3
br label %51
47: ; preds = %21
store i32 31, i32* %3
br label %51
48: ; preds = %21
store i32 30, i32* %3
br label %51
49: ; preds = %21
store i32 31, i32* %3
br label %51
50: ; preds = %21
store i32 0, i32* %3
br label %51
51: ; preds = %50, %49, %48, %47, %46, %45, %44, %43, %42, %41, %40, %39, %38, %33, %28, %23
%52 = load i32, i32* %3
ret i32 %52
}

LLVM IR (-O2):
define i32 @caldays(i32 %0, i32 %1) {
%3 = icmp slt i32 %1, 1
%4 = add nsw i32 %1, 12
%5 = zext i1 %3 to i32
%6 = add nsw i32 %5, %0
%7 = select i1 %3, i32 %4, i32 %1
%8 = icmp sgt i32 %7, 12
%9 = add nsw i32 %7, -12
%10 = zext i1 %8 to i32
%11 = add nsw i32 %6, %10
%12 = select i1 %8, i32 %9, i32 %7
switch i32 %12, label %27 [
i32 1, label %28
i32 2, label %13
i32 3, label %28
i32 4, label %23
i32 5, label %28
i32 6, label %24
i32 7, label %28
i32 8, label %28
i32 9, label %25
i32 10, label %28
i32 11, label %26
i32 12, label %28
]
13: ; preds = %2
%14 = srem i32 %11, 400
%15 = icmp eq i32 %14, 0
br i1 %15, label %28, label %16
16: ; preds = %13
%17 = srem i32 %11, 100
%18 = icmp eq i32 %17, 0
br i1 %18, label %28, label %19
19: ; preds = %16
%20 = and i32 %11, 3
%21 = icmp eq i32 %20, 0
%22 = select i1 %21, i32 29, i32 28
br label %28
23: ; preds = %2
br label %28
24: ; preds = %2
br label %28
25: ; preds = %2
br label %28
26: ; preds = %2
br label %28
27: ; preds = %2
br label %28
28: ; preds = %2, %2, %2, %2, %2, %2, %19, %16, %13, %2, %27, %26, %25, %24, %23
%29 = phi i32 [ 0, %27 ], [ 30, %26 ], [ 30, %25 ], [ 30, %24 ], [ 30, %23 ], [ 31, %2 ], [ 29, %13 ], [ 28, %16 ], [ %22, %19 ], [ 31, %2 ], [ 31, %2 ], [ 31, %2 ], [ 31, %2 ], [ 31, %2 ], [ 31, %2 ]
ret i32 %29
}