#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_isdst;
  int tm_hour;
  int tm_gmtoff;
  char *tm_zone;
  int /*<<< orphan*/ tm_sec;
  int /*<<< orphan*/ tm_year;
};

/* Variables and functions */
int /*<<< orphan*/ eprintf(char *, ...);
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ mktime(struct tm *);
size_t strlen(char *);
int /*<<< orphan*/ strptime(char *, char *, struct tm *);
int /*<<< orphan*/ weprintf(char *, char *);
time_t parsetime(char *str, time_t current) {
  struct tm *cur, t;
  int zulu = 0;
  char *format;
  size_t len = strlen(str);
  cur = localtime(&current);
  t.tm_isdst = -1;
  switch (len) {
  case 8:
    t.tm_sec = 0;
    t.tm_year = cur->tm_year;
    format = "%m%d%H%M";
    break;
  case 10:
    t.tm_sec = 0;
    format = "%y%m%d%H%M";
    break;
  case 11:
    t.tm_year = cur->tm_year;
    format = "%m%d%H%M.%S";
    break;
  case 12:
    t.tm_sec = 0;
    format = "%Y%m%d%H%M";
    break;
  case 13:
    format = "%y%m%d%H%M.%S";
    break;
  case 15:
    format = "%Y%m%d%H%M.%S";
    break;
  case 19:
    format = "%Y-%m-%dT%H:%M:%S";
    break;
  case 20:
    if (str[19] != 'Z')
      eprintf("Invalid time zone\n");
    str[19] = 0;
    zulu = 1;
    format = "%Y-%m-%dT%H:%M:%S";
    break;
  default:
    eprintf("Invalid date format length\n", str);
  }
  if (!strptime(str, format, &t))
    weprintf("strptime %s: Invalid date format\n", str);
  if (zulu) {
    t.tm_hour += t.tm_gmtoff / 60;
    t.tm_gmtoff = 0;
    t.tm_zone = "Z";
  }
  return mktime(&t);
}


