#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 */
scalar_t__ ceil(double);
int sscanf(char const *, char *, int *, int *, ...);
double parse_smpte(const char *str, double framerate) {
  int h = 0, m = 0, s = 0, n;
  float frames;
  double result;
  n = sscanf(str, "%d:%d:%d:%f", &h, &m, &s, &frames);
  if (n == 4) {
    goto done;
  }
  n = sscanf(str, "%d:%d:%f", &m, &s, &frames);
  if (n == 3) {
    h = 0;
    goto done;
  }
  return -1.0;
done:
  if (h < 0)
    return -1;
  if (m > 59 || m < 0)
    return -1;
  if (s > 59 || s < 0)
    return -1;
  if (frames > (float)ceil(framerate) || frames < 0)
    return -1;
  result = ((h * 3600.0) + (m * 60.0) + s) + (frames / framerate);
  return result;
}


x86 assembly (clang, -O0):
<parse_smpte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xec7(%rip),%rsi
lea    -0x1c(%rbp),%rdx
lea    -0x20(%rbp),%rcx
lea    -0x24(%rbp),%r8
lea    -0x2c(%rbp),%r9
mov    $0x0,%al
call   1040 <sscanf@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x4,-0x28(%rbp)
jne    117a <parse_smpte+0x5a>
jmp    11c3 <parse_smpte+0xa3>
mov    -0x10(%rbp),%rdi
lea    0xe96(%rip),%rsi
lea    -0x20(%rbp),%rdx
lea    -0x24(%rbp),%rcx
lea    -0x2c(%rbp),%r8
mov    $0x0,%al
call   1040 <sscanf@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x3,-0x28(%rbp)
jne    11b1 <parse_smpte+0x91>
movl   $0x0,-0x1c(%rbp)
jmp    11c3 <parse_smpte+0xa3>
movsd  0xe47(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12c1 <parse_smpte+0x1a1>
cmpl   $0x0,-0x1c(%rbp)
jge    11df <parse_smpte+0xbf>
movsd  0xe2b(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12c1 <parse_smpte+0x1a1>
cmpl   $0x3b,-0x20(%rbp)
jg     11f3 <parse_smpte+0xd3>
cmpl   $0x0,-0x20(%rbp)
jge    1205 <parse_smpte+0xe5>
movsd  0xe05(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12c1 <parse_smpte+0x1a1>
cmpl   $0x3b,-0x24(%rbp)
jg     1219 <parse_smpte+0xf9>
cmpl   $0x0,-0x24(%rbp)
jge    122b <parse_smpte+0x10b>
movsd  0xddf(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12c1 <parse_smpte+0x1a1>
movss  -0x2c(%rbp),%xmm0
movss  %xmm0,-0x3c(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1030 <ceil@plt>
movss  -0x3c(%rbp),%xmm0
cvtsi2ss %rax,%xmm1
ucomiss %xmm1,%xmm0
ja     125f <parse_smpte+0x13f>
xorps  %xmm0,%xmm0
ucomiss -0x2c(%rbp),%xmm0
jbe    1271 <parse_smpte+0x151>
movsd  0xd99(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12c1 <parse_smpte+0x1a1>
cvtsi2sdl -0x1c(%rbp),%xmm0
cvtsi2sdl -0x20(%rbp),%xmm1
movsd  0xd8d(%rip),%xmm2
mulsd  %xmm2,%xmm1
movsd  0xd79(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvtsi2sdl -0x24(%rbp),%xmm1
addsd  %xmm1,%xmm0
movss  -0x2c(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
divsd  -0x18(%rbp),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_smpte>:
push   %rbx
sub    $0x20,%rsp
movsd  %xmm0,0x18(%rsp)
mov    %rdi,%rbx
movl   $0x0,0xc(%rsp)
movl   $0x0,0x8(%rsp)
movl   $0x0,0x4(%rsp)
lea    0xecb(%rip),%rsi
lea    0xc(%rsp),%rdx
lea    0x8(%rsp),%rcx
lea    0x4(%rsp),%r8
lea    0x10(%rsp),%r9
xor    %eax,%eax
call   1040 <sscanf@plt>
cmp    $0x4,%eax
jne    1176 <parse_smpte+0x56>
mov    0xc(%rsp),%eax
shr    $0x1f,%eax
jmp    11a9 <parse_smpte+0x89>
lea    0xe9e(%rip),%rsi
lea    0x8(%rsp),%rdx
lea    0x4(%rsp),%rcx
lea    0x10(%rsp),%r8
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <sscanf@plt>
cmp    $0x3,%eax
jne    1252 <parse_smpte+0x132>
movl   $0x0,0xc(%rsp)
xor    %eax,%eax
movsd  0xe4f(%rip),%xmm0
test   %al,%al
jne    125a <parse_smpte+0x13a>
cmpl   $0x3b,0x8(%rsp)
ja     125a <parse_smpte+0x13a>
cmpl   $0x3b,0x4(%rsp)
ja     125a <parse_smpte+0x13a>
movss  0x10(%rsp),%xmm0
movss  %xmm0,0x14(%rsp)
movsd  0x18(%rsp),%xmm0
call   1030 <ceil@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
movss  0x14(%rsp),%xmm1
ucomiss %xmm0,%xmm1
ja     1252 <parse_smpte+0x132>
movss  0x10(%rsp),%xmm3
xorps  %xmm1,%xmm1
ucomiss %xmm3,%xmm1
movsd  0xdf3(%rip),%xmm0
ja     125a <parse_smpte+0x13a>
xorps  %xmm1,%xmm1
cvtsi2sdl 0xc(%rsp),%xmm1
cvtsi2sdl 0x8(%rsp),%xmm2
mulsd  0xde2(%rip),%xmm2
mulsd  0xde2(%rip),%xmm1
addsd  %xmm2,%xmm1
xorps  %xmm2,%xmm2
cvtsi2sdl 0x4(%rsp),%xmm2
addsd  %xmm1,%xmm2
xorps  %xmm0,%xmm0
cvtss2sd %xmm3,%xmm0
divsd  0x18(%rsp),%xmm0
addsd  %xmm2,%xmm0
jmp    125a <parse_smpte+0x13a>
movsd  0xda6(%rip),%xmm0
add    $0x20,%rsp
pop    %rbx
ret

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

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