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

/* Variables and functions */
int /*<<< orphan*/ memset(int /*<<< orphan*/ *, int /*<<< orphan*/, int);
int /*<<< orphan*/ mktime(struct tm *);
int sscanf(char *, char *, scalar_t__ *, scalar_t__ *, scalar_t__ *,
           scalar_t__ *, scalar_t__ *, scalar_t__ *);
time_t parsetm(char *ts) {
  struct tm u, origu;
  time_t tm;
  memset(&tm, 0, sizeof(tm));
  if (sscanf(ts, "%4d%2d%2d%2d%2d%2d", &u.tm_year, &u.tm_mon, &u.tm_mday,
             &u.tm_hour, &u.tm_min, &u.tm_sec) != 6)
    return (time_t)-1;
  u.tm_year -= 1900;
  u.tm_mon -= 1;
  u.tm_isdst = -1;
  origu = u;
  if ((tm = mktime(&u)) == (time_t)-1)
    return tm;
  if (u.tm_year != origu.tm_year || u.tm_mon != origu.tm_mon ||
      u.tm_mday != origu.tm_mday || u.tm_hour != origu.tm_hour ||
      u.tm_min != origu.tm_min || u.tm_sec != origu.tm_sec)
    return (time_t)-1;
  return tm;
}


x86 assembly (clang, -O0):
<parsetm>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x84(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
mov    -0x10(%rbp),%rdi
lea    -0x48(%rbp),%rdx
lea    -0x48(%rbp),%rcx
add    $0x8,%rcx
lea    -0x48(%rbp),%r8
add    $0x10,%r8
lea    -0x48(%rbp),%r9
add    $0x18,%r9
lea    -0x48(%rbp),%r10
add    $0x20,%r10
lea    -0x48(%rbp),%rax
add    $0x28,%rax
lea    0xe67(%rip),%rsi
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1050 <sscanf@plt>
cmp    $0x6,%eax
je     11bc <parsetm+0x7c>
movl   $0xffffffff,-0x4(%rbp)
jmp    127e <parsetm+0x13e>
mov    -0x48(%rbp),%rax
sub    $0x76c,%rax
mov    %rax,-0x48(%rbp)
mov    -0x40(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x40(%rbp)
movl   $0xffffffff,-0x18(%rbp)
lea    -0x80(%rbp),%rdi
lea    -0x48(%rbp),%rsi
mov    $0x38,%edx
call   1040 <memcpy@plt>
lea    -0x48(%rbp),%rdi
call   1060 <mktime@plt>
mov    %eax,-0x84(%rbp)
cmp    $0xffffffff,%eax
jne    1215 <parsetm+0xd5>
mov    -0x84(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    127e <parsetm+0x13e>
mov    -0x48(%rbp),%rax
cmp    -0x80(%rbp),%rax
jne    1269 <parsetm+0x129>
mov    -0x40(%rbp),%rax
cmp    -0x78(%rbp),%rax
jne    1269 <parsetm+0x129>
mov    -0x38(%rbp),%rax
cmp    -0x70(%rbp),%rax
jne    1269 <parsetm+0x129>
mov    -0x30(%rbp),%rax
cmp    -0x68(%rbp),%rax
jne    1269 <parsetm+0x129>
mov    -0x28(%rbp),%rax
cmp    -0x60(%rbp),%rax
jne    1269 <parsetm+0x129>
mov    -0x20(%rbp),%rax
cmp    -0x58(%rbp),%rax
je     1275 <parsetm+0x135>
movl   $0xffffffff,-0x4(%rbp)
jmp    127e <parsetm+0x13e>
mov    -0x84(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parsetm>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rdi,%rbx
lea    0x44(%rsp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
lea    0x8(%rsp),%rcx
lea    0x10(%rsp),%r8
lea    0x18(%rsp),%r9
lea    0x20(%rsp),%rax
lea    0x28(%rsp),%rbp
lea    0xe8e(%rip),%rsi
mov    %rsp,%rdx
mov    %rbx,%rdi
push   %rbp
push   %rax
call   1040 <sscanf@plt>
add    $0x10,%rsp
mov    $0xffffffff,%r14d
cmp    $0x6,%eax
jne    1218 <parsetm+0xe8>
mov    $0xfffffffffffff894,%r15
add    (%rsp),%r15
mov    %r15,(%rsp)
mov    0x8(%rsp),%rbx
mov    0x10(%rsp),%r13
add    $0xffffffffffffffff,%rbx
mov    %rbx,0x8(%rsp)
movl   $0xffffffff,0x30(%rsp)
ff
mov    0x18(%rsp),%r12
mov    0x20(%rsp),%rax
mov    %rax,0x38(%rsp)
mov    0x28(%rsp),%rbp
mov    %rsp,%rdi
call   1050 <mktime@plt>
cmp    $0xffffffff,%eax
je     1218 <parsetm+0xe8>
xor    (%rsp),%r15
xor    0x8(%rsp),%rbx
xor    0x10(%rsp),%r13
xor    0x18(%rsp),%r12
or     %r15,%rbx
or     %r13,%r12
mov    0x38(%rsp),%rcx
xor    0x20(%rsp),%rcx
xor    0x28(%rsp),%rbp
or     %rcx,%rbp
or     %r12,%rbp
or     %rbx,%rbp
mov    $0xffffffff,%r14d
cmove  %eax,%r14d
mov    %r14d,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i64, i64, i64, i64, i64, i64, i32 }
@.str = [19 x i8] c"%4d%2d%2d%2d%2d%2d\00"
define i32 @parsetm(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.tm
%5 = alloca %struct.tm
%6 = alloca i32
store i8* %0, i8** %3
%7 = call i32 @memset(i32* %6, i32 0, i32 4)
%8 = load i8*, i8** %3
%9 = getelementptr inbounds %struct.tm, %struct.tm* %4, i32 0, i32 0
%10 = getelementptr inbounds %struct.tm, %struct.tm* %4, i32 0, i32 1
%11 = getelementptr inbounds %struct.tm, %struct.tm* %4, i32 0, i32 2
%12 = getelementptr inbounds %struct.tm, %struct.tm* %4, i32 0, i32 3
%13 = getelementptr inbounds %struct.tm, %struct.tm* %4, i32 0, i32 4
%14 = getelementptr inbounds %struct.tm, %struct.tm* %4, i32 0, i32 5
%15 = call i32 @sscanf(i8* %8, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i64* %9, i64* %10, i64* %11, i64* %12, i64* %13, i64* %14)
%16 = icmp ne i32 %15, 6
br i1 %16, label %17, label %18
17: ; preds = %1
store i32 -1, i32* %2
br label %71
18: ; preds = %1
%19 = getelementptr inbounds %struct.tm, %struct.tm* %4, i32 0, i32 0
%20 = load i64, i64* %19
%21 = sub nsw i64 %20, 1900
store i64 %21, i64* %19
%22 = getelementptr inbounds %struct.tm, %struct.tm* %4, i32 0, i32 1
%23 = load i64, i64* %22
%24 = sub nsw i64 %23, 1
store i64 %24, i64* %22
%25 = getelementptr inbounds %struct.tm, %struct.tm* %4, i32 0, i32 6
store i32 -1, i32* %25
%26 = bitcast %struct.tm* %5 to i8*
%27 = bitcast %struct.tm* %4 to i8*
%28 = call i32 @mktime(%struct.tm* %4)
store i32 %28, i32* %6
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %32
30: ; preds = %18
%31 = load i32, i32* %6
store i32 %31, i32* %2
br label %71
32: ; preds = %18
%33 = getelementptr inbounds %struct.tm, %struct.tm* %4, i32 0, i32 0
%34 = load i64, i64* %33
%35 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 0
%36 = load i64, i64* %35
%37 = icmp ne i64 %34, %36
br i1 %37, label %68, label %38
38: ; preds = %32
%39 = getelementptr inbounds %struct.tm, %struct.tm* %4, i32 0, i32 1
%40 = load i64, i64* %39
%41 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 1
%42 = load i64, i64* %41
%43 = icmp ne i64 %40, %42
br i1 %43, label %68, label %44
44: ; preds = %38
%45 = getelementptr inbounds %struct.tm, %struct.tm* %4, i32 0, i32 2
%46 = load i64, i64* %45
%47 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 2
%48 = load i64, i64* %47
%49 = icmp ne i64 %46, %48
br i1 %49, label %68, label %50
50: ; preds = %44
%51 = getelementptr inbounds %struct.tm, %struct.tm* %4, i32 0, i32 3
%52 = load i64, i64* %51
%53 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 3
%54 = load i64, i64* %53
%55 = icmp ne i64 %52, %54
br i1 %55, label %68, label %56
56: ; preds = %50
%57 = getelementptr inbounds %struct.tm, %struct.tm* %4, i32 0, i32 4
%58 = load i64, i64* %57
%59 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 4
%60 = load i64, i64* %59
%61 = icmp ne i64 %58, %60
br i1 %61, label %68, label %62
62: ; preds = %56
%63 = getelementptr inbounds %struct.tm, %struct.tm* %4, i32 0, i32 5
%64 = load i64, i64* %63
%65 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 5
%66 = load i64, i64* %65
%67 = icmp ne i64 %64, %66
br i1 %67, label %68, label %69
68: ; preds = %62, %56, %50, %44, %38, %32
store i32 -1, i32* %2
br label %71
69: ; preds = %62
%70 = load i32, i32* %6
store i32 %70, i32* %2
br label %71
71: ; preds = %69, %68, %30, %17
%72 = load i32, i32* %2
ret i32 %72
}

LLVM IR (-O2):
%struct.tm = type { i64, i64, i64, i64, i64, i64, i32 }
@.str = [19 x i8] c"%4d%2d%2d%2d%2d%2d\00"
define i32 @parsetm(i8* nocapture %0) {
%2 = alloca %struct.tm
%3 = alloca i32
%4 = bitcast %struct.tm* %2 to i8*
%5 = bitcast i32* %3 to i8*
%6 = call i32 @memset(i32* %3, i32 0, i32 4)
%7 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 0
%8 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 1
%9 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 2
%10 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 3
%11 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 4
%12 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 5
%13 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i64* %7, i64* %8, i64* %9, i64* %10, i64* %11, i64* %12)
%14 = icmp eq i32 %13, 6
br i1 %14, label %15, label %46
15: ; preds = %1
%16 = load i64, i64* %7
%17 = add nsw i64 %16, -1900
store i64 %17, i64* %7
%18 = load i64, i64* %8
%19 = add nsw i64 %18, -1
store i64 %19, i64* %8
%20 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 6
store i32 -1, i32* %20
%21 = load i64, i64* %9
%22 = load i64, i64* %10
%23 = load i64, i64* %11
%24 = load i64, i64* %12
%25 = call i32 @mktime(%struct.tm* %2)
%26 = icmp eq i32 %25, -1
br i1 %26, label %46, label %27
27: ; preds = %15
%28 = load i64, i64* %7
%29 = icmp eq i64 %28, %17
%30 = load i64, i64* %8
%31 = icmp eq i64 %30, %19
%32 = select i1 %29, i1 %31, i1 false
%33 = load i64, i64* %9
%34 = icmp eq i64 %33, %21
%35 = select i1 %32, i1 %34, i1 false
%36 = load i64, i64* %10
%37 = icmp eq i64 %36, %22
%38 = select i1 %35, i1 %37, i1 false
%39 = load i64, i64* %11
%40 = icmp eq i64 %39, %23
%41 = select i1 %38, i1 %40, i1 false
%42 = load i64, i64* %12
%43 = icmp eq i64 %42, %24
%44 = select i1 %41, i1 %43, i1 false
%45 = select i1 %44, i32 %25, i32 -1
br label %46
46: ; preds = %27, %15, %1
%47 = phi i32 [ -1, %1 ], [ -1, %15 ], [ %45, %27 ]
ret i32 %47
}