#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*/ strrev(char *);
char *itoa_date(unsigned long long int x, char *buffer) {
  char *c = buffer;
  if (x < 10) {
    switch (x) {
    case 0:
      return "00";
    case 1:
      return "01";
    case 2:
      return "02";
    case 3:
      return "03";
    case 4:
      return "04";
    case 5:
      return "05";
    case 6:
      return "06";
    case 7:
      return "07";
    case 8:
      return "08";
    case 9:
      return "09";
    }
  }
  while (x) {
    *c = x % 10 + '0';
    x = x / 10;
    c++;
  }
  *c = 0;
  strrev(buffer);
  return buffer;
}


x86 assembly (clang, -O0):
<itoa_date>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0xa,-0x10(%rbp)
jae    11fe <itoa_date+0xee>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
sub    $0x9,%rax
ja     11f9 <itoa_date+0xe9>
mov    -0x28(%rbp),%rax
lea    0xeb0(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xec8(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1263 <itoa_date+0x153>
lea    0xebb(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1263 <itoa_date+0x153>
lea    0xeae(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1263 <itoa_date+0x153>
lea    0xea1(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1263 <itoa_date+0x153>
lea    0xe94(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1263 <itoa_date+0x153>
lea    0xe87(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1263 <itoa_date+0x153>
lea    0xe7a(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1263 <itoa_date+0x153>
lea    0xe6d(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1263 <itoa_date+0x153>
lea    0xe60(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1263 <itoa_date+0x153>
lea    0xe53(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1263 <itoa_date+0x153>
jmp    11fe <itoa_date+0xee>
jmp    1203 <itoa_date+0xf3>
cmpq   $0x0,-0x10(%rbp)
je     124b <itoa_date+0x13b>
mov    -0x10(%rbp),%rax
mov    $0xa,%ecx
xor    %edx,%edx
div    %rcx
add    $0x30,%rdx
mov    %dl,%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
mov    $0xa,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1203 <itoa_date+0xf3>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
call   1030 <strrev@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<itoa_date>:
push   %r14
push   %rbx
push   %rax
cmp    $0xa,%rdi
jae    112a <itoa_date+0x1a>
lea    0xeff(%rip),%rax
movslq (%rax,%rdi,4),%r14
add    %rax,%r14
jmp    1171 <itoa_date+0x61>
mov    %rsi,%r14
movabs $0xcccccccccccccccd,%rsi
cc cc cc
mov    %r14,%rcx
nopw   0x0(%rax,%rax,1)
mov    %rdi,%rax
mul    %rsi
shr    $0x3,%rdx
lea    (%rdx,%rdx,1),%eax
lea    (%rax,%rax,4),%eax
mov    %edi,%ebx
sub    %eax,%ebx
or     $0x30,%bl
mov    %bl,(%rcx)
add    $0x1,%rcx
cmp    $0x9,%rdi
mov    %rdx,%rdi
ja     1140 <itoa_date+0x30>
movb   $0x0,(%rcx)
mov    %r14,%rdi
call   1030 <strrev@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [3 x i8] c"00\00"
@.str.1 = [3 x i8] c"01\00"
@.str.2 = [3 x i8] c"02\00"
@.str.3 = [3 x i8] c"03\00"
@.str.4 = [3 x i8] c"04\00"
@.str.5 = [3 x i8] c"05\00"
@.str.6 = [3 x i8] c"06\00"
@.str.7 = [3 x i8] c"07\00"
@.str.8 = [3 x i8] c"08\00"
@.str.9 = [3 x i8] c"09\00"
define i8* @itoa_date(i64 %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i8*
store i64 %0, i64* %4
store i8* %1, i8** %5
%7 = load i8*, i8** %5
store i8* %7, i8** %6
%8 = load i64, i64* %4
%9 = icmp ult i64 %8, 10
br i1 %9, label %10, label %23
10: ; preds = %2
%11 = load i64, i64* %4
switch i64 %11, label %22 [
i64 0, label %12
i64 1, label %13
i64 2, label %14
i64 3, label %15
i64 4, label %16
i64 5, label %17
i64 6, label %18
i64 7, label %19
i64 8, label %20
i64 9, label %21
]
12: ; preds = %10
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %3
br label %42
13: ; preds = %10
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %3
br label %42
14: ; preds = %10
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %3
br label %42
15: ; preds = %10
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8** %3
br label %42
16: ; preds = %10
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8** %3
br label %42
17: ; preds = %10
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8** %3
br label %42
18: ; preds = %10
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8** %3
br label %42
19: ; preds = %10
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8** %3
br label %42
20: ; preds = %10
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i8** %3
br label %42
21: ; preds = %10
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i8** %3
br label %42
22: ; preds = %10
br label %23
23: ; preds = %22, %2
br label %24
24: ; preds = %27, %23
%25 = load i64, i64* %4
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %37
27: ; preds = %24
%28 = load i64, i64* %4
%29 = urem i64 %28, 10
%30 = add i64 %29, 48
%31 = trunc i64 %30 to i8
%32 = load i8*, i8** %6
store i8 %31, i8* %32
%33 = load i64, i64* %4
%34 = udiv i64 %33, 10
store i64 %34, i64* %4
%35 = load i8*, i8** %6
%36 = getelementptr inbounds i8, i8* %35, i32 1
store i8* %36, i8** %6
br label %24
37: ; preds = %24
%38 = load i8*, i8** %6
store i8 0, i8* %38
%39 = load i8*, i8** %5
%40 = call i32 @strrev(i8* %39)
%41 = load i8*, i8** %5
store i8* %41, i8** %3
br label %42
42: ; preds = %37, %21, %20, %19, %18, %17, %16, %15, %14, %13, %12
%43 = load i8*, i8** %3
ret i8* %43
}

LLVM IR (-O2):
@.str = [3 x i8] c"00\00"
@.str.1 = [3 x i8] c"01\00"
@.str.2 = [3 x i8] c"02\00"
@.str.3 = [3 x i8] c"03\00"
@.str.4 = [3 x i8] c"04\00"
@.str.5 = [3 x i8] c"05\00"
@.str.6 = [3 x i8] c"06\00"
@.str.7 = [3 x i8] c"07\00"
@.str.8 = [3 x i8] c"08\00"
@.str.9 = [3 x i8] c"09\00"
@reltable.itoa_date = [10 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str to i64), i64 ptrtoint ([10 x i32]* @reltable.itoa_date to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str.1 to i64), i64 ptrtoint ([10 x i32]* @reltable.itoa_date to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str.2 to i64), i64 ptrtoint ([10 x i32]* @reltable.itoa_date to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str.3 to i64), i64 ptrtoint ([10 x i32]* @reltable.itoa_date to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str.4 to i64), i64 ptrtoint ([10 x i32]* @reltable.itoa_date to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str.5 to i64), i64 ptrtoint ([10 x i32]* @reltable.itoa_date to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str.6 to i64), i64 ptrtoint ([10 x i32]* @reltable.itoa_date to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str.7 to i64), i64 ptrtoint ([10 x i32]* @reltable.itoa_date to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str.8 to i64), i64 ptrtoint ([10 x i32]* @reltable.itoa_date to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str.9 to i64), i64 ptrtoint ([10 x i32]* @reltable.itoa_date to i64)) to i32)]
define i8* @itoa_date(i64 %0, i8* %1) {
%3 = icmp ult i64 %0, 10
br i1 %3, label %15, label %4
4: ; preds = %2, %4
%5 = phi i8* [ %11, %4 ], [ %1, %2 ]
%6 = phi i64 [ %10, %4 ], [ %0, %2 ]
%7 = urem i64 %6, 10
%8 = trunc i64 %7 to i8
%9 = or i8 %8, 48
store i8 %9, i8* %5
%10 = udiv i64 %6, 10
%11 = getelementptr inbounds i8, i8* %5, i64 1
%12 = icmp ult i64 %6, 10
br i1 %12, label %13, label %4
13: ; preds = %4
store i8 0, i8* %11
%14 = tail call i32 @strrev(i8* %1)
br label %18
15: ; preds = %2
%16 = shl i64 %0, 2
%17 = call i8* @llvm.load.relative.i64(i8* bitcast ([10 x i32]* @reltable.itoa_date to i8*), i64 %16)
br label %18
18: ; preds = %15, %13
%19 = phi i8* [ %1, %13 ], [ %17, %15 ]
ret i8* %19
}