#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__ fprintf(int /*<<< orphan*/ *, char *, unsigned long, unsigned long,
                   unsigned long, unsigned long);
int Write_SRT_Timestamp(FILE *outf, unsigned long timestamp) {
  unsigned long hours = 0, minutes = 0, seconds = 0, millis = 0;
  if (outf == NULL)
    return -1;
  hours = timestamp / 3600000;
  timestamp -= (hours * 3600000);
  minutes = timestamp / 60000;
  timestamp -= (minutes * 60000);
  seconds = timestamp / 1000;
  timestamp -= (seconds * 1000);
  millis = timestamp;
  if (fprintf(outf, "%02lu:%02lu:%02lu,%03lu", hours, minutes, seconds,
              millis) < 0)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<Write_SRT_Timestamp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1157 <Write_SRT_Timestamp+0x47>
movl   $0xffffffff,-0x4(%rbp)
jmp    120b <Write_SRT_Timestamp+0xfb>
mov    -0x18(%rbp),%rax
mov    $0x36ee80,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,-0x20(%rbp)
imul   $0x36ee80,-0x20(%rbp),%rcx
mov    -0x18(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    $0xea60,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,-0x28(%rbp)
imul   $0xea60,-0x28(%rbp),%rcx
mov    -0x18(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    $0x3e8,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,-0x30(%rbp)
imul   $0x3e8,-0x30(%rbp),%rcx
mov    -0x18(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%r8
mov    -0x38(%rbp),%r9
lea    0xe17(%rip),%rsi
call   1030 <fprintf@plt>
cmp    $0x0,%rax
jge    1204 <Write_SRT_Timestamp+0xf4>
movl   $0xffffffff,-0x4(%rbp)
jmp    120b <Write_SRT_Timestamp+0xfb>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Write_SRT_Timestamp>:
test   %rdi,%rdi
je     11a0 <Write_SRT_Timestamp+0x90>
push   %rax
movabs $0x4a90be587de6e565,%rcx
be 90 4a
mov    %rsi,%rax
mul    %rcx
mov    %rdx,%r8
shr    $0x14,%r8
imul   $0xffffffffffc91180,%r8,%r9
add    %rsi,%r9
mov    %r9,%rax
shr    $0x5,%rax
movabs $0x45e7b272f608771,%rcx
7b 5e 04
mul    %rcx
mov    %rdx,%rcx
shr    $0x5,%rcx
imul   $0xffffffffffff15a0,%rcx,%rsi
add    %r9,%rsi
mov    %rsi,%rax
shr    $0x3,%rax
movabs $0x20c49ba5e353f7cf,%rdx
9b c4 20
mul    %rdx
mov    %rdx,%rax
shr    $0x4,%rax
imul   $0xfffffffffffffc18,%rax,%r9
add    %rsi,%r9
lea    0xe74(%rip),%rsi
mov    %r8,%rdx
mov    %rax,%r8
call   1030 <fprintf@plt>
sar    $0x3f,%rax
add    $0x8,%rsp
ret
mov    $0xffffffff,%eax
ret

LLVM IR (-O0):
@.str = [24 x i8] c"%02lu:%02lu:%02lu,%03lu\00"
define i32 @Write_SRT_Timestamp(i32* %0, i64 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
store i32* %0, i32** %4
store i64 %1, i64* %5
store i64 0, i64* %6
store i64 0, i64* %7
store i64 0, i64* %8
store i64 0, i64* %9
%10 = load i32*, i32** %4
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 -1, i32* %3
br label %42
13: ; preds = %2
%14 = load i64, i64* %5
%15 = udiv i64 %14, 3600000
store i64 %15, i64* %6
%16 = load i64, i64* %6
%17 = mul i64 %16, 3600000
%18 = load i64, i64* %5
%19 = sub i64 %18, %17
store i64 %19, i64* %5
%20 = load i64, i64* %5
%21 = udiv i64 %20, 60000
store i64 %21, i64* %7
%22 = load i64, i64* %7
%23 = mul i64 %22, 60000
%24 = load i64, i64* %5
%25 = sub i64 %24, %23
store i64 %25, i64* %5
%26 = load i64, i64* %5
%27 = udiv i64 %26, 1000
store i64 %27, i64* %8
%28 = load i64, i64* %8
%29 = mul i64 %28, 1000
%30 = load i64, i64* %5
%31 = sub i64 %30, %29
store i64 %31, i64* %5
%32 = load i64, i64* %5
store i64 %32, i64* %9
%33 = load i32*, i32** %4
%34 = load i64, i64* %6
%35 = load i64, i64* %7
%36 = load i64, i64* %8
%37 = load i64, i64* %9
%38 = call i64 @fprintf(i32* %33, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i64 %34, i64 %35, i64 %36, i64 %37)
%39 = icmp slt i64 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %13
store i32 -1, i32* %3
br label %42
41: ; preds = %13
store i32 0, i32* %3
br label %42
42: ; preds = %41, %40, %12
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
@.str = [24 x i8] c"%02lu:%02lu:%02lu,%03lu\00"
define i32 @Write_SRT_Timestamp(i32* %0, i64 %1) {
%3 = icmp eq i32* %0, null
br i1 %3, label %17, label %4
4: ; preds = %2
%5 = udiv i64 %1, 3600000
%6 = mul i64 %5, -3600000
%7 = add i64 %6, %1
%8 = udiv i64 %7, 60000
%9 = mul i64 %8, -60000
%10 = add i64 %9, %7
%11 = udiv i64 %10, 1000
%12 = mul i64 %11, -1000
%13 = add i64 %12, %10
%14 = tail call i64 @fprintf(i32* %0, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i64 %5, i64 %8, i64 %11, i64 %13)
%15 = ashr i64 %14, 63
%16 = trunc i64 %15 to i32
br label %17
17: ; preds = %4, %2
%18 = phi i32 [ -1, %2 ], [ %16, %4 ]
ret i32 %18
}