#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(scalar_t__);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *, char *);
scalar_t__ strlen(char *);
char *strtok(char *, char *);
char *transform_date(char *date) {
  char *aux = (char *)malloc(strlen(date) + 1);
  char *d = strtok(date, "/");
  char *m = strtok(NULL, "/");
  char *y = strtok(NULL, "/");
  sprintf(aux, "%s-%s-%s", y, m, d);
  return aux;
}


x86 assembly (clang, -O0):
<transform_date>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe90(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe7c(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe68(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x18(%rbp),%r8
lea    0xe4a(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<transform_date>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <strlen@plt>
lea    0x1(%rax),%rdi
call   1040 <malloc@plt>
mov    %rax,%r14
lea    0xe9d(%rip),%r15
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <strtok@plt>
mov    %rax,%r12
xor    %edi,%edi
mov    %r15,%rsi
call   1050 <strtok@plt>
mov    %rax,%rbx
xor    %edi,%edi
mov    %r15,%rsi
call   1050 <strtok@plt>
lea    0xe73(%rip),%rsi
mov    %r14,%rdi
mov    %rax,%rdx
mov    %rbx,%rcx
mov    %r12,%r8
call   1060 <sprintf@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
@.str.1 = [9 x i8] c"%s-%s-%s\00"
define i8* @transform_date(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = call i64 @strlen(i8* %7)
%9 = add nsw i64 %8, 1
%10 = call i64 @malloc(i64 %9)
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %3
%12 = load i8*, i8** %2
%13 = call i8* @strtok(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %13, i8** %4
%14 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %14, i8** %5
%15 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %15, i8** %6
%16 = load i8*, i8** %3
%17 = load i8*, i8** %6
%18 = load i8*, i8** %5
%19 = load i8*, i8** %4
%20 = call i32 @sprintf(i8* %16, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %17, i8* %18, i8* %19)
%21 = load i8*, i8** %3
ret i8* %21
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
@.str.1 = [9 x i8] c"%s-%s-%s\00"
define i8* @transform_date(i8* %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = add nsw i64 %2, 1
%4 = tail call i64 @malloc(i64 %3)
%5 = inttoptr i64 %4 to i8*
%6 = tail call i8* @strtok(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @sprintf(i8* dereferenceable(1) %5, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %8, i8* %7, i8* %6)
ret i8* %5
}