#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 */
struct tm {
  long long tm_sec;
  long long tm_min;
  long long tm_hour;
  long long tm_mday;
  long long tm_mon;
  long long tm_year;
  scalar_t__ tm_isdst;
};

/* Variables and functions */
long long mktime(struct tm *);
long long usertime2ts(long long usertime) {
  long long msec;
  struct tm tm;
  long long ts;
  if (usertime < 0) {
    return -1LL;
  }
  msec = usertime % 1000;
  usertime /= 1000;
  tm.tm_sec = usertime % 100;
  if (!(tm.tm_sec < 60))
    return -1LL;
  usertime /= 100;
  tm.tm_min = usertime % 100;
  if (!(tm.tm_min < 60))
    return -1LL;
  usertime /= 100;
  tm.tm_hour = usertime % 100;
  if (!(tm.tm_hour < 24))
    return -1LL;
  usertime /= 100;
  tm.tm_mday = usertime % 100;
  if (!(tm.tm_mday > 0 && tm.tm_mday < 32))
    return -1LL;
  usertime /= 100;
  tm.tm_mon = usertime % 100 - 1;
  if (!(tm.tm_mon >= 0 && tm.tm_mon < 12))
    return -1LL;
  usertime /= 100;
  tm.tm_year = usertime - 1900;
  tm.tm_isdst = 0;
  ts = mktime(&tm);
  if (ts == -1) {
    return -1LL;
  }
  ts = ts * 1000LL + msec;
  return ts;
}


