#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 date_digit(char *);
scalar_t__ dd_val(unsigned int, unsigned int, unsigned int);
scalar_t__ get_dt_part(char *, char *, char *, char, int);
int mmm_val(char *);
int strlen(char *);
int set_date_tmpl(char *dt, char *tmpl, unsigned int *yyyy, unsigned int *mm,
                  unsigned int *dd) {
  int n;
  char yr[5], month[4], day[3];
  if (get_dt_part(dt, yr, tmpl, 'y', 4) < 0)
    return -1;
  if (get_dt_part(dt, month, tmpl, 'm', 3) < 0)
    return -1;
  if (get_dt_part(dt, day, tmpl, 'd', 2) < 0)
    return -1;
  if ((n = date_digit(yr)) < 0)
    return -2;
  *yyyy = (unsigned int)n;
  if (strlen(month) < 3) {
    if ((n = date_digit(month)) < 0)
      return -3;
  } else {
    if ((n = mmm_val(month)) < 0)
      return -4;
  }
  if (n < 1 || n > 12)
    return -3;
  *mm = (unsigned int)n;
  if ((n = date_digit(day)) < 0)
    return -5;
  *dd = (unsigned int)n;
  if ((dd_val(*dd, *mm, *yyyy)) < 0)
    return -5;
  return 1;
}


