#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 */
struct tm {
  int dummy;
};

/* Variables and functions */
char *strchr(char const *, char);
char *strptime(char const *, char *, struct tm *);
int rcsdatetotm(const char *revdate, struct tm *tm) {
  char *cp;
  size_t len;
  cp = strchr(revdate, '.');
  if (cp == NULL)
    return (-1);
  len = cp - revdate;
  if (len >= 4)
    cp = strptime(revdate, "%Y.%m.%d.%H.%M.%S", tm);
  else if (len == 2)
    cp = strptime(revdate, "%y.%m.%d.%H.%M.%S", tm);
  else
    return (-1);
  if (cp == NULL || *cp != '\0')
    return (-1);
  return (0);
}


x86 assembly (clang, -O0):
<rcsdatetotm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2e,%esi
call   1030 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1159 <rcsdatetotm+0x39>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f7 <rcsdatetotm+0xd7>
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x4,-0x28(%rbp)
jb     1190 <rcsdatetotm+0x70>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe7e(%rip),%rsi
call   1040 <strptime@plt>
mov    %rax,-0x20(%rbp)
jmp    11c9 <rcsdatetotm+0xa9>
cmpq   $0x2,-0x28(%rbp)
jne    11b8 <rcsdatetotm+0x98>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe68(%rip),%rsi
call   1040 <strptime@plt>
mov    %rax,-0x20(%rbp)
jmp    11c4 <rcsdatetotm+0xa4>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f7 <rcsdatetotm+0xd7>
jmp    11c9 <rcsdatetotm+0xa9>
cmpq   $0x0,-0x20(%rbp)
je     11e4 <rcsdatetotm+0xc4>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11f0 <rcsdatetotm+0xd0>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f7 <rcsdatetotm+0xd7>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rcsdatetotm>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
mov    $0x2e,%esi
call   1030 <strchr@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
je     1173 <rcsdatetotm+0x53>
sub    %rbx,%rax
cmp    $0x3,%rax
jbe    1150 <rcsdatetotm+0x30>
lea    0xeb2(%rip),%rsi
jmp    115d <rcsdatetotm+0x3d>
cmp    $0x2,%rax
jne    1173 <rcsdatetotm+0x53>
lea    0xeb5(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1040 <strptime@plt>
test   %rax,%rax
je     1173 <rcsdatetotm+0x53>
xor    %ecx,%ecx
cmp    (%rax),%cl
sbb    %ebp,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [18 x i8] c"%Y.%m.%d.%H.%M.%S\00"
@.str.1 = [18 x i8] c"%y.%m.%d.%H.%M.%S\00"
define i32 @rcsdatetotm(i8* %0, %struct.tm* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca %struct.tm*
%6 = alloca i8*
%7 = alloca i64
store i8* %0, i8** %4
store %struct.tm* %1, %struct.tm** %5
%8 = load i8*, i8** %4
%9 = call i8* @strchr(i8* %8, i8 signext 46)
store i8* %9, i8** %6
%10 = load i8*, i8** %6
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 -1, i32* %3
br label %44
13: ; preds = %2
%14 = load i8*, i8** %6
%15 = load i8*, i8** %4
%16 = ptrtoint i8* %14 to i64
%17 = ptrtoint i8* %15 to i64
%18 = sub i64 %16, %17
store i64 %18, i64* %7
%19 = load i64, i64* %7
%20 = icmp uge i64 %19, 4
br i1 %20, label %21, label %25
21: ; preds = %13
%22 = load i8*, i8** %4
%23 = load %struct.tm*, %struct.tm** %5
%24 = call i8* @strptime(i8* %22, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), %struct.tm* %23)
store i8* %24, i8** %6
br label %34
25: ; preds = %13
%26 = load i64, i64* %7
%27 = icmp eq i64 %26, 2
br i1 %27, label %28, label %32
28: ; preds = %25
%29 = load i8*, i8** %4
%30 = load %struct.tm*, %struct.tm** %5
%31 = call i8* @strptime(i8* %29, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), %struct.tm* %30)
store i8* %31, i8** %6
br label %33
32: ; preds = %25
store i32 -1, i32* %3
br label %44
33: ; preds = %28
br label %34
34: ; preds = %33, %21
%35 = load i8*, i8** %6
%36 = icmp eq i8* %35, null
br i1 %36, label %42, label %37
37: ; preds = %34
%38 = load i8*, i8** %6
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %43
42: ; preds = %37, %34
store i32 -1, i32* %3
br label %44
43: ; preds = %37
store i32 0, i32* %3
br label %44
44: ; preds = %43, %42, %32, %12
%45 = load i32, i32* %3
ret i32 %45
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [18 x i8] c"%Y.%m.%d.%H.%M.%S\00"
@.str.1 = [18 x i8] c"%y.%m.%d.%H.%M.%S\00"
define i32 @rcsdatetotm(i8* %0, %struct.tm* %1) {
%3 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 46)
%4 = icmp eq i8* %3, null
br i1 %4, label %20, label %5
5: ; preds = %2
%6 = ptrtoint i8* %3 to i64
%7 = ptrtoint i8* %0 to i64
%8 = sub i64 %6, %7
%9 = icmp ugt i64 %8, 3
br i1 %9, label %12, label %10
10: ; preds = %5
%11 = icmp eq i64 %8, 2
br i1 %11, label %12, label %20
12: ; preds = %10, %5
%13 = phi i8* [ getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), %5 ], [ getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), %10 ]
%14 = tail call i8* @strptime(i8* %0, i8* %13, %struct.tm* %1)
%15 = icmp eq i8* %14, null
br i1 %15, label %20, label %16
16: ; preds = %12
%17 = load i8, i8* %14
%18 = icmp ne i8 %17, 0
%19 = sext i1 %18 to i32
br label %20
20: ; preds = %16, %12, %10, %2
%21 = phi i32 [ -1, %2 ], [ -1, %10 ], [ -1, %12 ], [ %19, %16 ]
ret i32 %21
}