#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 */
char *mymalloc(scalar_t__);
char const *strcpy(char *, char const *);
scalar_t__ strlen(char const *);
scalar_t__ strncmp(char const *, char *, int);
char *strrchr(char *, char);
const char *newfilename(const char *inclfile, const char *parentfile) {
  char *newfile, *cp;
  newfile = mymalloc(strlen(parentfile) + strlen(inclfile));
  if (strncmp(inclfile, ".../", 4) != 0) {
    return strcpy(newfile, inclfile);
  }
  strcpy(newfile, parentfile);
  cp = strrchr(newfile, '/');
  strcpy(cp == 0 ? newfile : cp + 1, inclfile + 4);
  return newfile;
}


x86 assembly (clang, -O0):
<newfilename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x30(%rbp),%rdi
add    %rax,%rdi
call   1070 <mymalloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe6f(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     11bb <newfilename+0x6b>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
mov    %rax,-0x8(%rbp)
jmp    1217 <newfilename+0xc7>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x20(%rbp),%rdi
mov    $0x2f,%esi
call   1060 <strrchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11f2 <newfilename+0xa2>
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    11fe <newfilename+0xae>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    $0x4,%rsi
call   1040 <strcpy@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<newfilename>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r12
mov    %rsi,%rdi
call   1050 <strlen@plt>
mov    %rax,%rbx
mov    %r12,%rdi
call   1050 <strlen@plt>
add    %rax,%rbx
mov    %rbx,%rdi
call   1070 <mymalloc@plt>
mov    %rax,%r14
lea    0xe7a(%rip),%rsi
mov    %r12,%rdi
mov    $0x4,%edx
call   1030 <strncmp@plt>
mov    %r14,%rdi
test   %rax,%rax
jne    11bf <newfilename+0x6f>
mov    %r15,%rsi
call   1040 <strcpy@plt>
mov    %r14,%rdi
mov    $0x2f,%esi
call   1060 <strrchr@plt>
lea    0x1(%rax),%rdi
test   %rax,%rax
cmove  %r14,%rdi
add    $0x4,%r12
mov    %r12,%rsi
call   1040 <strcpy@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [5 x i8] c".../\00"
define i8* @newfilename(i8* %0, i8* nocapture %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = add nsw i64 %4, %3
%6 = tail call i8* @mymalloc(i64 %5)
%7 = tail call i64 @strncmp(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%8 = icmp eq i64 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %2
%10 = tail call i8* @strcpy(i8* dereferenceable(1) %6, i8* dereferenceable(1) %0)
br label %19
11: ; preds = %2
%12 = tail call i8* @strcpy(i8* dereferenceable(1) %6, i8* dereferenceable(1) %1)
%13 = tail call i8* @strrchr(i8* dereferenceable(1) %6, i8 signext 47)
%14 = icmp eq i8* %13, null
%15 = getelementptr inbounds i8, i8* %13, i64 1
%16 = select i1 %14, i8* %6, i8* %15
%17 = getelementptr inbounds i8, i8* %0, i64 4
%18 = tail call i8* @strcpy(i8* dereferenceable(1) %16, i8* %17)
br label %19
19: ; preds = %11, %9
ret i8* %6
}