#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 int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
double floor(double);
double fmod(double, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int sscanf(char *, char *, int *, int *, char *);
int /*<<< orphan*/ *stderr;
char *strtok(char *, char *);
void sub_to_srt(FILE *in, FILE *out, double framerate) {
  int idx, ret;
  int start, end;
  double s, sf, sm;
  double e, ef, em;
  char text[256 + 1];
  char line[256 + 1];
  char *token;
  idx = 1;
  while (fgets(line, 256, in)) {
    memset(text, 0, 256 + 1);
    ret = sscanf(line, "{%d}{%d}%256c", &start, &end, text);
    if (ret == 3) {
      s = start / framerate;
      sf = floor(s);
      sm = fmod(sf, 3600);
      e = end / framerate;
      ef = floor(e);
      em = fmod(ef, 3600);
      fprintf(out, "%d\r\n", idx++);
      fprintf(out,
              "%02.0f:%02.0f:%02.0f,%03.0f --> %02.0f:%02.0f:%02.0f,%03.0f\r\n",
              floor(sf / 3600), floor(sm / 60), fmod(sm, 60), (s - sf) * 1000,
              floor(ef / 3600), floor(em / 60), fmod(em, 60), (e - ef) * 1000);
      token = strtok(text, "|\r\n");
      while (token) {
        fprintf(out, "%s\r\n", token);
        token = strtok(NULL, "|\r\n");
      }
      fprintf(out, "\r\n");
    } else
      fprintf(stderr, "sub_to_srt: invalid format: %s\n", line);
  }
}


x86 assembly (clang, -O0):
<sub_to_srt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2b0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
lea    -0x270(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x100,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1430 <sub_to_srt+0x2c0>
lea    -0x160(%rbp),%rdi
xor    %esi,%esi
mov    $0x101,%edx
call   1040 <memset@plt>
lea    -0x270(%rbp),%rdi
lea    -0x160(%rbp),%r8
lea    0xe42(%rip),%rsi
lea    -0x24(%rbp),%rdx
lea    -0x28(%rbp),%rcx
call   1070 <sscanf@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x3,-0x20(%rbp)
jne    140c <sub_to_srt+0x29c>
cvtsi2sdl -0x24(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1090 <floor@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
mov    $0xe10,%edi
call   1030 <fmod@plt>
movsd  %xmm0,-0x40(%rbp)
cvtsi2sdl -0x28(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
call   1090 <floor@plt>
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
mov    $0xe10,%edi
call   1030 <fmod@plt>
movsd  %xmm0,-0x58(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    %edx,%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
lea    0xdbc(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x2b0(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  0xd87(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1090 <floor@plt>
movsd  %xmm0,-0x280(%rbp)
ff
movsd  -0x40(%rbp),%xmm0
movsd  0xd61(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1090 <floor@plt>
movsd  %xmm0,-0x2a8(%rbp)
ff
movsd  -0x40(%rbp),%xmm0
mov    $0x3c,%edi
call   1030 <fmod@plt>
movsd  %xmm0,-0x2a0(%rbp)
ff
movsd  -0x30(%rbp),%xmm0
subsd  -0x38(%rbp),%xmm0
movsd  0xd1f(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x298(%rbp)
ff
movsd  -0x50(%rbp),%xmm0
movsd  0xd16(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1090 <floor@plt>
movsd  %xmm0,-0x290(%rbp)
ff
movsd  -0x58(%rbp),%xmm0
movsd  0xcf0(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1090 <floor@plt>
movsd  %xmm0,-0x288(%rbp)
ff
movsd  -0x58(%rbp),%xmm0
mov    $0x3c,%edi
call   1030 <fmod@plt>
mov    -0x2b0(%rbp),%rdi
movsd  -0x2a8(%rbp),%xmm1
ff
movsd  -0x2a0(%rbp),%xmm2
ff
movsd  -0x298(%rbp),%xmm3
ff
movsd  -0x290(%rbp),%xmm4
ff
movsd  -0x288(%rbp),%xmm5
ff
movaps %xmm0,%xmm6
movsd  -0x280(%rbp),%xmm0
ff
movsd  -0x48(%rbp),%xmm7
subsd  -0x50(%rbp),%xmm7
movsd  0xc7b(%rip),%xmm8
mulsd  %xmm8,%xmm7
lea    0xc9a(%rip),%rsi
mov    $0x8,%al
call   1060 <fprintf@plt>
lea    -0x160(%rbp),%rdi
lea    0xcc3(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x278(%rbp)
cmpq   $0x0,-0x278(%rbp)
je     13f5 <sub_to_srt+0x285>
mov    -0x10(%rbp),%rdi
mov    -0x278(%rbp),%rdx
lea    0xc9b(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0xc85(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x278(%rbp)
jmp    13b2 <sub_to_srt+0x242>
mov    -0x10(%rbp),%rdi
lea    0xc28(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    142b <sub_to_srt+0x2bb>
mov    0x2bcd(%rip),%rax
mov    (%rax),%rdi
lea    -0x270(%rbp),%rdx
lea    0xc4e(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    118f <sub_to_srt+0x1f>
add    $0x2b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sub_to_srt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x278,%rsp
movsd  %xmm0,0x20(%rsp)
mov    %rsi,%rbx
mov    %rdi,%rdx
lea    0x60(%rsp),%rdi
mov    $0x100,%esi
mov    %rdx,0x58(%rsp)
call   1050 <fgets@plt>
test   %rax,%rax
je     1411 <sub_to_srt+0x291>
mov    $0x1,%ebp
lea    0x170(%rsp),%r15
lea    0x60(%rsp),%r13
lea    0xe96(%rip),%r12
lea    0xe93(%rip),%r14
jmp    1216 <sub_to_srt+0x96>
nopl   0x0(%rax)
mov    0x2df9(%rip),%rax
mov    (%rax),%rdi
lea    0xe81(%rip),%rsi
mov    %r13,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %r13,%rdi
mov    $0x100,%esi
mov    0x58(%rsp),%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1411 <sub_to_srt+0x291>
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x101,%edx
call   1040 <memset@plt>
mov    %r13,%rdi
lea    0xde9(%rip),%rsi
lea    0x1c(%rsp),%rdx
lea    0x18(%rsp),%rcx
mov    %r15,%r8
call   1070 <sscanf@plt>
cmp    $0x3,%eax
jne    11e0 <sub_to_srt+0x60>
xorps  %xmm0,%xmm0
cvtsi2sdl 0x1c(%rsp),%xmm0
divsd  0x20(%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
call   10a0 <floor@plt>
movsd  %xmm0,0x8(%rsp)
mov    $0xe10,%edi
call   1030 <fmod@plt>
movsd  %xmm0,(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sdl 0x18(%rsp),%xmm0
divsd  0x20(%rsp),%xmm0
movsd  %xmm0,0x50(%rsp)
call   10a0 <floor@plt>
movsd  %xmm0,0x30(%rsp)
mov    $0xe10,%edi
call   1030 <fmod@plt>
movsd  %xmm0,0x28(%rsp)
mov    %rbx,%rdi
lea    0xd77(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
movsd  0x8(%rsp),%xmm0
movsd  0xd3a(%rip),%xmm1
divsd  %xmm1,%xmm0
call   10a0 <floor@plt>
movsd  %xmm0,0x48(%rsp)
movsd  (%rsp),%xmm0
movsd  0xd26(%rip),%xmm1
divsd  %xmm1,%xmm0
call   10a0 <floor@plt>
movsd  %xmm0,0x40(%rsp)
movsd  (%rsp),%xmm0
mov    $0x3c,%edi
call   1030 <fmod@plt>
movsd  %xmm0,(%rsp)
movsd  0x10(%rsp),%xmm1
subsd  0x8(%rsp),%xmm1
movsd  0xcf7(%rip),%xmm0
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
movsd  0x30(%rsp),%xmm0
divsd  0xccf(%rip),%xmm0
call   10a0 <floor@plt>
movsd  %xmm0,0x8(%rsp)
movsd  0x28(%rsp),%xmm0
divsd  0xcbe(%rip),%xmm0
call   10a0 <floor@plt>
movsd  %xmm0,0x38(%rsp)
movsd  0x28(%rsp),%xmm0
mov    $0x3c,%edi
call   1030 <fmod@plt>
movaps %xmm0,%xmm6
movsd  0x50(%rsp),%xmm7
subsd  0x30(%rsp),%xmm7
mulsd  0xc94(%rip),%xmm7
mov    %rbx,%rdi
lea    0xca5(%rip),%rsi
movsd  0x48(%rsp),%xmm0
movsd  0x40(%rsp),%xmm1
movsd  (%rsp),%xmm2
movsd  0x10(%rsp),%xmm3
movsd  0x8(%rsp),%xmm4
movsd  0x38(%rsp),%xmm5
mov    $0x8,%al
call   1060 <fprintf@plt>
mov    %r15,%rdi
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r12,%rsi
call   1080 <strtok@plt>
test   %rax,%rax
je     13f0 <sub_to_srt+0x270>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
xor    %edi,%edi
jmp    13c0 <sub_to_srt+0x240>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebp
mov    $0x2,%esi
mov    $0x1,%edx
lea    0xc24(%rip),%rdi
mov    %rbx,%rcx
call   1090 <fwrite@plt>
jmp    11fb <sub_to_srt+0x7b>
add    $0x278,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"{%d}{%d}%256c\00"
@.str.1 = [5 x i8] c"%d\0D\0A\00"
@.str.2 = [62 x i8] c"%02.0f:%02.0f:%02.0f,%03.0f --> %02.0f:%02.0f:%02.0f,%03.0f\0D\0A\00"
@.str.3 = [4 x i8] c"|\0D\0A\00"
@.str.4 = [5 x i8] c"%s\0D\0A\00"
@.str.5 = [3 x i8] c"\0D\0A\00"
@stderr = global i32* null
@.str.6 = [32 x i8] c"sub_to_srt: invalid format: %s\0A\00"
define void @sub_to_srt(i32* %0, i32* %1, double %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca double
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double
%15 = alloca double
%16 = alloca double
%17 = alloca [257 x i8]
%18 = alloca [257 x i8]
%19 = alloca i8*
store i32* %0, i32** %4
store i32* %1, i32** %5
store double %2, double* %6
store i32 1, i32* %7
br label %20
20: ; preds = %97, %3
%21 = getelementptr inbounds [257 x i8], [257 x i8]* %18, i64 0, i64 0
%22 = load i32*, i32** %4
%23 = call i64 @fgets(i8* %21, i32 256, i32* %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %98
25: ; preds = %20
%26 = getelementptr inbounds [257 x i8], [257 x i8]* %17, i64 0, i64 0
%27 = call i32 @memset(i8* %26, i32 0, i32 257)
%28 = getelementptr inbounds [257 x i8], [257 x i8]* %18, i64 0, i64 0
%29 = getelementptr inbounds [257 x i8], [257 x i8]* %17, i64 0, i64 0
%30 = call i32 @sscanf(i8* %28, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32* %9, i32* %10, i8* %29)
store i32 %30, i32* %8
%31 = load i32, i32* %8
%32 = icmp eq i32 %31, 3
br i1 %32, label %33, label %93
33: ; preds = %25
%34 = load i32, i32* %9
%35 = sitofp i32 %34 to double
%36 = load double, double* %6
%37 = fdiv double %35, %36
store double %37, double* %11
%38 = load double, double* %11
%39 = call double @llvm.floor.f64(double %38)
store double %39, double* %12
%40 = load double, double* %12
%41 = call double @fmod(double %40, i32 3600)
store double %41, double* %13
%42 = load i32, i32* %10
%43 = sitofp i32 %42 to double
%44 = load double, double* %6
%45 = fdiv double %43, %44
store double %45, double* %14
%46 = load double, double* %14
%47 = call double @llvm.floor.f64(double %46)
store double %47, double* %15
%48 = load double, double* %15
%49 = call double @fmod(double %48, i32 3600)
store double %49, double* %16
%50 = load i32*, i32** %5
%51 = load i32, i32* %7
%52 = add nsw i32 %51, 1
store i32 %52, i32* %7
%53 = call i32 (i32*, i8*, ...) @fprintf(i32* %50, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %51)
%54 = load i32*, i32** %5
%55 = load double, double* %12
%56 = fdiv double %55, 3.600000e+03
%57 = call double @llvm.floor.f64(double %56)
%58 = load double, double* %13
%59 = fdiv double %58, 6.000000e+01
%60 = call double @llvm.floor.f64(double %59)
%61 = load double, double* %13
%62 = call double @fmod(double %61, i32 60)
%63 = load double, double* %11
%64 = load double, double* %12
%65 = fsub double %63, %64
%66 = fmul double %65, 1.000000e+03
%67 = load double, double* %15
%68 = fdiv double %67, 3.600000e+03
%69 = call double @llvm.floor.f64(double %68)
%70 = load double, double* %16
%71 = fdiv double %70, 6.000000e+01
%72 = call double @llvm.floor.f64(double %71)
%73 = load double, double* %16
%74 = call double @fmod(double %73, i32 60)
%75 = load double, double* %14
%76 = load double, double* %15
%77 = fsub double %75, %76
%78 = fmul double %77, 1.000000e+03
%79 = call i32 (i32*, i8*, ...) @fprintf(i32* %54, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.2, i64 0, i64 0), double %57, double %60, double %62, double %66, double %69, double %72, double %74, double %78)
%80 = getelementptr inbounds [257 x i8], [257 x i8]* %17, i64 0, i64 0
%81 = call i8* @strtok(i8* %80, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
store i8* %81, i8** %19
br label %82
82: ; preds = %85, %33
%83 = load i8*, i8** %19
%84 = icmp ne i8* %83, null
br i1 %84, label %85, label %90
85: ; preds = %82
%86 = load i32*, i32** %5
%87 = load i8*, i8** %19
%88 = call i32 (i32*, i8*, ...) @fprintf(i32* %86, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* %87)
%89 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
store i8* %89, i8** %19
br label %82
90: ; preds = %82
%91 = load i32*, i32** %5
%92 = call i32 (i32*, i8*, ...) @fprintf(i32* %91, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
br label %97
93: ; preds = %25
%94 = load i32*, i32** @stderr
%95 = getelementptr inbounds [257 x i8], [257 x i8]* %18, i64 0, i64 0
%96 = call i32 (i32*, i8*, ...) @fprintf(i32* %94, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i64 0, i64 0), i8* %95)
br label %97
97: ; preds = %93, %90
br label %20
98: ; preds = %20
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c"{%d}{%d}%256c\00"
@.str.1 = [5 x i8] c"%d\0D\0A\00"
@.str.2 = [62 x i8] c"%02.0f:%02.0f:%02.0f,%03.0f --> %02.0f:%02.0f:%02.0f,%03.0f\0D\0A\00"
@.str.3 = [4 x i8] c"|\0D\0A\00"
@.str.4 = [5 x i8] c"%s\0D\0A\00"
@.str.5 = [3 x i8] c"\0D\0A\00"
@stderr = global i32* null
@.str.6 = [32 x i8] c"sub_to_srt: invalid format: %s\0A\00"
define void @sub_to_srt(i32* nocapture %0, i32* nocapture %1, double %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca [257 x i8]
%7 = alloca [257 x i8]
%8 = bitcast i32* %4 to i8*
%9 = bitcast i32* %5 to i8*
%10 = getelementptr inbounds [257 x i8], [257 x i8]* %6, i64 0, i64 0
%11 = getelementptr inbounds [257 x i8], [257 x i8]* %7, i64 0, i64 0
%12 = call i64 @fgets(i8* %11, i32 256, i32* %0)
%13 = icmp eq i64 %12, 0
br i1 %13, label %63, label %14
14: ; preds = %3, %59
%15 = phi i32 [ %60, %59 ], [ 1, %3 ]
%16 = call i32 @memset(i8* %10, i32 0, i32 257)
%17 = call i32 @sscanf(i8* %11, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32* %4, i32* %5, i8* %10)
%18 = icmp eq i32 %17, 3
br i1 %18, label %19, label %56
19: ; preds = %14
%20 = load i32, i32* %4
%21 = sitofp i32 %20 to double
%22 = fdiv double %21, %2
%23 = call double @llvm.floor.f64(double %22)
%24 = call double @fmod(double %23, i32 3600)
%25 = load i32, i32* %5
%26 = sitofp i32 %25 to double
%27 = fdiv double %26, %2
%28 = call double @llvm.floor.f64(double %27)
%29 = call double @fmod(double %28, i32 3600)
%30 = add nsw i32 %15, 1
%31 = call i32 (i32*, i8*, ...) @fprintf(i32* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%32 = fdiv double %23, 3.600000e+03
%33 = call double @llvm.floor.f64(double %32)
%34 = fdiv double %24, 6.000000e+01
%35 = call double @llvm.floor.f64(double %34)
%36 = call double @fmod(double %24, i32 60)
%37 = fsub double %22, %23
%38 = fmul double %37, 1.000000e+03
%39 = fdiv double %28, 3.600000e+03
%40 = call double @llvm.floor.f64(double %39)
%41 = fdiv double %29, 6.000000e+01
%42 = call double @llvm.floor.f64(double %41)
%43 = call double @fmod(double %29, i32 60)
%44 = fsub double %27, %28
%45 = fmul double %44, 1.000000e+03
%46 = call i32 (i32*, i8*, ...) @fprintf(i32* %1, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.2, i64 0, i64 0), double %33, double %35, double %36, double %38, double %40, double %42, double %43, double %45)
%47 = call i8* @strtok(i8* %10, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%48 = icmp eq i8* %47, null
br i1 %48, label %54, label %49
49: ; preds = %19, %49
%50 = phi i8* [ %52, %49 ], [ %47, %19 ]
%51 = call i32 (i32*, i8*, ...) @fprintf(i32* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* %50)
%52 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%53 = icmp eq i8* %52, null
br i1 %53, label %54, label %49
54: ; preds = %49, %19
%55 = call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i64 2, i64 1, i32* %1)
br label %59
56: ; preds = %14
%57 = load i32*, i32** @stderr
%58 = call i32 (i32*, i8*, ...) @fprintf(i32* %57, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i64 0, i64 0), i8* %11)
br label %59
59: ; preds = %56, %54
%60 = phi i32 [ %30, %54 ], [ %15, %56 ]
%61 = call i64 @fgets(i8* %11, i32 256, i32* %0)
%62 = icmp eq i64 %61, 0
br i1 %62, label %63, label %14
63: ; preds = %59, %3
ret void
}