x86 assembly (clang, -O0):
<parsetime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x50(%rbp)
lea    -0xc(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x18(%rbp)
movl   $0xffffffff,-0x38(%rbp)
mov    -0x50(%rbp),%rax
add    $0xfffffffffffffff8,%rax
mov    %rax,-0x58(%rbp)
sub    $0xc,%rax
ja     1298 <parsetime+0x138>
mov    -0x58(%rbp),%rax
lea    0xe48(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    0x1c(%rax),%eax
mov    %eax,-0x1c(%rbp)
lea    0xe68(%rip),%rax
mov    %rax,-0x48(%rbp)
jmp    12aa <parsetime+0x14a>
movl   $0x0,-0x20(%rbp)
lea    0xe44(%rip),%rax
mov    %rax,-0x48(%rbp)
jmp    12aa <parsetime+0x14a>
mov    -0x18(%rbp),%rax
mov    0x1c(%rax),%eax
mov    %eax,-0x1c(%rbp)
lea    0xe50(%rip),%rax
mov    %rax,-0x48(%rbp)
jmp    12aa <parsetime+0x14a>
movl   $0x0,-0x20(%rbp)
lea    0xe1e(%rip),%rax
mov    %rax,-0x48(%rbp)
jmp    12aa <parsetime+0x14a>
lea    0xe19(%rip),%rax
mov    %rax,-0x48(%rbp)
jmp    12aa <parsetime+0x14a>
lea    0xe17(%rip),%rax
mov    %rax,-0x48(%rbp)
jmp    12aa <parsetime+0x14a>
lea    0xe15(%rip),%rax
mov    %rax,-0x48(%rbp)
jmp    12aa <parsetime+0x14a>
mov    -0x8(%rbp),%rax
movsbl 0x13(%rax),%eax
cmp    $0x5a,%eax
je     1279 <parsetime+0x119>
lea    0xe06(%rip),%rdi
mov    $0x0,%al
call   1070 <eprintf@plt>
mov    -0x8(%rbp),%rax
movb   $0x0,0x13(%rax)
movl   $0x1,-0x3c(%rbp)
lea    0xdd7(%rip),%rax
mov    %rax,-0x48(%rbp)
jmp    12aa <parsetime+0x14a>
mov    -0x8(%rbp),%rsi
lea    0xde8(%rip),%rdi
mov    $0x0,%al
call   1070 <eprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x48(%rbp),%rsi
lea    -0x38(%rbp),%rdx
call   1080 <strptime@plt>
cmp    $0x0,%eax
jne    12d4 <parsetime+0x174>
mov    -0x8(%rbp),%rsi
lea    0xdd8(%rip),%rdi
call   1050 <weprintf@plt>
cmpl   $0x0,-0x3c(%rbp)
je     1301 <parsetime+0x1a1>
mov    -0x30(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
add    -0x34(%rbp),%eax
mov    %eax,-0x34(%rbp)
movl   $0x0,-0x30(%rbp)
lea    0xdcc(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    -0x38(%rbp),%rdi
call   1060 <mktime@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parsetime>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    %rdi,%r14
mov    %esi,0xc(%rsp)
call   1040 <strlen@plt>
mov    %rax,%rbx
lea    0xc(%rsp),%rdi
call   1030 <localtime@plt>
movl   $0xffffffff,0x10(%rsp)
ff
add    $0xfffffffffffffff8,%rbx
cmp    $0xc,%rbx
ja     12a3 <parsetime+0x143>
mov    $0x1,%bpl
lea    0xea9(%rip),%rsi
lea    0xe58(%rip),%rcx
movslq (%rcx,%rbx,4),%rdx
add    %rcx,%rdx
jmp    *%rdx
movl   $0x0,0x28(%rsp)
mov    0x1c(%rax),%eax
mov    %eax,0x2c(%rsp)
lea    0xe7a(%rip),%rsi
jmp    1230 <parsetime+0xd0>
mov    0x1c(%rax),%eax
mov    %eax,0x2c(%rsp)
lea    0xe83(%rip),%rsi
jmp    1230 <parsetime+0xd0>
cmpb   $0x5a,0x13(%r14)
je     11ee <parsetime+0x8e>
lea    0xe91(%rip),%rdi
xor    %eax,%eax
call   1070 <eprintf@plt>
movb   $0x0,0x13(%r14)
lea    0xe6c(%rip),%rsi
xor    %ebp,%ebp
jmp    1230 <parsetime+0xd0>
movl   $0x0,0x28(%rsp)
lea    0xe27(%rip),%rsi
jmp    1230 <parsetime+0xd0>
lea    0xe42(%rip),%rsi
jmp    1230 <parsetime+0xd0>
lea    0xe47(%rip),%rsi
jmp    1230 <parsetime+0xd0>
movl   $0x0,0x28(%rsp)
lea    0xe0f(%rip),%rsi
lea    0x10(%rsp),%rdx
mov    %r14,%rdi
call   1080 <strptime@plt>
test   %eax,%eax
je     128d <parsetime+0x12d>
test   %bpl,%bpl
jne    127a <parsetime+0x11a>
movslq 0x18(%rsp),%rax
imul   $0xffffffff88888889,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%eax
shr    $0x1f,%eax
sar    $0x5,%ecx
add    %eax,%ecx
add    %ecx,0x14(%rsp)
movl   $0x0,0x18(%rsp)
lea    0xe54(%rip),%rax
mov    %rax,0x20(%rsp)
lea    0x10(%rsp),%rdi
call   1060 <mktime@plt>
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe13(%rip),%rdi
mov    %r14,%rsi
call   1050 <weprintf@plt>
test   %bpl,%bpl
je     1246 <parsetime+0xe6>
jmp    127a <parsetime+0x11a>
lea    0xde1(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <eprintf@plt>

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32, i8*, i32, i32 }
@.str = [9 x i8] c"%m%d%H%M\00"
@.str.1 = [11 x i8] c"%y%m%d%H%M\00"
@.str.2 = [12 x i8] c"%m%d%H%M.%S\00"
@.str.3 = [11 x i8] c"%Y%m%d%H%M\00"
@.str.4 = [14 x i8] c"%y%m%d%H%M.%S\00"
@.str.5 = [14 x i8] c"%Y%m%d%H%M.%S\00"
@.str.6 = [18 x i8] c"%Y-%m-%dT%H:%M:%S\00"
@.str.7 = [19 x i8] c"Invalid time zone\0A\00"
@.str.8 = [28 x i8] c"Invalid date format length\0A\00"
@.str.9 = [34 x i8] c"strptime %s: Invalid date format\0A\00"
@.str.10 = [2 x i8] c"Z\00"
define i32 @parsetime(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.tm*
%6 = alloca %struct.tm
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 0, i32* %7
%10 = load i8*, i8** %3
%11 = call i64 @strlen(i8* %10)
store i64 %11, i64* %9
%12 = call %struct.tm* @localtime(i32* %4)
store %struct.tm* %12, %struct.tm** %5
%13 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 0
store i32 -1, i32* %13
%14 = load i64, i64* %9
switch i64 %14, label %44 [
i64 8, label %15
i64 10, label %21
i64 11, label %23
i64 12, label %28
i64 13, label %30
i64 15, label %31
i64 19, label %32
i64 20, label %33
]
15: ; preds = %2
%16 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 4
store i32 0, i32* %16
%17 = load %struct.tm*, %struct.tm** %5
%18 = getelementptr inbounds %struct.tm, %struct.tm* %17, i32 0, i32 5
%19 = load i32, i32* %18
%20 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 5
store i32 %19, i32* %20
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8** %8
br label %47
21: ; preds = %2
%22 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 4
store i32 0, i32* %22
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8** %8
br label %47
23: ; preds = %2
%24 = load %struct.tm*, %struct.tm** %5
%25 = getelementptr inbounds %struct.tm, %struct.tm* %24, i32 0, i32 5
%26 = load i32, i32* %25
%27 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 5
store i32 %26, i32* %27
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8** %8
br label %47
28: ; preds = %2
%29 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 4
store i32 0, i32* %29
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8** %8
br label %47
30: ; preds = %2
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8** %8
br label %47
31: ; preds = %2
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8** %8
br label %47
32: ; preds = %2
store i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i8** %8
br label %47
33: ; preds = %2
%34 = load i8*, i8** %3
%35 = getelementptr inbounds i8, i8* %34, i64 19
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp ne i32 %37, 90
br i1 %38, label %39, label %41
39: ; preds = %33
%40 = call i32 (i8*, ...) @eprintf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0))
br label %41
41: ; preds = %39, %33
%42 = load i8*, i8** %3
%43 = getelementptr inbounds i8, i8* %42, i64 19
store i8 0, i8* %43
store i32 1, i32* %7
store i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i8** %8
br label %47
44: ; preds = %2
%45 = load i8*, i8** %3
%46 = call i32 (i8*, ...) @eprintf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.8, i64 0, i64 0), i8* %45)
br label %47
47: ; preds = %44, %41, %32, %31, %30, %28, %23, %21, %15
%48 = load i8*, i8** %3
%49 = load i8*, i8** %8
%50 = call i32 @strptime(i8* %48, i8* %49, %struct.tm* %6)
%51 = icmp ne i32 %50, 0
br i1 %51, label %55, label %52
52: ; preds = %47
%53 = load i8*, i8** %3
%54 = call i32 @weprintf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.9, i64 0, i64 0), i8* %53)
br label %55
55: ; preds = %52, %47
%56 = load i32, i32* %7
%57 = icmp ne i32 %56, 0
br i1 %57, label %58, label %67
58: ; preds = %55
%59 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 2
%60 = load i32, i32* %59
%61 = sdiv i32 %60, 60
%62 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 1
%63 = load i32, i32* %62
%64 = add nsw i32 %63, %61
store i32 %64, i32* %62
%65 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 2
store i32 0, i32* %65
%66 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 3
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0), i8** %66
br label %67
67: ; preds = %58, %55
%68 = call i32 @mktime(%struct.tm* %6)
ret i32 %68
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32, i8*, i32, i32 }
@.str = [9 x i8] c"%m%d%H%M\00"
@.str.1 = [11 x i8] c"%y%m%d%H%M\00"
@.str.2 = [12 x i8] c"%m%d%H%M.%S\00"
@.str.3 = [11 x i8] c"%Y%m%d%H%M\00"
@.str.4 = [14 x i8] c"%y%m%d%H%M.%S\00"
@.str.5 = [14 x i8] c"%Y%m%d%H%M.%S\00"
@.str.6 = [18 x i8] c"%Y-%m-%dT%H:%M:%S\00"
@.str.7 = [19 x i8] c"Invalid time zone\0A\00"
@.str.8 = [28 x i8] c"Invalid date format length\0A\00"
@.str.9 = [34 x i8] c"strptime %s: Invalid date format\0A\00"
@.str.10 = [2 x i8] c"Z\00"
define i32 @parsetime(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca %struct.tm
store i32 %1, i32* %3
%5 = bitcast %struct.tm* %4 to i8*
%6 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%7 = call %struct.tm* @localtime(i32* %3)
%8 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 0
store i32 -1, i32* %8
switch i64 %6, label %31 [
i64 8, label %9
i64 10, label %14
i64 11, label %16
i64 12, label %20
i64 13, label %33
i64 15, label %22
i64 19, label %23
i64 20, label %24
]
9: ; preds = %2
%10 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 4
store i32 0, i32* %10
%11 = getelementptr inbounds %struct.tm, %struct.tm* %7, i64 0, i32 5
%12 = load i32, i32* %11
%13 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 5
store i32 %12, i32* %13
br label %33
14: ; preds = %2
%15 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 4
store i32 0, i32* %15
br label %33
16: ; preds = %2
%17 = getelementptr inbounds %struct.tm, %struct.tm* %7, i64 0, i32 5
%18 = load i32, i32* %17
%19 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 5
store i32 %18, i32* %19
br label %33
20: ; preds = %2
%21 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 4
store i32 0, i32* %21
br label %33
22: ; preds = %2
br label %33
23: ; preds = %2
br label %33
24: ; preds = %2
%25 = getelementptr inbounds i8, i8* %0, i64 19
%26 = load i8, i8* %25
%27 = icmp eq i8 %26, 90
br i1 %27, label %30, label %28
28: ; preds = %24
%29 = call i32 (i8*, ...) @eprintf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0))
br label %30
30: ; preds = %28, %24
store i8 0, i8* %25
br label %33
31: ; preds = %2
%32 = call i32 (i8*, ...) @eprintf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.8, i64 0, i64 0), i8* %0)
unreachable
33: ; preds = %2, %30, %23, %22, %20, %16, %14, %9
%34 = phi i8* [ getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), %30 ], [ getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), %23 ], [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), %22 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), %20 ], [ getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), %16 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), %14 ], [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), %9 ], [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), %2 ]
%35 = phi i1 [ false, %30 ], [ true, %23 ], [ true, %22 ], [ true, %20 ], [ true, %16 ], [ true, %14 ], [ true, %9 ], [ true, %2 ]
%36 = call i32 @strptime(i8* %0, i8* %34, %struct.tm* %4)
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %33
%39 = call i32 @weprintf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.9, i64 0, i64 0), i8* %0)
br label %40
40: ; preds = %38, %33
br i1 %35, label %49, label %41
41: ; preds = %40
%42 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 2
%43 = load i32, i32* %42
%44 = sdiv i32 %43, 60
%45 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 1
%46 = load i32, i32* %45
%47 = add nsw i32 %46, %44
store i32 %47, i32* %45
store i32 0, i32* %42
%48 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 3
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0), i8** %48
br label %49
49: ; preds = %41, %40
%50 = call i32 @mktime(%struct.tm* %4)
ret i32 %50
}