#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__ emalloc(int);
int /*<<< orphan*/ sprintf(char *, char *, float, ...);
int sscanf(char const *, char *, ...);
char *fix_npt_str(const char *str) {
  int h = 0, m = 0, n;
  float s;
  char *fixed_string;
  n = sscanf(str, "%d:%d:%f", &h, &m, &s);
  if (n == 3) {
    goto pdone;
  }
  n = sscanf(str, "%d:%f", &m, &s);
  if (n == 2) {
    h = 0;
    goto pdone;
  }
  n = sscanf(str, "%f", &s);
  if (n == 1) {
    h = 0;
    m = 0;
    goto psec_only;
  }
  return NULL;
pdone:
  if (h < 0)
    return NULL;
  if (m > 59 || m < 0)
    return NULL;
  if (s >= 60.0 || s < 0.0)
    return NULL;
  fixed_string = (char *)emalloc(32);
  if (s < 10.0) {
    sprintf(fixed_string, "%01d:%02d:0%2.3f", h, m, s);
  } else {
    sprintf(fixed_string, "%01d:%02d:%02.3f", h, m, s);
  }
  return fixed_string;
psec_only:
  fixed_string = (char *)emalloc(32);
  sprintf(fixed_string, "%.3f", s);
  return fixed_string;
  ;
}


