void cli_create_default_file(char *target_file_spec,
                             const char *source_file_spec,
                             const char *target_file_ext) {
  char *token;
  char *prev_token;
  char *dot_posn;
  strcpy(target_file_spec, source_file_spec);
  prev_token = target_file_spec;
  token = strtok(target_file_spec, "/");
  while (token != ((void *)0)) {
    prev_token = token;
    token = strtok(((void *)0), "/");
  }
  memmove(target_file_spec, prev_token, strlen(prev_token) + 1);
  dot_posn = strrchr(target_file_spec, '.');
  if (dot_posn == ((void *)0))
    strcat(target_file_spec, target_file_ext);
  else
    strcpy(dot_posn, target_file_ext);
}


x86 assembly (clang, -O0):
<cli_create_default_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe6c(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11c9 <cli_create_default_file+0x69>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe45(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x20(%rbp)
jmp    119d <cli_create_default_file+0x3d>
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1060 <memmove@plt>
mov    -0x8(%rbp),%rdi
mov    $0x2e,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1225 <cli_create_default_file+0xc5>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1080 <strcat@plt>
jmp    1232 <cli_create_default_file+0xd2>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cli_create_default_file>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rdi,%r15
call   1030 <strcpy@plt>
lea    0xe86(%rip),%rsi
mov    %r15,%rdi
call   1070 <strtok@plt>
mov    %r15,%rbx
test   %rax,%rax
je     11b2 <cli_create_default_file+0x52>
lea    0xe6f(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rax,%rbx
xor    %edi,%edi
mov    %r12,%rsi
call   1070 <strtok@plt>
test   %rax,%rax
jne    11a0 <cli_create_default_file+0x40>
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <memmove@plt>
mov    %r15,%rdi
mov    $0x2e,%esi
call   1050 <strrchr@plt>
test   %rax,%rax
je     11f1 <cli_create_default_file+0x91>
mov    %rax,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <strcpy@plt>
mov    %r15,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1080 <strcat@plt>

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

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
define void @cli_create_default_file(i8* %0, i8* nocapture %1, i8* nocapture %2) {
%4 = tail call i8* @strcpy(i8* dereferenceable(1) %0, i8* dereferenceable(1) %1)
%5 = tail call i8* @strtok(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i8* %5, null
br i1 %6, label %11, label %7
7: ; preds = %3, %7
%8 = phi i8* [ %9, %7 ], [ %5, %3 ]
%9 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %7
11: ; preds = %7, %3
%12 = phi i8* [ %0, %3 ], [ %8, %7 ]
%13 = tail call i64 @strlen(i8* dereferenceable(1) %12)
%14 = add i64 %13, 1
tail call void @llvm.memmove.p0i8.p0i8.i64(i8* align 1 %0, i8* align 1 %12, i64 %14, i1 false)
%15 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i32 46)
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %19
17: ; preds = %11
%18 = tail call i8* @strcat(i8* dereferenceable(1) %0, i8* dereferenceable(1) %2)
br label %21
19: ; preds = %11
%20 = tail call i8* @strcpy(i8* %15, i8* dereferenceable(1) %2)
br label %21
21: ; preds = %19, %17
ret void
}