#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 ControlNum(char *);
int GetMaxDateForMonth(int, int);
int /*<<< orphan*/ GetStringPart(char *, char *, int, int);
int atoi(char *);
int /*<<< orphan*/ isdigit(char);
int /*<<< orphan*/ printf(char *, char);
int /*<<< orphan*/ scanf(char *, char *);
int strlen(char *);
int main() {
  char id[12], temp[12], valid = 1;
  int i;
  scanf("%s", id);
  for (i = 0; i < strlen(id); i++)
    if (!isdigit(id[i])) {
      valid = 0;
      break;
    }
  if (i > 10)
    valid = 0;
  if (valid == 1) {
    GetStringPart(id, temp, 0, 2);
    int year = atoi(temp);
    GetStringPart(id, temp, 2, 2);
    int month = atoi(temp);
    if (!((month >= 1 && month <= 12) ||
          (month >= 1 + 20 && month <= 12 + 20) ||
          (month >= 1 + 40 && month <= 12 + 40))) {
      valid = 0;
    }
    GetStringPart(id, temp, 4, 2);
    if (atoi(temp) > GetMaxDateForMonth(month, year)) {
      valid = 0;
    }
    int ctrlNum = ControlNum(id);
    if (atoi(&id[9]) != ctrlNum)
      valid = 0;
  }
  printf("%d", valid);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movb   $0x1,-0x1d(%rbp)
lea    -0x10(%rbp),%rsi
lea    0xe62(%rip),%rdi
call   1080 <scanf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x34(%rbp)
lea    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
cmp    %ecx,%eax
jge    11f9 <main+0x79>
movslq -0x24(%rbp),%rax
movsbl -0x10(%rbp,%rax,1),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
jne    11e6 <main+0x66>
movb   $0x0,-0x1d(%rbp)
jmp    11f9 <main+0x79>
jmp    11eb <main+0x6b>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11aa <main+0x2a>
cmpl   $0xa,-0x24(%rbp)
jle    1207 <main+0x87>
movb   $0x0,-0x1d(%rbp)
movsbl -0x1d(%rbp),%eax
cmp    $0x1,%eax
jne    12fe <main+0x17e>
lea    -0x10(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
xor    %edx,%edx
mov    $0x2,%ecx
call   1040 <GetStringPart@plt>
lea    -0x1c(%rbp),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x28(%rbp)
lea    -0x10(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
mov    $0x2,%ecx
mov    %ecx,%edx
call   1040 <GetStringPart@plt>
lea    -0x1c(%rbp),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x1,-0x2c(%rbp)
jl     1268 <main+0xe8>
cmpl   $0xc,-0x2c(%rbp)
jle    1294 <main+0x114>
cmpl   $0x15,-0x2c(%rbp)
jl     127c <main+0xfc>
cmpl   $0x20,-0x2c(%rbp)
jle    1294 <main+0x114>
cmpl   $0x29,-0x2c(%rbp)
jl     1290 <main+0x110>
cmpl   $0x34,-0x2c(%rbp)
jle    1294 <main+0x114>
movb   $0x0,-0x1d(%rbp)
lea    -0x10(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
mov    $0x4,%edx
mov    $0x2,%ecx
call   1040 <GetStringPart@plt>
lea    -0x1c(%rbp),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x38(%rbp)
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%esi
call   1070 <GetMaxDateForMonth@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%eax
cmp    %ecx,%eax
jle    12d3 <main+0x153>
movb   $0x0,-0x1d(%rbp)
lea    -0x10(%rbp),%rdi
call   10a0 <ControlNum@plt>
mov    %eax,-0x30(%rbp)
lea    -0x10(%rbp),%rdi
add    $0x9,%rdi
call   1090 <atoi@plt>
cmp    -0x30(%rbp),%eax
je     12f9 <main+0x179>
movb   $0x0,-0x1d(%rbp)
jmp    12fe <main+0x17e>
lea    0xcfe(%rip),%rdi
movsbl -0x1d(%rbp),%esi
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
lea    0xe6d(%rip),%rdi
lea    0x8(%rsp),%rbx
mov    %rbx,%rsi
call   1080 <scanf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
jle    11e5 <main+0x65>
xor    %ebp,%ebp
lea    0x8(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl 0x8(%rsp,%rbp,1),%edi
call   1030 <isdigit@plt>
test   %eax,%eax
je     11eb <main+0x6b>
add    $0x1,%rbp
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
cmp    %rax,%rbp
jl     11c0 <main+0x40>
mov    $0x1,%al
jmp    11ed <main+0x6d>
mov    $0x1,%dl
mov    $0x1,%al
jmp    11f3 <main+0x73>
xor    %eax,%eax
cmp    $0xb,%ebp
setb   %dl
xor    %ecx,%ecx
test   %dl,%dl
je     12ba <main+0x13a>
test   %al,%al
je     12ba <main+0x13a>
lea    0x8(%rsp),%r14
lea    0x14(%rsp),%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
mov    $0x2,%ecx
call   1040 <GetStringPart@plt>
mov    %rbx,%rdi
call   1090 <atoi@plt>
mov    %eax,%r15d
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x2,%edx
mov    $0x2,%ecx
call   1040 <GetStringPart@plt>
mov    %rbx,%rdi
call   1090 <atoi@plt>
mov    %eax,%ebp
lea    -0x1(%rbp),%eax
cmp    $0xc,%eax
setb   %al
lea    -0x15(%rbp),%ecx
cmp    $0xc,%ecx
setb   %cl
or     %al,%cl
lea    -0x29(%rbp),%eax
cmp    $0xc,%eax
setb   %r12b
or     %cl,%r12b
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x4,%edx
mov    $0x2,%ecx
call   1040 <GetStringPart@plt>
mov    %rbx,%rdi
call   1090 <atoi@plt>
mov    %eax,%ebx
mov    %ebp,%edi
mov    %r15d,%esi
call   1070 <GetMaxDateForMonth@plt>
cmp    %eax,%ebx
setle  %bpl
mov    %r14,%rdi
call   10a0 <ControlNum@plt>
mov    %eax,%ebx
lea    0x11(%rsp),%rdi
call   1090 <atoi@plt>
cmp    %ebx,%eax
sete   %cl
and    %bpl,%cl
and    %r12b,%cl
movzbl %cl,%esi
lea    0xd3f(%rip),%rdi
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [12 x i8]
%3 = alloca [12 x i8]
%4 = alloca i8
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
store i8 1, i8* %4
%9 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 0
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %9)
store i32 0, i32* %5
br label %11
11: ; preds = %25, %0
%12 = load i32, i32* %5
%13 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 0
%14 = call i32 @strlen(i8* %13)
%15 = icmp slt i32 %12, %14
br i1 %15, label %16, label %28
16: ; preds = %11
%17 = load i32, i32* %5
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 %18
%20 = load i8, i8* %19
%21 = call i32 @isdigit(i8 signext %20)
%22 = icmp ne i32 %21, 0
br i1 %22, label %24, label %23
23: ; preds = %16
store i8 0, i8* %4
br label %28
24: ; preds = %16
br label %25
25: ; preds = %24
%26 = load i32, i32* %5
%27 = add nsw i32 %26, 1
store i32 %27, i32* %5
br label %11
28: ; preds = %23, %11
%29 = load i32, i32* %5
%30 = icmp sgt i32 %29, 10
br i1 %30, label %31, label %32
31: ; preds = %28
store i8 0, i8* %4
br label %32
32: ; preds = %31, %28
%33 = load i8, i8* %4
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 1
br i1 %35, label %36, label %85
36: ; preds = %32
%37 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 0
%38 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%39 = call i32 @GetStringPart(i8* %37, i8* %38, i32 0, i32 2)
%40 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%41 = call i32 @atoi(i8* %40)
store i32 %41, i32* %6
%42 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 0
%43 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%44 = call i32 @GetStringPart(i8* %42, i8* %43, i32 2, i32 2)
%45 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%46 = call i32 @atoi(i8* %45)
store i32 %46, i32* %7
%47 = load i32, i32* %7
%48 = icmp sge i32 %47, 1
br i1 %48, label %49, label %52
49: ; preds = %36
%50 = load i32, i32* %7
%51 = icmp sle i32 %50, 12
br i1 %51, label %65, label %52
52: ; preds = %49, %36
%53 = load i32, i32* %7
%54 = icmp sge i32 %53, 21
br i1 %54, label %55, label %58
55: ; preds = %52
%56 = load i32, i32* %7
%57 = icmp sle i32 %56, 32
br i1 %57, label %65, label %58
58: ; preds = %55, %52
%59 = load i32, i32* %7
%60 = icmp sge i32 %59, 41
br i1 %60, label %61, label %64
61: ; preds = %58
%62 = load i32, i32* %7
%63 = icmp sle i32 %62, 52
br i1 %63, label %65, label %64
64: ; preds = %61, %58
store i8 0, i8* %4
br label %65
65: ; preds = %64, %61, %55, %49
%66 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 0
%67 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%68 = call i32 @GetStringPart(i8* %66, i8* %67, i32 4, i32 2)
%69 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%70 = call i32 @atoi(i8* %69)
%71 = load i32, i32* %7
%72 = load i32, i32* %6
%73 = call i32 @GetMaxDateForMonth(i32 %71, i32 %72)
%74 = icmp sgt i32 %70, %73
br i1 %74, label %75, label %76
75: ; preds = %65
store i8 0, i8* %4
br label %76
76: ; preds = %75, %65
%77 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 0
%78 = call i32 @ControlNum(i8* %77)
store i32 %78, i32* %8
%79 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 9
%80 = call i32 @atoi(i8* %79)
%81 = load i32, i32* %8
%82 = icmp ne i32 %80, %81
br i1 %82, label %83, label %84
83: ; preds = %76
store i8 0, i8* %4
br label %84
84: ; preds = %83, %76
br label %85
85: ; preds = %84, %32
%86 = load i8, i8* %4
%87 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8 signext %86)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca [12 x i8]
%2 = alloca [12 x i8]
%3 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 0
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %3)
%6 = call i32 @strlen(i8* %3)
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %24
8: ; preds = %0, %14
%9 = phi i64 [ %15, %14 ], [ 0, %0 ]
%10 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 %9
%11 = load i8, i8* %10
%12 = call i32 @isdigit(i8 signext %11)
%13 = icmp eq i32 %12, 0
br i1 %13, label %19, label %14
14: ; preds = %8
%15 = add nuw nsw i64 %9, 1
%16 = call i32 @strlen(i8* %3)
%17 = sext i32 %16 to i64
%18 = icmp slt i64 %15, %17
br i1 %18, label %8, label %19
19: ; preds = %8, %14
%20 = phi i64 [ %15, %14 ], [ %9, %8 ]
%21 = phi i8 [ 1, %14 ], [ 0, %8 ]
%22 = trunc i64 %20 to i32
%23 = icmp ult i32 %22, 11
br label %24
24: ; preds = %19, %0
%25 = phi i1 [ true, %0 ], [ %23, %19 ]
%26 = phi i8 [ 1, %0 ], [ %21, %19 ]
%27 = icmp eq i8 %26, 1
%28 = and i1 %25, %27
br i1 %28, label %29, label %53
29: ; preds = %24
%30 = call i32 @GetStringPart(i8* %3, i8* %4, i32 0, i32 2)
%31 = call i32 @atoi(i8* %4)
%32 = call i32 @GetStringPart(i8* %3, i8* %4, i32 2, i32 2)
%33 = call i32 @atoi(i8* %4)
%34 = add i32 %33, -1
%35 = icmp ult i32 %34, 12
%36 = add i32 %33, -21
%37 = icmp ult i32 %36, 12
%38 = or i1 %35, %37
%39 = add i32 %33, -41
%40 = icmp ult i32 %39, 12
%41 = select i1 %38, i1 true, i1 %40
%42 = call i32 @GetStringPart(i8* %3, i8* %4, i32 4, i32 2)
%43 = call i32 @atoi(i8* %4)
%44 = call i32 @GetMaxDateForMonth(i32 %33, i32 %31)
%45 = icmp sle i32 %43, %44
%46 = call i32 @ControlNum(i8* %3)
%47 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 9
%48 = call i32 @atoi(i8* %47)
%49 = icmp eq i32 %48, %46
%50 = select i1 %49, i1 %45, i1 false
%51 = select i1 %50, i1 %41, i1 false
%52 = zext i1 %51 to i8
br label %53
53: ; preds = %29, %24
%54 = phi i8 [ %52, %29 ], [ 0, %24 ]
%55 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8 signext %54)
ret i32 0
}