#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 time_t;
struct tm {
  unsigned int tm_sec;
  unsigned int tm_min;
  unsigned int tm_hour;
  unsigned int tm_mday;
  unsigned int tm_mon;
  unsigned int tm_year;
  int tm_isdst;
  scalar_t__ tm_yday;
  scalar_t__ tm_wday;
};

/* Variables and functions */
int mktime(struct tm *);
int sscanf(char *, char *, unsigned int *, unsigned int *, unsigned int *,
           unsigned int *, unsigned int *, unsigned int *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int _glh_decode_timestamp(char *string, char **endp, time_t *timestamp) {
  unsigned year, month, day, hour, min, sec;
  struct tm t;
  enum { TSLEN = 14 };
  char timestr[TSLEN + 1];
  if (string[0] == '\?') {
    *endp = string + 1;
    *timestamp = -1;
    return 0;
  };
  if (strlen(string) < TSLEN) {
    *endp = string;
    return 1;
  };
  strncpy(timestr, string, TSLEN);
  timestr[TSLEN] = '\0';
  if (sscanf(timestr, "%4u%2u%2u%2u%2u%2u", &year, &month, &day, &hour, &min,
             &sec) != 6) {
    *endp = string;
    return 1;
  };
  *endp = string + TSLEN;
  t.tm_sec = sec;
  t.tm_min = min;
  t.tm_hour = hour;
  t.tm_mday = day;
  t.tm_wday = 0;
  t.tm_yday = 0;
  t.tm_mon = month - 1;
  t.tm_year = year - 1900;
  t.tm_isdst = -1;
  *timestamp = mktime(&t);
  return 0;
}


x86 assembly (clang, -O0):
<_glh_decode_timestamp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3f,%eax
jne    118c <_glh_decode_timestamp+0x4c>
mov    -0x10(%rbp),%rcx
add    $0x1,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
movl   $0xffffffff,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    1286 <_glh_decode_timestamp+0x146>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0xe,%eax
jge    11b5 <_glh_decode_timestamp+0x75>
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    1286 <_glh_decode_timestamp+0x146>
lea    -0x77(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0xe,%edx
call   1030 <strncpy@plt>
movb   $0x0,-0x69(%rbp)
lea    -0x77(%rbp),%rdi
lea    0xe2a(%rip),%rsi
lea    -0x24(%rbp),%rdx
lea    -0x28(%rbp),%rcx
lea    -0x2c(%rbp),%r8
lea    -0x30(%rbp),%r9
lea    -0x34(%rbp),%r10
lea    -0x38(%rbp),%rax
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1050 <sscanf@plt>
cmp    $0x6,%eax
je     121c <_glh_decode_timestamp+0xdc>
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    1286 <_glh_decode_timestamp+0x146>
mov    -0x10(%rbp),%rcx
add    $0xe,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x38(%rbp),%eax
mov    %eax,-0x68(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x64(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x60(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x5c(%rbp)
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
mov    -0x28(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x58(%rbp)
mov    -0x24(%rbp),%eax
sub    $0x76c,%eax
mov    %eax,-0x54(%rbp)
movl   $0xffffffff,-0x50(%rbp)
lea    -0x68(%rbp),%rdi
call   1060 <mktime@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_glh_decode_timestamp>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
cmpb   $0x3f,(%rdi)
jne    116c <_glh_decode_timestamp+0x2c>
add    $0x1,%rbx
mov    %rbx,(%r15)
movl   $0xffffffff,(%r14)
jmp    1229 <_glh_decode_timestamp+0xe9>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    $0xd,%eax
jle    122d <_glh_decode_timestamp+0xed>
lea    0x49(%rsp),%r12
mov    %r12,%rdi
mov    %rbx,%rsi
mov    $0xe,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x57(%rsp)
mov    %rsp,%rax
lea    0x4(%rsp),%r10
lea    0xe5a(%rip),%rsi
lea    0x14(%rsp),%rdx
lea    0x10(%rsp),%rcx
lea    0xc(%rsp),%r8
lea    0x8(%rsp),%r9
mov    %r12,%rdi
push   %rax
push   %r10
call   1050 <sscanf@plt>
add    $0x10,%rsp
cmp    $0x6,%eax
jne    122d <_glh_decode_timestamp+0xed>
add    $0xe,%rbx
mov    %rbx,(%r15)
mov    (%rsp),%eax
mov    %eax,0x18(%rsp)
mov    0x4(%rsp),%eax
mov    %eax,0x1c(%rsp)
mov    0x8(%rsp),%eax
mov    %eax,0x20(%rsp)
mov    0xc(%rsp),%eax
mov    %eax,0x24(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x38(%rsp)
mov    0x10(%rsp),%eax
add    $0xffffffff,%eax
mov    %eax,0x28(%rsp)
mov    $0xfffff894,%eax
add    0x14(%rsp),%eax
mov    %eax,0x2c(%rsp)
movl   $0xffffffff,0x30(%rsp)
ff
lea    0x18(%rsp),%rdi
call   1060 <mktime@plt>
mov    %eax,(%r14)
xor    %eax,%eax
jmp    1235 <_glh_decode_timestamp+0xf5>
mov    %rbx,(%r15)
mov    $0x1,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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