int is_valid_date_format(const char *date, int silent_errors) {
  int d;
  int m;
  int y;
  int ret;
  int day_count[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  ret = sscanf(date, "%04d-%02d-%02d", &y, &m, &d);
  if (ret != 3) {
    if (!silent_errors)
      fail("invalid date format: %s\n", date);
    return -1;
  }
  if (y % 400 == 0 || y % 100 != 0 || y % 4 == 0)
    day_count[1] = 29;
  if (m <= 0 || m >= 13) {
    if (!silent_errors)
      fail("%s: invalid month %d\n", __func__, m);
    return -1;
  }
  if (d <= 0 || d > day_count[m - 1]) {
    if (!silent_errors)
      fail("%s: invalid day %d\n", __func__, d);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<is_valid_date_format>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
lea    -0x60(%rbp),%rdi
lea    0xeb6(%rip),%rsi
mov    $0x30,%edx
call   1040 <memcpy@plt>
mov    -0x10(%rbp),%rdi
lea    0xed1(%rip),%rsi
lea    -0x20(%rbp),%rdx
lea    -0x1c(%rbp),%rcx
lea    -0x18(%rbp),%r8
mov    $0x0,%al
call   1050 <sscanf@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x3,-0x24(%rbp)
je     11a7 <is_valid_date_format+0x77>
cmpl   $0x0,-0x14(%rbp)
jne    119b <is_valid_date_format+0x6b>
mov    -0x10(%rbp),%rsi
lea    0xeab(%rip),%rdi
mov    $0x0,%al
call   1030 <fail@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1281 <is_valid_date_format+0x151>
mov    -0x20(%rbp),%eax
mov    $0x190,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     11e3 <is_valid_date_format+0xb3>
mov    -0x20(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11e3 <is_valid_date_format+0xb3>
mov    -0x20(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11ea <is_valid_date_format+0xba>
movl   $0x1d,-0x5c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jle    11fe <is_valid_date_format+0xce>
cmpl   $0xd,-0x1c(%rbp)
jl     122c <is_valid_date_format+0xfc>
cmpl   $0x0,-0x14(%rbp)
jne    1220 <is_valid_date_format+0xf0>
mov    -0x1c(%rbp),%edx
lea    0xe46(%rip),%rdi
lea    0xe55(%rip),%rsi
mov    $0x0,%al
call   1030 <fail@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1281 <is_valid_date_format+0x151>
cmpl   $0x0,-0x18(%rbp)
jle    124c <is_valid_date_format+0x11c>
mov    -0x18(%rbp),%eax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
cmp    -0x60(%rbp,%rcx,4),%eax
jle    127a <is_valid_date_format+0x14a>
cmpl   $0x0,-0x14(%rbp)
jne    126e <is_valid_date_format+0x13e>
mov    -0x18(%rbp),%edx
lea    0xe23(%rip),%rdi
lea    0xe07(%rip),%rsi
mov    $0x0,%al
call   1030 <fail@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1281 <is_valid_date_format+0x151>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_valid_date_format>:
push   %rbp
push   %r14
push   %rbx
sub    $0x40,%rsp
mov    %esi,%r14d
mov    %rdi,%rbx
movaps 0xeeb(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xecf(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xeb3(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
lea    0xed7(%rip),%rsi
lea    0x4(%rsp),%rdx
lea    0x8(%rsp),%rcx
lea    0xc(%rsp),%r8
xor    %eax,%eax
call   1040 <sscanf@plt>
cmp    $0x3,%eax
jne    11e0 <is_valid_date_format+0xc0>
movslq 0x4(%rsp),%rax
imul   $0xc28f5c29,%eax,%ecx
add    $0x51eb850,%ecx
ror    $0x4,%ecx
cmp    $0xa3d70b,%ecx
jb     11b2 <is_valid_date_format+0x92>
imul   $0x51eb851f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x25,%rcx
add    %edx,%ecx
imul   $0x64,%ecx,%ecx
mov    %eax,%edx
sub    %ecx,%edx
jne    11b2 <is_valid_date_format+0x92>
and    $0x3,%eax
jne    11ba <is_valid_date_format+0x9a>
movl   $0x1d,0x14(%rsp)
mov    0x8(%rsp),%edx
lea    -0xd(%rdx),%eax
cmp    $0xfffffff3,%eax
ja     11fd <is_valid_date_format+0xdd>
mov    $0xffffffff,%ebp
test   %r14d,%r14d
jne    1231 <is_valid_date_format+0x111>
lea    0xe81(%rip),%rdi
lea    0xe90(%rip),%rsi
jmp    122a <is_valid_date_format+0x10a>
mov    $0xffffffff,%ebp
test   %r14d,%r14d
jne    1231 <is_valid_date_format+0x111>
lea    0xe4e(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <fail@plt>
jmp    1231 <is_valid_date_format+0x111>
mov    0xc(%rsp),%eax
test   %eax,%eax
jle    1210 <is_valid_date_format+0xf0>
add    $0xffffffff,%edx
xor    %ebp,%ebp
cmp    0x10(%rsp,%rdx,4),%eax
jle    1231 <is_valid_date_format+0x111>
mov    $0xffffffff,%ebp
test   %r14d,%r14d
jne    1231 <is_valid_date_format+0x111>
lea    0xe62(%rip),%rdi
lea    0xe46(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <fail@plt>
mov    %ebp,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@__const.is_valid_date_format.day_count = [12 x i32] [i32 31, i32 28, i32 31, i32 30, i32 31, i32 30, i32 31, i32 31, i32 30, i32 31, i32 30, i32 31]
@.str = [15 x i8] c"%04d-%02d-%02d\00"
@.str.1 = [25 x i8] c"invalid date format: %s\0A\00"
@.str.2 = [22 x i8] c"%s: invalid month %d\0A\00"
@__func__.is_valid_date_format = [21 x i8] c"is_valid_date_format\00"
@.str.3 = [20 x i8] c"%s: invalid day %d\0A\00"
define i32 @is_valid_date_format(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca [12 x i32]
store i8* %0, i8** %4
store i32 %1, i32* %5
%11 = bitcast [12 x i32]* %10 to i8*
%12 = load i8*, i8** %4
%13 = call i32 (i8*, i8*, ...) @sscanf(i8* %12, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32* %8, i32* %7, i32* %6)
store i32 %13, i32* %9
%14 = load i32, i32* %9
%15 = icmp ne i32 %14, 3
br i1 %15, label %16, label %23
16: ; preds = %2
%17 = load i32, i32* %5
%18 = icmp ne i32 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %16
%20 = load i8*, i8** %4
%21 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @fail to i32 (i8*, i8*, ...)*)(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %20)
br label %22
22: ; preds = %19, %16
store i32 -1, i32* %3
br label %69
23: ; preds = %2
%24 = load i32, i32* %8
%25 = srem i32 %24, 400
%26 = icmp eq i32 %25, 0
br i1 %26, label %35, label %27
27: ; preds = %23
%28 = load i32, i32* %8
%29 = srem i32 %28, 100
%30 = icmp ne i32 %29, 0
br i1 %30, label %35, label %31
31: ; preds = %27
%32 = load i32, i32* %8
%33 = srem i32 %32, 4
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %31, %27, %23
%36 = getelementptr inbounds [12 x i32], [12 x i32]* %10, i64 0, i64 1
store i32 29, i32* %36
br label %37
37: ; preds = %35, %31
%38 = load i32, i32* %7
%39 = icmp sle i32 %38, 0
br i1 %39, label %43, label %40
40: ; preds = %37
%41 = load i32, i32* %7
%42 = icmp sge i32 %41, 13
br i1 %42, label %43, label %50
43: ; preds = %40, %37
%44 = load i32, i32* %5
%45 = icmp ne i32 %44, 0
br i1 %45, label %49, label %46
46: ; preds = %43
%47 = load i32, i32* %7
%48 = call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @fail to i32 (i8*, i8*, i32, ...)*)(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @__func__.is_valid_date_format, i64 0, i64 0), i32 %47)
br label %49
49: ; preds = %46, %43
store i32 -1, i32* %3
br label %69
50: ; preds = %40
%51 = load i32, i32* %6
%52 = icmp sle i32 %51, 0
br i1 %52, label %61, label %53
53: ; preds = %50
%54 = load i32, i32* %6
%55 = load i32, i32* %7
%56 = sub nsw i32 %55, 1
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds [12 x i32], [12 x i32]* %10, i64 0, i64 %57
%59 = load i32, i32* %58
%60 = icmp sgt i32 %54, %59
br i1 %60, label %61, label %68
61: ; preds = %53, %50
%62 = load i32, i32* %5
%63 = icmp ne i32 %62, 0
br i1 %63, label %67, label %64
64: ; preds = %61
%65 = load i32, i32* %6
%66 = call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @fail to i32 (i8*, i8*, i32, ...)*)(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @__func__.is_valid_date_format, i64 0, i64 0), i32 %65)
br label %67
67: ; preds = %64, %61
store i32 -1, i32* %3
br label %69
68: ; preds = %53
store i32 0, i32* %3
br label %69
69: ; preds = %68, %67, %49, %22
%70 = load i32, i32* %3
ret i32 %70
}

LLVM IR (-O2):
@__const.is_valid_date_format.day_count = [12 x i32] [i32 31, i32 28, i32 31, i32 30, i32 31, i32 30, i32 31, i32 31, i32 30, i32 31, i32 30, i32 31]
@.str = [15 x i8] c"%04d-%02d-%02d\00"
@.str.1 = [25 x i8] c"invalid date format: %s\0A\00"
@.str.2 = [22 x i8] c"%s: invalid month %d\0A\00"
@__func__.is_valid_date_format = [21 x i8] c"is_valid_date_format\00"
@.str.3 = [20 x i8] c"%s: invalid day %d\0A\00"
define i32 @is_valid_date_format(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [12 x i32]
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = bitcast i32* %5 to i8*
%10 = bitcast [12 x i32]* %6 to i8*
%11 = call i32 (i8*, i8*, ...) @sscanf(i8* %0, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32* %5, i32* %4, i32* %3)
%12 = icmp eq i32 %11, 3
br i1 %12, label %17, label %13
13: ; preds = %2
%14 = icmp eq i32 %1, 0
br i1 %14, label %15, label %50
15: ; preds = %13
%16 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @fail to i32 (i8*, i8*, ...)*)(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %50
17: ; preds = %2
%18 = load i32, i32* %5
%19 = srem i32 %18, 400
%20 = icmp eq i32 %19, 0
%21 = srem i32 %18, 100
%22 = icmp ne i32 %21, 0
%23 = or i1 %20, %22
%24 = and i32 %18, 3
%25 = icmp eq i32 %24, 0
%26 = select i1 %23, i1 true, i1 %25
br i1 %26, label %27, label %29
27: ; preds = %17
%28 = getelementptr inbounds [12 x i32], [12 x i32]* %6, i64 0, i64 1
store i32 29, i32* %28
br label %29
29: ; preds = %17, %27
%30 = load i32, i32* %4
%31 = add i32 %30, -13
%32 = icmp ult i32 %31, -12
br i1 %32, label %33, label %37
33: ; preds = %29
%34 = icmp eq i32 %1, 0
br i1 %34, label %35, label %50
35: ; preds = %33
%36 = call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @fail to i32 (i8*, i8*, i32, ...)*)(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @__func__.is_valid_date_format, i64 0, i64 0), i32 %30)
br label %50
37: ; preds = %29
%38 = load i32, i32* %3
%39 = icmp slt i32 %38, 1
br i1 %39, label %46, label %40
40: ; preds = %37
%41 = add nsw i32 %30, -1
%42 = zext i32 %41 to i64
%43 = getelementptr inbounds [12 x i32], [12 x i32]* %6, i64 0, i64 %42
%44 = load i32, i32* %43
%45 = icmp sgt i32 %38, %44
br i1 %45, label %46, label %50
46: ; preds = %40, %37
%47 = icmp eq i32 %1, 0
br i1 %47, label %48, label %50
48: ; preds = %46
%49 = call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @fail to i32 (i8*, i8*, i32, ...)*)(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @__func__.is_valid_date_format, i64 0, i64 0), i32 %38)
br label %50
50: ; preds = %40, %46, %48, %33, %35, %13, %15
%51 = phi i32 [ -1, %15 ], [ -1, %13 ], [ -1, %35 ], [ -1, %33 ], [ -1, %48 ], [ -1, %46 ], [ 0, %40 ]
ret i32 %51
}