#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 */
typedef int /*<<< orphan*/ time_t;
struct tm {
  int tm_year;
  int tm_mon;
  int tm_mday;
};

/* Variables and functions */
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ puts(char *);
int sscanf(char *, char *, int *, int *, int *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int val_date(char *date) {
  int year, month, day;
  time_t t = time(NULL);
  struct tm *now = localtime(&t);
  if (sscanf(date, "%d-%d-%d", &year, &month, &day) == 3) {
    printf("Validating date \"%s\"\n", date);
    if ((year - 1900) <= now->tm_year) {
      puts("year is current or old");
      if ((month - 1) <= now->tm_mon) {
        puts("month is current or old");
        if (day < now->tm_mday) {
          puts("Warning: date is in the past");
        }
      }
    }
    puts("date isn't in the past");
    if (month > 12) {
      puts("Too many months");
      return 1;
    }
    puts("month isn't imaginary");
    switch (month) {
    case 2:
      if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) {
        if (day > 29) {
          puts("Too many days");
          return 1;
        }
      } else {
        if (day > 28) {
          puts("Too many days");
          return 1;
        }
      }
      break;
    case 3:
    case 5:
    case 9:
    case 11:
      if (day > 30) {
        puts("Too many days");
        return 1;
      }
      break;
    default:
      if (day > 31) {
        puts("Too many days");
        return 1;
      }
      break;
    }
    puts("Date formatted ok");
    return 0;
  } else {
    puts("Warning: Invalid date format.");
    return 1;
  }
}