x86 assembly (clang, -O0):
<set_date_tmpl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x39(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    $0x79,%ecx
mov    $0x4,%r8d
call   1030 <get_dt_part@plt>
cmp    $0x0,%rax
jge    119e <set_date_tmpl+0x4e>
movl   $0xffffffff,-0x4(%rbp)
jmp    1311 <set_date_tmpl+0x1c1>
mov    -0x10(%rbp),%rdi
lea    -0x3d(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    $0x6d,%ecx
mov    $0x3,%r8d
call   1030 <get_dt_part@plt>
cmp    $0x0,%rax
jge    11d0 <set_date_tmpl+0x80>
movl   $0xffffffff,-0x4(%rbp)
jmp    1311 <set_date_tmpl+0x1c1>
mov    -0x10(%rbp),%rdi
lea    -0x40(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    $0x64,%ecx
mov    $0x2,%r8d
call   1030 <get_dt_part@plt>
cmp    $0x0,%rax
jge    1202 <set_date_tmpl+0xb2>
movl   $0xffffffff,-0x4(%rbp)
jmp    1311 <set_date_tmpl+0x1c1>
lea    -0x39(%rbp),%rdi
call   1070 <date_digit@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
jge    1223 <set_date_tmpl+0xd3>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1311 <set_date_tmpl+0x1c1>
mov    -0x34(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
lea    -0x3d(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x3,%eax
jge    1264 <set_date_tmpl+0x114>
lea    -0x3d(%rbp),%rdi
call   1070 <date_digit@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
jge    125f <set_date_tmpl+0x10f>
movl   $0xfffffffd,-0x4(%rbp)
jmp    1311 <set_date_tmpl+0x1c1>
jmp    128a <set_date_tmpl+0x13a>
lea    -0x3d(%rbp),%rdi
call   1060 <mmm_val@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
jge    1285 <set_date_tmpl+0x135>
movl   $0xfffffffc,-0x4(%rbp)
jmp    1311 <set_date_tmpl+0x1c1>
jmp    128a <set_date_tmpl+0x13a>
cmpl   $0x1,-0x34(%rbp)
jl     129e <set_date_tmpl+0x14e>
cmpl   $0xc,-0x34(%rbp)
jle    12aa <set_date_tmpl+0x15a>
movl   $0xfffffffd,-0x4(%rbp)
jmp    1311 <set_date_tmpl+0x1c1>
mov    -0x34(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
lea    -0x40(%rbp),%rdi
call   1070 <date_digit@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
jge    12d4 <set_date_tmpl+0x184>
movl   $0xfffffffb,-0x4(%rbp)
jmp    1311 <set_date_tmpl+0x1c1>
mov    -0x34(%rbp),%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x30(%rbp),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rax
mov    (%rax),%esi
mov    -0x20(%rbp),%rax
mov    (%rax),%edx
call   1050 <dd_val@plt>
cmp    $0x0,%rax
jge    130a <set_date_tmpl+0x1ba>
movl   $0xfffffffb,-0x4(%rbp)
jmp    1311 <set_date_tmpl+0x1c1>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_date_tmpl>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8,%r15
mov    %rcx,%r14
mov    %rdx,%r12
mov    %rsi,%rbx
mov    %rdi,%rbp
lea    0x13(%rsp),%rsi
mov    %rbx,%rdx
mov    $0x79,%ecx
mov    $0x4,%r8d
call   1030 <get_dt_part@plt>
mov    $0xffffffff,%r13d
test   %rax,%rax
js     1276 <set_date_tmpl+0x126>
lea    0xc(%rsp),%rsi
mov    %rbp,%rdi
mov    %rbx,%rdx
mov    $0x6d,%ecx
mov    $0x3,%r8d
call   1030 <get_dt_part@plt>
test   %rax,%rax
js     1276 <set_date_tmpl+0x126>
lea    0x10(%rsp),%rsi
mov    %rbp,%rdi
mov    %rbx,%rdx
mov    $0x64,%ecx
mov    $0x2,%r8d
call   1030 <get_dt_part@plt>
test   %rax,%rax
js     1276 <set_date_tmpl+0x126>
lea    0x13(%rsp),%rdi
call   1070 <date_digit@plt>
test   %eax,%eax
js     1213 <set_date_tmpl+0xc3>
mov    %eax,(%r12)
lea    0xc(%rsp),%rdi
call   1040 <strlen@plt>
lea    0xc(%rsp),%rdi
cmp    $0x2,%eax
jg     121b <set_date_tmpl+0xcb>
call   1070 <date_digit@plt>
test   %eax,%eax
jns    1224 <set_date_tmpl+0xd4>
mov    $0xfffffffd,%r13d
jmp    1276 <set_date_tmpl+0x126>
mov    $0xfffffffe,%r13d
jmp    1276 <set_date_tmpl+0x126>
call   1060 <mmm_val@plt>
test   %eax,%eax
js     1268 <set_date_tmpl+0x118>
lea    -0xd(%rax),%ecx
mov    $0xfffffffd,%r13d
cmp    $0xfffffff4,%ecx
jb     1276 <set_date_tmpl+0x126>
mov    %eax,(%r14)
lea    0x10(%rsp),%rdi
call   1070 <date_digit@plt>
test   %eax,%eax
js     1270 <set_date_tmpl+0x120>
mov    %eax,(%r15)
mov    (%r14),%esi
mov    (%r12),%edx
mov    %eax,%edi
call   1050 <dd_val@plt>
test   %rax,%rax
mov    $0xfffffffb,%eax
mov    $0x1,%r13d
cmovs  %eax,%r13d
jmp    1276 <set_date_tmpl+0x126>
mov    $0xfffffffc,%r13d
jmp    1276 <set_date_tmpl+0x126>
mov    $0xfffffffb,%r13d
mov    %r13d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @set_date_tmpl(i8* %0, i8* %1, i32* nocapture %2, i32* nocapture %3, i32* nocapture writeonly %4) {
%6 = alloca [5 x i8]
%7 = alloca [4 x i8]
%8 = alloca [3 x i8]
%9 = getelementptr inbounds [5 x i8], [5 x i8]* %6, i64 0, i64 0
%10 = getelementptr inbounds [4 x i8], [4 x i8]* %7, i64 0, i64 0
%11 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 0, i64 0
%12 = call i64 @get_dt_part(i8* %0, i8* %9, i8* %1, i8 signext 121, i32 4)
%13 = icmp slt i64 %12, 0
br i1 %13, label %45, label %14
14: ; preds = %5
%15 = call i64 @get_dt_part(i8* %0, i8* %10, i8* %1, i8 signext 109, i32 3)
%16 = icmp slt i64 %15, 0
br i1 %16, label %45, label %17
17: ; preds = %14
%18 = call i64 @get_dt_part(i8* %0, i8* %11, i8* %1, i8 signext 100, i32 2)
%19 = icmp slt i64 %18, 0
br i1 %19, label %45, label %20
20: ; preds = %17
%21 = call i32 @date_digit(i8* %9)
%22 = icmp slt i32 %21, 0
br i1 %22, label %45, label %23
23: ; preds = %20
store i32 %21, i32* %2
%24 = call i32 @strlen(i8* %10)
%25 = icmp slt i32 %24, 3
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = call i32 @date_digit(i8* %10)
%28 = icmp slt i32 %27, 0
br i1 %28, label %45, label %32
29: ; preds = %23
%30 = call i32 @mmm_val(i8* %10)
%31 = icmp slt i32 %30, 0
br i1 %31, label %45, label %32
32: ; preds = %29, %26
%33 = phi i32 [ %27, %26 ], [ %30, %29 ]
%34 = add nsw i32 %33, -13
%35 = icmp ult i32 %34, -12
br i1 %35, label %45, label %36
36: ; preds = %32
store i32 %33, i32* %3
%37 = call i32 @date_digit(i8* %11)
%38 = icmp slt i32 %37, 0
br i1 %38, label %45, label %39
39: ; preds = %36
store i32 %37, i32* %4
%40 = load i32, i32* %3
%41 = load i32, i32* %2
%42 = call i64 @dd_val(i32 %37, i32 %40, i32 %41)
%43 = icmp slt i64 %42, 0
%44 = select i1 %43, i32 -5, i32 1
br label %45
45: ; preds = %39, %36, %32, %29, %26, %20, %17, %14, %5
%46 = phi i32 [ -1, %5 ], [ -1, %14 ], [ -1, %17 ], [ -2, %20 ], [ -3, %26 ], [ -4, %29 ], [ -3, %32 ], [ -5, %36 ], [ %44, %39 ]
ret i32 %46
}