#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*/ free(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *, char *);
char *strdup(char *);
char *strtok(char *, char *);
void formatDate(char *newDate, char *oldDate) {
  char *word, *toParse, *year, *month, *day;
  int numParses;
  numParses = 0;
  word = toParse = year = month = day = NULL;
  toParse = strdup(oldDate);
  word = strtok(toParse, "/");
  while (word != NULL) {
    switch (numParses) {
    case 0:
      month = strdup(word);
      break;
    case 1:
      day = strdup(word);
      break;
    case 2:
      year = strdup(word);
      break;
    }
    numParses++;
    word = strtok(NULL, "/");
  }
  sprintf(newDate, "%s/%s/%s", year, month, day);
  free(month);
  free(day);
  free(year);
  free(toParse);
}


x86 assembly (clang, -O0):
<formatDate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x3c(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe69(%rip),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1233 <formatDate+0xf3>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x40(%rbp)
test   %eax,%eax
je     11e0 <formatDate+0xa0>
jmp    11be <formatDate+0x7e>
mov    -0x40(%rbp),%eax
sub    $0x1,%eax
je     11f2 <formatDate+0xb2>
jmp    11cf <formatDate+0x8f>
mov    -0x40(%rbp),%eax
sub    $0x2,%eax
je     1204 <formatDate+0xc4>
jmp    1211 <formatDate+0xd1>
mov    -0x18(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x30(%rbp)
jmp    1211 <formatDate+0xd1>
mov    -0x18(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x38(%rbp)
jmp    1211 <formatDate+0xd1>
mov    -0x18(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x28(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xddb(%rip),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x18(%rbp)
jmp    11a0 <formatDate+0x60>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x38(%rbp),%r8
lea    0xdb8(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<formatDate>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,(%rsp)
mov    %rsi,%rdi
call   1060 <strdup@plt>
mov    %rax,%r15
lea    0xe9f(%rip),%rsi
mov    %rax,%rdi
call   1040 <strtok@plt>
xor    %r14d,%r14d
test   %rax,%rax
je     11dd <formatDate+0x9d>
lea    0xe88(%rip),%rbp
xor    %r13d,%r13d
xor    %ebx,%ebx
xor    %r12d,%r12d
jmp    11ae <formatDate+0x6e>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rax,%rdi
call   1060 <strdup@plt>
mov    %rax,%r12
add    $0x1,%r14d
xor    %edi,%edi
mov    %rbp,%rsi
call   1040 <strtok@plt>
test   %rax,%rax
je     11e5 <formatDate+0xa5>
cmp    $0x2,%r14d
je     1190 <formatDate+0x50>
cmp    $0x1,%r14d
je     11d0 <formatDate+0x90>
test   %r14d,%r14d
jne    119b <formatDate+0x5b>
mov    %rax,%rdi
call   1060 <strdup@plt>
mov    %rax,%rbx
jmp    119b <formatDate+0x5b>
nopl   0x0(%rax)
mov    %rax,%rdi
call   1060 <strdup@plt>
mov    %rax,%r13
jmp    119b <formatDate+0x5b>
xor    %r12d,%r12d
xor    %ebx,%ebx
xor    %r13d,%r13d
lea    0xe16(%rip),%rsi
mov    (%rsp),%rdi
mov    %r12,%rdx
mov    %rbx,%rcx
mov    %r13,%r8
call   1050 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r13,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
@.str.1 = [9 x i8] c"%s/%s/%s\00"
define void @formatDate(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %10
store i8* null, i8** %9
store i8* null, i8** %8
store i8* null, i8** %7
store i8* null, i8** %6
store i8* null, i8** %5
%11 = load i8*, i8** %4
%12 = call i8* @strdup(i8* %11)
store i8* %12, i8** %6
%13 = load i8*, i8** %6
%14 = call i8* @strtok(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %14, i8** %5
br label %15
15: ; preds = %29, %2
%16 = load i8*, i8** %5
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %33
18: ; preds = %15
%19 = load i32, i32* %10
switch i32 %19, label %29 [
i32 0, label %20
i32 1, label %23
i32 2, label %26
]
20: ; preds = %18
%21 = load i8*, i8** %5
%22 = call i8* @strdup(i8* %21)
store i8* %22, i8** %8
br label %29
23: ; preds = %18
%24 = load i8*, i8** %5
%25 = call i8* @strdup(i8* %24)
store i8* %25, i8** %9
br label %29
26: ; preds = %18
%27 = load i8*, i8** %5
%28 = call i8* @strdup(i8* %27)
store i8* %28, i8** %7
br label %29
29: ; preds = %18, %26, %23, %20
%30 = load i32, i32* %10
%31 = add nsw i32 %30, 1
store i32 %31, i32* %10
%32 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %32, i8** %5
br label %15
33: ; preds = %15
%34 = load i8*, i8** %3
%35 = load i8*, i8** %7
%36 = load i8*, i8** %8
%37 = load i8*, i8** %9
%38 = call i32 @sprintf(i8* %34, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %35, i8* %36, i8* %37)
%39 = load i8*, i8** %8
%40 = call i32 @free(i8* %39)
%41 = load i8*, i8** %9
%42 = call i32 @free(i8* %41)
%43 = load i8*, i8** %7
%44 = call i32 @free(i8* %43)
%45 = load i8*, i8** %6
%46 = call i32 @free(i8* %45)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
@.str.1 = [9 x i8] c"%s/%s/%s\00"
define void @formatDate(i8* nocapture writeonly %0, i8* nocapture %1) {
%3 = tail call i8* @strdup(i8* %1)
%4 = tail call i8* @strtok(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i8* %4, null
br i1 %5, label %25, label %6
6: ; preds = %2, %18
%7 = phi i32 [ %22, %18 ], [ 0, %2 ]
%8 = phi i8* [ %21, %18 ], [ null, %2 ]
%9 = phi i8* [ %20, %18 ], [ null, %2 ]
%10 = phi i8* [ %19, %18 ], [ null, %2 ]
%11 = phi i8* [ %23, %18 ], [ %4, %2 ]
switch i32 %7, label %18 [
i32 0, label %12
i32 1, label %14
i32 2, label %16
]
12: ; preds = %6
%13 = tail call i8* @strdup(i8* %11)
br label %18
14: ; preds = %6
%15 = tail call i8* @strdup(i8* %11)
br label %18
16: ; preds = %6
%17 = tail call i8* @strdup(i8* %11)
br label %18
18: ; preds = %6, %16, %14, %12
%19 = phi i8* [ %10, %6 ], [ %17, %16 ], [ %10, %14 ], [ %10, %12 ]
%20 = phi i8* [ %9, %6 ], [ %9, %16 ], [ %9, %14 ], [ %13, %12 ]
%21 = phi i8* [ %8, %6 ], [ %8, %16 ], [ %15, %14 ], [ %8, %12 ]
%22 = add nuw nsw i32 %7, 1
%23 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %6
25: ; preds = %18, %2
%26 = phi i8* [ null, %2 ], [ %19, %18 ]
%27 = phi i8* [ null, %2 ], [ %20, %18 ]
%28 = phi i8* [ null, %2 ], [ %21, %18 ]
%29 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %26, i8* %27, i8* %28)
%30 = tail call i32 @free(i8* %27)
%31 = tail call i32 @free(i8* %28)
%32 = tail call i32 @free(i8* %26)
%33 = tail call i32 @free(i8* %3)
ret void
}