#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 *malloc(int);
int /*<<< orphan*/ memcpy(char *, char const *, int);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char const *);
char *mkfilename(const char *path, char *filename) {
  int n = strlen(path);
  char *buf = malloc(n + 1 + strlen(filename) + 1);
  if (buf == NULL)
    return NULL;
  memcpy(buf, path, n);
  if (buf[n - 1] != '/')
    buf[n++] = '/';
  strcpy(buf + n, filename);
  return buf;
}


x86 assembly (clang, -O0):
<mkfilename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x2c(%rbp),%edi
add    %eax,%edi
add    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1197 <mkfilename+0x57>
movq   $0x0,-0x8(%rbp)
jmp    11f3 <mkfilename+0xb3>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0x28(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
je     11d7 <mkfilename+0x97>
mov    -0x28(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x1c(%rbp)
movslq %ecx,%rcx
movb   $0x2f,(%rax,%rcx,1)
mov    -0x28(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mkfilename>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r12
call   1040 <strlen@plt>
mov    %eax,%r15d
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    (%rax,%r15,1),%edi
add    $0x2,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11a3 <mkfilename+0x63>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r15d,%edx
call   1050 <memcpy@plt>
movslq %r15d,%rax
cmpb   $0x2f,-0x1(%rax,%rbx,1)
je     1192 <mkfilename+0x52>
lea    0x1(%rax),%r15d
movb   $0x2f,(%rbx,%rax,1)
movslq %r15d,%rax
mov    %rbx,%rdi
add    %rax,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @mkfilename(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %4
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = add nsw i32 %10, 1
%12 = load i8*, i8** %5
%13 = call i32 @strlen(i8* %12)
%14 = add nsw i32 %11, %13
%15 = add nsw i32 %14, 1
%16 = call i8* @malloc(i32 %15)
store i8* %16, i8** %7
%17 = load i8*, i8** %7
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %20
19: ; preds = %2
store i8* null, i8** %3
br label %47
20: ; preds = %2
%21 = load i8*, i8** %7
%22 = load i8*, i8** %4
%23 = load i32, i32* %6
%24 = call i32 @memcpy(i8* %21, i8* %22, i32 %23)
%25 = load i8*, i8** %7
%26 = load i32, i32* %6
%27 = sub nsw i32 %26, 1
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %25, i64 %28
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp ne i32 %31, 47
br i1 %32, label %33, label %39
33: ; preds = %20
%34 = load i8*, i8** %7
%35 = load i32, i32* %6
%36 = add nsw i32 %35, 1
store i32 %36, i32* %6
%37 = sext i32 %35 to i64
%38 = getelementptr inbounds i8, i8* %34, i64 %37
store i8 47, i8* %38
br label %39
39: ; preds = %33, %20
%40 = load i8*, i8** %7
%41 = load i32, i32* %6
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %40, i64 %42
%44 = load i8*, i8** %5
%45 = call i32 @strcpy(i8* %43, i8* %44)
%46 = load i8*, i8** %7
store i8* %46, i8** %3
br label %47
47: ; preds = %39, %19
%48 = load i8*, i8** %3
ret i8* %48
}

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