#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 time_t;

/* Variables and functions */
int /*<<< orphan*/ is_fatal(int, char *, char const *);
int sscanf(char const *, char *, int *, char *, int *, char *, int *, double *);
int unicsv_parse_date(char const *, int *);
time_t unicsv_parse_time(const char *str, int *msec, time_t *date) {
  int hour, min, ct, sec;
  int consumed = 0;
  double ms;
  char sep[2];
  time_t ldate;
  ldate = unicsv_parse_date(str, &consumed);
  if (consumed && ldate) {
    str += consumed;
    if (date) {
      *date = ldate;
    }
  }
  ct = sscanf(str, "%d%1[.://]%d%1[.://]%d%lf", &hour, sep, &min, sep, &sec,
              &ms);
  is_fatal(ct < 5,
           "unicsv"
           ": Could not parse time string (%s).\n",
           str);
  if (ct == 6) {
    *msec = (ms * 1000000) + 0.5;
    if (*msec > 999999) {
      *msec = 0;
      sec++;
    }
  } else
    *msec = 0;
  return ((hour * (60L * 60)) + (min * 60) + (int)sec);
}


x86 assembly (clang, -O0):
<unicsv_parse_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x2c(%rbp),%rsi
call   1040 <unicsv_parse_date@plt>
mov    %eax,-0x40(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     1199 <unicsv_parse_time+0x69>
cmpl   $0x0,-0x40(%rbp)
je     1199 <unicsv_parse_time+0x69>
mov    -0x2c(%rbp),%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1194 <unicsv_parse_time+0x64>
mov    -0x40(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
jmp    1199 <unicsv_parse_time+0x69>
mov    -0x8(%rbp),%rdi
lea    -0x3a(%rbp),%rcx
lea    -0x3a(%rbp),%r9
lea    0xe64(%rip),%rsi
lea    -0x1c(%rbp),%rdx
lea    -0x20(%rbp),%r8
lea    -0x28(%rbp),%r10
lea    -0x38(%rbp),%rax
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1050 <sscanf@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x5,-0x24(%rbp)
setl   %al
and    $0x1,%al
movzbl %al,%edi
mov    -0x8(%rbp),%rdx
lea    0xe46(%rip),%rsi
call   1030 <is_fatal@plt>
cmpl   $0x6,-0x24(%rbp)
jne    1242 <unicsv_parse_time+0x112>
movsd  -0x38(%rbp),%xmm0
movsd  0xe00(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xdfc(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
cmpl   $0xf423f,(%rax)
jle    123d <unicsv_parse_time+0x10d>
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    124c <unicsv_parse_time+0x11c>
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
movslq -0x1c(%rbp),%rax
imul   $0xe10,%rax,%rax
imul   $0x3c,-0x20(%rbp),%ecx
movslq %ecx,%rcx
add    %rcx,%rax
movslq -0x28(%rbp),%rcx
add    %rcx,%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unicsv_parse_time>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
movl   $0x0,0xc(%rsp)
lea    0xc(%rsp),%rsi
call   1040 <unicsv_parse_date@plt>
movslq 0xc(%rsp),%rcx
test   %rcx,%rcx
je     116e <unicsv_parse_time+0x3e>
test   %eax,%eax
je     116e <unicsv_parse_time+0x3e>
add    %rcx,%rbx
test   %r15,%r15
je     116e <unicsv_parse_time+0x3e>
mov    %eax,(%r15)
lea    0x20(%rsp),%rax
lea    0x10(%rsp),%rbp
lea    0xe91(%rip),%rsi
lea    0x18(%rsp),%rdx
lea    0x14(%rsp),%r8
lea    0x1e(%rsp),%rcx
mov    %rbx,%rdi
mov    %rcx,%r9
push   %rax
push   %rbp
call   1050 <sscanf@plt>
add    $0x10,%rsp
mov    %eax,%ebp
xor    %edi,%edi
cmp    $0x5,%eax
setl   %dil
lea    0xe79(%rip),%rsi
mov    %rbx,%rdx
call   1030 <is_fatal@plt>
cmp    $0x6,%ebp
jne    11f0 <unicsv_parse_time+0xc0>
movsd  0x20(%rsp),%xmm0
mulsd  0xe34(%rip),%xmm0
addsd  0xe34(%rip),%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,(%r14)
cmp    $0xf4240,%eax
jl     11f7 <unicsv_parse_time+0xc7>
movl   $0x0,(%r14)
addl   $0x1,0x10(%rsp)
jmp    11f7 <unicsv_parse_time+0xc7>
movl   $0x0,(%r14)
imul   $0xe10,0x18(%rsp),%ecx
imul   $0x3c,0x14(%rsp),%eax
add    %ecx,%eax
add    0x10(%rsp),%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"%d%1[.://]%d%1[.://]%d%lf\00"
@.str.1 = [43 x i8] c"unicsv: Could not parse time string (%s).\0A\00"
define i32 @unicsv_parse_time(i8* %0, i32* %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca double
%13 = alloca [2 x i8]
%14 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32* %2, i32** %6
store i32 0, i32* %11
%15 = load i8*, i8** %4
%16 = call i32 @unicsv_parse_date(i8* %15, i32* %11)
store i32 %16, i32* %14
%17 = load i32, i32* %11
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %33
19: ; preds = %3
%20 = load i32, i32* %14
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %33
22: ; preds = %19
%23 = load i32, i32* %11
%24 = load i8*, i8** %4
%25 = sext i32 %23 to i64
%26 = getelementptr inbounds i8, i8* %24, i64 %25
store i8* %26, i8** %4
%27 = load i32*, i32** %6
%28 = icmp ne i32* %27, null
br i1 %28, label %29, label %32
29: ; preds = %22
%30 = load i32, i32* %14
%31 = load i32*, i32** %6
store i32 %30, i32* %31
br label %32
32: ; preds = %29, %22
br label %33
33: ; preds = %32, %19, %3
%34 = load i8*, i8** %4
%35 = getelementptr inbounds [2 x i8], [2 x i8]* %13, i64 0, i64 0
%36 = getelementptr inbounds [2 x i8], [2 x i8]* %13, i64 0, i64 0
%37 = call i32 @sscanf(i8* %34, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32* %7, i8* %35, i32* %8, i8* %36, i32* %10, double* %12)
store i32 %37, i32* %9
%38 = load i32, i32* %9
%39 = icmp slt i32 %38, 5
%40 = zext i1 %39 to i32
%41 = load i8*, i8** %4
%42 = call i32 @is_fatal(i32 %40, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i8* %41)
%43 = load i32, i32* %9
%44 = icmp eq i32 %43, 6
br i1 %44, label %45, label %58
45: ; preds = %33
%46 = load double, double* %12
%47 = call double @llvm.fmuladd.f64(double %46, double 1.000000e+06, double 5.000000e-01)
%48 = fptosi double %47 to i32
%49 = load i32*, i32** %5
store i32 %48, i32* %49
%50 = load i32*, i32** %5
%51 = load i32, i32* %50
%52 = icmp sgt i32 %51, 999999
br i1 %52, label %53, label %57
53: ; preds = %45
%54 = load i32*, i32** %5
store i32 0, i32* %54
%55 = load i32, i32* %10
%56 = add nsw i32 %55, 1
store i32 %56, i32* %10
br label %57
57: ; preds = %53, %45
br label %60
58: ; preds = %33
%59 = load i32*, i32** %5
store i32 0, i32* %59
br label %60
60: ; preds = %58, %57
%61 = load i32, i32* %7
%62 = sext i32 %61 to i64
%63 = mul nsw i64 %62, 3600
%64 = load i32, i32* %8
%65 = mul nsw i32 %64, 60
%66 = sext i32 %65 to i64
%67 = add nsw i64 %63, %66
%68 = load i32, i32* %10
%69 = sext i32 %68 to i64
%70 = add nsw i64 %67, %69
%71 = trunc i64 %70 to i32
ret i32 %71
}

LLVM IR (-O2):
@.str = [26 x i8] c"%d%1[.://]%d%1[.://]%d%lf\00"
@.str.1 = [43 x i8] c"unicsv: Could not parse time string (%s).\0A\00"
define i32 @unicsv_parse_time(i8* %0, i32* nocapture writeonly %1, i32* writeonly %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca double
%9 = alloca [2 x i8]
%10 = bitcast i32* %4 to i8*
%11 = bitcast i32* %5 to i8*
%12 = bitcast i32* %6 to i8*
%13 = bitcast i32* %7 to i8*
store i32 0, i32* %7
%14 = bitcast double* %8 to i8*
%15 = getelementptr inbounds [2 x i8], [2 x i8]* %9, i64 0, i64 0
%16 = call i32 @unicsv_parse_date(i8* %0, i32* %7)
%17 = load i32, i32* %7
%18 = icmp ne i32 %17, 0
%19 = icmp ne i32 %16, 0
%20 = select i1 %18, i1 %19, i1 false
br i1 %20, label %21, label %26
21: ; preds = %3
%22 = sext i32 %17 to i64
%23 = getelementptr inbounds i8, i8* %0, i64 %22
%24 = icmp eq i32* %2, null
br i1 %24, label %26, label %25
25: ; preds = %21
store i32 %16, i32* %2
br label %26
26: ; preds = %21, %25, %3
%27 = phi i8* [ %23, %25 ], [ %23, %21 ], [ %0, %3 ]
%28 = call i32 @sscanf(i8* %27, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32* %4, i8* %15, i32* %5, i8* %15, i32* %6, double* %8)
%29 = icmp slt i32 %28, 5
%30 = zext i1 %29 to i32
%31 = call i32 @is_fatal(i32 %30, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i8* %27)
%32 = icmp eq i32 %28, 6
br i1 %32, label %33, label %41
33: ; preds = %26
%34 = load double, double* %8
%35 = call double @llvm.fmuladd.f64(double %34, double 1.000000e+06, double 5.000000e-01)
%36 = fptosi double %35 to i32
store i32 %36, i32* %1
%37 = icmp sgt i32 %36, 999999
br i1 %37, label %38, label %42
38: ; preds = %33
store i32 0, i32* %1
%39 = load i32, i32* %6
%40 = add nsw i32 %39, 1
store i32 %40, i32* %6
br label %42
41: ; preds = %26
store i32 0, i32* %1
br label %42
42: ; preds = %33, %38, %41
%43 = load i32, i32* %4
%44 = mul i32 %43, 3600
%45 = load i32, i32* %5
%46 = mul nsw i32 %45, 60
%47 = add i32 %46, %44
%48 = load i32, i32* %6
%49 = add i32 %47, %48
ret i32 %49
}