#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 atoi(char *);
int /*<<< orphan*/ isNumber(char *);
int /*<<< orphan*/ memcpy(char *, char *, int);
int strlen(char *);
int isRightfulDate(char *sDate) {
  if (!sDate || strlen(sDate) != 8)
    return 0;
  int iYear, iMonth, iDay;
  char sBuffer[5];
  if (!isNumber(sDate))
    return 0;
  memcpy(sBuffer, sDate, 4);
  sBuffer[4] = 0;
  iYear = atoi(sBuffer);
  memcpy(sBuffer, sDate + 4, 2);
  sBuffer[2] = 0;
  iMonth = atoi(sBuffer);
  memcpy(sBuffer, sDate + 6, 2);
  sBuffer[2] = 0;
  iDay = atoi(sBuffer);
  if (iYear <= 1990) {
    return 0;
  }
  if (iMonth > 12 || iDay > 31 || iMonth == 0 || iDay == 0) {
    return 0;
  }
  if ((iMonth == 4 || iMonth == 6 || iMonth == 9 || iMonth == 11) &&
      iDay > 30) {
    return 0;
  }
  if (iMonth == 2) {
    if ((iYear % 100 != 0 && iYear % 4 == 0) ||
        (iYear % 400 == 0 && iYear % 4 == 0)) {
      if (iDay > 29)
        return 0;
    } else {
      if (iDay > 28)
        return 0;
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<isRightfulDate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1169 <isRightfulDate+0x29>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x8,%eax
je     1175 <isRightfulDate+0x35>
movl   $0x0,-0x4(%rbp)
jmp    1328 <isRightfulDate+0x1e8>
mov    -0x10(%rbp),%rdi
call   1040 <isNumber@plt>
cmp    $0x0,%eax
jne    1193 <isRightfulDate+0x53>
movl   $0x0,-0x4(%rbp)
jmp    1328 <isRightfulDate+0x1e8>
lea    -0x21(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x4,%edx
call   1050 <memcpy@plt>
movb   $0x0,-0x1d(%rbp)
lea    -0x21(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x14(%rbp)
lea    -0x21(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    $0x4,%rsi
mov    $0x2,%edx
call   1050 <memcpy@plt>
movb   $0x0,-0x1f(%rbp)
lea    -0x21(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x18(%rbp)
lea    -0x21(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    $0x6,%rsi
mov    $0x2,%edx
call   1050 <memcpy@plt>
movb   $0x0,-0x1f(%rbp)
lea    -0x21(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x7c6,-0x14(%rbp)
jg     121a <isRightfulDate+0xda>
movl   $0x0,-0x4(%rbp)
jmp    1328 <isRightfulDate+0x1e8>
cmpl   $0xc,-0x18(%rbp)
jg     1242 <isRightfulDate+0x102>
cmpl   $0x1f,-0x1c(%rbp)
jg     1242 <isRightfulDate+0x102>
cmpl   $0x0,-0x18(%rbp)
je     1242 <isRightfulDate+0x102>
cmpl   $0x0,-0x1c(%rbp)
jne    124e <isRightfulDate+0x10e>
movl   $0x0,-0x4(%rbp)
jmp    1328 <isRightfulDate+0x1e8>
cmpl   $0x4,-0x18(%rbp)
je     1276 <isRightfulDate+0x136>
cmpl   $0x6,-0x18(%rbp)
je     1276 <isRightfulDate+0x136>
cmpl   $0x9,-0x18(%rbp)
je     1276 <isRightfulDate+0x136>
cmpl   $0xb,-0x18(%rbp)
jne    128c <isRightfulDate+0x14c>
cmpl   $0x1e,-0x1c(%rbp)
jle    128c <isRightfulDate+0x14c>
movl   $0x0,-0x4(%rbp)
jmp    1328 <isRightfulDate+0x1e8>
cmpl   $0x2,-0x18(%rbp)
jne    1321 <isRightfulDate+0x1e1>
mov    -0x14(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     12be <isRightfulDate+0x17e>
mov    -0x14(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     12e6 <isRightfulDate+0x1a6>
mov    -0x14(%rbp),%eax
mov    $0x190,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1301 <isRightfulDate+0x1c1>
mov    -0x14(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1301 <isRightfulDate+0x1c1>
cmpl   $0x1d,-0x1c(%rbp)
jle    12fc <isRightfulDate+0x1bc>
movl   $0x0,-0x4(%rbp)
jmp    1328 <isRightfulDate+0x1e8>
jmp    131c <isRightfulDate+0x1dc>
cmpl   $0x1c,-0x1c(%rbp)
jle    1317 <isRightfulDate+0x1d7>
movl   $0x0,-0x4(%rbp)
jmp    1328 <isRightfulDate+0x1e8>
jmp    131c <isRightfulDate+0x1dc>
jmp    1321 <isRightfulDate+0x1e1>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isRightfulDate>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
xor    %ebx,%ebx
test   %rdi,%rdi
je     1268 <isRightfulDate+0x128>
mov    %rdi,%rbp
call   1030 <strlen@plt>
cmp    $0x8,%eax
jne    1268 <isRightfulDate+0x128>
mov    %rbp,%rdi
call   1040 <isNumber@plt>
xor    %ebx,%ebx
test   %eax,%eax
je     1268 <isRightfulDate+0x128>
lea    0xb(%rsp),%r12
mov    %r12,%rdi
mov    %rbp,%rsi
mov    $0x4,%edx
call   1050 <memcpy@plt>
movb   $0x0,0xf(%rsp)
mov    %r12,%rdi
call   1060 <atoi@plt>
mov    %eax,%r14d
lea    0x4(%rbp),%rsi
mov    %r12,%rdi
mov    $0x2,%edx
call   1050 <memcpy@plt>
movb   $0x0,0xd(%rsp)
mov    %r12,%rdi
call   1060 <atoi@plt>
mov    %eax,%r15d
add    $0x6,%rbp
mov    %r12,%rdi
mov    %rbp,%rsi
mov    $0x2,%edx
call   1050 <memcpy@plt>
movb   $0x0,0xd(%rsp)
mov    %r12,%rdi
call   1060 <atoi@plt>
cmp    $0x7c7,%r14d
jl     1268 <isRightfulDate+0x128>
test   %r15d,%r15d
je     1268 <isRightfulDate+0x128>
cmp    $0xc,%r15d
jg     1268 <isRightfulDate+0x128>
cmp    $0x1f,%eax
jg     1268 <isRightfulDate+0x128>
test   %eax,%eax
je     1268 <isRightfulDate+0x128>
mov    %r15d,%ecx
and    $0xfffffffd,%ecx
cmp    $0x4,%ecx
setne  %dl
cmp    $0x9,%ecx
setne  %cl
test   %dl,%cl
jne    1219 <isRightfulDate+0xd9>
cmp    $0x1e,%eax
jg     1268 <isRightfulDate+0x128>
cmp    $0x2,%r15d
jne    1263 <isRightfulDate+0x123>
imul   $0xc28f5c29,%r14d,%edx
ror    $0x2,%edx
mov    %r14d,%ecx
and    $0x3,%ecx
cmp    $0x28f5c29,%edx
jb     123b <isRightfulDate+0xfb>
test   %ecx,%ecx
je     125e <isRightfulDate+0x11e>
mov    %r14d,%edx
imul   $0x51eb851f,%rdx,%rdx
shr    $0x27,%rdx
imul   $0x190,%edx,%edx
sub    %edx,%r14d
or     %ecx,%r14d
je     125e <isRightfulDate+0x11e>
cmp    $0x1c,%eax
jle    1263 <isRightfulDate+0x123>
jmp    1268 <isRightfulDate+0x128>
cmp    $0x1d,%eax
jg     1268 <isRightfulDate+0x128>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @isRightfulDate(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [5 x i8]
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %14
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = call i32 @strlen(i8* %11)
%13 = icmp ne i32 %12, 8
br i1 %13, label %14, label %15
14: ; preds = %10, %1
store i32 0, i32* %2
br label %104
15: ; preds = %10
%16 = load i8*, i8** %3
%17 = call i32 @isNumber(i8* %16)
%18 = icmp ne i32 %17, 0
br i1 %18, label %20, label %19
19: ; preds = %15
store i32 0, i32* %2
br label %104
20: ; preds = %15
%21 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 0
%22 = load i8*, i8** %3
%23 = call i32 @memcpy(i8* %21, i8* %22, i32 4)
%24 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 4
store i8 0, i8* %24
%25 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 0
%26 = call i32 @atoi(i8* %25)
store i32 %26, i32* %4
%27 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 0
%28 = load i8*, i8** %3
%29 = getelementptr inbounds i8, i8* %28, i64 4
%30 = call i32 @memcpy(i8* %27, i8* %29, i32 2)
%31 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 2
store i8 0, i8* %31
%32 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 0
%33 = call i32 @atoi(i8* %32)
store i32 %33, i32* %5
%34 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 0
%35 = load i8*, i8** %3
%36 = getelementptr inbounds i8, i8* %35, i64 6
%37 = call i32 @memcpy(i8* %34, i8* %36, i32 2)
%38 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 2
store i8 0, i8* %38
%39 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 0
%40 = call i32 @atoi(i8* %39)
store i32 %40, i32* %6
%41 = load i32, i32* %4
%42 = icmp sle i32 %41, 1990
br i1 %42, label %43, label %44
43: ; preds = %20
store i32 0, i32* %2
br label %104
44: ; preds = %20
%45 = load i32, i32* %5
%46 = icmp sgt i32 %45, 12
br i1 %46, label %56, label %47
47: ; preds = %44
%48 = load i32, i32* %6
%49 = icmp sgt i32 %48, 31
br i1 %49, label %56, label %50
50: ; preds = %47
%51 = load i32, i32* %5
%52 = icmp eq i32 %51, 0
br i1 %52, label %56, label %53
53: ; preds = %50
%54 = load i32, i32* %6
%55 = icmp eq i32 %54, 0
br i1 %55, label %56, label %57
56: ; preds = %53, %50, %47, %44
store i32 0, i32* %2
br label %104
57: ; preds = %53
%58 = load i32, i32* %5
%59 = icmp eq i32 %58, 4
br i1 %59, label %69, label %60
60: ; preds = %57
%61 = load i32, i32* %5
%62 = icmp eq i32 %61, 6
br i1 %62, label %69, label %63
63: ; preds = %60
%64 = load i32, i32* %5
%65 = icmp eq i32 %64, 9
br i1 %65, label %69, label %66
66: ; preds = %63
%67 = load i32, i32* %5
%68 = icmp eq i32 %67, 11
br i1 %68, label %69, label %73
69: ; preds = %66, %63, %60, %57
%70 = load i32, i32* %6
%71 = icmp sgt i32 %70, 30
br i1 %71, label %72, label %73
72: ; preds = %69
store i32 0, i32* %2
br label %104
73: ; preds = %69, %66
%74 = load i32, i32* %5
%75 = icmp eq i32 %74, 2
br i1 %75, label %76, label %103
76: ; preds = %73
%77 = load i32, i32* %4
%78 = srem i32 %77, 100
%79 = icmp ne i32 %78, 0
br i1 %79, label %80, label %84
80: ; preds = %76
%81 = load i32, i32* %4
%82 = srem i32 %81, 4
%83 = icmp eq i32 %82, 0
br i1 %83, label %92, label %84
84: ; preds = %80, %76
%85 = load i32, i32* %4
%86 = srem i32 %85, 400
%87 = icmp eq i32 %86, 0
br i1 %87, label %88, label %97
88: ; preds = %84
%89 = load i32, i32* %4
%90 = srem i32 %89, 4
%91 = icmp eq i32 %90, 0
br i1 %91, label %92, label %97
92: ; preds = %88, %80
%93 = load i32, i32* %6
%94 = icmp sgt i32 %93, 29
br i1 %94, label %95, label %96
95: ; preds = %92
store i32 0, i32* %2
br label %104
96: ; preds = %92
br label %102
97: ; preds = %88, %84
%98 = load i32, i32* %6
%99 = icmp sgt i32 %98, 28
br i1 %99, label %100, label %101
100: ; preds = %97
store i32 0, i32* %2
br label %104
101: ; preds = %97
br label %102
102: ; preds = %101, %96
br label %103
103: ; preds = %102, %73
store i32 1, i32* %2
br label %104
104: ; preds = %103, %100, %95, %72, %56, %43, %19, %14
%105 = load i32, i32* %2
ret i32 %105
}

LLVM IR (-O2):
define i32 @isRightfulDate(i8* %0) {
%2 = alloca [5 x i8]
%3 = icmp eq i8* %0, null
br i1 %3, label %57, label %4
4: ; preds = %1
%5 = tail call i32 @strlen(i8* %0)
%6 = icmp eq i32 %5, 8
br i1 %6, label %7, label %57
7: ; preds = %4
%8 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 0
%9 = tail call i32 @isNumber(i8* %0)
%10 = icmp eq i32 %9, 0
br i1 %10, label %55, label %11
11: ; preds = %7
%12 = call i32 @memcpy(i8* %8, i8* %0, i32 4)
%13 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 4
store i8 0, i8* %13
%14 = call i32 @atoi(i8* %8)
%15 = getelementptr inbounds i8, i8* %0, i64 4
%16 = call i32 @memcpy(i8* %8, i8* %15, i32 2)
%17 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 2
store i8 0, i8* %17
%18 = call i32 @atoi(i8* %8)
%19 = getelementptr inbounds i8, i8* %0, i64 6
%20 = call i32 @memcpy(i8* %8, i8* %19, i32 2)
store i8 0, i8* %17
%21 = call i32 @atoi(i8* %8)
%22 = icmp slt i32 %14, 1991
br i1 %22, label %55, label %23
23: ; preds = %11
%24 = icmp sgt i32 %18, 12
%25 = icmp sgt i32 %21, 31
%26 = select i1 %24, i1 true, i1 %25
%27 = icmp eq i32 %18, 0
%28 = or i1 %27, %26
%29 = icmp eq i32 %21, 0
%30 = select i1 %28, i1 true, i1 %29
br i1 %30, label %55, label %31
31: ; preds = %23
%32 = and i32 %18, -3
%33 = icmp eq i32 %32, 4
%34 = icmp eq i32 %32, 9
%35 = or i1 %34, %33
%36 = icmp sgt i32 %21, 30
%37 = select i1 %35, i1 %36, i1 false
br i1 %37, label %55, label %38
38: ; preds = %31
%39 = icmp eq i32 %18, 2
br i1 %39, label %40, label %54
40: ; preds = %38
%41 = urem i32 %14, 100
%42 = icmp ne i32 %41, 0
%43 = and i32 %14, 3
%44 = icmp eq i32 %43, 0
%45 = and i1 %42, %44
br i1 %45, label %50, label %46
46: ; preds = %40
%47 = urem i32 %14, 400
%48 = or i32 %47, %43
%49 = icmp eq i32 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %46, %40
%51 = icmp sgt i32 %21, 29
br i1 %51, label %55, label %54
52: ; preds = %46
%53 = icmp sgt i32 %21, 28
br i1 %53, label %55, label %54
54: ; preds = %50, %52, %38
br label %55
55: ; preds = %52, %50, %31, %23, %11, %7, %54
%56 = phi i32 [ 1, %54 ], [ 0, %7 ], [ 0, %11 ], [ 0, %23 ], [ 0, %31 ], [ 0, %50 ], [ 0, %52 ]
br label %57
57: ; preds = %1, %4, %55
%58 = phi i32 [ %56, %55 ], [ 0, %4 ], [ 0, %1 ]
ret i32 %58
}