#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*/ free(char *);
scalar_t__ malloc(scalar_t__);
char *realpath(char const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ strcat(char *, char const *);
int /*<<< orphan*/ strcpy(char *, char const *);
scalar_t__ strlen(char const *);
int /*<<< orphan*/ *strstr(char const *, char *);
char *make_full_filename(const char *pszCurDir, const char *pszFilename) {
  char *ret;
  if (pszFilename[0] != '/') {
    char *tmp = (char *)malloc(strlen(pszCurDir) + 1 + strlen(pszFilename) + 1);
    strcpy(tmp, pszCurDir);
    strcat(tmp, "/");
    strcat(tmp, pszFilename);
    ret = realpath(tmp, NULL);
    if (ret == NULL && strstr(pszFilename, "..") == NULL &&
        strstr(pszFilename, "./") == NULL) {
      return tmp;
    }
    free(tmp);
  } else
    ret = realpath(pszFilename, NULL);
  return ret;
}


x86 assembly (clang, -O0):
<make_full_filename>:
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
je     1253 <make_full_filename+0xe3>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x30(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x28(%rbp),%rdi
lea    0xe2e(%rip),%rsi
call   1080 <strcat@plt>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <realpath@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1245 <make_full_filename+0xd5>
mov    -0x18(%rbp),%rdi
lea    0xdf1(%rip),%rsi
call   1090 <strstr@plt>
cmp    $0x0,%rax
jne    1245 <make_full_filename+0xd5>
mov    -0x18(%rbp),%rdi
lea    0xdda(%rip),%rsi
call   1090 <strstr@plt>
cmp    $0x0,%rax
jne    1245 <make_full_filename+0xd5>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    126c <make_full_filename+0xfc>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
jmp    1264 <make_full_filename+0xf4>
mov    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <realpath@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_full_filename>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
cmpb   $0x2f,(%rsi)
jne    1195 <make_full_filename+0x25>
mov    %r12,%rdi
xor    %esi,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1060 <realpath@plt>
mov    %rdi,%rbx
call   1050 <strlen@plt>
mov    %rax,%r14
mov    %r12,%rdi
call   1050 <strlen@plt>
lea    (%r14,%rax,1),%rdi
add    $0x2,%rdi
call   1070 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
lea    0xe3a(%rip),%rsi
mov    %r14,%rdi
call   1080 <strcat@plt>
mov    %r14,%rdi
mov    %r12,%rsi
call   1080 <strcat@plt>
mov    %r14,%rdi
xor    %esi,%esi
call   1060 <realpath@plt>
mov    %rax,%r15
test   %rax,%rax
jne    1217 <make_full_filename+0xa7>
lea    0xe0a(%rip),%rsi
mov    %r12,%rdi
call   1090 <strstr@plt>
test   %rax,%rax
jne    1217 <make_full_filename+0xa7>
lea    0xdf9(%rip),%rsi
mov    %r12,%rdi
call   1090 <strstr@plt>
test   %rax,%rax
je     122e <make_full_filename+0xbe>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    %r14,%r15
jmp    121f <make_full_filename+0xaf>

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

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
@.str.1 = [3 x i8] c"..\00"
@.str.2 = [3 x i8] c"./\00"
define i8* @make_full_filename(i8* %0, i8* %1) {
%3 = load i8, i8* %1
%4 = icmp eq i8 %3, 47
br i1 %4, label %25, label %5
5: ; preds = %2
%6 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%7 = tail call i64 @strlen(i8* %1)
%8 = add i64 %6, 2
%9 = add i64 %8, %7
%10 = tail call i64 @malloc(i64 %9)
%11 = inttoptr i64 %10 to i8*
%12 = tail call i32 @strcpy(i8* %11, i8* %0)
%13 = tail call i32 @strcat(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%14 = tail call i32 @strcat(i8* %11, i8* %1)
%15 = tail call i8* @realpath(i8* %11, i32* null)
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %23
17: ; preds = %5
%18 = tail call i32* @strstr(i8* %1, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = tail call i32* @strstr(i8* %1, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%22 = icmp eq i32* %21, null
br i1 %22, label %27, label %23
23: ; preds = %20, %17, %5
%24 = tail call i32 @free(i8* %11)
br label %27
25: ; preds = %2
%26 = tail call i8* @realpath(i8* %1, i32* null)
br label %27
27: ; preds = %25, %23, %20
%28 = phi i8* [ %11, %20 ], [ %26, %25 ], [ %15, %23 ]
ret i8* %28
}