x86 assembly (clang, -O0):
<usertime2ts>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jge    1134 <usertime2ts+0x24>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    12f1 <usertime2ts+0x1e1>
mov    -0x10(%rbp),%rax
mov    $0x3e8,%ecx
cqto
idiv   %rcx
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    $0x3e8,%ecx
cqto
idiv   %rcx
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    $0x64,%ecx
cqto
idiv   %rcx
mov    %rdx,-0x50(%rbp)
cmpq   $0x3c,-0x50(%rbp)
jl     1182 <usertime2ts+0x72>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    12f1 <usertime2ts+0x1e1>
mov    -0x10(%rbp),%rax
mov    $0x64,%ecx
cqto
idiv   %rcx
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    $0x64,%ecx
cqto
idiv   %rcx
mov    %rdx,-0x48(%rbp)
cmpq   $0x3c,-0x48(%rbp)
jl     11be <usertime2ts+0xae>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    12f1 <usertime2ts+0x1e1>
mov    -0x10(%rbp),%rax
mov    $0x64,%ecx
cqto
idiv   %rcx
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    $0x64,%ecx
cqto
idiv   %rcx
mov    %rdx,-0x40(%rbp)
cmpq   $0x18,-0x40(%rbp)
jl     11fa <usertime2ts+0xea>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    12f1 <usertime2ts+0x1e1>
mov    -0x10(%rbp),%rax
mov    $0x64,%ecx
cqto
idiv   %rcx
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    $0x64,%ecx
cqto
idiv   %rcx
mov    %rdx,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jle    1234 <usertime2ts+0x124>
cmpq   $0x20,-0x38(%rbp)
jl     1241 <usertime2ts+0x131>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    12f1 <usertime2ts+0x1e1>
mov    -0x10(%rbp),%rax
mov    $0x64,%ecx
cqto
idiv   %rcx
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    $0x64,%ecx
cqto
idiv   %rcx
sub    $0x1,%rdx
mov    %rdx,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jl     127f <usertime2ts+0x16f>
cmpq   $0xc,-0x30(%rbp)
jl     128c <usertime2ts+0x17c>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    12f1 <usertime2ts+0x1e1>
mov    -0x10(%rbp),%rax
mov    $0x64,%ecx
cqto
idiv   %rcx
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
sub    $0x76c,%rax
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x20(%rbp)
lea    -0x50(%rbp),%rdi
call   1030 <mktime@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0xffffffffffffffff,-0x58(%rbp)
jne    12d9 <usertime2ts+0x1c9>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    12f1 <usertime2ts+0x1e1>
imul   $0x3e8,-0x58(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<usertime2ts>:
push   %r15
push   %r14
push   %rbx
sub    $0x40,%rsp
mov    $0xffffffffffffffff,%r14
test   %rdi,%rdi
js     12b5 <usertime2ts+0x1a5>
mov    %rdi,%rbx
mov    %rdi,%rax
shr    $0x3,%rax
movabs $0x20c49ba5e353f7cf,%rcx
9b c4 20
mul    %rcx
mov    %rdx,%rax
mov    %rdx,%r15
shr    $0x4,%r15
shr    $0x6,%rax
movabs $0x28f5c28f5c28f5c3,%rcx
c2 f5 28
mul    %rcx
shr    $0x2,%rdx
imul   $0x64,%rdx,%rax
mov    %r15,%rdx
sub    %rax,%rdx
mov    %rdx,0x8(%rsp)
cmp    $0x3b,%rdx
ja     12b5 <usertime2ts+0x1a5>
mov    %rbx,%rax
shr    $0x5,%rax
movabs $0xa7c5ac471b47843,%rdx
5a 7c 0a
mul    %rdx
mov    %rdx,%rax
mov    %rdx,%rsi
shr    $0x7,%rsi
shr    $0x9,%rax
mul    %rcx
shr    $0x2,%rdx
imul   $0x64,%rdx,%rax
sub    %rax,%rsi
mov    %rsi,0x10(%rsp)
cmp    $0x3b,%rsi
ja     12b5 <usertime2ts+0x1a5>
movabs $0xd6bf94d5e57a42bd,%rdx
94 bf d6
mov    %rbx,%rax
mul    %rdx
mov    %rdx,%rax
mov    %rdx,%rsi
shr    $0x17,%rsi
shr    $0x19,%rax
mul    %rcx
shr    $0x2,%rdx
imul   $0x64,%rdx,%rax
sub    %rax,%rsi
mov    %rsi,0x18(%rsp)
cmp    $0x17,%rsi
ja     12b5 <usertime2ts+0x1a5>
mov    %rbx,%rax
shr    $0x9,%rax
movabs $0x44b82fa09b5a53,%rdx
mul    %rdx
mov    %rdx,%rax
mov    %rdx,%rsi
shr    $0xb,%rsi
shr    $0xd,%rax
mul    %rcx
shr    $0x2,%rdx
imul   $0x64,%rdx,%rax
sub    %rax,%rsi
mov    %rsi,0x20(%rsp)
add    $0xffffffffffffffff,%rsi
cmp    $0x1e,%rsi
ja     12b5 <usertime2ts+0x1a5>
movabs $0xafebff0bcb24aaff,%rcx
ff eb af
mov    %rbx,%rax
mul    %rcx
shr    $0x24,%rdx
imul   $0x51eb851f,%rdx,%rax
shr    $0x25,%rax
imul   $0x64,%eax,%eax
sub    %eax,%edx
add    $0xffffffffffffffff,%rdx
mov    %rdx,0x28(%rsp)
cmp    $0xb,%rdx
ja     12b5 <usertime2ts+0x1a5>
movabs $0x384b84d092ed0385,%rcx
84 4b 38
mov    %rbx,%rax
mul    %rcx
shr    $0x29,%rdx
add    $0xfffffffffffff894,%rdx
mov    %rdx,0x30(%rsp)
movq   $0x0,0x38(%rsp)
lea    0x8(%rsp),%rdi
call   1030 <mktime@plt>
cmp    $0xffffffffffffffff,%rax
je     12b5 <usertime2ts+0x1a5>
imul   $0x3e8,%r15,%rcx
sub    %rcx,%rbx
imul   $0x3e8,%rax,%r14
add    %rbx,%r14
mov    %r14,%rax
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.tm = type { i64, i64, i64, i64, i64, i64, i64 }
define i64 @usertime2ts(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca %struct.tm
%6 = alloca i64
store i64 %0, i64* %3
%7 = load i64, i64* %3
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %1
store i64 -1, i64* %2
br label %88
10: ; preds = %1
%11 = load i64, i64* %3
%12 = srem i64 %11, 1000
store i64 %12, i64* %4
%13 = load i64, i64* %3
%14 = sdiv i64 %13, 1000
store i64 %14, i64* %3
%15 = load i64, i64* %3
%16 = srem i64 %15, 100
%17 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 0
store i64 %16, i64* %17
%18 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 0
%19 = load i64, i64* %18
%20 = icmp slt i64 %19, 60
br i1 %20, label %22, label %21
21: ; preds = %10
store i64 -1, i64* %2
br label %88
22: ; preds = %10
%23 = load i64, i64* %3
%24 = sdiv i64 %23, 100
store i64 %24, i64* %3
%25 = load i64, i64* %3
%26 = srem i64 %25, 100
%27 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 1
store i64 %26, i64* %27
%28 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 1
%29 = load i64, i64* %28
%30 = icmp slt i64 %29, 60
br i1 %30, label %32, label %31
31: ; preds = %22
store i64 -1, i64* %2
br label %88
32: ; preds = %22
%33 = load i64, i64* %3
%34 = sdiv i64 %33, 100
store i64 %34, i64* %3
%35 = load i64, i64* %3
%36 = srem i64 %35, 100
%37 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 2
store i64 %36, i64* %37
%38 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 2
%39 = load i64, i64* %38
%40 = icmp slt i64 %39, 24
br i1 %40, label %42, label %41
41: ; preds = %32
store i64 -1, i64* %2
br label %88
42: ; preds = %32
%43 = load i64, i64* %3
%44 = sdiv i64 %43, 100
store i64 %44, i64* %3
%45 = load i64, i64* %3
%46 = srem i64 %45, 100
%47 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 3
store i64 %46, i64* %47
%48 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 3
%49 = load i64, i64* %48
%50 = icmp sgt i64 %49, 0
br i1 %50, label %51, label %55
51: ; preds = %42
%52 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 3
%53 = load i64, i64* %52
%54 = icmp slt i64 %53, 32
br i1 %54, label %56, label %55
55: ; preds = %51, %42
store i64 -1, i64* %2
br label %88
56: ; preds = %51
%57 = load i64, i64* %3
%58 = sdiv i64 %57, 100
store i64 %58, i64* %3
%59 = load i64, i64* %3
%60 = srem i64 %59, 100
%61 = sub nsw i64 %60, 1
%62 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 4
store i64 %61, i64* %62
%63 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 4
%64 = load i64, i64* %63
%65 = icmp sge i64 %64, 0
br i1 %65, label %66, label %70
66: ; preds = %56
%67 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 4
%68 = load i64, i64* %67
%69 = icmp slt i64 %68, 12
br i1 %69, label %71, label %70
70: ; preds = %66, %56
store i64 -1, i64* %2
br label %88
71: ; preds = %66
%72 = load i64, i64* %3
%73 = sdiv i64 %72, 100
store i64 %73, i64* %3
%74 = load i64, i64* %3
%75 = sub nsw i64 %74, 1900
%76 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 5
store i64 %75, i64* %76
%77 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 6
store i64 0, i64* %77
%78 = call i64 @mktime(%struct.tm* %5)
store i64 %78, i64* %6
%79 = load i64, i64* %6
%80 = icmp eq i64 %79, -1
br i1 %80, label %81, label %82
81: ; preds = %71
store i64 -1, i64* %2
br label %88
82: ; preds = %71
%83 = load i64, i64* %6
%84 = mul nsw i64 %83, 1000
%85 = load i64, i64* %4
%86 = add nsw i64 %84, %85
store i64 %86, i64* %6
%87 = load i64, i64* %6
store i64 %87, i64* %2
br label %88
88: ; preds = %82, %81, %70, %55, %41, %31, %21, %9
%89 = load i64, i64* %2
ret i64 %89
}

LLVM IR (-O2):
%struct.tm = type { i64, i64, i64, i64, i64, i64, i64 }
define i64 @usertime2ts(i64 %0) {
%2 = alloca %struct.tm
%3 = bitcast %struct.tm* %2 to i8*
%4 = icmp slt i64 %0, 0
br i1 %4, label %45, label %5
5: ; preds = %1
%6 = urem i64 %0, 1000
%7 = udiv i64 %0, 1000
%8 = urem i64 %7, 100
%9 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 0
store i64 %8, i64* %9
%10 = icmp ult i64 %8, 60
br i1 %10, label %11, label %45
11: ; preds = %5
%12 = udiv i64 %0, 100000
%13 = urem i64 %12, 100
%14 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 1
store i64 %13, i64* %14
%15 = icmp ult i64 %13, 60
br i1 %15, label %16, label %45
16: ; preds = %11
%17 = udiv i64 %0, 10000000
%18 = urem i64 %17, 100
%19 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 2
store i64 %18, i64* %19
%20 = icmp ult i64 %18, 24
br i1 %20, label %21, label %45
21: ; preds = %16
%22 = udiv i64 %0, 1000000000
%23 = urem i64 %22, 100
%24 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 3
store i64 %23, i64* %24
%25 = add nsw i64 %23, -1
%26 = icmp ult i64 %25, 31
br i1 %26, label %27, label %45
27: ; preds = %21
%28 = udiv i64 %0, 100000000000
%29 = trunc i64 %28 to i32
%30 = urem i32 %29, 100
%31 = zext i32 %30 to i64
%32 = add nsw i64 %31, -1
%33 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 4
store i64 %32, i64* %33
%34 = icmp ult i64 %32, 12
br i1 %34, label %35, label %45
35: ; preds = %27
%36 = udiv i64 %0, 10000000000000
%37 = add nsw i64 %36, -1900
%38 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 5
store i64 %37, i64* %38
%39 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 6
store i64 0, i64* %39
%40 = call i64 @mktime(%struct.tm* %2)
%41 = icmp eq i64 %40, -1
br i1 %41, label %45, label %42
42: ; preds = %35
%43 = mul nsw i64 %40, 1000
%44 = add nsw i64 %43, %6
br label %45
45: ; preds = %35, %27, %21, %16, %11, %5, %1, %42
%46 = phi i64 [ %44, %42 ], [ -1, %1 ], [ -1, %5 ], [ -1, %11 ], [ -1, %16 ], [ -1, %21 ], [ -1, %27 ], [ -1, %35 ]
ret i64 %46
}