#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*/ TGM_ErrQuit(char *);
scalar_t__ calloc(int, unsigned int);
unsigned int strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, unsigned int);
char *TGM_CreateFileName(const char *workingDir, const char *fileName) {
  unsigned int dirLen = strlen(workingDir);
  unsigned int nameLen = strlen(fileName);
  if (dirLen < 1 || nameLen < 1)
    return NULL;
  char *fullName = (char *)calloc(sizeof(char), dirLen + nameLen + 2);
  if (fullName == NULL)
    TGM_ErrQuit("ERROR: Not enough memory for the file name.\n");
  strncpy(fullName, workingDir, dirLen);
  if (workingDir[dirLen - 1] == '/')
    strncpy(fullName + dirLen, fileName, nameLen);
  else {
    fullName[dirLen] = '/';
    strncpy(fullName + dirLen + 1, fileName, nameLen);
  }
  return fullName;
}


x86 assembly (clang, -O0):
<TGM_CreateFileName>:
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    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x1,-0x1c(%rbp)
jb     117c <TGM_CreateFileName+0x3c>
cmpl   $0x1,-0x20(%rbp)
jae    1189 <TGM_CreateFileName+0x49>
movq   $0x0,-0x8(%rbp)
jmp    1228 <TGM_CreateFileName+0xe8>
mov    -0x1c(%rbp),%esi
add    -0x20(%rbp),%esi
add    $0x2,%esi
mov    $0x1,%edi
call   1050 <calloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11b7 <TGM_CreateFileName+0x77>
lea    0xe4e(%rip),%rdi
call   1060 <TGM_ErrQuit@plt>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
mov    %ecx,%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    11fb <TGM_CreateFileName+0xbb>
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%eax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   1030 <strncpy@plt>
jmp    1220 <TGM_CreateFileName+0xe0>
mov    -0x28(%rbp),%rax
mov    -0x1c(%rbp),%ecx
movb   $0x2f,(%rax,%rcx,1)
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%eax
add    %rax,%rdi
add    $0x1,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<TGM_CreateFileName>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r13
call   1040 <strlen@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1040 <strlen@plt>
xor    %r12d,%r12d
test   %ebx,%ebx
je     11c9 <TGM_CreateFileName+0x89>
mov    %eax,%r15d
test   %eax,%eax
je     11c9 <TGM_CreateFileName+0x89>
lea    (%rbx,%r15,1),%esi
add    $0x2,%esi
mov    $0x1,%edi
call   1050 <calloc@plt>
mov    %rax,%rbp
mov    %rax,%r12
test   %rax,%rax
jne    1196 <TGM_CreateFileName+0x56>
lea    0xe6f(%rip),%rdi
call   1060 <TGM_ErrQuit@plt>
mov    %r12,%rdi
mov    %r13,%rsi
mov    %ebx,%edx
call   1030 <strncpy@plt>
lea    -0x1(%rbx),%eax
mov    %ebx,%ecx
add    %rcx,%rbp
cmpb   $0x2f,0x0(%r13,%rax,1)
je     11bb <TGM_CreateFileName+0x7b>
movb   $0x2f,0x0(%rbp)
add    $0x1,%rbp
mov    %rbp,%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   1030 <strncpy@plt>
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [45 x i8] c"ERROR: Not enough memory for the file name.\0A\00"
define i8* @TGM_CreateFileName(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %4
%10 = call i32 @strlen(i8* %9)
store i32 %10, i32* %6
%11 = load i8*, i8** %5
%12 = call i32 @strlen(i8* %11)
store i32 %12, i32* %7
%13 = load i32, i32* %6
%14 = icmp ult i32 %13, 1
br i1 %14, label %18, label %15
15: ; preds = %2
%16 = load i32, i32* %7
%17 = icmp ult i32 %16, 1
br i1 %17, label %18, label %19
18: ; preds = %15, %2
store i8* null, i8** %3
br label %66
19: ; preds = %15
%20 = load i32, i32* %6
%21 = load i32, i32* %7
%22 = add i32 %20, %21
%23 = add i32 %22, 2
%24 = call i64 @calloc(i32 1, i32 %23)
%25 = inttoptr i64 %24 to i8*
store i8* %25, i8** %8
%26 = load i8*, i8** %8
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %30
28: ; preds = %19
%29 = call i32 @TGM_ErrQuit(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
br label %30
30: ; preds = %28, %19
%31 = load i8*, i8** %8
%32 = load i8*, i8** %4
%33 = load i32, i32* %6
%34 = call i32 @strncpy(i8* %31, i8* %32, i32 %33)
%35 = load i8*, i8** %4
%36 = load i32, i32* %6
%37 = sub i32 %36, 1
%38 = zext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %35, i64 %38
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp eq i32 %41, 47
br i1 %42, label %43, label %51
43: ; preds = %30
%44 = load i8*, i8** %8
%45 = load i32, i32* %6
%46 = zext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %44, i64 %46
%48 = load i8*, i8** %5
%49 = load i32, i32* %7
%50 = call i32 @strncpy(i8* %47, i8* %48, i32 %49)
br label %64
51: ; preds = %30
%52 = load i8*, i8** %8
%53 = load i32, i32* %6
%54 = zext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %52, i64 %54
store i8 47, i8* %55
%56 = load i8*, i8** %8
%57 = load i32, i32* %6
%58 = zext i32 %57 to i64
%59 = getelementptr inbounds i8, i8* %56, i64 %58
%60 = getelementptr inbounds i8, i8* %59, i64 1
%61 = load i8*, i8** %5
%62 = load i32, i32* %7
%63 = call i32 @strncpy(i8* %60, i8* %61, i32 %62)
br label %64
64: ; preds = %51, %43
%65 = load i8*, i8** %8
store i8* %65, i8** %3
br label %66
66: ; preds = %64, %18
%67 = load i8*, i8** %3
ret i8* %67
}

LLVM IR (-O2):
@.str = [45 x i8] c"ERROR: Not enough memory for the file name.\0A\00"
define i8* @TGM_CreateFileName(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = tail call i32 @strlen(i8* %1)
%5 = icmp eq i32 %3, 0
%6 = icmp eq i32 %4, 0
%7 = select i1 %5, i1 true, i1 %6
br i1 %7, label %30, label %8
8: ; preds = %2
%9 = add i32 %3, 2
%10 = add i32 %9, %4
%11 = tail call i64 @calloc(i32 1, i32 %10)
%12 = inttoptr i64 %11 to i8*
%13 = icmp eq i64 %11, 0
br i1 %13, label %14, label %16
14: ; preds = %8
%15 = tail call i32 @TGM_ErrQuit(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %14, %8
%17 = tail call i32 @strncpy(i8* %12, i8* %0, i32 %3)
%18 = add i32 %3, -1
%19 = zext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %0, i64 %19
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 47
%23 = zext i32 %3 to i64
%24 = getelementptr inbounds i8, i8* %12, i64 %23
br i1 %22, label %25, label %27
25: ; preds = %16
%26 = tail call i32 @strncpy(i8* %24, i8* %1, i32 %4)
br label %30
27: ; preds = %16
store i8 47, i8* %24
%28 = getelementptr inbounds i8, i8* %24, i64 1
%29 = tail call i32 @strncpy(i8* %28, i8* %1, i32 %4)
br label %30
30: ; preds = %25, %27, %2
%31 = phi i8* [ null, %2 ], [ %12, %27 ], [ %12, %25 ]
ret i8* %31
}