#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__ iTestStrDecimal(unsigned char *, int);
scalar_t__ strcmp(unsigned char *, char *);
int strlen(unsigned char *);
scalar_t__ ulA2L(unsigned char *, int);
int iTestIfValidDate8(unsigned char *pszDate) {
  int iYear, iMonth, iDay;
  int aiDaysPerMonth[13];
  if (strlen(pszDate) != 8)
    return (1);
  if (iTestStrDecimal(pszDate, 8) != 0)
    return (1);
  if (strcmp(pszDate, "20491231") > 0)
    return (1);
  if (strcmp(pszDate, "19500101") < 0)
    return (1);
  iYear = (int)ulA2L(pszDate, 4);
  iMonth = (int)ulA2L(pszDate + 4, 2);
  iDay = (int)ulA2L(pszDate + 6, 2);
  aiDaysPerMonth[1] = aiDaysPerMonth[3] = aiDaysPerMonth[5] =
      aiDaysPerMonth[7] = aiDaysPerMonth[8] = aiDaysPerMonth[10] =
          aiDaysPerMonth[12] = 31;
  aiDaysPerMonth[4] = aiDaysPerMonth[6] = aiDaysPerMonth[9] =
      aiDaysPerMonth[11] = 30;
  if (iYear % 400 == 0 || iYear % 4 == 0 && iYear % 100 != 0)
    aiDaysPerMonth[2] = 29;
  else
    aiDaysPerMonth[2] = 28;
  if (iMonth < 1 || iMonth > 12)
    return (1);
  if (iDay < 1 || iDay > aiDaysPerMonth[iMonth])
    return (1);
  return (0);
}


