#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 */

/* Variables and functions */
int sscanf(char const *, char *, ...);
double parse_npt(const char *str) {
  int h = 0, m = 0, n;
  float s;
  double result;
  n = sscanf(str, "%d:%d:%f", &h, &m, &s);
  if (n == 3) {
    goto done;
  }
  n = sscanf(str, "%d:%f", &m, &s);
  if (n == 2) {
    h = 0;
    goto done;
  }
  n = sscanf(str, "%f", &s);
  if (n == 1) {
    h = 0;
    m = 0;
    goto sec_only;
  }
  return -1.0;
done:
  if (h < 0)
    return -1;
  if (m > 59 || m < 0)
    return -1;
  if (s >= 60.0 || s < 0)
    return -1;
sec_only:
  result = ((h * 3600.0) + (m * 60.0) + s);
  return result;
}


x86 assembly (clang, -O0):
<parse_npt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xee3(%rip),%rsi
lea    -0x14(%rbp),%rdx
lea    -0x18(%rbp),%rcx
lea    -0x20(%rbp),%r8
mov    $0x0,%al
call   1030 <sscanf@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x3,-0x1c(%rbp)
jne    115a <parse_npt+0x4a>
jmp    11d5 <parse_npt+0xc5>
mov    -0x10(%rbp),%rdi
lea    0xeb6(%rip),%rsi
lea    -0x18(%rbp),%rdx
lea    -0x20(%rbp),%rcx
mov    $0x0,%al
call   1030 <sscanf@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x2,-0x1c(%rbp)
jne    118d <parse_npt+0x7d>
movl   $0x0,-0x14(%rbp)
jmp    11d5 <parse_npt+0xc5>
mov    -0x10(%rbp),%rdi
lea    0xe86(%rip),%rsi
lea    -0x20(%rbp),%rdx
mov    $0x0,%al
call   1030 <sscanf@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x1,-0x1c(%rbp)
jne    11c3 <parse_npt+0xb3>
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
jmp    1256 <parse_npt+0x146>
movsd  0xe35(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1298 <parse_npt+0x188>
cmpl   $0x0,-0x14(%rbp)
jge    11f1 <parse_npt+0xe1>
movsd  0xe19(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1298 <parse_npt+0x188>
cmpl   $0x3b,-0x18(%rbp)
jg     1205 <parse_npt+0xf5>
cmpl   $0x0,-0x18(%rbp)
jge    1217 <parse_npt+0x107>
movsd  0xdf3(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1298 <parse_npt+0x188>
movss  -0x20(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xde0(%rip),%xmm1
ucomisd %xmm1,%xmm0
jae    123f <parse_npt+0x12f>
xorps  %xmm0,%xmm0
ucomiss -0x20(%rbp),%xmm0
jbe    1251 <parse_npt+0x141>
movsd  0xdb9(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1298 <parse_npt+0x188>
jmp    1256 <parse_npt+0x146>
cvtsi2sdl -0x14(%rbp),%xmm0
cvtsi2sdl -0x18(%rbp),%xmm1
movsd  0xda0(%rip),%xmm2
mulsd  %xmm2,%xmm1
movsd  0xd9c(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movss  -0x20(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_npt>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
movl   $0x0,0xc(%rsp)
movl   $0x0,0x8(%rsp)
lea    0xeea(%rip),%rsi
xor    %ebp,%ebp
lea    0xc(%rsp),%rdx
lea    0x8(%rsp),%rcx
lea    0x4(%rsp),%r8
xor    %eax,%eax
call   1030 <sscanf@plt>
cmp    $0x3,%eax
jne    1155 <parse_npt+0x45>
mov    0xc(%rsp),%ebp
jmp    1175 <parse_npt+0x65>
lea    0xec3(%rip),%rsi
lea    0x8(%rsp),%rdx
lea    0x4(%rsp),%rcx
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <sscanf@plt>
cmp    $0x2,%eax
jne    11a9 <parse_npt+0x99>
movsd  0xe83(%rip),%xmm0
test   %ebp,%ebp
js     1207 <parse_npt+0xf7>
mov    0x8(%rsp),%r14d
cmp    $0x3b,%r14d
ja     1207 <parse_npt+0xf7>
movss  0x4(%rsp),%xmm1
ucomiss 0xe7b(%rip),%xmm1
jae    1207 <parse_npt+0xf7>
xorps  %xmm2,%xmm2
ucomiss %xmm1,%xmm2
jbe    11cf <parse_npt+0xbf>
jmp    1207 <parse_npt+0xf7>
lea    0xe72(%rip),%rsi
xor    %r14d,%r14d
lea    0x4(%rsp),%rdx
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <sscanf@plt>
cmp    $0x1,%eax
jne    11ff <parse_npt+0xef>
movss  0x4(%rsp),%xmm1
xor    %ebp,%ebp
xorps  %xmm2,%xmm2
cvtsi2sd %ebp,%xmm2
xorps  %xmm0,%xmm0
cvtsi2sd %r14d,%xmm0
mulsd  0xe22(%rip),%xmm0
mulsd  0xe22(%rip),%xmm2
addsd  %xmm0,%xmm2
xorps  %xmm0,%xmm0
cvtss2sd %xmm1,%xmm0
addsd  %xmm2,%xmm0
jmp    1207 <parse_npt+0xf7>
movsd  0xdf9(%rip),%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"%d:%d:%f\00"
@.str.1 = [6 x i8] c"%d:%f\00"
@.str.2 = [3 x i8] c"%f\00"
define double @parse_npt(i8* %0) {
%2 = alloca double
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca float
%8 = alloca double
store i8* %0, i8** %3
store i32 0, i32* %4
store i32 0, i32* %5
%9 = load i8*, i8** %3
%10 = call i32 (i8*, i8*, ...) @sscanf(i8* %9, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32* %4, i32* %5, float* %7)
store i32 %10, i32* %6
%11 = load i32, i32* %6
%12 = icmp eq i32 %11, 3
br i1 %12, label %13, label %14
13: ; preds = %1
br label %27
14: ; preds = %1
%15 = load i8*, i8** %3
%16 = call i32 (i8*, i8*, ...) @sscanf(i8* %15, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %5, float* %7)
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = icmp eq i32 %17, 2
br i1 %18, label %19, label %20
19: ; preds = %14
store i32 0, i32* %4
br label %27
20: ; preds = %14
%21 = load i8*, i8** %3
%22 = call i32 (i8*, i8*, ...) @sscanf(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), float* %7)
store i32 %22, i32* %6
%23 = load i32, i32* %6
%24 = icmp eq i32 %23, 1
br i1 %24, label %25, label %26
25: ; preds = %20
store i32 0, i32* %4
store i32 0, i32* %5
br label %47
26: ; preds = %20
store double -1.000000e+00, double* %2
br label %58
27: ; preds = %19, %13
%28 = load i32, i32* %4
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %27
store double -1.000000e+00, double* %2
br label %58
31: ; preds = %27
%32 = load i32, i32* %5
%33 = icmp sgt i32 %32, 59
br i1 %33, label %37, label %34
34: ; preds = %31
%35 = load i32, i32* %5
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %34, %31
store double -1.000000e+00, double* %2
br label %58
38: ; preds = %34
%39 = load float, float* %7
%40 = fpext float %39 to double
%41 = fcmp oge double %40, 6.000000e+01
br i1 %41, label %45, label %42
42: ; preds = %38
%43 = load float, float* %7
%44 = fcmp olt float %43, 0.000000e+00
br i1 %44, label %45, label %46
45: ; preds = %42, %38
store double -1.000000e+00, double* %2
br label %58
46: ; preds = %42
br label %47
47: ; preds = %46, %25
%48 = load i32, i32* %4
%49 = sitofp i32 %48 to double
%50 = load i32, i32* %5
%51 = sitofp i32 %50 to double
%52 = fmul double %51, 6.000000e+01
%53 = call double @llvm.fmuladd.f64(double %49, double 3.600000e+03, double %52)
%54 = load float, float* %7
%55 = fpext float %54 to double
%56 = fadd double %53, %55
store double %56, double* %8
%57 = load double, double* %8
store double %57, double* %2
br label %58
58: ; preds = %47, %45, %37, %30, %26
%59 = load double, double* %2
ret double %59
}

LLVM IR (-O2):
@.str = [9 x i8] c"%d:%d:%f\00"
@.str.1 = [6 x i8] c"%d:%f\00"
@.str.2 = [3 x i8] c"%f\00"
define double @parse_npt(i8* nocapture %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca float
%5 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%6 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%7 = bitcast float* %4 to i8*
%8 = call i32 (i8*, i8*, ...) @sscanf(i8* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32* %2, i32* %3, float* %4)
%9 = icmp eq i32 %8, 3
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = load i32, i32* %2
br label %20
12: ; preds = %1
%13 = call i32 (i8*, i8*, ...) @sscanf(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %3, float* %4)
%14 = icmp eq i32 %13, 2
br i1 %14, label %20, label %15
15: ; preds = %12
%16 = call i32 (i8*, i8*, ...) @sscanf(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), float* %4)
%17 = icmp eq i32 %16, 1
br i1 %17, label %18, label %41
18: ; preds = %15
%19 = load float, float* %4
br label %31
20: ; preds = %12, %10
%21 = phi i32 [ %11, %10 ], [ 0, %12 ]
%22 = icmp slt i32 %21, 0
%23 = load i32, i32* %3
%24 = icmp ugt i32 %23, 59
%25 = select i1 %22, i1 true, i1 %24
br i1 %25, label %41, label %26
26: ; preds = %20
%27 = load float, float* %4
%28 = fcmp oge float %27, 6.000000e+01
%29 = fcmp olt float %27, 0.000000e+00
%30 = or i1 %28, %29
br i1 %30, label %41, label %31
31: ; preds = %26, %18
%32 = phi float [ %27, %26 ], [ %19, %18 ]
%33 = phi i32 [ %23, %26 ], [ 0, %18 ]
%34 = phi i32 [ %21, %26 ], [ 0, %18 ]
%35 = sitofp i32 %34 to double
%36 = sitofp i32 %33 to double
%37 = fmul double %36, 6.000000e+01
%38 = call double @llvm.fmuladd.f64(double %35, double 3.600000e+03, double %37)
%39 = fpext float %32 to double
%40 = fadd double %38, %39
br label %41
41: ; preds = %26, %20, %15, %31
%42 = phi double [ %40, %31 ], [ -1.000000e+00, %15 ], [ -1.000000e+00, %20 ], [ -1.000000e+00, %26 ]
ret double %42
}