#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 {
  void *tm_sec;
  void *tm_min;
  void *tm_hour;
  void *tm_mday;
  void *tm_mon;
  void *tm_year;
};

/* Variables and functions */
void *atoi(char *);
int /*<<< orphan*/ memset(struct tm *, int /*<<< orphan*/, int);
int /*<<< orphan*/ mktime(struct tm *);
int strlen(char *);
time_t str2timet(char *str) {
  int len;
  struct tm tms;
  if (!str)
    return 0;
  len = strlen(str);
  if (len == 0)
    return 0;
  memset(&tms, 0, sizeof(struct tm));
  if ((len >= 19) && ((str[4] == '-') || (str[4] == '/'))) {
    tms.tm_year = atoi(str) - 1900;
    tms.tm_mon = atoi(str + 5) - 1;
    tms.tm_mday = atoi(str + 8);
    tms.tm_hour = atoi(str + 11);
    tms.tm_min = atoi(str + 14);
    tms.tm_sec = atoi(str + 17);
    return mktime(&tms);
  }
  return 0;
}


x86 assembly (clang, -O0):
<str2timet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1163 <str2timet+0x23>
movl   $0x0,-0x4(%rbp)
jmp    1245 <str2timet+0x105>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1185 <str2timet+0x45>
movl   $0x0,-0x4(%rbp)
jmp    1245 <str2timet+0x105>
lea    -0x48(%rbp),%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1040 <memset@plt>
cmpl   $0x13,-0x14(%rbp)
jl     123e <str2timet+0xfe>
mov    -0x10(%rbp),%rax
movsbl 0x4(%rax),%eax
cmp    $0x2d,%eax
je     11c1 <str2timet+0x81>
mov    -0x10(%rbp),%rax
movsbl 0x4(%rax),%eax
cmp    $0x2f,%eax
jne    123e <str2timet+0xfe>
mov    -0x10(%rbp),%rdi
call   1060 <atoi@plt>
add    $0xfffffffffffff894,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x5,%rdi
call   1060 <atoi@plt>
add    $0xffffffffffffffff,%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x8,%rdi
call   1060 <atoi@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
add    $0xb,%rdi
call   1060 <atoi@plt>
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
add    $0xe,%rdi
call   1060 <atoi@plt>
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x11,%rdi
call   1060 <atoi@plt>
mov    %rax,-0x48(%rbp)
lea    -0x48(%rbp),%rdi
call   1050 <mktime@plt>
mov    %eax,-0x4(%rbp)
jmp    1245 <str2timet+0x105>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str2timet>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30,%rsp
xor    %ebp,%ebp
test   %rdi,%rdi
je     11ee <str2timet+0xae>
mov    %rdi,%r14
call   1030 <strlen@plt>
test   %eax,%eax
je     11ee <str2timet+0xae>
mov    %eax,%ebx
mov    %rsp,%rdi
xor    %ebp,%ebp
xor    %esi,%esi
mov    $0x30,%edx
call   1040 <memset@plt>
cmp    $0x13,%ebx
jl     11ee <str2timet+0xae>
mov    0x4(%r14),%al
or     $0x2,%al
cmp    $0x2f,%al
jne    11ee <str2timet+0xae>
mov    %r14,%rdi
call   1060 <atoi@plt>
add    $0xfffffffffffff894,%rax
mov    %rax,0x28(%rsp)
lea    0x5(%r14),%rdi
call   1060 <atoi@plt>
add    $0xffffffffffffffff,%rax
mov    %rax,0x20(%rsp)
lea    0x8(%r14),%rdi
call   1060 <atoi@plt>
mov    %rax,0x18(%rsp)
lea    0xb(%r14),%rdi
call   1060 <atoi@plt>
mov    %rax,0x10(%rsp)
lea    0xe(%r14),%rdi
call   1060 <atoi@plt>
mov    %rax,0x8(%rsp)
add    $0x11,%r14
mov    %r14,%rdi
call   1060 <atoi@plt>
mov    %rax,(%rsp)
mov    %rsp,%rdi
call   1050 <mktime@plt>
mov    %eax,%ebp
mov    %ebp,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i8*, i8*, i8*, i8*, i8*, i8* }
define i32 @str2timet(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.tm
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = icmp ne i8* %6, null
br i1 %7, label %9, label %8
8: ; preds = %1
store i32 0, i32* %2
br label %59
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = call i32 @strlen(i8* %10)
store i32 %11, i32* %4
%12 = load i32, i32* %4
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %9
store i32 0, i32* %2
br label %59
15: ; preds = %9
%16 = call i32 @memset(%struct.tm* %5, i32 0, i32 48)
%17 = load i32, i32* %4
%18 = icmp sge i32 %17, 19
br i1 %18, label %19, label %58
19: ; preds = %15
%20 = load i8*, i8** %3
%21 = getelementptr inbounds i8, i8* %20, i64 4
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 45
br i1 %24, label %31, label %25
25: ; preds = %19
%26 = load i8*, i8** %3
%27 = getelementptr inbounds i8, i8* %26, i64 4
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 47
br i1 %30, label %31, label %58
31: ; preds = %25, %19
%32 = load i8*, i8** %3
%33 = call i8* @atoi(i8* %32)
%34 = getelementptr i8, i8* %33, i64 -1900
%35 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 5
store i8* %34, i8** %35
%36 = load i8*, i8** %3
%37 = getelementptr inbounds i8, i8* %36, i64 5
%38 = call i8* @atoi(i8* %37)
%39 = getelementptr i8, i8* %38, i64 -1
%40 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 4
store i8* %39, i8** %40
%41 = load i8*, i8** %3
%42 = getelementptr inbounds i8, i8* %41, i64 8
%43 = call i8* @atoi(i8* %42)
%44 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 3
store i8* %43, i8** %44
%45 = load i8*, i8** %3
%46 = getelementptr inbounds i8, i8* %45, i64 11
%47 = call i8* @atoi(i8* %46)
%48 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 2
store i8* %47, i8** %48
%49 = load i8*, i8** %3
%50 = getelementptr inbounds i8, i8* %49, i64 14
%51 = call i8* @atoi(i8* %50)
%52 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 1
store i8* %51, i8** %52
%53 = load i8*, i8** %3
%54 = getelementptr inbounds i8, i8* %53, i64 17
%55 = call i8* @atoi(i8* %54)
%56 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 0
store i8* %55, i8** %56
%57 = call i32 @mktime(%struct.tm* %5)
store i32 %57, i32* %2
br label %59
58: ; preds = %25, %15
store i32 0, i32* %2
br label %59
59: ; preds = %58, %31, %14, %8
%60 = load i32, i32* %2
ret i32 %60
}

