#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 *);
scalar_t__ malloc(int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char const *);
char *strstr(char *, char *);
int get_des_filename(char *des_filename, const char *des_filepath,
                     const char *src_filename) {
  char *p, *path;
  char *position;
  int l;
  p = (char *)malloc(sizeof(char) * strlen(src_filename));
  path = p;
  strcpy(path, src_filename);
  position = strstr(path, "/");
  do {
    l = strlen(position) + 1;
    path = &path[strlen(path) - l + 2];
    position = strstr(path, "/");
  } while (position);
  strcpy(des_filename, des_filepath);
  strcat(des_filename, path);
  free(p);
  return 1;
}


x86 assembly (clang, -O0):
<get_des_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x28(%rbp),%rdi
lea    0xe52(%rip),%rsi
call   1080 <strstr@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%rax
sub    -0x34(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xe08(%rip),%rsi
call   1080 <strstr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11b7 <get_des_filename+0x57>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    $0x1,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_des_filename>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rdx,%rdi
call   1050 <strlen@plt>
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
mov    %r12,%rdi
mov    $0x2f,%esi
call   1060 <strchr@plt>
mov    %r12,%rbx
nop
mov    %rbx,%r13
mov    %rax,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebx
mov    %r13,%rdi
call   1050 <strlen@plt>
sub    %ebx,%eax
add    $0x1,%eax
movslq %eax,%rbx
add    %r13,%rbx
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1060 <strchr@plt>
test   %rax,%rax
jne    11a0 <get_des_filename+0x40>
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1080 <strcat@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
define i32 @get_des_filename(i8* %0, i8* %1, i8* %2) {
%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** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%11 = load i8*, i8** %6
%12 = call i32 @strlen(i8* %11)
%13 = sext i32 %12 to i64
%14 = mul i64 1, %13
%15 = trunc i64 %14 to i32
%16 = call i64 @malloc(i32 %15)
%17 = inttoptr i64 %16 to i8*
store i8* %17, i8** %7
%18 = load i8*, i8** %7
store i8* %18, i8** %8
%19 = load i8*, i8** %8
%20 = load i8*, i8** %6
%21 = call i32 @strcpy(i8* %19, i8* %20)
%22 = load i8*, i8** %8
%23 = call i8* @strstr(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %23, i8** %9
br label %24
24: ; preds = %38, %3
%25 = load i8*, i8** %9
%26 = call i32 @strlen(i8* %25)
%27 = add nsw i32 %26, 1
store i32 %27, i32* %10
%28 = load i8*, i8** %8
%29 = load i8*, i8** %8
%30 = call i32 @strlen(i8* %29)
%31 = load i32, i32* %10
%32 = sub nsw i32 %30, %31
%33 = add nsw i32 %32, 2
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %28, i64 %34
store i8* %35, i8** %8
%36 = load i8*, i8** %8
%37 = call i8* @strstr(i8* %36, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %37, i8** %9
br label %38
38: ; preds = %24
%39 = load i8*, i8** %9
%40 = icmp ne i8* %39, null
br i1 %40, label %24, label %41
41: ; preds = %38
%42 = load i8*, i8** %4
%43 = load i8*, i8** %5
%44 = call i32 @strcpy(i8* %42, i8* %43)
%45 = load i8*, i8** %4
%46 = load i8*, i8** %8
%47 = call i32 @strcat(i8* %45, i8* %46)
%48 = load i8*, i8** %7
%49 = call i32 @free(i8* %48)
ret i32 1
}

LLVM IR (-O2):
define i32 @get_des_filename(i8* %0, i8* %1, i8* %2) {
%4 = tail call i32 @strlen(i8* %2)
%5 = tail call i64 @malloc(i32 %4)
%6 = inttoptr i64 %5 to i8*
%7 = tail call i32 @strcpy(i8* %6, i8* %2)
%8 = tail call i8* @strchr(i8* dereferenceable(1) %6, i32 47)
br label %9
9: ; preds = %9, %3
%10 = phi i8* [ %8, %3 ], [ %18, %9 ]
%11 = phi i8* [ %6, %3 ], [ %17, %9 ]
%12 = tail call i32 @strlen(i8* %10)
%13 = tail call i32 @strlen(i8* %11)
%14 = sub i32 1, %12
%15 = add i32 %14, %13
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %11, i64 %16
%18 = tail call i8* @strchr(i8* dereferenceable(1) %17, i32 47)
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %9
20: ; preds = %9
%21 = tail call i32 @strcpy(i8* %0, i8* %1)
%22 = tail call i32 @strcat(i8* %0, i8* %17)
%23 = tail call i32 @free(i8* %6)
ret i32 1
}