#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(scalar_t__);
char *fix_npt_str(char const *);
int sscanf(char const *, char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *cmml_tstr_fix(const char *str) {
  char timespec[16];
  char *fix_timespec = NULL;
  char *full_timespec = NULL;
  int speclen = 0;
  if (str == NULL) {
    return NULL;
  }
  if ((sscanf(str, "smpte-24:%16s", timespec) == 1) ||
      (sscanf(str, "smpte-24-drop:%16s", timespec) == 1) ||
      (sscanf(str, "smpte-25:%16s", timespec) == 1) ||
      (sscanf(str, "smpte-30:%16s", timespec) == 1) ||
      (sscanf(str, "smpte-30-drop:%16s", timespec) == 1) ||
      (sscanf(str, "smpte-50:%16s", timespec) == 1) ||
      (sscanf(str, "smpte-60:%16s", timespec) == 1) ||
      (sscanf(str, "smpte-60-drop:%16s", timespec) == 1)) {
    return (char *)str;
  }
  if (sscanf(str, "npt:%16s", timespec) == 1) {
    speclen = 4;
    fix_timespec = fix_npt_str(str + speclen);
  } else {
    speclen = 0;
    fix_timespec = fix_npt_str(str);
  }
  if (fix_timespec == NULL)
    return NULL;
  full_timespec = (char *)emalloc(strlen(fix_timespec) + speclen + 1);
  if (speclen > 0) {
    strncpy(full_timespec, "npt:", 4);
  }
  full_timespec[speclen] = '\0';
  strcat(full_timespec, fix_timespec);
  return full_timespec;
}


x86 assembly (clang, -O0):
<cmml_tstr_fix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    119b <cmml_tstr_fix+0x3b>
movq   $0x0,-0x8(%rbp)
jmp    1359 <cmml_tstr_fix+0x1f9>
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rdx
lea    0xe56(%rip),%rsi
call   1050 <sscanf@plt>
cmp    $0x1,%eax
je     1283 <cmml_tstr_fix+0x123>
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rdx
lea    0xe47(%rip),%rsi
call   1050 <sscanf@plt>
cmp    $0x1,%eax
je     1283 <cmml_tstr_fix+0x123>
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rdx
lea    0xe3d(%rip),%rsi
call   1050 <sscanf@plt>
cmp    $0x1,%eax
je     1283 <cmml_tstr_fix+0x123>
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rdx
lea    0xe2e(%rip),%rsi
call   1050 <sscanf@plt>
cmp    $0x1,%eax
je     1283 <cmml_tstr_fix+0x123>
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rdx
lea    0xe1f(%rip),%rsi
call   1050 <sscanf@plt>
cmp    $0x1,%eax
je     1283 <cmml_tstr_fix+0x123>
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rdx
lea    0xe15(%rip),%rsi
call   1050 <sscanf@plt>
cmp    $0x1,%eax
je     1283 <cmml_tstr_fix+0x123>
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rdx
lea    0xe06(%rip),%rsi
call   1050 <sscanf@plt>
cmp    $0x1,%eax
je     1283 <cmml_tstr_fix+0x123>
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rdx
lea    0xdf7(%rip),%rsi
call   1050 <sscanf@plt>
cmp    $0x1,%eax
jne    1290 <cmml_tstr_fix+0x130>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1359 <cmml_tstr_fix+0x1f9>
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rdx
lea    0xde0(%rip),%rsi
call   1050 <sscanf@plt>
cmp    $0x1,%eax
jne    12cd <cmml_tstr_fix+0x16d>
movl   $0x4,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
movslq -0x34(%rbp),%rax
add    %rax,%rdi
call   1080 <fix_npt_str@plt>
mov    %rax,-0x28(%rbp)
jmp    12e1 <cmml_tstr_fix+0x181>
movl   $0x0,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
call   1080 <fix_npt_str@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    12f9 <cmml_tstr_fix+0x199>
movq   $0x0,-0x8(%rbp)
jmp    1359 <cmml_tstr_fix+0x1f9>
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
movslq -0x34(%rbp),%rax
add    %rax,%rdi
add    $0x1,%rdi
call   1060 <emalloc@plt>
mov    %rax,-0x30(%rbp)
cmpl   $0x0,-0x34(%rbp)
jle    1338 <cmml_tstr_fix+0x1d8>
mov    -0x30(%rbp),%rdi
lea    0xd5a(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
mov    -0x30(%rbp),%rax
movslq -0x34(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmml_tstr_fix>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
test   %rdi,%rdi
je     12bf <cmml_tstr_fix+0x15f>
mov    %rdi,%rbx
lea    0xe83(%rip),%rsi
mov    %rsp,%rdx
call   1050 <sscanf@plt>
cmp    $0x1,%eax
je     12c1 <cmml_tstr_fix+0x161>
lea    0xe79(%rip),%rsi
mov    %rsp,%rdx
mov    %rbx,%rdi
call   1050 <sscanf@plt>
cmp    $0x1,%eax
je     12c1 <cmml_tstr_fix+0x161>
lea    0xe71(%rip),%rsi
mov    %rsp,%rdx
mov    %rbx,%rdi
call   1050 <sscanf@plt>
cmp    $0x1,%eax
je     12c1 <cmml_tstr_fix+0x161>
lea    0xe64(%rip),%rsi
mov    %rsp,%rdx
mov    %rbx,%rdi
call   1050 <sscanf@plt>
cmp    $0x1,%eax
je     12c1 <cmml_tstr_fix+0x161>
lea    0xe57(%rip),%rsi
mov    %rsp,%rdx
mov    %rbx,%rdi
call   1050 <sscanf@plt>
cmp    $0x1,%eax
je     12c1 <cmml_tstr_fix+0x161>
lea    0xe4f(%rip),%rsi
mov    %rsp,%rdx
mov    %rbx,%rdi
call   1050 <sscanf@plt>
cmp    $0x1,%eax
je     12c1 <cmml_tstr_fix+0x161>
lea    0xe42(%rip),%rsi
mov    %rsp,%rdx
mov    %rbx,%rdi
call   1050 <sscanf@plt>
cmp    $0x1,%eax
je     12c1 <cmml_tstr_fix+0x161>
lea    0xe35(%rip),%rsi
mov    %rsp,%rdx
mov    %rbx,%rdi
call   1050 <sscanf@plt>
cmp    $0x1,%eax
je     12c1 <cmml_tstr_fix+0x161>
lea    0xe31(%rip),%rsi
mov    %rsp,%rdx
mov    %rbx,%rdi
call   1050 <sscanf@plt>
mov    %eax,%r15d
xor    %ebp,%ebp
cmp    $0x1,%eax
sete   %bpl
lea    (%rbx,%rbp,4),%rdi
call   1080 <fix_npt_str@plt>
test   %rax,%rax
je     12bf <cmml_tstr_fix+0x15f>
mov    %rax,%r14
shl    $0x2,%rbp
mov    %rax,%rdi
call   1040 <strlen@plt>
mov    %rbp,%rdi
or     $0x1,%rdi
add    %rax,%rdi
call   1060 <emalloc@plt>
mov    %rax,%rbx
cmp    $0x1,%r15d
jne    12ae <cmml_tstr_fix+0x14e>
lea    0xde7(%rip),%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1030 <strncpy@plt>
movb   $0x0,(%rbx,%rbp,1)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <strcat@plt>
jmp    12c1 <cmml_tstr_fix+0x161>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"smpte-24:%16s\00"
@.str.1 = [19 x i8] c"smpte-24-drop:%16s\00"
@.str.2 = [14 x i8] c"smpte-25:%16s\00"
@.str.3 = [14 x i8] c"smpte-30:%16s\00"
@.str.4 = [19 x i8] c"smpte-30-drop:%16s\00"
@.str.5 = [14 x i8] c"smpte-50:%16s\00"
@.str.6 = [14 x i8] c"smpte-60:%16s\00"
@.str.7 = [19 x i8] c"smpte-60-drop:%16s\00"
@.str.8 = [9 x i8] c"npt:%16s\00"
@.str.9 = [5 x i8] c"npt:\00"
define i8* @cmml_tstr_fix(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca [16 x i8]
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %3
store i8* null, i8** %5
store i8* null, i8** %6
store i32 0, i32* %7
%8 = load i8*, i8** %3
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %11
10: ; preds = %1
store i8* null, i8** %2
br label %94
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%14 = call i32 @sscanf(i8* %12, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = icmp eq i32 %14, 1
br i1 %15, label %51, label %16
16: ; preds = %11
%17 = load i8*, i8** %3
%18 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%19 = call i32 @sscanf(i8* %17, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = icmp eq i32 %19, 1
br i1 %20, label %51, label %21
21: ; preds = %16
%22 = load i8*, i8** %3
%23 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%24 = call i32 @sscanf(i8* %22, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %23)
%25 = icmp eq i32 %24, 1
br i1 %25, label %51, label %26
26: ; preds = %21
%27 = load i8*, i8** %3
%28 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%29 = call i32 @sscanf(i8* %27, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* %28)
%30 = icmp eq i32 %29, 1
br i1 %30, label %51, label %31
31: ; preds = %26
%32 = load i8*, i8** %3
%33 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%34 = call i32 @sscanf(i8* %32, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %33)
%35 = icmp eq i32 %34, 1
br i1 %35, label %51, label %36
36: ; preds = %31
%37 = load i8*, i8** %3
%38 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%39 = call i32 @sscanf(i8* %37, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* %38)
%40 = icmp eq i32 %39, 1
br i1 %40, label %51, label %41
41: ; preds = %36
%42 = load i8*, i8** %3
%43 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%44 = call i32 @sscanf(i8* %42, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i8* %43)
%45 = icmp eq i32 %44, 1
br i1 %45, label %51, label %46
46: ; preds = %41
%47 = load i8*, i8** %3
%48 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%49 = call i32 @sscanf(i8* %47, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), i8* %48)
%50 = icmp eq i32 %49, 1
br i1 %50, label %51, label %53
51: ; preds = %46, %41, %36, %31, %26, %21, %16, %11
%52 = load i8*, i8** %3
store i8* %52, i8** %2
br label %94
53: ; preds = %46
%54 = load i8*, i8** %3
%55 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%56 = call i32 @sscanf(i8* %54, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0), i8* %55)
%57 = icmp eq i32 %56, 1
br i1 %57, label %58, label %64
58: ; preds = %53
store i32 4, i32* %7
%59 = load i8*, i8** %3
%60 = load i32, i32* %7
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i8, i8* %59, i64 %61
%63 = call i8* @fix_npt_str(i8* %62)
store i8* %63, i8** %5
br label %67
64: ; preds = %53
store i32 0, i32* %7
%65 = load i8*, i8** %3
%66 = call i8* @fix_npt_str(i8* %65)
store i8* %66, i8** %5
br label %67
67: ; preds = %64, %58
%68 = load i8*, i8** %5
%69 = icmp eq i8* %68, null
br i1 %69, label %70, label %71
70: ; preds = %67
store i8* null, i8** %2
br label %94
71: ; preds = %67
%72 = load i8*, i8** %5
%73 = call i64 @strlen(i8* %72)
%74 = load i32, i32* %7
%75 = sext i32 %74 to i64
%76 = add nsw i64 %73, %75
%77 = add nsw i64 %76, 1
%78 = call i64 @emalloc(i64 %77)
%79 = inttoptr i64 %78 to i8*
store i8* %79, i8** %6
%80 = load i32, i32* %7
%81 = icmp sgt i32 %80, 0
br i1 %81, label %82, label %85
82: ; preds = %71
%83 = load i8*, i8** %6
%84 = call i32 @strncpy(i8* %83, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0), i32 4)
br label %85
85: ; preds = %82, %71
%86 = load i8*, i8** %6
%87 = load i32, i32* %7
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds i8, i8* %86, i64 %88
store i8 0, i8* %89
%90 = load i8*, i8** %6
%91 = load i8*, i8** %5
%92 = call i32 @strcat(i8* %90, i8* %91)
%93 = load i8*, i8** %6
store i8* %93, i8** %2
br label %94
94: ; preds = %85, %70, %51, %10
%95 = load i8*, i8** %2
ret i8* %95
}

LLVM IR (-O2):
@.str = [14 x i8] c"smpte-24:%16s\00"
@.str.1 = [19 x i8] c"smpte-24-drop:%16s\00"
@.str.2 = [14 x i8] c"smpte-25:%16s\00"
@.str.3 = [14 x i8] c"smpte-30:%16s\00"
@.str.4 = [19 x i8] c"smpte-30-drop:%16s\00"
@.str.5 = [14 x i8] c"smpte-50:%16s\00"
@.str.6 = [14 x i8] c"smpte-60:%16s\00"
@.str.7 = [19 x i8] c"smpte-60-drop:%16s\00"
@.str.8 = [9 x i8] c"npt:%16s\00"
@.str.9 = [5 x i8] c"npt:\00"
define i8* @cmml_tstr_fix(i8* %0) {
%2 = alloca [16 x i8]
%3 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%4 = icmp eq i8* %0, null
br i1 %4, label %48, label %5
5: ; preds = %1
%6 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %3)
%7 = icmp eq i32 %6, 1
br i1 %7, label %48, label %8
8: ; preds = %5
%9 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%10 = icmp eq i32 %9, 1
br i1 %10, label %48, label %11
11: ; preds = %8
%12 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %3)
%13 = icmp eq i32 %12, 1
br i1 %13, label %48, label %14
14: ; preds = %11
%15 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* %3)
%16 = icmp eq i32 %15, 1
br i1 %16, label %48, label %17
17: ; preds = %14
%18 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %3)
%19 = icmp eq i32 %18, 1
br i1 %19, label %48, label %20
20: ; preds = %17
%21 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* %3)
%22 = icmp eq i32 %21, 1
br i1 %22, label %48, label %23
23: ; preds = %20
%24 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i8* %3)
%25 = icmp eq i32 %24, 1
br i1 %25, label %48, label %26
26: ; preds = %23
%27 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), i8* %3)
%28 = icmp eq i32 %27, 1
br i1 %28, label %48, label %29
29: ; preds = %26
%30 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0), i8* %3)
%31 = icmp eq i32 %30, 1
%32 = select i1 %31, i64 4, i64 0
%33 = getelementptr i8, i8* %0, i64 %32
%34 = select i1 %31, i64 4, i64 0
%35 = call i8* @fix_npt_str(i8* %33)
%36 = icmp eq i8* %35, null
br i1 %36, label %48, label %37
37: ; preds = %29
%38 = call i64 @strlen(i8* %35)
%39 = or i64 %34, 1
%40 = add i64 %39, %38
%41 = call i64 @emalloc(i64 %40)
%42 = inttoptr i64 %41 to i8*
br i1 %31, label %43, label %45
43: ; preds = %37
%44 = call i32 @strncpy(i8* %42, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0), i32 4)
br label %45
45: ; preds = %43, %37
%46 = getelementptr inbounds i8, i8* %42, i64 %34
store i8 0, i8* %46
%47 = call i32 @strcat(i8* %42, i8* %35)
br label %48
48: ; preds = %29, %5, %8, %11, %14, %17, %20, %23, %26, %1, %45
%49 = phi i8* [ %42, %45 ], [ null, %1 ], [ %0, %26 ], [ %0, %23 ], [ %0, %20 ], [ %0, %17 ], [ %0, %14 ], [ %0, %11 ], [ %0, %8 ], [ %0, %5 ], [ null, %29 ]
ret i8* %49
}