#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, char const *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
void *strrchr(char const *, char);
FILE *get_dst_file(const char *src_path) {
  char dst_path[1024] = {0};
  const char *src_name = strrchr(src_path, '/');
  if (!src_name) {
    src_name = src_path;
  }
  char *p = strrchr(src_name, '.');
  if (p && p > src_name) {
    int name_len = p - src_path;
    strncpy(dst_path, src_path, name_len);
    strcpy(dst_path + name_len, ".o");
    printf("%s->%s\n", src_path, dst_path);
    return fopen(dst_path, "wb");
  }
  return NULL;
}


x86 assembly (clang, -O0):
<get_dst_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1060 <strrchr@plt>
mov    %rax,-0x418(%rbp)
cmpq   $0x0,-0x418(%rbp)
jne    11b0 <get_dst_file+0x50>
mov    -0x10(%rbp),%rax
mov    %rax,-0x418(%rbp)
mov    -0x418(%rbp),%rdi
mov    $0x2e,%esi
call   1060 <strrchr@plt>
mov    %rax,-0x420(%rbp)
cmpq   $0x0,-0x420(%rbp)
je     1264 <get_dst_file+0x104>
mov    -0x420(%rbp),%rax
cmp    -0x418(%rbp),%rax
jbe    1264 <get_dst_file+0x104>
mov    -0x420(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x424(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x424(%rbp),%edx
call   1030 <strncpy@plt>
lea    -0x410(%rbp),%rdi
movslq -0x424(%rbp),%rax
add    %rax,%rdi
lea    0xdd4(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x10(%rbp),%rsi
lea    -0x410(%rbp),%rdx
lea    0xdc0(%rip),%rdi
call   1050 <printf@plt>
lea    -0x410(%rbp),%rdi
lea    0xdb5(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x8(%rbp)
jmp    126c <get_dst_file+0x10c>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_dst_file>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %rdi,%r15
mov    %rsp,%rdi
xor    %r14d,%r14d
mov    $0x400,%edx
xor    %esi,%esi
call   1070 <memset@plt>
mov    %r15,%rdi
mov    $0x2f,%esi
call   1060 <strrchr@plt>
mov    %rax,%rbx
test   %rax,%rax
cmove  %r15,%rbx
mov    %rbx,%rdi
mov    $0x2e,%esi
call   1060 <strrchr@plt>
cmp    %rbx,%rax
jbe    11fa <get_dst_file+0x9a>
mov    %rax,%r12
sub    %r15,%r12
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12d,%edx
call   1030 <strncpy@plt>
movslq %r12d,%rax
lea    (%rsp,%rax,1),%rdi
lea    0xe2f(%rip),%rsi
call   1040 <strcpy@plt>
lea    0xe26(%rip),%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1050 <printf@plt>
lea    0xe1c(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
mov    %rax,%r14
mov    %r14,%rax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c".o\00"
@.str.1 = [8 x i8] c"%s->%s\0A\00"
@.str.2 = [3 x i8] c"wb\00"
define i32* @get_dst_file(i8* %0) {
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca [1024 x i8]
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %3
%8 = bitcast [1024 x i8]* %4 to i8*
%9 = load i8*, i8** %3
%10 = call i8* @strrchr(i8* %9, i8 signext 47)
store i8* %10, i8** %5
%11 = load i8*, i8** %5
%12 = icmp ne i8* %11, null
br i1 %12, label %15, label %13
13: ; preds = %1
%14 = load i8*, i8** %3
store i8* %14, i8** %5
br label %15
15: ; preds = %13, %1
%16 = load i8*, i8** %5
%17 = call i8* @strrchr(i8* %16, i8 signext 46)
store i8* %17, i8** %6
%18 = load i8*, i8** %6
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %45
20: ; preds = %15
%21 = load i8*, i8** %6
%22 = load i8*, i8** %5
%23 = icmp ugt i8* %21, %22
br i1 %23, label %24, label %45
24: ; preds = %20
%25 = load i8*, i8** %6
%26 = load i8*, i8** %3
%27 = ptrtoint i8* %25 to i64
%28 = ptrtoint i8* %26 to i64
%29 = sub i64 %27, %28
%30 = trunc i64 %29 to i32
store i32 %30, i32* %7
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%32 = load i8*, i8** %3
%33 = load i32, i32* %7
%34 = call i32 @strncpy(i8* %31, i8* %32, i32 %33)
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%36 = load i32, i32* %7
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
%39 = call i32 @strcpy(i8* %38, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%40 = load i8*, i8** %3
%41 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%42 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %40, i8* %41)
%43 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%44 = call i32* @fopen(i8* %43, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %44, i32** %2
br label %46
45: ; preds = %20, %15
store i32* null, i32** %2
br label %46
46: ; preds = %45, %24
%47 = load i32*, i32** %2
ret i32* %47
}

LLVM IR (-O2):
@.str = [3 x i8] c".o\00"
@.str.1 = [8 x i8] c"%s->%s\0A\00"
@.str.2 = [3 x i8] c"wb\00"
define noalias i32* @get_dst_file(i8* %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%5 = icmp eq i8* %4, null
%6 = select i1 %5, i8* %0, i8* %4
%7 = tail call i8* @strrchr(i8* dereferenceable(1) %6, i8 signext 46)
%8 = icmp ugt i8* %7, %6
br i1 %8, label %9, label %21
9: ; preds = %1
%10 = ptrtoint i8* %7 to i64
%11 = ptrtoint i8* %0 to i64
%12 = sub i64 %10, %11
%13 = trunc i64 %12 to i32
%14 = call i32 @strncpy(i8* %3, i8* %0, i32 %13)
%15 = shl i64 %12, 32
%16 = ashr exact i64 %15, 32
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %16
%18 = call i32 @strcpy(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %3)
%20 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %21
21: ; preds = %1, %9
%22 = phi i32* [ %20, %9 ], [ null, %1 ]
ret i32* %22
}