#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 */

/* Variables and functions */
int /*<<< orphan*/ leapyear(unsigned int);
int valid_date(unsigned int day, unsigned int month, unsigned int year) {
  int days_in_month[12] = {
      31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,
  };
  if (month == 0 || month > 12)
    return 0;
  if (day == 0 || day > days_in_month[month - 1])
    return 0;
  if (month == 2 && day == 29 && !leapyear(year))
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<valid_date>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xec4(%rip),%rsi
mov    $0x30,%edx
call   1030 <memcpy@plt>
cmpl   $0x0,-0xc(%rbp)
je     115a <valid_date+0x3a>
cmpl   $0xc,-0xc(%rbp)
jbe    1166 <valid_date+0x46>
movl   $0x0,-0x4(%rbp)
jmp    11c9 <valid_date+0xa9>
cmpl   $0x0,-0x8(%rbp)
je     1185 <valid_date+0x65>
mov    -0x8(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
mov    %ecx,%ecx
cmp    -0x40(%rbp,%rcx,4),%eax
jbe    1191 <valid_date+0x71>
movl   $0x0,-0x4(%rbp)
jmp    11c9 <valid_date+0xa9>
cmpl   $0x2,-0xc(%rbp)
jne    11c2 <valid_date+0xa2>
cmpl   $0x1d,-0x8(%rbp)
jne    11c2 <valid_date+0xa2>
mov    -0x10(%rbp),%edi
call   1040 <leapyear@plt>
cmp    $0x0,%eax
jne    11c2 <valid_date+0xa2>
movl   $0x0,-0x4(%rbp)
jmp    11c9 <valid_date+0xa9>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<valid_date>:
push   %rbx
xor    %ebx,%ebx
test   %edi,%edi
je     1148 <valid_date+0x38>
lea    -0xd(%rsi),%eax
cmp    $0xfffffff4,%eax
jb     1148 <valid_date+0x38>
lea    -0x1(%rsi),%eax
lea    0xed7(%rip),%rcx
cmp    %edi,(%rcx,%rax,4)
jb     1148 <valid_date+0x38>
cmp    $0x1d,%edi
jne    1143 <valid_date+0x33>
cmp    $0x2,%esi
jne    1143 <valid_date+0x33>
mov    %edx,%edi
call   1030 <leapyear@plt>
test   %eax,%eax
je     1148 <valid_date+0x38>
mov    $0x1,%ebx
mov    %ebx,%eax
pop    %rbx
ret

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

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