x86 assembly (clang, -O0):
<fix_npt_str>:
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    0xebb(%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    117a <fix_npt_str+0x4a>
jmp    11f0 <fix_npt_str+0xc0>
mov    -0x10(%rbp),%rdi
lea    0xe8e(%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    11ad <fix_npt_str+0x7d>
movl   $0x0,-0x14(%rbp)
jmp    11f0 <fix_npt_str+0xc0>
mov    -0x10(%rbp),%rdi
lea    0xe5e(%rip),%rsi
lea    -0x20(%rbp),%rdx
mov    $0x0,%al
call   1030 <sscanf@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x1,-0x1c(%rbp)
jne    11e3 <fix_npt_str+0xb3>
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
jmp    12e7 <fix_npt_str+0x1b7>
movq   $0x0,-0x8(%rbp)
jmp    1314 <fix_npt_str+0x1e4>
cmpl   $0x0,-0x14(%rbp)
jge    1207 <fix_npt_str+0xd7>
movq   $0x0,-0x8(%rbp)
jmp    1314 <fix_npt_str+0x1e4>
cmpl   $0x3b,-0x18(%rbp)
jg     121b <fix_npt_str+0xeb>
cmpl   $0x0,-0x18(%rbp)
jge    1228 <fix_npt_str+0xf8>
movq   $0x0,-0x8(%rbp)
jmp    1314 <fix_npt_str+0x1e4>
movss  -0x20(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xdc7(%rip),%xmm1
ucomisd %xmm1,%xmm0
jae    1259 <fix_npt_str+0x129>
movss  -0x20(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
xorps  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jbe    1266 <fix_npt_str+0x136>
movq   $0x0,-0x8(%rbp)
jmp    1314 <fix_npt_str+0x1e4>
mov    $0x20,%edi
call   1040 <emalloc@plt>
mov    %rax,-0x28(%rbp)
movss  -0x20(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xd83(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    12b7 <fix_npt_str+0x187>
mov    -0x28(%rbp),%rdi
cvtsi2ssl -0x14(%rbp),%xmm0
mov    -0x18(%rbp),%edx
movss  -0x20(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
lea    0xd6e(%rip),%rsi
mov    $0x2,%al
call   1050 <sprintf@plt>
jmp    12da <fix_npt_str+0x1aa>
mov    -0x28(%rbp),%rdi
cvtsi2ssl -0x14(%rbp),%xmm0
mov    -0x18(%rbp),%edx
movss  -0x20(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
lea    0xd57(%rip),%rsi
mov    $0x2,%al
call   1050 <sprintf@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1314 <fix_npt_str+0x1e4>
mov    $0x20,%edi
call   1040 <emalloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
movss  -0x20(%rbp),%xmm0
lea    0xd36(%rip),%rsi
mov    $0x1,%al
call   1050 <sprintf@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fix_npt_str>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
movl   $0x0,0x14(%rsp)
movl   $0x0,0x10(%rsp)
lea    0xeb7(%rip),%rsi
lea    0x14(%rsp),%rdx
lea    0x10(%rsp),%rcx
lea    0xc(%rsp),%r8
xor    %eax,%eax
call   1030 <sscanf@plt>
cmp    $0x3,%eax
jne    1175 <fix_npt_str+0x45>
mov    0x14(%rsp),%eax
shr    $0x1f,%eax
jmp    119f <fix_npt_str+0x6f>
lea    0xe8f(%rip),%rsi
lea    0x10(%rsp),%rdx
lea    0xc(%rsp),%rcx
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <sscanf@plt>
cmp    $0x2,%eax
jne    1214 <fix_npt_str+0xe4>
movl   $0x0,0x14(%rsp)
xor    %eax,%eax
xor    %r14d,%r14d
test   %al,%al
jne    1279 <fix_npt_str+0x149>
cmpl   $0x3b,0x10(%rsp)
ja     1279 <fix_npt_str+0x149>
movss  0xc(%rsp),%xmm0
xor    %r14d,%r14d
ucomiss 0xe3b(%rip),%xmm0
jae    1279 <fix_npt_str+0x149>
xorps  %xmm1,%xmm1
ucomiss %xmm0,%xmm1
ja     1279 <fix_npt_str+0x149>
mov    $0x20,%edi
call   1040 <emalloc@plt>
mov    %rax,%r14
movss  0xc(%rsp),%xmm0
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
movss  0xe0b(%rip),%xmm2
ucomiss %xmm0,%xmm2
xorps  %xmm0,%xmm0
cvtsi2ssl 0x14(%rsp),%xmm0
mov    0x10(%rsp),%edx
jbe    1268 <fix_npt_str+0x138>
lea    0xdff(%rip),%rsi
jmp    126f <fix_npt_str+0x13f>
lea    0xdf3(%rip),%rsi
xor    %r14d,%r14d
lea    0xc(%rsp),%rdx
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <sscanf@plt>
cmp    $0x1,%eax
jne    1279 <fix_npt_str+0x149>
movl   $0x0,0x14(%rsp)
movl   $0x0,0x10(%rsp)
mov    $0x20,%edi
call   1040 <emalloc@plt>
mov    %rax,%r14
movss  0xc(%rsp),%xmm0
lea    0xdd7(%rip),%rsi
mov    %rax,%rdi
mov    $0x1,%al
call   1050 <sprintf@plt>
jmp    1279 <fix_npt_str+0x149>
lea    0xdb3(%rip),%rsi
mov    %r14,%rdi
mov    $0x2,%al
call   1050 <sprintf@plt>
mov    %r14,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r14
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"
@.str.3 = [17 x i8] c"%01d:%02d:0%2.3f\00"
@.str.4 = [17 x i8] c"%01d:%02d:%02.3f\00"
@.str.5 = [5 x i8] c"%.3f\00"
define i8* @fix_npt_str(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca float
%8 = alloca i8*
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 %71
26: ; preds = %20
store i8* null, i8** %2
br label %78
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 i8* null, i8** %2
br label %78
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 i8* null, i8** %2
br label %78
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 %46, label %42
42: ; preds = %38
%43 = load float, float* %7
%44 = fpext float %43 to double
%45 = fcmp olt double %44, 0.000000e+00
br i1 %45, label %46, label %47
46: ; preds = %42, %38
store i8* null, i8** %2
br label %78
47: ; preds = %42
%48 = call i64 @emalloc(i32 32)
%49 = inttoptr i64 %48 to i8*
store i8* %49, i8** %8
%50 = load float, float* %7
%51 = fpext float %50 to double
%52 = fcmp olt double %51, 1.000000e+01
br i1 %52, label %53, label %61
53: ; preds = %47
%54 = load i8*, i8** %8
%55 = load i32, i32* %4
%56 = sitofp i32 %55 to float
%57 = load i32, i32* %5
%58 = load float, float* %7
%59 = fpext float %58 to double
%60 = call i32 (i8*, i8*, float, ...) @sprintf(i8* %54, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), float %56, i32 %57, double %59)
br label %69
61: ; preds = %47
%62 = load i8*, i8** %8
%63 = load i32, i32* %4
%64 = sitofp i32 %63 to float
%65 = load i32, i32* %5
%66 = load float, float* %7
%67 = fpext float %66 to double
%68 = call i32 (i8*, i8*, float, ...) @sprintf(i8* %62, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), float %64, i32 %65, double %67)
br label %69
69: ; preds = %61, %53
%70 = load i8*, i8** %8
store i8* %70, i8** %2
br label %78
71: ; preds = %25
%72 = call i64 @emalloc(i32 32)
%73 = inttoptr i64 %72 to i8*
store i8* %73, i8** %8
%74 = load i8*, i8** %8
%75 = load float, float* %7
%76 = call i32 (i8*, i8*, float, ...) @sprintf(i8* %74, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), float %75)
%77 = load i8*, i8** %8
store i8* %77, i8** %2
br label %78
78: ; preds = %71, %69, %46, %37, %30, %26
%79 = load i8*, i8** %2
ret i8* %79
}

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"
@.str.3 = [17 x i8] c"%01d:%02d:0%2.3f\00"
@.str.4 = [17 x i8] c"%01d:%02d:%02.3f\00"
@.str.5 = [5 x i8] c"%.3f\00"
define i8* @fix_npt_str(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 %13
10: ; preds = %1
%11 = load i32, i32* %2
%12 = icmp slt i32 %11, 0
br label %25
13: ; preds = %1
%14 = 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)
%15 = icmp eq i32 %14, 2
br i1 %15, label %16, label %17
16: ; preds = %13
store i32 0, i32* %2
br label %25
17: ; preds = %13
%18 = call i32 (i8*, i8*, ...) @sscanf(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), float* %4)
%19 = icmp eq i32 %18, 1
br i1 %19, label %20, label %48
20: ; preds = %17
store i32 0, i32* %2
store i32 0, i32* %3
%21 = call i64 @emalloc(i32 32)
%22 = inttoptr i64 %21 to i8*
%23 = load float, float* %4
%24 = call i32 (i8*, i8*, float, ...) @sprintf(i8* dereferenceable(1) %22, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), float %23)
br label %48
25: ; preds = %10, %16
%26 = phi i1 [ %12, %10 ], [ false, %16 ]
%27 = load i32, i32* %3
%28 = icmp ugt i32 %27, 59
%29 = select i1 %26, i1 true, i1 %28
br i1 %29, label %48, label %30
30: ; preds = %25
%31 = load float, float* %4
%32 = fcmp oge float %31, 6.000000e+01
%33 = fcmp olt float %31, 0.000000e+00
%34 = or i1 %32, %33
br i1 %34, label %48, label %35
35: ; preds = %30
%36 = call i64 @emalloc(i32 32)
%37 = inttoptr i64 %36 to i8*
%38 = load float, float* %4
%39 = fpext float %38 to double
%40 = fcmp olt float %38, 1.000000e+01
%41 = load i32, i32* %2
%42 = sitofp i32 %41 to float
%43 = load i32, i32* %3
br i1 %40, label %44, label %46
44: ; preds = %35
%45 = call i32 (i8*, i8*, float, ...) @sprintf(i8* dereferenceable(1) %37, i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), float %42, i32 %43, double %39)
br label %48
46: ; preds = %35
%47 = call i32 (i8*, i8*, float, ...) @sprintf(i8* dereferenceable(1) %37, i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), float %42, i32 %43, double %39)
br label %48
48: ; preds = %44, %46, %30, %25, %17, %20
%49 = phi i8* [ %22, %20 ], [ null, %17 ], [ null, %25 ], [ null, %30 ], [ %37, %46 ], [ %37, %44 ]
ret i8* %49
}