#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 *get_sourcedir();
int /*<<< orphan*/ strcat(char *, char const *);
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char const *);
char *xmalloc(int);
char *make_sourcename(const char *name) {
  const char *sdir = get_sourcedir();
  char *fname;
  fname = xmalloc(strlen(sdir) + 1 + strlen(name) + 1);
  strcpy(fname, sdir);
  if (*fname && fname[strlen(fname) - 1] != '/')
    strcat(fname, "/");
  strcat(fname, name);
  return fname;
}


x86 assembly (clang, -O0):
<make_sourcename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1060 <get_sourcedir@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x1c(%rbp),%edi
add    %eax,%edi
add    $0x1,%edi
call   1050 <xmalloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11e7 <make_sourcename+0x97>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
je     11e7 <make_sourcename+0x97>
mov    -0x18(%rbp),%rdi
lea    0xe1e(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_sourcename>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
xor    %eax,%eax
call   1060 <get_sourcedir@plt>
mov    %rax,%r15
mov    %rax,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    (%rbx,%rax,1),%edi
add    $0x2,%edi
call   1050 <xmalloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
cmpb   $0x0,(%rbx)
je     11b2 <make_sourcename+0x62>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
cmpb   $0x2f,-0x1(%rax,%rbx,1)
je     11b2 <make_sourcename+0x62>
lea    0xe56(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <strcat@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
define i8* @make_sourcename(i8* %0) {
%2 = tail call i8* (...) @get_sourcedir()
%3 = tail call i32 @strlen(i8* %2)
%4 = tail call i32 @strlen(i8* %0)
%5 = add i32 %3, 2
%6 = add i32 %5, %4
%7 = tail call i8* @xmalloc(i32 %6)
%8 = tail call i32 @strcpy(i8* %7, i8* %2)
%9 = load i8, i8* %7
%10 = icmp eq i8 %9, 0
br i1 %10, label %20, label %11
11: ; preds = %1
%12 = tail call i32 @strlen(i8* %7)
%13 = add nsw i32 %12, -1
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %7, i64 %14
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 47
br i1 %17, label %20, label %18
18: ; preds = %11
%19 = tail call i32 @strcat(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %20
20: ; preds = %18, %11, %1
%21 = tail call i32 @strcat(i8* %7, i8* %0)
ret i8* %7
}