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

/* Variables and functions */
int /*<<< orphan*/ memset(struct tm *, int /*<<< orphan*/, int);
int /*<<< orphan*/ mktime(struct tm *);
int sscanf(char const *, char *, int *, int *, int *, int *, int *, int *);
time_t str2time(const char *str) {
  struct tm tmb;
  int year, month, day, hour, min, sec;
  year = month = day = hour = min = sec = 0;
  memset(&tmb, 0, sizeof(tmb));
  if (sscanf(str, "%u-%u-%u %u:%u:%u", &year, &month, &day, &hour, &min, &sec) <
      1)
    return (time_t)-1;
  tmb.tm_year = year - 1900;
  tmb.tm_mon = month - 1;
  tmb.tm_mday = day;
  tmb.tm_hour = hour;
  tmb.tm_min = min;
  tmb.tm_sec = sec;
  tmb.tm_isdst = -1;
  return mktime(&tmb);
}


x86 assembly (clang, -O0):
<str2time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x48(%rbp)
movl   $0x0,-0x44(%rbp)
movl   $0x0,-0x40(%rbp)
movl   $0x0,-0x3c(%rbp)
movl   $0x0,-0x38(%rbp)
movl   $0x0,-0x34(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x1c,%edx
call   1030 <memset@plt>
mov    -0x10(%rbp),%rdi
lea    0xe7f(%rip),%rsi
lea    -0x34(%rbp),%rdx
lea    -0x38(%rbp),%rcx
lea    -0x3c(%rbp),%r8
lea    -0x40(%rbp),%r9
lea    -0x44(%rbp),%r10
lea    -0x48(%rbp),%rax
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1040 <sscanf@plt>
cmp    $0x1,%eax
jge    11bc <str2time+0x8c>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fb <str2time+0xcb>
mov    -0x34(%rbp),%eax
sub    $0x76c,%eax
mov    %eax,-0x30(%rbp)
mov    -0x38(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x3c(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x40(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x44(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x48(%rbp),%eax
mov    %eax,-0x1c(%rbp)
movl   $0xffffffff,-0x18(%rbp)
lea    -0x30(%rbp),%rdi
call   1050 <mktime@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str2time>:
push   %rbx
sub    $0x40,%rsp
mov    %rdi,%rbx
movl   $0x0,0x8(%rsp)
movl   $0x0,0xc(%rsp)
movl   $0x0,0x10(%rsp)
movl   $0x0,0x14(%rsp)
movl   $0x0,0x18(%rsp)
movl   $0x0,0x1c(%rsp)
lea    0x20(%rsp),%rdi
xor    %esi,%esi
mov    $0x1c,%edx
call   1030 <memset@plt>
lea    0x8(%rsp),%rax
lea    0xc(%rsp),%r10
lea    0xe76(%rip),%rsi
lea    0x1c(%rsp),%rdx
lea    0x18(%rsp),%rcx
lea    0x14(%rsp),%r8
lea    0x10(%rsp),%r9
mov    %rbx,%rdi
push   %rax
push   %r10
call   1040 <sscanf@plt>
add    $0x10,%rsp
test   %eax,%eax
jle    11fd <str2time+0xcd>
mov    $0xfffff894,%eax
add    0x1c(%rsp),%eax
mov    %eax,0x20(%rsp)
mov    0x18(%rsp),%eax
add    $0xffffffff,%eax
mov    %eax,0x24(%rsp)
mov    0x14(%rsp),%eax
mov    %eax,0x28(%rsp)
mov    0x10(%rsp),%eax
mov    %eax,0x2c(%rsp)
mov    0xc(%rsp),%eax
mov    %eax,0x30(%rsp)
mov    0x8(%rsp),%eax
mov    %eax,0x34(%rsp)
movl   $0xffffffff,0x38(%rsp)
ff
lea    0x20(%rsp),%rdi
call   1050 <mktime@plt>
jmp    1202 <str2time+0xd2>
mov    $0xffffffff,%eax
add    $0x40,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32, i32, i32, i32, i32 }
@.str = [18 x i8] c"%u-%u-%u %u:%u:%u\00"
define i32 @str2time(i8* nocapture %0) {
%2 = alloca %struct.tm
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = bitcast %struct.tm* %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 = bitcast i32* %8 to i8*
store i32 0, i32* %8
store i32 0, i32* %7
store i32 0, i32* %6
store i32 0, i32* %5
store i32 0, i32* %4
store i32 0, i32* %3
%16 = call i32 @memset(%struct.tm* %2, i32 0, i32 28)
%17 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32* %3, i32* %4, i32* %5, i32* %6, i32* %7, i32* %8)
%18 = icmp slt i32 %17, 1
br i1 %18, label %36, label %19
19: ; preds = %1
%20 = load i32, i32* %3
%21 = add nsw i32 %20, -1900
%22 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 0
store i32 %21, i32* %22
%23 = load i32, i32* %4
%24 = add nsw i32 %23, -1
%25 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 1
store i32 %24, i32* %25
%26 = load i32, i32* %5
%27 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 2
store i32 %26, i32* %27
%28 = load i32, i32* %6
%29 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 3
store i32 %28, i32* %29
%30 = load i32, i32* %7
%31 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 4
store i32 %30, i32* %31
%32 = load i32, i32* %8
%33 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 5
store i32 %32, i32* %33
%34 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 6
store i32 -1, i32* %34
%35 = call i32 @mktime(%struct.tm* %2)
br label %36
36: ; preds = %1, %19
%37 = phi i32 [ %35, %19 ], [ -1, %1 ]
ret i32 %37
}