LLVM IR (-O2):
%struct.tm = type { i8*, i8*, i8*, i8*, i8*, i8* }
define i32 @str2timet(i8* %0) {
%2 = alloca %struct.tm
%3 = bitcast %struct.tm* %2 to i8*
%4 = icmp eq i8* %0, null
br i1 %4, label %35, label %5
5: ; preds = %1
%6 = tail call i32 @strlen(i8* %0)
%7 = icmp eq i32 %6, 0
br i1 %7, label %35, label %8
8: ; preds = %5
%9 = call i32 @memset(%struct.tm* %2, i32 0, i32 48)
%10 = icmp sgt i32 %6, 18
br i1 %10, label %11, label %35
11: ; preds = %8
%12 = getelementptr inbounds i8, i8* %0, i64 4
%13 = load i8, i8* %12
switch i8 %13, label %35 [
i8 45, label %14
i8 47, label %14
]
14: ; preds = %11, %11
%15 = call i8* @atoi(i8* %0)
%16 = getelementptr i8, i8* %15, i64 -1900
%17 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 5
store i8* %16, i8** %17
%18 = getelementptr inbounds i8, i8* %0, i64 5
%19 = call i8* @atoi(i8* %18)
%20 = getelementptr i8, i8* %19, i64 -1
%21 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 4
store i8* %20, i8** %21
%22 = getelementptr inbounds i8, i8* %0, i64 8
%23 = call i8* @atoi(i8* %22)
%24 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 3
store i8* %23, i8** %24
%25 = getelementptr inbounds i8, i8* %0, i64 11
%26 = call i8* @atoi(i8* %25)
%27 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 2
store i8* %26, i8** %27
%28 = getelementptr inbounds i8, i8* %0, i64 14
%29 = call i8* @atoi(i8* %28)
%30 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 1
store i8* %29, i8** %30
%31 = getelementptr inbounds i8, i8* %0, i64 17
%32 = call i8* @atoi(i8* %31)
%33 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 0
store i8* %32, i8** %33
%34 = call i32 @mktime(%struct.tm* %2)
br label %35
35: ; preds = %8, %11, %5, %1, %14
%36 = phi i32 [ %34, %14 ], [ 0, %1 ], [ 0, %5 ], [ 0, %11 ], [ 0, %8 ]
ret i32 %36
}