#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_mon;
  int tm_mday;
  int tm_year;
  int tm_hour;
  int tm_min;
  int tm_sec;
  int tm_isdst;
};

/* Variables and functions */
int /*<<< orphan*/ mktime(struct tm *);
short sscanf(char *, char *, int *, int *, int *, int *, int *, int *);
time_t parse_timestamp(char *timestamp) {
  int month, dd, yy, hh, mm, ss;
  short numfields =
      sscanf(timestamp, "%2d%2d%2d%2d%2d%2d", &month, &dd, &yy, &hh, &mm, &ss);
  time_t time = (time_t)-1;
  if (6 == numfields) {
    struct tm t;
    t.tm_mon = month - 1;
    t.tm_mday = dd;
    t.tm_year = 100 + yy;
    t.tm_hour = hh;
    t.tm_min = mm;
    t.tm_sec = ss;
    t.tm_isdst = -1;
    time = mktime(&t);
  }
  return time;
}


x86 assembly (clang, -O0):
<parse_timestamp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xec9(%rip),%rsi
lea    -0xc(%rbp),%rdx
lea    -0x10(%rbp),%rcx
lea    -0x14(%rbp),%r8
lea    -0x18(%rbp),%r9
lea    -0x1c(%rbp),%r10
lea    -0x20(%rbp),%rax
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1030 <sscanf@plt>
mov    %ax,-0x22(%rbp)
movl   $0xffffffff,-0x28(%rbp)
movswl -0x22(%rbp),%ecx
mov    $0x6,%eax
cmp    %ecx,%eax
jne    11b6 <parse_timestamp+0x96>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x48(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x14(%rbp),%eax
add    $0x64,%eax
mov    %eax,-0x40(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x34(%rbp)
movl   $0xffffffff,-0x30(%rbp)
lea    -0x48(%rbp),%rdi
call   1040 <mktime@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_timestamp>:
sub    $0x38,%rsp
mov    %rsp,%rax
lea    0x4(%rsp),%r10
lea    0xecd(%rip),%rsi
lea    0x14(%rsp),%rdx
lea    0x10(%rsp),%rcx
lea    0xc(%rsp),%r8
lea    0x8(%rsp),%r9
push   %rax
push   %r10
call   1030 <sscanf@plt>
add    $0x10,%rsp
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    $0x6,%cx
jne    11a7 <parse_timestamp+0x87>
mov    0x14(%rsp),%eax
add    $0xffffffff,%eax
mov    %eax,0x18(%rsp)
mov    0x10(%rsp),%eax
mov    %eax,0x1c(%rsp)
mov    0xc(%rsp),%eax
add    $0x64,%eax
mov    %eax,0x20(%rsp)
mov    0x8(%rsp),%eax
mov    %eax,0x24(%rsp)
mov    0x4(%rsp),%eax
mov    %eax,0x28(%rsp)
mov    (%rsp),%eax
mov    %eax,0x2c(%rsp)
movl   $0xffffffff,0x30(%rsp)
ff
lea    0x18(%rsp),%rdi
call   1040 <mktime@plt>
add    $0x38,%rsp
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32, i32, i32, i32, i32 }
@.str = [19 x i8] c"%2d%2d%2d%2d%2d%2d\00"
define i32 @parse_timestamp(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i16
%10 = alloca i32
%11 = alloca %struct.tm
store i8* %0, i8** %2
%12 = load i8*, i8** %2
%13 = call signext i16 @sscanf(i8* %12, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32* %3, i32* %4, i32* %5, i32* %6, i32* %7, i32* %8)
store i16 %13, i16* %9
store i32 -1, i32* %10
%14 = load i16, i16* %9
%15 = sext i16 %14 to i32
%16 = icmp eq i32 6, %15
br i1 %16, label %17, label %34
17: ; preds = %1
%18 = load i32, i32* %3
%19 = sub nsw i32 %18, 1
%20 = getelementptr inbounds %struct.tm, %struct.tm* %11, i32 0, i32 0
store i32 %19, i32* %20
%21 = load i32, i32* %4
%22 = getelementptr inbounds %struct.tm, %struct.tm* %11, i32 0, i32 1
store i32 %21, i32* %22
%23 = load i32, i32* %5
%24 = add nsw i32 100, %23
%25 = getelementptr inbounds %struct.tm, %struct.tm* %11, i32 0, i32 2
store i32 %24, i32* %25
%26 = load i32, i32* %6
%27 = getelementptr inbounds %struct.tm, %struct.tm* %11, i32 0, i32 3
store i32 %26, i32* %27
%28 = load i32, i32* %7
%29 = getelementptr inbounds %struct.tm, %struct.tm* %11, i32 0, i32 4
store i32 %28, i32* %29
%30 = load i32, i32* %8
%31 = getelementptr inbounds %struct.tm, %struct.tm* %11, i32 0, i32 5
store i32 %30, i32* %31
%32 = getelementptr inbounds %struct.tm, %struct.tm* %11, i32 0, i32 6
store i32 -1, i32* %32
%33 = call i32 @mktime(%struct.tm* %11)
store i32 %33, i32* %10
br label %34
34: ; preds = %17, %1
%35 = load i32, i32* %10
ret i32 %35
}

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