#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 scalar_t__ ssize_t;
typedef int int64_t;

/* Variables and functions */
int parseDouble(char const *, double *);
char *strstr(char const *, char *);
int64_t parseMetaDataDurationUs(const char *line) {
  const char *match = strstr(line, ":");
  if (match == NULL) {
    return -1;
  }
  ssize_t colonPos = match - line;
  if (colonPos < 0) {
    return -1;
  }
  double x;
  int err = parseDouble(line + colonPos + 1, &x);
  if (err != 0) {
    return err;
  }
  return ((int64_t)(x * 1E6));
}


x86 assembly (clang, -O0):
<parseMetaDataDurationUs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xed1(%rip),%rsi
call   1040 <strstr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1157 <parseMetaDataDurationUs+0x37>
movl   $0xffffffff,-0x4(%rbp)
jmp    11be <parseMetaDataDurationUs+0x9e>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jge    117d <parseMetaDataDurationUs+0x5d>
movl   $0xffffffff,-0x4(%rbp)
jmp    11be <parseMetaDataDurationUs+0x9e>
mov    -0x10(%rbp),%rdi
add    -0x20(%rbp),%rdi
add    $0x1,%rdi
lea    -0x28(%rbp),%rsi
call   1030 <parseDouble@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     11aa <parseMetaDataDurationUs+0x8a>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11be <parseMetaDataDurationUs+0x9e>
movsd  0xe4e(%rip),%xmm0
mulsd  -0x28(%rbp),%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parseMetaDataDurationUs>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    $0x3a,%esi
call   1040 <strchr@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
je     116f <parseMetaDataDurationUs+0x4f>
sub    %rbx,%rcx
js     116f <parseMetaDataDurationUs+0x4f>
lea    (%rbx,%rcx,1),%rdi
add    $0x1,%rdi
lea    0x8(%rsp),%rsi
call   1030 <parseDouble@plt>
mov    %eax,%ecx
test   %eax,%eax
movsd  0x8(%rsp),%xmm0
mulsd  0xe98(%rip),%xmm0
cvttsd2si %xmm0,%eax
cmovne %ecx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [2 x i8] c":\00"
define i32 @parseMetaDataDurationUs(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca double
%7 = alloca i32
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = call i8* @strstr(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %9, i8** %4
%10 = load i8*, i8** %4
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %13
12: ; preds = %1
store i32 -1, i32* %2
br label %36
13: ; preds = %1
%14 = load i8*, i8** %4
%15 = load i8*, i8** %3
%16 = ptrtoint i8* %14 to i64
%17 = ptrtoint i8* %15 to i64
%18 = sub i64 %16, %17
store i64 %18, i64* %5
%19 = load i64, i64* %5
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %13
store i32 -1, i32* %2
br label %36
22: ; preds = %13
%23 = load i8*, i8** %3
%24 = load i64, i64* %5
%25 = getelementptr inbounds i8, i8* %23, i64 %24
%26 = getelementptr inbounds i8, i8* %25, i64 1
%27 = call i32 @parseDouble(i8* %26, double* %6)
store i32 %27, i32* %7
%28 = load i32, i32* %7
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %22
%31 = load i32, i32* %7
store i32 %31, i32* %2
br label %36
32: ; preds = %22
%33 = load double, double* %6
%34 = fmul double %33, 1.000000e+06
%35 = fptosi double %34 to i32
store i32 %35, i32* %2
br label %36
36: ; preds = %32, %30, %21, %12
%37 = load i32, i32* %2
ret i32 %37
}

LLVM IR (-O2):
define i32 @parseMetaDataDurationUs(i8* %0) {
%2 = alloca double
%3 = tail call i8* @strchr(i8* dereferenceable(1) %0, i32 58)
%4 = icmp eq i8* %3, null
br i1 %4, label %20, label %5
5: ; preds = %1
%6 = ptrtoint i8* %3 to i64
%7 = ptrtoint i8* %0 to i64
%8 = sub i64 %6, %7
%9 = icmp slt i64 %8, 0
br i1 %9, label %20, label %10
10: ; preds = %5
%11 = bitcast double* %2 to i8*
%12 = getelementptr inbounds i8, i8* %0, i64 %8
%13 = getelementptr inbounds i8, i8* %12, i64 1
%14 = call i32 @parseDouble(i8* %13, double* %2)
%15 = icmp eq i32 %14, 0
%16 = load double, double* %2
%17 = fmul double %16, 1.000000e+06
%18 = fptosi double %17 to i32
%19 = select i1 %15, i32 %18, i32 %14
br label %20
20: ; preds = %10, %5, %1
%21 = phi i32 [ -1, %1 ], [ %19, %10 ], [ -1, %5 ]
ret i32 %21
}