#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ strcat(int /*<<< orphan*/, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *translateDate(char *date) {
  int size = strlen(date);
  int pos_dest = strlen(date) - 1;
  char day[3];
  char month[3];
  char year[5];
  strncpy(day, date, 2);
  day[2] = '\0';
  date += 3;
  strncpy(month, date, 2);
  month[2] = '\0';
  date += 3;
  strncpy(year, date, 4);
  year[4] = '\0';
  char *dest = (char *)malloc(size);
  strcat(strcat(strcat(strcat(strcpy(dest, year), "-"), month), "-"), day);
  return dest;
}


x86 assembly (clang, -O0):
<translateDate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
lea    -0x13(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x2,%edx
call   1030 <strncpy@plt>
movb   $0x0,-0x11(%rbp)
mov    -0x8(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x8(%rbp)
lea    -0x16(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x2,%edx
call   1030 <strncpy@plt>
movb   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x8(%rbp)
lea    -0x1b(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
movb   $0x0,-0x17(%rbp)
mov    -0xc(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    -0x1b(%rbp),%rsi
call   1040 <strcpy@plt>
mov    %eax,%edi
lea    0xe0d(%rip),%rsi
call   1070 <strcat@plt>
mov    %eax,%edi
lea    -0x16(%rbp),%rsi
call   1070 <strcat@plt>
mov    %eax,%edi
lea    0xdf4(%rip),%rsi
call   1070 <strcat@plt>
mov    %eax,%edi
lea    -0x13(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<translateDate>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
call   1050 <strlen@plt>
mov    %eax,%r12d
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0x8(%rsp),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x2,%edx
call   1030 <strncpy@plt>
movb   $0x0,0xa(%rsp)
lea    0x3(%rbx),%rsi
lea    0x5(%rsp),%r15
mov    %r15,%rdi
mov    $0x2,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x7(%rsp)
add    $0x6,%rbx
lea    0xb(%rsp),%rbp
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
movb   $0x0,0xf(%rsp)
mov    %r12d,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %rbp,%rsi
call   1040 <strcpy@plt>
lea    0xe21(%rip),%rbp
mov    %eax,%edi
mov    %rbp,%rsi
call   1070 <strcat@plt>
mov    %eax,%edi
mov    %r15,%rsi
call   1070 <strcat@plt>
mov    %eax,%edi
mov    %rbp,%rsi
call   1070 <strcat@plt>
mov    %eax,%edi
mov    %r14,%rsi
call   1070 <strcat@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"-\00"
define i8* @translateDate(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca [3 x i8]
%6 = alloca [3 x i8]
%7 = alloca [5 x i8]
%8 = alloca i8*
store i8* %0, i8** %2
%9 = load i8*, i8** %2
%10 = call i32 @strlen(i8* %9)
store i32 %10, i32* %3
%11 = load i8*, i8** %2
%12 = call i32 @strlen(i8* %11)
%13 = sub nsw i32 %12, 1
store i32 %13, i32* %4
%14 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
%15 = load i8*, i8** %2
%16 = call i32 @strncpy(i8* %14, i8* %15, i32 2)
%17 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 2
store i8 0, i8* %17
%18 = load i8*, i8** %2
%19 = getelementptr inbounds i8, i8* %18, i64 3
store i8* %19, i8** %2
%20 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 0
%21 = load i8*, i8** %2
%22 = call i32 @strncpy(i8* %20, i8* %21, i32 2)
%23 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 2
store i8 0, i8* %23
%24 = load i8*, i8** %2
%25 = getelementptr inbounds i8, i8* %24, i64 3
store i8* %25, i8** %2
%26 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 0
%27 = load i8*, i8** %2
%28 = call i32 @strncpy(i8* %26, i8* %27, i32 4)
%29 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 4
store i8 0, i8* %29
%30 = load i32, i32* %3
%31 = call i64 @malloc(i32 %30)
%32 = inttoptr i64 %31 to i8*
store i8* %32, i8** %8
%33 = load i8*, i8** %8
%34 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 0
%35 = call i32 @strcpy(i8* %33, i8* %34)
%36 = call i32 @strcat(i32 %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%37 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 0
%38 = call i32 @strcat(i32 %36, i8* %37)
%39 = call i32 @strcat(i32 %38, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%40 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
%41 = call i32 @strcat(i32 %39, i8* %40)
%42 = load i8*, i8** %8
ret i8* %42
}

LLVM IR (-O2):
@.str = [2 x i8] c"-\00"
define i8* @translateDate(i8* %0) {
%2 = alloca [3 x i8]
%3 = alloca [3 x i8]
%4 = alloca [5 x i8]
%5 = tail call i32 @strlen(i8* %0)
%6 = tail call i32 @strlen(i8* %0)
%7 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 0
%8 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%9 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%10 = call i32 @strncpy(i8* %7, i8* %0, i32 2)
%11 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 2
store i8 0, i8* %11
%12 = getelementptr inbounds i8, i8* %0, i64 3
%13 = call i32 @strncpy(i8* %8, i8* %12, i32 2)
%14 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 2
store i8 0, i8* %14
%15 = getelementptr inbounds i8, i8* %0, i64 6
%16 = call i32 @strncpy(i8* %9, i8* %15, i32 4)
%17 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 4
store i8 0, i8* %17
%18 = call i64 @malloc(i32 %5)
%19 = inttoptr i64 %18 to i8*
%20 = call i32 @strcpy(i8* %19, i8* %9)
%21 = call i32 @strcat(i32 %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%22 = call i32 @strcat(i32 %21, i8* %8)
%23 = call i32 @strcat(i32 %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%24 = call i32 @strcat(i32 %23, i8* %7)
ret i8* %19
}