#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 *checking_malloc(scalar_t__);
char *checking_strdup(char const *);
int /*<<< orphan*/ memcpy(char *, char const *, int);
int /*<<< orphan*/ strcpy(char *, char const *);
scalar_t__ strlen(char const *);
scalar_t__ strrchr(char const *, char);
char *file_merge(const char *base, const char *file) {
  char *result;
  const char *cut = (const char *)strrchr(base, '/');
  if (!cut)
    return checking_strdup(file);
  result = checking_malloc(cut - base + 1 + strlen(file) + 1);
  memcpy(result, base, cut - base);
  result[cut - base] = '/';
  strcpy(result + (cut - base) + 1, file);
  return result;
}


x86 assembly (clang, -O0):
<file_merge>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    119f <file_merge+0x3f>
mov    -0x18(%rbp),%rdi
call   1080 <checking_strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    1223 <file_merge+0xc3>
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x30(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
call   1070 <checking_malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1060 <memcpy@plt>
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    -0x10(%rbp),%rdx
sub    %rdx,%rcx
movb   $0x2f,(%rax,%rcx,1)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
add    %rax,%rdi
add    $0x1,%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_merge>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0x2f,%esi
call   1050 <strrchr@plt>
test   %rax,%rax
je     11cc <file_merge+0x6c>
mov    %rax,%rbx
sub    %r15,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    (%rbx,%rax,1),%rdi
add    $0x2,%rdi
call   1070 <checking_malloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1060 <memcpy@plt>
movb   $0x2f,(%r12,%rbx,1)
lea    (%r12,%rbx,1),%rdi
add    $0x1,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1080 <checking_strdup@plt>

LLVM IR (-O0):
define i8* @file_merge(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** %4
%9 = call i64 @strrchr(i8* %8, i8 signext 47)
%10 = inttoptr i64 %9 to i8*
store i8* %10, i8** %7
%11 = load i8*, i8** %7
%12 = icmp ne i8* %11, null
br i1 %12, label %16, label %13
13: ; preds = %2
%14 = load i8*, i8** %5
%15 = call i8* @checking_strdup(i8* %14)
store i8* %15, i8** %3
br label %55
16: ; preds = %2
%17 = load i8*, i8** %7
%18 = load i8*, i8** %4
%19 = ptrtoint i8* %17 to i64
%20 = ptrtoint i8* %18 to i64
%21 = sub i64 %19, %20
%22 = add nsw i64 %21, 1
%23 = load i8*, i8** %5
%24 = call i64 @strlen(i8* %23)
%25 = add nsw i64 %22, %24
%26 = add nsw i64 %25, 1
%27 = call i8* @checking_malloc(i64 %26)
store i8* %27, i8** %6
%28 = load i8*, i8** %6
%29 = load i8*, i8** %4
%30 = load i8*, i8** %7
%31 = load i8*, i8** %4
%32 = ptrtoint i8* %30 to i64
%33 = ptrtoint i8* %31 to i64
%34 = sub i64 %32, %33
%35 = trunc i64 %34 to i32
%36 = call i32 @memcpy(i8* %28, i8* %29, i32 %35)
%37 = load i8*, i8** %6
%38 = load i8*, i8** %7
%39 = load i8*, i8** %4
%40 = ptrtoint i8* %38 to i64
%41 = ptrtoint i8* %39 to i64
%42 = sub i64 %40, %41
%43 = getelementptr inbounds i8, i8* %37, i64 %42
store i8 47, i8* %43
%44 = load i8*, i8** %6
%45 = load i8*, i8** %7
%46 = load i8*, i8** %4
%47 = ptrtoint i8* %45 to i64
%48 = ptrtoint i8* %46 to i64
%49 = sub i64 %47, %48
%50 = getelementptr inbounds i8, i8* %44, i64 %49
%51 = getelementptr inbounds i8, i8* %50, i64 1
%52 = load i8*, i8** %5
%53 = call i32 @strcpy(i8* %51, i8* %52)
%54 = load i8*, i8** %6
store i8* %54, i8** %3
br label %55
55: ; preds = %16, %13
%56 = load i8*, i8** %3
ret i8* %56
}

LLVM IR (-O2):
define i8* @file_merge(i8* %0, i8* %1) {
%3 = tail call i64 @strrchr(i8* %0, i8 signext 47)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i8* @checking_strdup(i8* %1)
br label %19
7: ; preds = %2
%8 = ptrtoint i8* %0 to i64
%9 = sub i64 %3, %8
%10 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%11 = add i64 %9, 2
%12 = add i64 %11, %10
%13 = tail call i8* @checking_malloc(i64 %12)
%14 = trunc i64 %9 to i32
%15 = tail call i32 @memcpy(i8* %13, i8* %0, i32 %14)
%16 = getelementptr inbounds i8, i8* %13, i64 %9
store i8 47, i8* %16
%17 = getelementptr inbounds i8, i8* %16, i64 1
%18 = tail call i32 @strcpy(i8* %17, i8* %1)
br label %19
19: ; preds = %7, %5
%20 = phi i8* [ %13, %7 ], [ %6, %5 ]
ret i8* %20
}