#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 */
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
typedef int time_t;
struct TYPE_3__ {
  size_t rem;
  int quot;
};
typedef TYPE_1__ div_t;

/* Variables and functions */
TYPE_1__ div(int, int);
int /*<<< orphan*/ strreverse(unsigned char *, unsigned char *);
size_t hawkc_ttoa(unsigned char *buf, time_t value) {
  static unsigned char num[] = "0123456789";
  unsigned char *wstr = buf;
  int sign;
  div_t res;
  if ((sign = value) < 0)
    value = -value;
  do {
    res = div(value, 10);
    *wstr++ = num[res.rem];
    value = res.quot;
  } while (value);
  if (sign < 0)
    *wstr++ = '-';
  strreverse(buf, wstr - 1);
  return wstr - buf;
}


x86 assembly (clang, -O0):
<hawkc_ttoa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    114e <hawkc_ttoa+0x2e>
xor    %eax,%eax
sub    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    1153 <hawkc_ttoa+0x33>
mov    -0xc(%rbp),%edi
mov    $0xa,%esi
call   1040 <div@plt>
mov    %rax,-0x40(%rbp)
mov    %edx,-0x38(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rcx
lea    0x2eae(%rip),%rax
mov    (%rax,%rcx,1),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
mov    -0x28(%rbp),%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1153 <hawkc_ttoa+0x33>
cmpl   $0x0,-0x1c(%rbp)
jge    11c2 <hawkc_ttoa+0xa2>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x2d,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
add    $0xffffffffffffffff,%rsi
call   1030 <strreverse@plt>
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hawkc_ttoa>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %rdi,%r14
mov    %esi,%edx
neg    %edx
cmovs  %esi,%edx
lea    0xec5(%rip),%rbp
mov    %rdi,%rbx
xchg   %ax,%ax
mov    %edx,%edi
mov    $0xa,%esi
call   1040 <div@plt>
movzbl (%rax,%rbp,1),%eax
mov    %al,(%rbx)
add    $0x1,%rbx
test   %edx,%edx
jne    1140 <hawkc_ttoa+0x20>
test   %r15d,%r15d
jns    1166 <hawkc_ttoa+0x46>
movb   $0x2d,(%rbx)
add    $0x1,%rbx
lea    -0x1(%rbx),%rsi
mov    %r14,%rdi
call   1030 <strreverse@plt>
sub    %r14,%rbx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i64, i32 }
@hawkc_ttoa.num = internal global [11 x i8] c"0123456789\00"
define i64 @hawkc_ttoa(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca %struct.TYPE_3__
%8 = alloca %struct.TYPE_3__
store i8* %0, i8** %3
store i32 %1, i32* %4
%9 = load i8*, i8** %3
store i8* %9, i8** %5
%10 = load i32, i32* %4
store i32 %10, i32* %6
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i32, i32* %4
%14 = sub nsw i32 0, %13
store i32 %14, i32* %4
br label %15
15: ; preds = %12, %2
br label %16
16: ; preds = %34, %15
%17 = load i32, i32* %4
%18 = call { i64, i32 } @div(i32 %17, i32 10)
%19 = bitcast %struct.TYPE_3__* %8 to { i64, i32 }*
%20 = getelementptr inbounds { i64, i32 }, { i64, i32 }* %19, i32 0, i32 0
%21 = extractvalue { i64, i32 } %18, 0
store i64 %21, i64* %20
%22 = getelementptr inbounds { i64, i32 }, { i64, i32 }* %19, i32 0, i32 1
%23 = extractvalue { i64, i32 } %18, 1
store i32 %23, i32* %22
%24 = bitcast %struct.TYPE_3__* %7 to i8*
%25 = bitcast %struct.TYPE_3__* %8 to i8*
%26 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %7, i32 0, i32 0
%27 = load i64, i64* %26
%28 = getelementptr inbounds [11 x i8], [11 x i8]* @hawkc_ttoa.num, i64 0, i64 %27
%29 = load i8, i8* %28
%30 = load i8*, i8** %5
%31 = getelementptr inbounds i8, i8* %30, i32 1
store i8* %31, i8** %5
store i8 %29, i8* %30
%32 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %7, i32 0, i32 1
%33 = load i32, i32* %32
store i32 %33, i32* %4
br label %34
34: ; preds = %16
%35 = load i32, i32* %4
%36 = icmp ne i32 %35, 0
br i1 %36, label %16, label %37
37: ; preds = %34
%38 = load i32, i32* %6
%39 = icmp slt i32 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %37
%41 = load i8*, i8** %5
%42 = getelementptr inbounds i8, i8* %41, i32 1
store i8* %42, i8** %5
store i8 45, i8* %41
br label %43
43: ; preds = %40, %37
%44 = load i8*, i8** %3
%45 = load i8*, i8** %5
%46 = getelementptr inbounds i8, i8* %45, i64 -1
%47 = call i32 @strreverse(i8* %44, i8* %46)
%48 = load i8*, i8** %5
%49 = load i8*, i8** %3
%50 = ptrtoint i8* %48 to i64
%51 = ptrtoint i8* %49 to i64
%52 = sub i64 %50, %51
ret i64 %52
}

LLVM IR (-O2):
@hawkc_ttoa.num = internal unnamed_addr constant [11 x i8] c"0123456789\00"
define i64 @hawkc_ttoa(i8* %0, i32 %1) {
%3 = icmp slt i32 %1, 0
%4 = sub nsw i32 0, %1
%5 = select i1 %3, i32 %4, i32 %1
br label %6
6: ; preds = %6, %2
%7 = phi i8* [ %0, %2 ], [ %14, %6 ]
%8 = phi i32 [ %5, %2 ], [ %11, %6 ]
%9 = tail call { i64, i32 } @div(i32 %8, i32 10)
%10 = extractvalue { i64, i32 } %9, 0
%11 = extractvalue { i64, i32 } %9, 1
%12 = getelementptr inbounds [11 x i8], [11 x i8]* @hawkc_ttoa.num, i64 0, i64 %10
%13 = load i8, i8* %12
%14 = getelementptr inbounds i8, i8* %7, i64 1
store i8 %13, i8* %7
%15 = icmp eq i32 %11, 0
br i1 %15, label %16, label %6
16: ; preds = %6
br i1 %3, label %17, label %19
17: ; preds = %16
%18 = getelementptr inbounds i8, i8* %7, i64 2
store i8 45, i8* %14
br label %19
19: ; preds = %17, %16
%20 = phi i8* [ %18, %17 ], [ %14, %16 ]
%21 = getelementptr inbounds i8, i8* %20, i64 -1
%22 = tail call i32 @strreverse(i8* %0, i8* %21)
%23 = ptrtoint i8* %20 to i64
%24 = ptrtoint i8* %0 to i64
%25 = sub i64 %23, %24
ret i64 %25
}