#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 const *getenv(char *);
int /*<<< orphan*/ strformat(char *, unsigned int, char *, char const *, ...);
int BuildFilename(const char *strPath, const char *strFile, char *strOut,
                  unsigned int nSize) {
  ;
  ;
  ;
  ;
  if (!strPath || !strFile || !strOut || nSize <= 0)
    return 0;
  if (*strFile == '/')
    strformat(strOut, nSize, "%s", strFile);
  else if (*strFile == '~')
    strformat(strOut, nSize, "%s%s", getenv("HOME"), strFile + 1);
  else if (*strPath == '~')
    strformat(strOut, nSize, "%s%s/%s", getenv("HOME"), strPath + 1, strFile);
  else
    strformat(strOut, nSize, "%s/%s", strPath, strFile);
  return 1;
}


x86 assembly (clang, -O0):
<BuildFilename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1162 <BuildFilename+0x42>
cmpq   $0x0,-0x18(%rbp)
je     1162 <BuildFilename+0x42>
cmpq   $0x0,-0x20(%rbp)
je     1162 <BuildFilename+0x42>
cmpl   $0x0,-0x24(%rbp)
ja     116e <BuildFilename+0x4e>
movl   $0x0,-0x4(%rbp)
jmp    126c <BuildFilename+0x14c>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    119c <BuildFilename+0x7c>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x18(%rbp),%rcx
lea    0xe7f(%rip),%rdx
mov    $0x0,%al
call   1040 <strformat@plt>
jmp    1265 <BuildFilename+0x145>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x7e,%eax
jne    11eb <BuildFilename+0xcb>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
lea    0xe44(%rip),%rdi
call   1030 <getenv@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%esi
mov    %rax,%rcx
mov    -0x18(%rbp),%r8
add    $0x1,%r8
lea    0xe21(%rip),%rdx
mov    $0x0,%al
call   1040 <strformat@plt>
jmp    1260 <BuildFilename+0x140>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x7e,%eax
jne    123e <BuildFilename+0x11e>
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x34(%rbp)
lea    0xdf5(%rip),%rdi
call   1030 <getenv@plt>
mov    -0x40(%rbp),%rdi
mov    -0x34(%rbp),%esi
mov    %rax,%rcx
mov    -0x10(%rbp),%r8
add    $0x1,%r8
mov    -0x18(%rbp),%r9
lea    0xdd8(%rip),%rdx
mov    $0x0,%al
call   1040 <strformat@plt>
jmp    125b <BuildFilename+0x13b>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%r8
lea    0xdb8(%rip),%rdx
mov    $0x0,%al
call   1040 <strformat@plt>
jmp    1260 <BuildFilename+0x140>
jmp    1265 <BuildFilename+0x145>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BuildFilename>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
test   %rdi,%rdi
je     11f0 <BuildFilename+0xd0>
mov    %rsi,%rbx
test   %rsi,%rsi
je     11f0 <BuildFilename+0xd0>
mov    %rdx,%r15
test   %rdx,%rdx
je     11f0 <BuildFilename+0xd0>
mov    %ecx,%r14d
test   %ecx,%ecx
je     11f0 <BuildFilename+0xd0>
mov    (%rbx),%al
cmp    $0x7e,%al
je     1178 <BuildFilename+0x58>
cmp    $0x2f,%al
jne    119a <BuildFilename+0x7a>
lea    0xea9(%rip),%rdx
mov    %r15,%rdi
mov    %r14d,%esi
mov    %rbx,%rcx
xor    %eax,%eax
call   1040 <strformat@plt>
jmp    11eb <BuildFilename+0xcb>
lea    0xe86(%rip),%rdi
call   1030 <getenv@plt>
add    $0x1,%rbx
lea    0xe71(%rip),%rdx
mov    %r15,%rdi
mov    %r14d,%esi
mov    %rax,%rcx
jmp    11e1 <BuildFilename+0xc1>
mov    %rdi,%rbp
cmpb   $0x7e,(%rdi)
jne    11d1 <BuildFilename+0xb1>
lea    0xe5c(%rip),%rdi
call   1030 <getenv@plt>
add    $0x1,%rbp
lea    0xe51(%rip),%rdx
mov    %r15,%rdi
mov    %r14d,%esi
mov    %rax,%rcx
mov    %rbp,%r8
mov    %rbx,%r9
xor    %eax,%eax
call   1040 <strformat@plt>
jmp    11eb <BuildFilename+0xcb>
lea    0xe34(%rip),%rdx
mov    %r15,%rdi
mov    %r14d,%esi
mov    %rbp,%rcx
mov    %rbx,%r8
xor    %eax,%eax
call   1040 <strformat@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [5 x i8] c"%s%s\00"
@.str.2 = [5 x i8] c"HOME\00"
@.str.3 = [8 x i8] c"%s%s/%s\00"
@.str.4 = [6 x i8] c"%s/%s\00"
define i32 @BuildFilename(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = icmp ne i8* %0, null
%6 = icmp ne i8* %1, null
%7 = and i1 %5, %6
%8 = icmp ne i8* %2, null
%9 = and i1 %7, %8
%10 = icmp ne i32 %3, 0
%11 = and i1 %9, %10
br i1 %11, label %12, label %29
12: ; preds = %4
%13 = load i8, i8* %1
switch i8 %13, label %20 [
i8 47, label %14
i8 126, label %16
]
14: ; preds = %12
%15 = tail call i32 (i8*, i32, i8*, i8*, ...) @strformat(i8* %2, i32 %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %1)
br label %29
16: ; preds = %12
%17 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%18 = getelementptr inbounds i8, i8* %1, i64 1
%19 = tail call i32 (i8*, i32, i8*, i8*, ...) @strformat(i8* %2, i32 %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %17, i8* %18)
br label %29
20: ; preds = %12
%21 = load i8, i8* %0
%22 = icmp eq i8 %21, 126
br i1 %22, label %23, label %27
23: ; preds = %20
%24 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%25 = getelementptr inbounds i8, i8* %0, i64 1
%26 = tail call i32 (i8*, i32, i8*, i8*, ...) @strformat(i8* %2, i32 %3, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %24, i8* %25, i8* %1)
br label %29
27: ; preds = %20
%28 = tail call i32 (i8*, i32, i8*, i8*, ...) @strformat(i8* %2, i32 %3, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %0, i8* %1)
br label %29
29: ; preds = %14, %23, %27, %16, %4
%30 = phi i32 [ 0, %4 ], [ 1, %16 ], [ 1, %27 ], [ 1, %23 ], [ 1, %14 ]
ret i32 %30
}