#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*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
scalar_t__ strncmp(char *, char *, int);
char *filePath(char *path, char *fname) {
  int len;
  char *ptr;
  static char base[2048];
  if (fname[0] == '/')
    return (fname);
  ptr = fname;
  if (strlen(fname) >= 2 && strncmp(fname, "./", 2) == 0)
    ptr += 2;
  strcpy(base, path);
  len = strlen(base);
  if (len > 0) {
    if (base[len - 1] != '/')
      strcat(base, "/");
  }
  strcat(base, ptr);
  return (base);
}


x86 assembly (clang, -O0):
<filePath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    116d <filePath+0x2d>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    122b <filePath+0xeb>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x2,%eax
jl     11b2 <filePath+0x72>
mov    -0x18(%rbp),%rdi
lea    0xe6e(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11b2 <filePath+0x72>
mov    -0x28(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rsi
lea    0x2e93(%rip),%rdi
call   1040 <strcpy@plt>
lea    0x2e87(%rip),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jle    1210 <filePath+0xd0>
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
movslq %eax,%rcx
lea    0x2e65(%rip),%rax
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
je     120b <filePath+0xcb>
lea    0x2e51(%rip),%rdi
lea    0xdfb(%rip),%rsi
call   1060 <strcat@plt>
jmp    1210 <filePath+0xd0>
mov    -0x28(%rbp),%rsi
lea    0x2e35(%rip),%rdi
call   1060 <strcat@plt>
lea    0x2e29(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<filePath>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
cmpb   $0x2f,(%rsi)
jne    1152 <filePath+0x12>
mov    %r14,%rbx
jmp    11ce <filePath+0x8e>
mov    %rdi,%r15
mov    %r14,%rdi
call   1050 <strlen@plt>
cmp    $0x2,%eax
jl     1182 <filePath+0x42>
lea    0xe97(%rip),%rsi
mov    %r14,%rdi
mov    $0x2,%edx
call   1030 <strncmp@plt>
xor    %ecx,%ecx
test   %rax,%rax
sete   %cl
lea    (%r14,%rcx,2),%r14
lea    0x2ec7(%rip),%rbx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
jle    11c3 <filePath+0x83>
add    $0xffffffff,%eax
lea    0x2ea6(%rip),%rcx
cmpb   $0x2f,(%rax,%rcx,1)
je     11c3 <filePath+0x83>
lea    0x2e99(%rip),%rdi
lea    0xe43(%rip),%rsi
call   1060 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <strcat@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@filePath.base = internal global [2048 x i8] zeroinitializer
@.str = [3 x i8] c"./\00"
@.str.1 = [2 x i8] c"/\00"
define i8* @filePath(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** %5
%9 = getelementptr inbounds i8, i8* %8, i64 0
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp eq i32 %11, 47
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = load i8*, i8** %5
store i8* %14, i8** %3
br label %47
15: ; preds = %2
%16 = load i8*, i8** %5
store i8* %16, i8** %7
%17 = load i8*, i8** %5
%18 = call i32 @strlen(i8* %17)
%19 = icmp sge i32 %18, 2
br i1 %19, label %20, label %27
20: ; preds = %15
%21 = load i8*, i8** %5
%22 = call i64 @strncmp(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %20
%25 = load i8*, i8** %7
%26 = getelementptr inbounds i8, i8* %25, i64 2
store i8* %26, i8** %7
br label %27
27: ; preds = %24, %20, %15
%28 = load i8*, i8** %4
%29 = call i32 @strcpy(i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @filePath.base, i64 0, i64 0), i8* %28)
%30 = call i32 @strlen(i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @filePath.base, i64 0, i64 0))
store i32 %30, i32* %6
%31 = load i32, i32* %6
%32 = icmp sgt i32 %31, 0
br i1 %32, label %33, label %44
33: ; preds = %27
%34 = load i32, i32* %6
%35 = sub nsw i32 %34, 1
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [2048 x i8], [2048 x i8]* @filePath.base, i64 0, i64 %36
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp ne i32 %39, 47
br i1 %40, label %41, label %43
41: ; preds = %33
%42 = call i32 @strcat(i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @filePath.base, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %43
43: ; preds = %41, %33
br label %44
44: ; preds = %43, %27
%45 = load i8*, i8** %7
%46 = call i32 @strcat(i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @filePath.base, i64 0, i64 0), i8* %45)
store i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @filePath.base, i64 0, i64 0), i8** %3
br label %47
47: ; preds = %44, %13
%48 = load i8*, i8** %3
ret i8* %48
}

LLVM IR (-O2):
@filePath.base = internal global [2048 x i8] zeroinitializer
@.str = [3 x i8] c"./\00"
@.str.1 = [2 x i8] c"/\00"
define i8* @filePath(i8* %0, i8* %1) {
%3 = load i8, i8* %1
%4 = icmp eq i8 %3, 47
br i1 %4, label %28, label %5
5: ; preds = %2
%6 = tail call i32 @strlen(i8* %1)
%7 = icmp sgt i32 %6, 1
br i1 %7, label %8, label %13
8: ; preds = %5
%9 = tail call i64 @strncmp(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
%10 = icmp eq i64 %9, 0
%11 = select i1 %10, i64 2, i64 0
%12 = getelementptr i8, i8* %1, i64 %11
br label %13
13: ; preds = %8, %5
%14 = phi i8* [ %1, %5 ], [ %12, %8 ]
%15 = tail call i32 @strcpy(i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @filePath.base, i64 0, i64 0), i8* %0)
%16 = tail call i32 @strlen(i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @filePath.base, i64 0, i64 0))
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %26
18: ; preds = %13
%19 = add nsw i32 %16, -1
%20 = zext i32 %19 to i64
%21 = getelementptr inbounds [2048 x i8], [2048 x i8]* @filePath.base, i64 0, i64 %20
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, 47
br i1 %23, label %26, label %24
24: ; preds = %18
%25 = tail call i32 @strcat(i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @filePath.base, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %26
26: ; preds = %18, %24, %13
%27 = tail call i32 @strcat(i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @filePath.base, i64 0, i64 0), i8* %14)
br label %28
28: ; preds = %2, %26
%29 = phi i8* [ getelementptr inbounds ([2048 x i8], [2048 x i8]* @filePath.base, i64 0, i64 0), %26 ], [ %1, %2 ]
ret i8* %29
}