#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 {
  int tm_isdst;
  int /*<<< orphan*/ tm_sec;
};
struct timeval {
  int /*<<< orphan*/ tv_sec;
  scalar_t__ tv_usec;
};

/* Variables and functions */
int /*<<< orphan*/ errx(int, char *);
scalar_t__ isdigit(unsigned char);
int /*<<< orphan*/ mktime(struct tm *);
char *strchr(char const *, char);
char *strptime(char const *, char const *, struct tm *);
int /*<<< orphan*/ timegm(struct tm *);
void stime_darg(const char *arg, struct timeval *tvp) {
  struct tm t = {.tm_sec = 0};
  const char *fmt, *colon;
  char *p;
  int val, isutc = 0;
  tvp[0].tv_usec = 0;
  t.tm_isdst = -1;
  colon = strchr(arg, ':');
  if (colon == NULL || strchr(colon + 1, ':') == NULL)
    goto bad;
  fmt = strchr(arg, 'T') != NULL ? "%Y-%m-%dT%H:%M:%S" : "%Y-%m-%d %H:%M:%S";
  p = strptime(arg, fmt, &t);
  if (p == NULL)
    goto bad;
  if ((*p == '.' || *p == ',') && isdigit((unsigned char)p[1])) {
    p++;
    val = 100000;
    while (isdigit((unsigned char)*p)) {
      tvp[0].tv_usec += val * (*p - '0');
      p++;
      val /= 10;
    }
  }
  if (*p == 'Z') {
    isutc = 1;
    p++;
  }
  if (*p != '\0')
    goto bad;
  tvp[0].tv_sec = isutc ? timegm(&t) : mktime(&t);
  tvp[1] = tvp[0];
  return;
bad:
  errx(1, "out of range or illegal time specification: "
          "YYYY-MM-DDThh:mm:SS[.frac][tz]");
}


