#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ memset(char *, int, int);
int sprintf(char *, char *, unsigned int, unsigned short, unsigned short,
            unsigned long);
int /*<<< orphan*/ stderr;
int srt_render_time(unsigned long ms, char *buf) {
  unsigned int hour = ms / (60 * 60 * 1000);
  unsigned short min = (ms / (60 * 1000)) % 60;
  unsigned short sec = (ms / 1000) % 60;
  ms = ms - 1000 * (ms / 1000);
  if (hour > 99) {
    fprintf(stderr, "PTS should be less than 99 hours.\n");
    return -1;
  }
  memset(buf, 0x00, 12 + 1);
  if (sprintf(buf, "%02u:%02u:%02u,%03lu", hour, min, sec, ms) != 12) {
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<srt_render_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    $0x36ee80,%ecx
xor    %edx,%edx
div    %rcx
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    $0xea60,%ecx
xor    %edx,%edx
div    %rcx
mov    $0x3c,%ecx
xor    %edx,%edx
div    %rcx
mov    %dx,%ax
mov    %ax,-0x1e(%rbp)
mov    -0x10(%rbp),%rax
mov    $0x3e8,%ecx
xor    %edx,%edx
div    %rcx
mov    $0x3c,%ecx
xor    %edx,%edx
div    %rcx
mov    %dx,%ax
mov    %ax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    $0x3e8,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
imul   $0x3e8,%rcx,%rcx
sub    %rcx,%rax
mov    %rax,-0x10(%rbp)
cmpl   $0x63,-0x1c(%rbp)
jbe    11e5 <srt_render_time+0xb5>
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
lea    0xe2c(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1237 <srt_render_time+0x107>
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0xd,%edx
call   1030 <memset@plt>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    -0x1e(%rbp),%cx
mov    -0x20(%rbp),%ax
mov    -0x10(%rbp),%r9
lea    0xe14(%rip),%rsi
movzwl %cx,%ecx
movzwl %ax,%r8d
call   1050 <sprintf@plt>
cmp    $0xc,%eax
je     1230 <srt_render_time+0x100>
movl   $0xffffffff,-0x4(%rbp)
jmp    1237 <srt_render_time+0x107>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<srt_render_time>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
movabs $0x4a90be587de6e565,%rcx
be 90 4a
mov    %rdi,%rax
mul    %rcx
mov    %rdx,%r15
shr    $0x14,%r15
mov    %rdi,%rax
shr    $0x3,%rax
movabs $0x20c49ba5e353f7cf,%rcx
9b c4 20
mul    %rcx
cmp    $0x64,%r15d
jb     1189 <srt_render_time+0x59>
mov    0x2e6f(%rip),%rax
mov    (%rax),%edi
lea    0xe86(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    1219 <srt_render_time+0xe9>
mov    %rsi,%r14
mov    %rdx,%r13
shr    $0x4,%r13
imul   $0xfffffffffffffc18,%r13,%r12
add    %rdi,%r12
movabs $0x8888888888888889,%rsi
88 88 88
mov    %r13,%rax
mul    %rsi
mov    %rdx,%rcx
shr    $0x5,%rcx
shr    $0x5,%rdi
movabs $0x45e7b272f608771,%rdx
7b 5e 04
mov    %rdi,%rax
mul    %rdx
mov    %rdx,%rbx
imul   $0x3c,%ecx,%ecx
shr    $0x5,%rbx
mov    %rbx,%rax
mul    %rsi
sub    %ecx,%r13d
shr    $0x5,%rdx
imul   $0x3c,%edx,%eax
sub    %eax,%ebx
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xd,%edx
call   1030 <memset@plt>
lea    0xe29(%rip),%rsi
mov    %r14,%rdi
mov    %r15d,%edx
mov    %ebx,%ecx
mov    %r13d,%r8d
mov    %r12,%r9
call   1050 <sprintf@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xc,%ecx
setne  %al
neg    %eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [35 x i8] c"PTS should be less than 99 hours.\0A\00"
@.str.1 = [21 x i8] c"%02u:%02u:%02u,%03lu\00"
define i32 @srt_render_time(i64 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i16
%8 = alloca i16
store i64 %0, i64* %4
store i8* %1, i8** %5
%9 = load i64, i64* %4
%10 = udiv i64 %9, 3600000
%11 = trunc i64 %10 to i32
store i32 %11, i32* %6
%12 = load i64, i64* %4
%13 = udiv i64 %12, 60000
%14 = urem i64 %13, 60
%15 = trunc i64 %14 to i16
store i16 %15, i16* %7
%16 = load i64, i64* %4
%17 = udiv i64 %16, 1000
%18 = urem i64 %17, 60
%19 = trunc i64 %18 to i16
store i16 %19, i16* %8
%20 = load i64, i64* %4
%21 = load i64, i64* %4
%22 = udiv i64 %21, 1000
%23 = mul i64 1000, %22
%24 = sub i64 %20, %23
store i64 %24, i64* %4
%25 = load i32, i32* %6
%26 = icmp ugt i32 %25, 99
br i1 %26, label %27, label %30
27: ; preds = %2
%28 = load i32, i32* @stderr
%29 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %42
30: ; preds = %2
%31 = load i8*, i8** %5
%32 = call i32 @memset(i8* %31, i32 0, i32 13)
%33 = load i8*, i8** %5
%34 = load i32, i32* %6
%35 = load i16, i16* %7
%36 = load i16, i16* %8
%37 = load i64, i64* %4
%38 = call i32 @sprintf(i8* %33, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %34, i16 zeroext %35, i16 zeroext %36, i64 %37)
%39 = icmp ne i32 %38, 12
br i1 %39, label %40, label %41
40: ; preds = %30
store i32 -1, i32* %3
br label %42
41: ; preds = %30
store i32 0, i32* %3
br label %42
42: ; preds = %41, %40, %27
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [35 x i8] c"PTS should be less than 99 hours.\0A\00"
@.str.1 = [21 x i8] c"%02u:%02u:%02u,%03lu\00"
define i32 @srt_render_time(i64 %0, i8* %1) {
%3 = udiv i64 %0, 3600000
%4 = trunc i64 %3 to i32
%5 = udiv i64 %0, 1000
%6 = icmp ugt i32 %4, 99
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
br label %22
10: ; preds = %2
%11 = mul i64 %5, -1000
%12 = add i64 %11, %0
%13 = urem i64 %5, 60
%14 = trunc i64 %13 to i16
%15 = udiv i64 %0, 60000
%16 = urem i64 %15, 60
%17 = trunc i64 %16 to i16
%18 = tail call i32 @memset(i8* %1, i32 0, i32 13)
%19 = tail call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %4, i16 zeroext %17, i16 zeroext %14, i64 %12)
%20 = icmp ne i32 %19, 12
%21 = sext i1 %20 to i32
br label %22
22: ; preds = %10, %7
%23 = phi i32 [ -1, %7 ], [ %21, %10 ]
ret i32 %23
}