#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 */
scalar_t__ isleapyear(int);
int daysinmonth(int y, int m) {
  int month[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  int leap = isleapyear(y) ? 1 : 0;
  if (1 <= m && m <= 12) {
    return month[m] + leap;
  } else {
    return -1;
  }
}


x86 assembly (clang, -O0):
<daysinmonth>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xec7(%rip),%rsi
mov    $0x34,%edx
call   1040 <memcpy@plt>
mov    -0x8(%rbp),%edi
call   1030 <isleapyear@plt>
mov    %rax,%rdx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%rdx
cmovne %ecx,%eax
mov    %eax,-0x44(%rbp)
mov    $0x1,%eax
cmp    -0xc(%rbp),%eax
jg     118a <daysinmonth+0x6a>
cmpl   $0xc,-0xc(%rbp)
jg     118a <daysinmonth+0x6a>
movslq -0xc(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%eax
add    -0x44(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1191 <daysinmonth+0x71>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<daysinmonth>:
push   %rbx
mov    %esi,%ebx
call   1030 <isleapyear@plt>
lea    -0x1(%rbx),%edx
mov    $0xffffffff,%ecx
cmp    $0xb,%edx
ja     1138 <daysinmonth+0x28>
mov    %ebx,%ecx
lea    0xed2(%rip),%rdx
mov    (%rdx,%rcx,4),%ecx
cmp    $0x1,%rax
sbb    $0xffffffff,%ecx
mov    %ecx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@__const.daysinmonth.month = [13 x i32] [i32 0, 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 @daysinmonth(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [13 x i32]
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%8 = bitcast [13 x i32]* %6 to i8*
%9 = load i32, i32* %4
%10 = call i64 @isleapyear(i32 %9)
%11 = icmp ne i64 %10, 0
%12 = zext i1 %11 to i64
%13 = select i1 %11, i32 1, i32 0
store i32 %13, i32* %7
%14 = load i32, i32* %5
%15 = icmp sle i32 1, %14
br i1 %15, label %16, label %26
16: ; preds = %2
%17 = load i32, i32* %5
%18 = icmp sle i32 %17, 12
br i1 %18, label %19, label %26
19: ; preds = %16
%20 = load i32, i32* %5
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [13 x i32], [13 x i32]* %6, i64 0, i64 %21
%23 = load i32, i32* %22
%24 = load i32, i32* %7
%25 = add nsw i32 %23, %24
store i32 %25, i32* %3
br label %27
26: ; preds = %16, %2
store i32 -1, i32* %3
br label %27
27: ; preds = %26, %19
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
@__const.daysinmonth.month = [13 x i32] [i32 0, 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 @daysinmonth(i32 %0, i32 %1) {
%3 = tail call i64 @isleapyear(i32 %0)
%4 = add i32 %1, -1
%5 = icmp ult i32 %4, 12
br i1 %5, label %6, label %13
6: ; preds = %2
%7 = icmp ne i64 %3, 0
%8 = zext i1 %7 to i32
%9 = zext i32 %1 to i64
%10 = getelementptr inbounds [13 x i32], [13 x i32]* @__const.daysinmonth.month, i64 0, i64 %9
%11 = load i32, i32* %10
%12 = add nsw i32 %11, %8
br label %13
13: ; preds = %2, %6
%14 = phi i32 [ %12, %6 ], [ -1, %2 ]
ret i32 %14
}