int isvalid_date(int year, int month, int day) {
  int year_leap = (year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0);
  switch (month) {
  case 1:
  case 3:
  case 5:
  case 7:
  case 8:
  case 10:
  case 12:
    if (day <= 31)
      return 1;
    break;
  case 4:
  case 6:
  case 9:
  case 11:
    if (day <= 30)
      return 1;
    break;
  case 2:
    return (day <= (year_leap) ? 29 : 28);
    break;
  default:
    break;
  }
  return 0;
}


x86 assembly (clang, -O0):
<isvalid_date>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    113a <isvalid_date+0x3a>
mov    -0x8(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    $0x1,%al
cmp    $0x0,%edx
mov    %al,-0x15(%rbp)
jne    114e <isvalid_date+0x4e>
mov    -0x8(%rbp),%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    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
sub    $0x1,%eax
je     121b <isvalid_date+0x11b>
jmp    116e <isvalid_date+0x6e>
mov    -0x1c(%rbp),%eax
sub    $0x2,%eax
je     1251 <isvalid_date+0x151>
jmp    117f <isvalid_date+0x7f>
mov    -0x1c(%rbp),%eax
sub    $0x3,%eax
je     121b <isvalid_date+0x11b>
jmp    1190 <isvalid_date+0x90>
mov    -0x1c(%rbp),%eax
sub    $0x4,%eax
je     1236 <isvalid_date+0x136>
jmp    11a1 <isvalid_date+0xa1>
mov    -0x1c(%rbp),%eax
sub    $0x5,%eax
je     121b <isvalid_date+0x11b>
jmp    11b2 <isvalid_date+0xb2>
mov    -0x1c(%rbp),%eax
sub    $0x6,%eax
je     1236 <isvalid_date+0x136>
jmp    11c3 <isvalid_date+0xc3>
mov    -0x1c(%rbp),%eax
add    $0xfffffff9,%eax
sub    $0x2,%eax
jb     121b <isvalid_date+0x11b>
jmp    11d7 <isvalid_date+0xd7>
mov    -0x1c(%rbp),%eax
sub    $0x9,%eax
je     1236 <isvalid_date+0x136>
jmp    11e8 <isvalid_date+0xe8>
mov    -0x1c(%rbp),%eax
sub    $0xa,%eax
je     121b <isvalid_date+0x11b>
jmp    11f9 <isvalid_date+0xf9>
mov    -0x1c(%rbp),%eax
sub    $0xb,%eax
je     1236 <isvalid_date+0x136>
jmp    120a <isvalid_date+0x10a>
mov    -0x1c(%rbp),%eax
sub    $0xc,%eax
jne    126e <isvalid_date+0x16e>
jmp    121b <isvalid_date+0x11b>
cmpl   $0x1f,-0x10(%rbp)
jg     1231 <isvalid_date+0x131>
movl   $0x1,-0x4(%rbp)
jmp    127a <isvalid_date+0x17a>
jmp    1273 <isvalid_date+0x173>
cmpl   $0x1e,-0x10(%rbp)
jg     124c <isvalid_date+0x14c>
movl   $0x1,-0x4(%rbp)
jmp    127a <isvalid_date+0x17a>
jmp    1273 <isvalid_date+0x173>
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%esi
mov    $0x1c,%eax
mov    $0x1d,%ecx
cmp    %esi,%edx
cmovle %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    127a <isvalid_date+0x17a>
jmp    1273 <isvalid_date+0x173>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<isvalid_date>:
test   $0x3,%dil
jne    112c <isvalid_date+0x2c>
movslq %edi,%rax
imul   $0x51eb851f,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x25,%rax
add    %ecx,%eax
imul   $0x64,%eax,%eax
mov    %edi,%ecx
mov    $0x1,%r8d
sub    %eax,%ecx
jne    1146 <isvalid_date+0x46>
imul   $0xc28f5c29,%edi,%eax
add    $0x51eb850,%eax
ror    $0x4,%eax
xor    %r8d,%r8d
cmp    $0xa3d70b,%eax
setb   %r8b
cmp    $0xc,%esi
ja     1187 <isvalid_date+0x87>
mov    $0x15aa,%eax
bt     %esi,%eax
jae    1160 <isvalid_date+0x60>
mov    $0x1,%eax
cmp    $0x20,%edx
jge    1187 <isvalid_date+0x87>
ret
mov    $0xa50,%eax
bt     %esi,%eax
jae    1176 <isvalid_date+0x76>
mov    $0x1,%eax
cmp    $0x1f,%edx
jl     115f <isvalid_date+0x5f>
jmp    1187 <isvalid_date+0x87>
cmp    $0x2,%esi
jne    1187 <isvalid_date+0x87>
xor    %eax,%eax
cmp    %edx,%r8d
setl   %al
xor    $0x1d,%eax
ret
xor    %eax,%eax
ret

LLVM IR (-O0):
define i32 @isvalid_date(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%9 = load i32, i32* %5
%10 = srem i32 %9, 4
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %3
%13 = load i32, i32* %5
%14 = srem i32 %13, 100
%15 = icmp ne i32 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %12, %3
%17 = load i32, i32* %5
%18 = srem i32 %17, 400
%19 = icmp eq i32 %18, 0
br label %20
20: ; preds = %16, %12
%21 = phi i1 [ true, %12 ], [ %19, %16 ]
%22 = zext i1 %21 to i32
store i32 %22, i32* %8
%23 = load i32, i32* %6
switch i32 %23, label %40 [
i32 1, label %24
i32 3, label %24
i32 5, label %24
i32 7, label %24
i32 8, label %24
i32 10, label %24
i32 12, label %24
i32 4, label %29
i32 6, label %29
i32 9, label %29
i32 11, label %29
i32 2, label %34
]
24: ; preds = %20, %20, %20, %20, %20, %20, %20
%25 = load i32, i32* %7
%26 = icmp sle i32 %25, 31
br i1 %26, label %27, label %28
27: ; preds = %24
store i32 1, i32* %4
br label %42
28: ; preds = %24
br label %41
29: ; preds = %20, %20, %20, %20
%30 = load i32, i32* %7
%31 = icmp sle i32 %30, 30
br i1 %31, label %32, label %33
32: ; preds = %29
store i32 1, i32* %4
br label %42
33: ; preds = %29
br label %41
34: ; preds = %20
%35 = load i32, i32* %7
%36 = load i32, i32* %8
%37 = icmp sle i32 %35, %36
%38 = zext i1 %37 to i64
%39 = select i1 %37, i32 29, i32 28
store i32 %39, i32* %4
br label %42
40: ; preds = %20
br label %41
41: ; preds = %40, %33, %28
store i32 0, i32* %4
br label %42
42: ; preds = %41, %34, %32, %27
%43 = load i32, i32* %4
ret i32 %43
}

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