x86 assembly (clang, -O0):
<val_date>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,-0x20(%rbp)
lea    -0x20(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe80(%rip),%rsi
lea    -0x14(%rbp),%rdx
lea    -0x18(%rbp),%rcx
lea    -0x1c(%rbp),%r8
call   1070 <sscanf@plt>
cmp    $0x3,%eax
jne    1396 <val_date+0x246>
mov    -0x10(%rbp),%rsi
lea    0xe64(%rip),%rdi
call   1050 <printf@plt>
mov    -0x14(%rbp),%eax
sub    $0x76c,%eax
mov    -0x28(%rbp),%rcx
cmp    (%rcx),%eax
jg     120f <val_date+0xbf>
lea    0xe5a(%rip),%rdi
call   1040 <puts@plt>
mov    -0x18(%rbp),%eax
sub    $0x1,%eax
mov    -0x28(%rbp),%rcx
cmp    0x4(%rcx),%eax
jg     120a <val_date+0xba>
lea    0xe52(%rip),%rdi
call   1040 <puts@plt>
mov    -0x1c(%rbp),%eax
mov    -0x28(%rbp),%rcx
cmp    0x8(%rcx),%eax
jge    1205 <val_date+0xb5>
lea    0xe4e(%rip),%rdi
call   1040 <puts@plt>
jmp    120a <val_date+0xba>
jmp    120f <val_date+0xbf>
lea    0xe55(%rip),%rdi
call   1040 <puts@plt>
cmpl   $0xc,-0x18(%rbp)
jle    123d <val_date+0xed>
lea    0xe56(%rip),%rdi
call   1040 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    13a9 <val_date+0x259>
lea    0xe4e(%rip),%rdi
call   1040 <puts@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x2c(%rbp)
sub    $0x2,%eax
je     12a1 <val_date+0x151>
jmp    125d <val_date+0x10d>
mov    -0x2c(%rbp),%eax
sub    $0x3,%eax
je     1330 <val_date+0x1e0>
jmp    126e <val_date+0x11e>
mov    -0x2c(%rbp),%eax
sub    $0x5,%eax
je     1330 <val_date+0x1e0>
jmp    127f <val_date+0x12f>
mov    -0x2c(%rbp),%eax
sub    $0x9,%eax
je     1330 <val_date+0x1e0>
jmp    1290 <val_date+0x140>
mov    -0x2c(%rbp),%eax
sub    $0xb,%eax
je     1330 <val_date+0x1e0>
jmp    1357 <val_date+0x207>
mov    -0x14(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    12c9 <val_date+0x179>
mov    -0x14(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    12dd <val_date+0x18d>
mov    -0x14(%rbp),%eax
mov    $0x190,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1304 <val_date+0x1b4>
cmpl   $0x1d,-0x1c(%rbp)
jle    12ff <val_date+0x1af>
lea    0xdba(%rip),%rdi
call   1040 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    13a9 <val_date+0x259>
jmp    132b <val_date+0x1db>
cmpl   $0x1c,-0x1c(%rbp)
jle    1326 <val_date+0x1d6>
lea    0xd93(%rip),%rdi
call   1040 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    13a9 <val_date+0x259>
jmp    132b <val_date+0x1db>
jmp    137e <val_date+0x22e>
cmpl   $0x1e,-0x1c(%rbp)
jle    1352 <val_date+0x202>
lea    0xd67(%rip),%rdi
call   1040 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    13a9 <val_date+0x259>
jmp    137e <val_date+0x22e>
cmpl   $0x1f,-0x1c(%rbp)
jle    1379 <val_date+0x229>
lea    0xd40(%rip),%rdi
call   1040 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    13a9 <val_date+0x259>
jmp    137e <val_date+0x22e>
lea    0xd31(%rip),%rdi
call   1040 <puts@plt>
movl   $0x0,-0x4(%rbp)
jmp    13a9 <val_date+0x259>
lea    0xd2b(%rip),%rdi
call   1040 <puts@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<val_date>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbp
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1030 <localtime@plt>
mov    %rax,%rbx
lea    0xe86(%rip),%rsi
lea    0x8(%rsp),%rdx
lea    0x4(%rsp),%rcx
mov    %rsp,%r8
mov    %rbp,%rdi
call   1070 <sscanf@plt>
mov    $0x1,%r14d
cmp    $0x3,%eax
jne    120d <val_date+0xbd>
lea    0xe68(%rip),%rdi
mov    %rbp,%rsi
call   1050 <printf@plt>
mov    $0xfffff894,%eax
add    0x8(%rsp),%eax
cmp    (%rbx),%eax
jg     11ee <val_date+0x9e>
lea    0xe62(%rip),%rdi
call   1040 <puts@plt>
mov    0x4(%rsp),%eax
add    $0xffffffff,%eax
cmp    0x4(%rbx),%eax
jg     11ee <val_date+0x9e>
lea    0xe61(%rip),%rdi
call   1040 <puts@plt>
mov    (%rsp),%eax
cmp    0x8(%rbx),%eax
jge    11ee <val_date+0x9e>
lea    0xe65(%rip),%rdi
call   1040 <puts@plt>
lea    0xe76(%rip),%rdi
call   1040 <puts@plt>
cmpl   $0xc,0x4(%rsp)
jle    1219 <val_date+0xc9>
lea    0xe7a(%rip),%rdi
jmp    12aa <val_date+0x15a>
lea    0xeb4(%rip),%rdi
jmp    12aa <val_date+0x15a>
lea    0xe72(%rip),%rdi
call   1040 <puts@plt>
mov    0x4(%rsp),%eax
cmp    $0xb,%eax
ja     129a <val_date+0x14a>
mov    $0xa28,%ecx
bt     %eax,%ecx
jae    1247 <val_date+0xf7>
cmpl   $0x1e,(%rsp)
jle    12a0 <val_date+0x150>
lea    0xe63(%rip),%rdi
jmp    12aa <val_date+0x15a>
cmp    $0x2,%eax
jne    129a <val_date+0x14a>
movslq 0x8(%rsp),%rax
test   $0x3,%al
sete   %dl
imul   $0xc28f5c29,%eax,%ecx
add    $0x51eb850,%ecx
ror    $0x2,%ecx
cmp    $0x28f5c29,%ecx
setae  %bl
mov    (%rsp),%ecx
test   %bl,%dl
jne    12bb <val_date+0x16b>
imul   $0x51eb851f,%rax,%rdx
mov    %rdx,%rsi
shr    $0x3f,%rsi
sar    $0x27,%rdx
add    %esi,%edx
imul   $0x190,%edx,%edx
sub    %edx,%eax
je     12bb <val_date+0x16b>
cmp    $0x1c,%ecx
jle    12a0 <val_date+0x150>
jmp    123e <val_date+0xee>
cmpl   $0x1f,(%rsp)
jg     123e <val_date+0xee>
xor    %r14d,%r14d
lea    0xe0c(%rip),%rdi
call   1040 <puts@plt>
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
cmp    $0x1d,%ecx
jle    12a0 <val_date+0x150>
jmp    123e <val_date+0xee>

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32 }
@.str = [9 x i8] c"%d-%d-%d\00"
@.str.1 = [22 x i8] c"Validating date \22%s\22\0A\00"
@.str.2 = [23 x i8] c"year is current or old\00"
@.str.3 = [24 x i8] c"month is current or old\00"
@.str.4 = [29 x i8] c"Warning: date is in the past\00"
@.str.5 = [23 x i8] c"date isn't in the past\00"
@.str.6 = [16 x i8] c"Too many months\00"
@.str.7 = [22 x i8] c"month isn't imaginary\00"
@.str.8 = [14 x i8] c"Too many days\00"
@.str.9 = [18 x i8] c"Date formatted ok\00"
@.str.10 = [30 x i8] c"Warning: Invalid date format.\00"
define i32 @val_date(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.tm*
store i8* %0, i8** %3
%9 = call i32 @time(i32* null)
store i32 %9, i32* %7
%10 = call %struct.tm* @localtime(i32* %7)
store %struct.tm* %10, %struct.tm** %8
%11 = load i8*, i8** %3
%12 = call i32 @sscanf(i8* %11, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32* %4, i32* %5, i32* %6)
%13 = icmp eq i32 %12, 3
br i1 %13, label %14, label %90
14: ; preds = %1
%15 = load i8*, i8** %3
%16 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%17 = load i32, i32* %4
%18 = sub nsw i32 %17, 1900
%19 = load %struct.tm*, %struct.tm** %8
%20 = getelementptr inbounds %struct.tm, %struct.tm* %19, i32 0, i32 0
%21 = load i32, i32* %20
%22 = icmp sle i32 %18, %21
br i1 %22, label %23, label %42
23: ; preds = %14
%24 = call i32 @puts(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%25 = load i32, i32* %5
%26 = sub nsw i32 %25, 1
%27 = load %struct.tm*, %struct.tm** %8
%28 = getelementptr inbounds %struct.tm, %struct.tm* %27, i32 0, i32 1
%29 = load i32, i32* %28
%30 = icmp sle i32 %26, %29
br i1 %30, label %31, label %41
31: ; preds = %23
%32 = call i32 @puts(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%33 = load i32, i32* %6
%34 = load %struct.tm*, %struct.tm** %8
%35 = getelementptr inbounds %struct.tm, %struct.tm* %34, i32 0, i32 2
%36 = load i32, i32* %35
%37 = icmp slt i32 %33, %36
br i1 %37, label %38, label %40
38: ; preds = %31
%39 = call i32 @puts(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
br label %40
40: ; preds = %38, %31
br label %41
41: ; preds = %40, %23
br label %42
42: ; preds = %41, %14
%43 = call i32 @puts(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
%44 = load i32, i32* %5
%45 = icmp sgt i32 %44, 12
br i1 %45, label %46, label %48
46: ; preds = %42
%47 = call i32 @puts(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %2
br label %92
48: ; preds = %42
%49 = call i32 @puts(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0))
%50 = load i32, i32* %5
switch i32 %50, label %82 [
i32 2, label %51
i32 3, label %76
i32 5, label %76
i32 9, label %76
i32 11, label %76
]
51: ; preds = %48
%52 = load i32, i32* %4
%53 = srem i32 %52, 4
%54 = icmp eq i32 %53, 0
br i1 %54, label %55, label %59
55: ; preds = %51
%56 = load i32, i32* %4
%57 = srem i32 %56, 100
%58 = icmp ne i32 %57, 0
br i1 %58, label %63, label %59
59: ; preds = %55, %51
%60 = load i32, i32* %4
%61 = srem i32 %60, 400
%62 = icmp eq i32 %61, 0
br i1 %62, label %63, label %69
63: ; preds = %59, %55
%64 = load i32, i32* %6
%65 = icmp sgt i32 %64, 29
br i1 %65, label %66, label %68
66: ; preds = %63
%67 = call i32 @puts(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0))
store i32 1, i32* %2
br label %92
68: ; preds = %63
br label %75
69: ; preds = %59
%70 = load i32, i32* %6
%71 = icmp sgt i32 %70, 28
br i1 %71, label %72, label %74
72: ; preds = %69
%73 = call i32 @puts(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0))
store i32 1, i32* %2
br label %92
74: ; preds = %69
br label %75
75: ; preds = %74, %68
br label %88
76: ; preds = %48, %48, %48, %48
%77 = load i32, i32* %6
%78 = icmp sgt i32 %77, 30
br i1 %78, label %79, label %81
79: ; preds = %76
%80 = call i32 @puts(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0))
store i32 1, i32* %2
br label %92
81: ; preds = %76
br label %88
82: ; preds = %48
%83 = load i32, i32* %6
%84 = icmp sgt i32 %83, 31
br i1 %84, label %85, label %87
85: ; preds = %82
%86 = call i32 @puts(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0))
store i32 1, i32* %2
br label %92
87: ; preds = %82
br label %88
88: ; preds = %87, %81, %75
%89 = call i32 @puts(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.9, i64 0, i64 0))
store i32 0, i32* %2
br label %92
90: ; preds = %1
%91 = call i32 @puts(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.10, i64 0, i64 0))
store i32 1, i32* %2
br label %92
92: ; preds = %90, %88, %85, %79, %72, %66, %46
%93 = load i32, i32* %2
ret i32 %93
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32 }
@.str = [9 x i8] c"%d-%d-%d\00"
@.str.1 = [22 x i8] c"Validating date \22%s\22\0A\00"
@.str.2 = [23 x i8] c"year is current or old\00"
@.str.3 = [24 x i8] c"month is current or old\00"
@.str.4 = [29 x i8] c"Warning: date is in the past\00"
@.str.5 = [23 x i8] c"date isn't in the past\00"
@.str.6 = [16 x i8] c"Too many months\00"
@.str.7 = [22 x i8] c"month isn't imaginary\00"
@.str.8 = [14 x i8] c"Too many days\00"
@.str.9 = [18 x i8] c"Date formatted ok\00"
@.str.10 = [30 x i8] c"Warning: Invalid date format.\00"
define i32 @val_date(i8* %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = bitcast i32* %2 to i8*
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = bitcast i32* %5 to i8*
%10 = tail call i32 @time(i32* null)
store i32 %10, i32* %5
%11 = call %struct.tm* @localtime(i32* %5)
%12 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32* %2, i32* %3, i32* %4)
%13 = icmp eq i32 %12, 3
br i1 %13, label %14, label %65
14: ; preds = %1
%15 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%16 = load i32, i32* %2
%17 = add nsw i32 %16, -1900
%18 = getelementptr inbounds %struct.tm, %struct.tm* %11, i64 0, i32 0
%19 = load i32, i32* %18
%20 = icmp sgt i32 %17, %19
br i1 %20, label %36, label %21
21: ; preds = %14
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%23 = load i32, i32* %3
%24 = add nsw i32 %23, -1
%25 = getelementptr inbounds %struct.tm, %struct.tm* %11, i64 0, i32 1
%26 = load i32, i32* %25
%27 = icmp sgt i32 %24, %26
br i1 %27, label %36, label %28
28: ; preds = %21
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%30 = load i32, i32* %4
%31 = getelementptr inbounds %struct.tm, %struct.tm* %11, i64 0, i32 2
%32 = load i32, i32* %31
%33 = icmp slt i32 %30, %32
br i1 %33, label %34, label %36
34: ; preds = %28
%35 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
br label %36
36: ; preds = %21, %34, %28, %14
%37 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
%38 = load i32, i32* %3
%39 = icmp sgt i32 %38, 12
br i1 %39, label %65, label %40
40: ; preds = %36
%41 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0))
%42 = load i32, i32* %3
switch i32 %42, label %61 [
i32 2, label %43
i32 3, label %58
i32 5, label %58
i32 9, label %58
i32 11, label %58
]
43: ; preds = %40
%44 = load i32, i32* %2
%45 = and i32 %44, 3
%46 = icmp eq i32 %45, 0
%47 = srem i32 %44, 100
%48 = icmp ne i32 %47, 0
%49 = and i1 %46, %48
%50 = srem i32 %44, 400
%51 = icmp eq i32 %50, 0
%52 = select i1 %49, i1 true, i1 %51
%53 = load i32, i32* %4
br i1 %52, label %54, label %56
54: ; preds = %43
%55 = icmp sgt i32 %53, 29
br i1 %55, label %65, label %64
56: ; preds = %43
%57 = icmp sgt i32 %53, 28
br i1 %57, label %65, label %64
58: ; preds = %40, %40, %40, %40
%59 = load i32, i32* %4
%60 = icmp sgt i32 %59, 30
br i1 %60, label %65, label %64
61: ; preds = %40
%62 = load i32, i32* %4
%63 = icmp sgt i32 %62, 31
br i1 %63, label %65, label %64
64: ; preds = %61, %58, %54, %56
br label %65
65: ; preds = %1, %61, %58, %56, %54, %36, %64
%66 = phi i8* [ getelementptr inbounds ([18 x i8], [18 x i8]* @.str.9, i64 0, i64 0), %64 ], [ getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), %36 ], [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), %54 ], [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), %56 ], [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), %58 ], [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), %61 ], [ getelementptr inbounds ([30 x i8], [30 x i8]* @.str.10, i64 0, i64 0), %1 ]
%67 = phi i32 [ 0, %64 ], [ 1, %36 ], [ 1, %54 ], [ 1, %56 ], [ 1, %58 ], [ 1, %61 ], [ 1, %1 ]
%68 = call i32 @puts(i8* dereferenceable(1) %66)
ret i32 %67
}