#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*/ ASAPWriter_SecondsToString(unsigned char *,
                                              int /*<<< orphan*/, int);
int /*<<< orphan*/ ASAPWriter_TwoDigitsToString(unsigned char *, int, int);
int ASAPWriter_DurationToString(unsigned char *result, int value) {
  if (!ASAPWriter_SecondsToString(result, 0, value))
    return 0;
  value %= 1000;
  if (value == 0)
    return 5;
  result[5] = 46;
  ASAPWriter_TwoDigitsToString(result, 6, value / 10);
  value %= 10;
  if (value == 0)
    return 8;
  result[8] = 48 + value;
  return 9;
}


x86 assembly (clang, -O0):
<ASAPWriter_DurationToString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
xor    %esi,%esi
call   1040 <ASAPWriter_SecondsToString@plt>
cmp    $0x0,%eax
jne    1152 <ASAPWriter_DurationToString+0x32>
movl   $0x0,-0x4(%rbp)
jmp    11d3 <ASAPWriter_DurationToString+0xb3>
mov    -0x14(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %edx,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1176 <ASAPWriter_DurationToString+0x56>
movl   $0x5,-0x4(%rbp)
jmp    11d3 <ASAPWriter_DurationToString+0xb3>
mov    -0x10(%rbp),%rax
movb   $0x2e,0x5(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,%edx
mov    $0x6,%esi
call   1030 <ASAPWriter_TwoDigitsToString@plt>
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    11bd <ASAPWriter_DurationToString+0x9d>
movl   $0x8,-0x4(%rbp)
jmp    11d3 <ASAPWriter_DurationToString+0xb3>
mov    -0x14(%rbp),%eax
add    $0x30,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x8(%rax)
movl   $0x9,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ASAPWriter_DurationToString>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r14
xor    %ebx,%ebx
xor    %esi,%esi
mov    %ebp,%edx
call   1040 <ASAPWriter_SecondsToString@plt>
test   %eax,%eax
je     11a5 <ASAPWriter_DurationToString+0x85>
movslq %ebp,%rax
imul   $0x10624dd3,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x26,%rax
add    %ecx,%eax
imul   $0x3e8,%eax,%eax
sub    %eax,%ebp
je     1199 <ASAPWriter_DurationToString+0x79>
movb   $0x2e,0x5(%r14)
movswl %bp,%ebp
imul   $0x6667,%ebp,%ebx
mov    %ebx,%eax
shr    $0x1f,%eax
sar    $0x12,%ebx
add    %eax,%ebx
mov    %r14,%rdi
mov    $0x6,%esi
mov    %ebx,%edx
call   1030 <ASAPWriter_TwoDigitsToString@plt>
add    %ebx,%ebx
lea    (%rbx,%rbx,4),%eax
sub    %ax,%bp
je     11a0 <ASAPWriter_DurationToString+0x80>
add    $0x30,%bpl
mov    %bpl,0x8(%r14)
mov    $0x9,%ebx
jmp    11a5 <ASAPWriter_DurationToString+0x85>
mov    $0x5,%ebx
jmp    11a5 <ASAPWriter_DurationToString+0x85>
mov    $0x8,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @ASAPWriter_DurationToString(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%6 = load i8*, i8** %4
%7 = load i32, i32* %5
%8 = call i32 @ASAPWriter_SecondsToString(i8* %6, i32 0, i32 %7)
%9 = icmp ne i32 %8, 0
br i1 %9, label %11, label %10
10: ; preds = %2
store i32 0, i32* %3
br label %35
11: ; preds = %2
%12 = load i32, i32* %5
%13 = srem i32 %12, 1000
store i32 %13, i32* %5
%14 = load i32, i32* %5
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %11
store i32 5, i32* %3
br label %35
17: ; preds = %11
%18 = load i8*, i8** %4
%19 = getelementptr inbounds i8, i8* %18, i64 5
store i8 46, i8* %19
%20 = load i8*, i8** %4
%21 = load i32, i32* %5
%22 = sdiv i32 %21, 10
%23 = call i32 @ASAPWriter_TwoDigitsToString(i8* %20, i32 6, i32 %22)
%24 = load i32, i32* %5
%25 = srem i32 %24, 10
store i32 %25, i32* %5
%26 = load i32, i32* %5
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %17
store i32 8, i32* %3
br label %35
29: ; preds = %17
%30 = load i32, i32* %5
%31 = add nsw i32 48, %30
%32 = trunc i32 %31 to i8
%33 = load i8*, i8** %4
%34 = getelementptr inbounds i8, i8* %33, i64 8
store i8 %32, i8* %34
store i32 9, i32* %3
br label %35
35: ; preds = %29, %28, %16, %10
%36 = load i32, i32* %3
ret i32 %36
}

LLVM IR (-O2):
define i32 @ASAPWriter_DurationToString(i8* %0, i32 %1) {
%3 = tail call i32 @ASAPWriter_SecondsToString(i8* %0, i32 0, i32 %1)
%4 = icmp eq i32 %3, 0
br i1 %4, label %20, label %5
5: ; preds = %2
%6 = srem i32 %1, 1000
%7 = icmp eq i32 %6, 0
br i1 %7, label %20, label %8
8: ; preds = %5
%9 = getelementptr inbounds i8, i8* %0, i64 5
store i8 46, i8* %9
%10 = trunc i32 %6 to i16
%11 = sdiv i16 %10, 10
%12 = sext i16 %11 to i32
%13 = tail call i32 @ASAPWriter_TwoDigitsToString(i8* %0, i32 6, i32 %12)
%14 = srem i16 %10, 10
%15 = icmp eq i16 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %8
%17 = trunc i16 %14 to i8
%18 = add nsw i8 %17, 48
%19 = getelementptr inbounds i8, i8* %0, i64 8
store i8 %18, i8* %19
br label %20
20: ; preds = %8, %5, %2, %16
%21 = phi i32 [ 9, %16 ], [ 0, %2 ], [ 5, %5 ], [ 8, %8 ]
ret i32 %21
}