x86 assembly (clang, -O0):
<stime_darg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1060 <memset@plt>
movl   $0x0,-0x38(%rbp)
mov    -0x10(%rbp),%rax
movq   $0x0,0x8(%rax)
movl   $0xffffffff,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11e3 <stime_darg+0x73>
mov    -0x28(%rbp),%rdi
add    $0x1,%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
cmp    $0x0,%rax
jne    11e8 <stime_darg+0x78>
jmp    135f <stime_darg+0x1ef>
mov    -0x8(%rbp),%rdi
mov    $0x54,%esi
call   1050 <strchr@plt>
mov    %rax,%rdx
lea    0xe12(%rip),%rax
lea    0xdf9(%rip),%rcx
cmp    $0x0,%rdx
cmovne %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
lea    -0x18(%rbp),%rdx
call   1090 <strptime@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1238 <stime_darg+0xc8>
jmp    135f <stime_darg+0x1ef>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
je     1258 <stime_darg+0xe8>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2c,%eax
jne    12db <stime_darg+0x16b>
mov    -0x30(%rbp),%rax
movzbl 0x1(%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     12db <stime_darg+0x16b>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
movl   $0x186a0,-0x34(%rbp)
mov    -0x30(%rbp),%rax
movzbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     12d6 <stime_darg+0x166>
mov    -0x34(%rbp),%eax
mov    -0x30(%rbp),%rcx
movsbl (%rcx),%ecx
sub    $0x30,%ecx
imul   %ecx,%eax
movslq %eax,%rcx
mov    -0x10(%rbp),%rax
add    0x8(%rax),%rcx
mov    %rcx,0x8(%rax)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x34(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x34(%rbp)
jmp    1282 <stime_darg+0x112>
jmp    12db <stime_darg+0x16b>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5a,%eax
jne    12fe <stime_darg+0x18e>
movl   $0x1,-0x38(%rbp)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1313 <stime_darg+0x1a3>
jmp    135f <stime_darg+0x1ef>
cmpl   $0x0,-0x38(%rbp)
je     132e <stime_darg+0x1be>
lea    -0x18(%rbp),%rdi
call   1080 <timegm@plt>
mov    %eax,-0x3c(%rbp)
jmp    133a <stime_darg+0x1ca>
lea    -0x18(%rbp),%rdi
call   1070 <mktime@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%rdx
mov    %rdx,0x10(%rax)
mov    0x8(%rcx),%rcx
mov    %rcx,0x18(%rax)
jmp    1370 <stime_darg+0x200>
mov    $0x1,%edi
lea    0xcb9(%rip),%rsi
call   1040 <errx@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stime_darg>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    $0xffffffff,%eax
mov    %rax,0x8(%rsp)
movq   $0x0,0x8(%rsi)
mov    $0x3a,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     126b <stime_darg+0x10b>
add    $0x1,%rax
mov    %rax,%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     126b <stime_darg+0x10b>
mov    %rbx,%rdi
mov    $0x54,%esi
call   1050 <strchr@plt>
test   %rax,%rax
lea    0xe4d(%rip),%rax
lea    0xe34(%rip),%rsi
cmove  %rax,%rsi
lea    0x8(%rsp),%rdx
mov    %rbx,%rdi
call   1080 <strptime@plt>
test   %rax,%rax
je     126b <stime_darg+0x10b>
mov    %rax,%r15
mov    (%rax),%al
mov    %eax,%ecx
or     $0x2,%cl
cmp    $0x2e,%cl
jne    125d <stime_darg+0xfd>
movzbl 0x1(%r15),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     125a <stime_darg+0xfa>
add    $0x1,%r15
movzbl (%r15),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     125a <stime_darg+0xfa>
mov    $0x186a0,%ebx
nopl   0x0(%rax,%rax,1)
movsbq (%r15),%rax
add    $0xffffffffffffffd0,%rax
movslq %ebx,%rcx
imul   %rcx,%rax
add    %rax,0x8(%r14)
imul   $0x66666667,%rcx,%rbx
mov    %rbx,%rax
shr    $0x3f,%rax
sar    $0x22,%rbx
add    %eax,%ebx
movzbl 0x1(%r15),%edi
add    $0x1,%r15
call   1030 <isdigit@plt>
test   %rax,%rax
jne    1220 <stime_darg+0xc0>
mov    (%r15),%al
xor    %ecx,%ecx
cmp    $0x5a,%al
sete   %cl
cmpb   $0x0,(%r15,%rcx,1)
je     1286 <stime_darg+0x126>
lea    0xdb2(%rip),%rsi
mov    $0x1,%edi
call   1040 <errx@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0x8(%rsp),%rdi
cmp    $0x5a,%al
jne    1296 <stime_darg+0x136>
call   1070 <timegm@plt>
jmp    129b <stime_darg+0x13b>
call   1060 <mktime@plt>
mov    %eax,(%r14)
mov    (%r14),%eax
mov    %eax,0x10(%r14)
mov    0x4(%r14),%rax
mov    %rax,0x14(%r14)
mov    0xc(%r14),%eax
mov    %eax,0x1c(%r14)
jmp    127c <stime_darg+0x11c>

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
%struct.tm = type { i32, i32 }
@.str = [18 x i8] c"%Y-%m-%dT%H:%M:%S\00"
@.str.1 = [18 x i8] c"%Y-%m-%d %H:%M:%S\00"
@.str.2 = [75 x i8] c"out of range or illegal time specification: YYYY-MM-DDThh:mm:SS[.frac][tz]\00"
define void @stime_darg(i8* %0, %struct.timeval* %1) {
%3 = alloca i8*
%4 = alloca %struct.timeval*
%5 = alloca %struct.tm
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %3
store %struct.timeval* %1, %struct.timeval** %4
%11 = bitcast %struct.tm* %5 to i8*
store i32 0, i32* %10
%12 = load %struct.timeval*, %struct.timeval** %4
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i64 0
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %13, i32 0, i32 1
store i64 0, i64* %14
%15 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 0
store i32 -1, i32* %15
%16 = load i8*, i8** %3
%17 = call i8* @strchr(i8* %16, i8 signext 58)
store i8* %17, i8** %7
%18 = load i8*, i8** %7
%19 = icmp eq i8* %18, null
br i1 %19, label %25, label %20
20: ; preds = %2
%21 = load i8*, i8** %7
%22 = getelementptr inbounds i8, i8* %21, i64 1
%23 = call i8* @strchr(i8* %22, i8 signext 58)
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %26
25: ; preds = %20, %2
br label %112
26: ; preds = %20
%27 = load i8*, i8** %3
%28 = call i8* @strchr(i8* %27, i8 signext 84)
%29 = icmp ne i8* %28, null
%30 = zext i1 %29 to i64
%31 = select i1 %29, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0)
store i8* %31, i8** %6
%32 = load i8*, i8** %3
%33 = load i8*, i8** %6
%34 = call i8* @strptime(i8* %32, i8* %33, %struct.tm* %5)
store i8* %34, i8** %8
%35 = load i8*, i8** %8
%36 = icmp eq i8* %35, null
br i1 %36, label %37, label %38
37: ; preds = %26
br label %112
38: ; preds = %26
%39 = load i8*, i8** %8
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp eq i32 %41, 46
br i1 %42, label %48, label %43
43: ; preds = %38
%44 = load i8*, i8** %8
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = icmp eq i32 %46, 44
br i1 %47, label %48, label %80
48: ; preds = %43, %38
%49 = load i8*, i8** %8
%50 = getelementptr inbounds i8, i8* %49, i64 1
%51 = load i8, i8* %50
%52 = call i64 @isdigit(i8 zeroext %51)
%53 = icmp ne i64 %52, 0
br i1 %53, label %54, label %80
54: ; preds = %48
%55 = load i8*, i8** %8
%56 = getelementptr inbounds i8, i8* %55, i32 1
store i8* %56, i8** %8
store i32 100000, i32* %9
br label %57
57: ; preds = %62, %54
%58 = load i8*, i8** %8
%59 = load i8, i8* %58
%60 = call i64 @isdigit(i8 zeroext %59)
%61 = icmp ne i64 %60, 0
br i1 %61, label %62, label %79
62: ; preds = %57
%63 = load i32, i32* %9
%64 = load i8*, i8** %8
%65 = load i8, i8* %64
%66 = sext i8 %65 to i32
%67 = sub nsw i32 %66, 48
%68 = mul nsw i32 %63, %67
%69 = sext i32 %68 to i64
%70 = load %struct.timeval*, %struct.timeval** %4
%71 = getelementptr inbounds %struct.timeval, %struct.timeval* %70, i64 0
%72 = getelementptr inbounds %struct.timeval, %struct.timeval* %71, i32 0, i32 1
%73 = load i64, i64* %72
%74 = add nsw i64 %73, %69
store i64 %74, i64* %72
%75 = load i8*, i8** %8
%76 = getelementptr inbounds i8, i8* %75, i32 1
store i8* %76, i8** %8
%77 = load i32, i32* %9
%78 = sdiv i32 %77, 10
store i32 %78, i32* %9
br label %57
79: ; preds = %57
br label %80
80: ; preds = %79, %48, %43
%81 = load i8*, i8** %8
%82 = load i8, i8* %81
%83 = sext i8 %82 to i32
%84 = icmp eq i32 %83, 90
br i1 %84, label %85, label %88
85: ; preds = %80
store i32 1, i32* %10
%86 = load i8*, i8** %8
%87 = getelementptr inbounds i8, i8* %86, i32 1
store i8* %87, i8** %8
br label %88
88: ; preds = %85, %80
%89 = load i8*, i8** %8
%90 = load i8, i8* %89
%91 = sext i8 %90 to i32
%92 = icmp ne i32 %91, 0
br i1 %92, label %93, label %94
93: ; preds = %88
br label %112
94: ; preds = %88
%95 = load i32, i32* %10
%96 = icmp ne i32 %95, 0
br i1 %96, label %97, label %99
97: ; preds = %94
%98 = call i32 @timegm(%struct.tm* %5)
br label %101
99: ; preds = %94
%100 = call i32 @mktime(%struct.tm* %5)
br label %101
101: ; preds = %99, %97
%102 = phi i32 [ %98, %97 ], [ %100, %99 ]
%103 = load %struct.timeval*, %struct.timeval** %4
%104 = getelementptr inbounds %struct.timeval, %struct.timeval* %103, i64 0
%105 = getelementptr inbounds %struct.timeval, %struct.timeval* %104, i32 0, i32 0
store i32 %102, i32* %105
%106 = load %struct.timeval*, %struct.timeval** %4
%107 = getelementptr inbounds %struct.timeval, %struct.timeval* %106, i64 1
%108 = load %struct.timeval*, %struct.timeval** %4
%109 = getelementptr inbounds %struct.timeval, %struct.timeval* %108, i64 0
%110 = bitcast %struct.timeval* %107 to i8*
%111 = bitcast %struct.timeval* %109 to i8*
br label %114
112: ; preds = %93, %37, %25
%113 = call i32 @errx(i32 1, i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.2, i64 0, i64 0))
br label %114
114: ; preds = %112, %101
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
%struct.tm = type { i32, i32 }
@.str = [18 x i8] c"%Y-%m-%dT%H:%M:%S\00"
@.str.1 = [18 x i8] c"%Y-%m-%d %H:%M:%S\00"
@.str.2 = [75 x i8] c"out of range or illegal time specification: YYYY-MM-DDThh:mm:SS[.frac][tz]\00"
define void @stime_darg(i8* %0, %struct.timeval* nocapture %1) {
%3 = alloca i64
%4 = bitcast i64* %3 to %struct.tm*
%5 = bitcast i64* %3 to i8*
store i64 4294967295, i64* %3
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
store i64 0, i64* %6
%7 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 58)
%8 = icmp eq i8* %7, null
br i1 %8, label %67, label %9
9: ; preds = %2
%10 = getelementptr inbounds i8, i8* %7, i64 1
%11 = tail call i8* @strchr(i8* %10, i8 signext 58)
%12 = icmp eq i8* %11, null
br i1 %12, label %67, label %13
13: ; preds = %9
%14 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 84)
%15 = icmp eq i8* %14, null
%16 = select i1 %15, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0)
%17 = call i8* @strptime(i8* %0, i8* %16, %struct.tm* %4)
%18 = icmp eq i8* %17, null
br i1 %18, label %67, label %19
19: ; preds = %13
%20 = load i8, i8* %17
switch i8 %20, label %48 [
i8 46, label %21
i8 44, label %21
]
21: ; preds = %19, %19
%22 = getelementptr inbounds i8, i8* %17, i64 1
%23 = load i8, i8* %22
%24 = call i64 @isdigit(i8 zeroext %23)
%25 = icmp eq i64 %24, 0
br i1 %25, label %45, label %26
26: ; preds = %21
%27 = load i8, i8* %22
%28 = call i64 @isdigit(i8 zeroext %27)
%29 = icmp eq i64 %28, 0
br i1 %29, label %45, label %30
30: ; preds = %26, %30
%31 = phi i8* [ %41, %30 ], [ %22, %26 ]
%32 = phi i32 [ %40, %30 ], [ 100000, %26 ]
%33 = load i8, i8* %31
%34 = sext i8 %33 to i32
%35 = add nsw i32 %34, -48
%36 = mul nsw i32 %35, %32
%37 = sext i32 %36 to i64
%38 = load i64, i64* %6
%39 = add nsw i64 %38, %37
store i64 %39, i64* %6
%40 = sdiv i32 %32, 10
%41 = getelementptr inbounds i8, i8* %31, i64 1
%42 = load i8, i8* %41
%43 = call i64 @isdigit(i8 zeroext %42)
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %30
45: ; preds = %30, %26, %21
%46 = phi i8* [ %17, %21 ], [ %22, %26 ], [ %41, %30 ]
%47 = load i8, i8* %46
br label %48
48: ; preds = %45, %19
%49 = phi i8 [ %47, %45 ], [ %20, %19 ]
%50 = phi i8* [ %46, %45 ], [ %17, %19 ]
%51 = icmp eq i8 %49, 90
%52 = zext i1 %51 to i64
%53 = getelementptr i8, i8* %50, i64 %52
%54 = load i8, i8* %53
%55 = icmp eq i8 %54, 0
br i1 %55, label %56, label %67
56: ; preds = %48
br i1 %51, label %57, label %59
57: ; preds = %56
%58 = call i32 @timegm(%struct.tm* %4)
br label %61
59: ; preds = %56
%60 = call i32 @mktime(%struct.tm* %4)
br label %61
61: ; preds = %59, %57
%62 = phi i32 [ %58, %57 ], [ %60, %59 ]
%63 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
store i32 %62, i32* %63
%64 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 1
%65 = bitcast %struct.timeval* %64 to i8*
%66 = bitcast %struct.timeval* %1 to i8*
br label %69
67: ; preds = %48, %13, %2, %9
%68 = call i32 @errx(i32 1, i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.2, i64 0, i64 0))
br label %69
69: ; preds = %67, %61
ret void
}