x86 assembly (clang, -O0):
<iTestIfValidDate8>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x8,%eax
je     116a <iTestIfValidDate8+0x2a>
movl   $0x1,-0x4(%rbp)
jmp    12ff <iTestIfValidDate8+0x1bf>
mov    -0x10(%rbp),%rdi
mov    $0x8,%esi
call   1060 <iTestStrDecimal@plt>
cmp    $0x0,%rax
je     118e <iTestIfValidDate8+0x4e>
movl   $0x1,-0x4(%rbp)
jmp    12ff <iTestIfValidDate8+0x1bf>
mov    -0x10(%rbp),%rdi
lea    0xe67(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jle    11b4 <iTestIfValidDate8+0x74>
movl   $0x1,-0x4(%rbp)
jmp    12ff <iTestIfValidDate8+0x1bf>
mov    -0x10(%rbp),%rdi
lea    0xe4a(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jge    11da <iTestIfValidDate8+0x9a>
movl   $0x1,-0x4(%rbp)
jmp    12ff <iTestIfValidDate8+0x1bf>
mov    -0x10(%rbp),%rdi
mov    $0x4,%esi
call   1030 <ulA2L@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x4,%rdi
mov    $0x2,%esi
call   1030 <ulA2L@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x6,%rdi
mov    $0x2,%esi
call   1030 <ulA2L@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x1f,-0x20(%rbp)
movl   $0x1f,-0x28(%rbp)
movl   $0x1f,-0x30(%rbp)
movl   $0x1f,-0x34(%rbp)
movl   $0x1f,-0x3c(%rbp)
movl   $0x1f,-0x44(%rbp)
movl   $0x1f,-0x4c(%rbp)
movl   $0x1e,-0x24(%rbp)
movl   $0x1e,-0x2c(%rbp)
movl   $0x1e,-0x38(%rbp)
movl   $0x1e,-0x40(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x190,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     129e <iTestIfValidDate8+0x15e>
mov    -0x14(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    12aa <iTestIfValidDate8+0x16a>
mov    -0x14(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     12aa <iTestIfValidDate8+0x16a>
movl   $0x1d,-0x48(%rbp)
jmp    12b1 <iTestIfValidDate8+0x171>
movl   $0x1c,-0x48(%rbp)
cmpl   $0x1,-0x18(%rbp)
jl     12c5 <iTestIfValidDate8+0x185>
cmpl   $0xc,-0x18(%rbp)
jle    12d1 <iTestIfValidDate8+0x191>
movl   $0x1,-0x4(%rbp)
jmp    12ff <iTestIfValidDate8+0x1bf>
cmpl   $0x1,-0x1c(%rbp)
jl     12ec <iTestIfValidDate8+0x1ac>
mov    -0x1c(%rbp),%eax
movslq -0x18(%rbp),%rcx
cmp    -0x50(%rbp,%rcx,4),%eax
jle    12f8 <iTestIfValidDate8+0x1b8>
movl   $0x1,-0x4(%rbp)
jmp    12ff <iTestIfValidDate8+0x1bf>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iTestIfValidDate8>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x38,%rsp
mov    %rdi,%rbx
call   1040 <strlen@plt>
mov    $0x1,%ebp
cmp    $0x8,%eax
jne    1260 <iTestIfValidDate8+0x120>
mov    %rbx,%rdi
mov    $0x8,%esi
call   1060 <iTestStrDecimal@plt>
test   %rax,%rax
jne    1260 <iTestIfValidDate8+0x120>
lea    0xea3(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
jg     1260 <iTestIfValidDate8+0x120>
lea    0xe94(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
js     1260 <iTestIfValidDate8+0x120>
mov    %rbx,%rdi
mov    $0x4,%esi
call   1030 <ulA2L@plt>
mov    %rax,%r15
lea    0x4(%rbx),%rdi
mov    $0x2,%esi
call   1030 <ulA2L@plt>
mov    %rax,%r14
add    $0x6,%rbx
mov    %rbx,%rdi
mov    $0x2,%esi
call   1030 <ulA2L@plt>
movl   $0x1f,0x4(%rsp)
movabs $0x1f0000001e,%rcx
mov    %rcx,0x2c(%rsp)
movaps 0xe0a(%rip),%xmm0
movups %xmm0,0x1c(%rsp)
movaps 0xe0e(%rip),%xmm0
movups %xmm0,0xc(%rsp)
imul   $0xc28f5c29,%r15d,%ecx
add    $0x51eb850,%ecx
mov    %ecx,%edx
ror    $0x4,%edx
cmp    $0xa3d70b,%edx
jb     123e <iTestIfValidDate8+0xfe>
test   $0x3,%r15b
setne  %dl
ror    $0x2,%ecx
cmp    $0x28f5c29,%ecx
setb   %cl
or     %dl,%cl
movzbl %cl,%ecx
xor    $0x1d,%ecx
jmp    1243 <iTestIfValidDate8+0x103>
mov    $0x1d,%ecx
mov    %ecx,0x8(%rsp)
lea    -0xd(%r14),%ecx
cmp    $0xfffffff4,%ecx
jb     1260 <iTestIfValidDate8+0x120>
test   %eax,%eax
jle    1260 <iTestIfValidDate8+0x120>
movslq %r14d,%rcx
xor    %ebp,%ebp
cmp    %eax,(%rsp,%rcx,4)
setl   %bpl
mov    %ebp,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [9 x i8] c"20491231\00"
@.str.1 = [9 x i8] c"19500101\00"
define i32 @iTestIfValidDate8(i8* %0) {
%2 = alloca [13 x i32]
%3 = bitcast [13 x i32]* %2 to i8*
%4 = tail call i32 @strlen(i8* %0)
%5 = icmp eq i32 %4, 8
br i1 %5, label %6, label %54
6: ; preds = %1
%7 = tail call i64 @iTestStrDecimal(i8* %0, i32 8)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %54
9: ; preds = %6
%10 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%11 = icmp sgt i64 %10, 0
br i1 %11, label %54, label %12
12: ; preds = %9
%13 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp slt i64 %13, 0
br i1 %14, label %54, label %15
15: ; preds = %12
%16 = tail call i64 @ulA2L(i8* %0, i32 4)
%17 = trunc i64 %16 to i32
%18 = getelementptr inbounds i8, i8* %0, i64 4
%19 = tail call i64 @ulA2L(i8* %18, i32 2)
%20 = trunc i64 %19 to i32
%21 = getelementptr inbounds i8, i8* %0, i64 6
%22 = tail call i64 @ulA2L(i8* %21, i32 2)
%23 = trunc i64 %22 to i32
%24 = getelementptr inbounds [13 x i32], [13 x i32]* %2, i64 0, i64 12
store i32 31, i32* %24
%25 = getelementptr inbounds [13 x i32], [13 x i32]* %2, i64 0, i64 7
%26 = getelementptr inbounds [13 x i32], [13 x i32]* %2, i64 0, i64 3
%27 = getelementptr inbounds [13 x i32], [13 x i32]* %2, i64 0, i64 1
store i32 31, i32* %27
%28 = getelementptr inbounds [13 x i32], [13 x i32]* %2, i64 0, i64 11
store i32 30, i32* %28
%29 = bitcast i32* %25 to <4 x i32>*
store <4 x i32> <i32 31, i32 31, i32 30, i32 31>, <4 x i32>* %29
%30 = bitcast i32* %26 to <4 x i32>*
store <4 x i32> <i32 31, i32 30, i32 31, i32 30>, <4 x i32>* %30
%31 = srem i32 %17, 400
%32 = icmp eq i32 %31, 0
br i1 %32, label %40, label %33
33: ; preds = %15
%34 = and i32 %17, 3
%35 = icmp ne i32 %34, 0
%36 = srem i32 %17, 100
%37 = icmp eq i32 %36, 0
%38 = or i1 %35, %37
%39 = select i1 %38, i32 28, i32 29
br label %40
40: ; preds = %33, %15
%41 = phi i32 [ 29, %15 ], [ %39, %33 ]
%42 = getelementptr inbounds [13 x i32], [13 x i32]* %2, i64 0, i64 2
store i32 %41, i32* %42
%43 = add i32 %20, -13
%44 = icmp ult i32 %43, -12
%45 = icmp slt i32 %23, 1
%46 = select i1 %44, i1 true, i1 %45
br i1 %46, label %54, label %47
47: ; preds = %40
%48 = shl i64 %19, 32
%49 = ashr exact i64 %48, 32
%50 = getelementptr inbounds [13 x i32], [13 x i32]* %2, i64 0, i64 %49
%51 = load i32, i32* %50
%52 = icmp slt i32 %51, %23
%53 = zext i1 %52 to i32
br label %54
54: ; preds = %47, %40, %12, %9, %6, %1
%55 = phi i32 [ 1, %1 ], [ 1, %6 ], [ 1, %9 ], [ 1, %12 ], [ 1, %40 ], [ %53, %47 ]
ret i32 %55
}