#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 formatTime(char *newTime, char *oldTime) {
  char *word, *toParse, *hours, *minutes, *seconds;
  int numParses;
  numParses = 0;
  word = toParse = hours = minutes = seconds = NULL;
  toParse = strdup(oldTime);
  word = strtok(toParse, ":");
  while (word != NULL) {
    switch (numParses) {
    case 0:
      hours = strdup(word);
      break;
    case 1:
      minutes = strdup(word);
      break;
    case 2:
      seconds = strdup(word);
      break;
    }
    numParses++;
    word = strtok(NULL, ":");
  }
  sprintf(newTime, "%s:%s:%s", hours, minutes, seconds);
  free(hours);
  free(minutes);
  free(seconds);
  free(toParse);
}


x86 assembly (clang, -O0):
<formatTime>:
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 <formatTime+0xf3>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x40(%rbp)
test   %eax,%eax
je     11e0 <formatTime+0xa0>
jmp    11be <formatTime+0x7e>
mov    -0x40(%rbp),%eax
sub    $0x1,%eax
je     11f2 <formatTime+0xb2>
jmp    11cf <formatTime+0x8f>
mov    -0x40(%rbp),%eax
sub    $0x2,%eax
je     1204 <formatTime+0xc4>
jmp    1211 <formatTime+0xd1>
mov    -0x18(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x28(%rbp)
jmp    1211 <formatTime+0xd1>
mov    -0x18(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x30(%rbp)
jmp    1211 <formatTime+0xd1>
mov    -0x18(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x38(%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 <formatTime+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    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<formatTime>:
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 <formatTime+0x9d>
lea    0xe88(%rip),%rbp
xor    %r12d,%r12d
xor    %r13d,%r13d
xor    %ebx,%ebx
jmp    11ae <formatTime+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 <formatTime+0xa5>
cmp    $0x2,%r14d
je     1190 <formatTime+0x50>
cmp    $0x1,%r14d
je     11d0 <formatTime+0x90>
test   %r14d,%r14d
jne    119b <formatTime+0x5b>
mov    %rax,%rdi
call   1060 <strdup@plt>
mov    %rax,%rbx
jmp    119b <formatTime+0x5b>
nopl   0x0(%rax)
mov    %rax,%rdi
call   1060 <strdup@plt>
mov    %rax,%r13
jmp    119b <formatTime+0x5b>
xor    %ebx,%ebx
xor    %r13d,%r13d
xor    %r12d,%r12d
lea    0xe16(%rip),%rsi
mov    (%rsp),%rdi
mov    %rbx,%rdx
mov    %r13,%rcx
mov    %r12,%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 @formatTime(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** %7
br label %29
23: ; preds = %18
%24 = load i8*, i8** %5
%25 = call i8* @strdup(i8* %24)
store i8* %25, i8** %8
br label %29
26: ; preds = %18
%27 = load i8*, i8** %5
%28 = call i8* @strdup(i8* %27)
store i8* %28, i8** %9
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** %7
%40 = call i32 @free(i8* %39)
%41 = load i8*, i8** %8
%42 = call i32 @free(i8* %41)
%43 = load i8*, i8** %9
%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 @formatTime(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 ], [ %10, %16 ], [ %10, %14 ], [ %13, %12 ]
%20 = phi i8* [ %9, %6 ], [ %9, %16 ], [ %15, %14 ], [ %9, %12 ]
%21 = phi i8* [ %8, %6 ], [ %17, %16 ], [ %8, %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* %26)
%31 = tail call i32 @free(i8* %27)
%32 = tail call i32 @free(i8* %28)
%33 = tail call i32 @free(i8* %3)
ret void
}