#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 */
typedef scalar_t__ allocsize;

/* Variables and functions */
int /*<<< orphan*/ PHYSFS_addToSearchPath(char *, int);
char *PHYSFS_getRealDir(char const *);
scalar_t__ __PHYSFS_initSmallAlloc(int /*<<< orphan*/ *, size_t const);
int /*<<< orphan*/ __PHYSFS_smallFree(char *);
int /*<<< orphan*/ *alloca(size_t);
int /*<<< orphan*/ sprintf(char *, char *, char const *, char const *,
                           char const *);
size_t const strlen(char const *);
void setSaneCfgAddPath(const char *i, const size_t l, const char *dirsep,
                       int archivesFirst) {
  const char *d = PHYSFS_getRealDir(i);
  const size_t allocsize = strlen(d) + strlen(dirsep) + l + 1;
  char *str = (char *)(__PHYSFS_initSmallAlloc(
      (((allocsize) < 128) ? alloca((size_t)((allocsize) + 1)) : NULL),
      (allocsize)));
  if (str != NULL) {
    sprintf(str, "%s%s%s", d, dirsep, i);
    PHYSFS_addToSearchPath(str, archivesFirst == 0);
    __PHYSFS_smallFree(str);
  }
}


x86 assembly (clang, -O0):
<setSaneCfgAddPath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <PHYSFS_getRealDir@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
add    %rcx,%rax
add    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x80,-0x30(%rbp)
jae    11e4 <setSaneCfgAddPath+0x74>
mov    -0x30(%rbp),%rdi
add    $0x1,%rdi
call   1070 <alloca@plt>
mov    %rax,-0x48(%rbp)
jmp    11ef <setSaneCfgAddPath+0x7f>
xor    %eax,%eax
mov    %rax,-0x48(%rbp)
jmp    11ef <setSaneCfgAddPath+0x7f>
mov    -0x48(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1060 <__PHYSFS_initSmallAlloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     1245 <setSaneCfgAddPath+0xd5>
mov    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x8(%rbp),%r8
lea    0xdde(%rip),%rsi
call   1080 <sprintf@plt>
mov    -0x38(%rbp),%rdi
cmpl   $0x0,-0x1c(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%esi
call   1090 <PHYSFS_addToSearchPath@plt>
mov    -0x38(%rbp),%rdi
call   1050 <__PHYSFS_smallFree@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setSaneCfgAddPath>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %rsi,%rbp
mov    %rdi,%r12
call   1030 <PHYSFS_getRealDir@plt>
mov    %rax,%r13
mov    %rax,%rdi
call   1040 <strlen@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1040 <strlen@plt>
add    %rbp,%rbx
lea    (%rax,%rbx,1),%rbp
add    $0x1,%rbp
cmp    $0x7f,%rbp
ja     11c7 <setSaneCfgAddPath+0x57>
add    %rax,%rbx
add    $0x2,%rbx
mov    %rbx,%rdi
call   1070 <alloca@plt>
mov    %rax,%rdi
jmp    11c9 <setSaneCfgAddPath+0x59>
xor    %edi,%edi
mov    %rbp,%rsi
call   1060 <__PHYSFS_initSmallAlloc@plt>
test   %rax,%rax
je     1218 <setSaneCfgAddPath+0xa8>
mov    %rax,%rbp
lea    0xe20(%rip),%rsi
mov    %rax,%rdi
mov    %r13,%rdx
mov    %r15,%rcx
mov    %r12,%r8
call   1080 <sprintf@plt>
xor    %esi,%esi
test   %r14d,%r14d
sete   %sil
mov    %rbp,%rdi
call   1090 <PHYSFS_addToSearchPath@plt>
mov    %rbp,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <__PHYSFS_smallFree@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%s%s%s\00"
define void @setSaneCfgAddPath(i8* %0, i64 %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i8*
store i8* %0, i8** %5
store i64 %1, i64* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%12 = load i8*, i8** %5
%13 = call i8* @PHYSFS_getRealDir(i8* %12)
store i8* %13, i8** %9
%14 = load i8*, i8** %9
%15 = call i64 @strlen(i8* %14)
%16 = load i8*, i8** %7
%17 = call i64 @strlen(i8* %16)
%18 = add i64 %15, %17
%19 = load i64, i64* %6
%20 = add i64 %18, %19
%21 = add i64 %20, 1
store i64 %21, i64* %10
%22 = load i64, i64* %10
%23 = icmp ult i64 %22, 128
br i1 %23, label %24, label %28
24: ; preds = %4
%25 = load i64, i64* %10
%26 = add i64 %25, 1
%27 = call i32* @alloca(i64 %26)
br label %29
28: ; preds = %4
br label %29
29: ; preds = %28, %24
%30 = phi i32* [ %27, %24 ], [ null, %28 ]
%31 = load i64, i64* %10
%32 = call i64 @__PHYSFS_initSmallAlloc(i32* %30, i64 %31)
%33 = inttoptr i64 %32 to i8*
store i8* %33, i8** %11
%34 = load i8*, i8** %11
%35 = icmp ne i8* %34, null
br i1 %35, label %36, label %49
36: ; preds = %29
%37 = load i8*, i8** %11
%38 = load i8*, i8** %9
%39 = load i8*, i8** %7
%40 = load i8*, i8** %5
%41 = call i32 @sprintf(i8* %37, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %38, i8* %39, i8* %40)
%42 = load i8*, i8** %11
%43 = load i32, i32* %8
%44 = icmp eq i32 %43, 0
%45 = zext i1 %44 to i32
%46 = call i32 @PHYSFS_addToSearchPath(i8* %42, i32 %45)
%47 = load i8*, i8** %11
%48 = call i32 @__PHYSFS_smallFree(i8* %47)
br label %49
49: ; preds = %36, %29
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"%s%s%s\00"
define void @setSaneCfgAddPath(i8* %0, i64 %1, i8* %2, i32 %3) {
%5 = tail call i8* @PHYSFS_getRealDir(i8* %0)
%6 = tail call i64 @strlen(i8* dereferenceable(1) %5)
%7 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%8 = add i64 %6, %1
%9 = add i64 %8, %7
%10 = add i64 %9, 1
%11 = icmp ult i64 %10, 128
br i1 %11, label %12, label %15
12: ; preds = %4
%13 = add nsw i64 %9, 2
%14 = tail call i32* @alloca(i64 %13)
br label %15
15: ; preds = %4, %12
%16 = phi i32* [ %14, %12 ], [ null, %4 ]
%17 = tail call i64 @__PHYSFS_initSmallAlloc(i32* %16, i64 %10)
%18 = inttoptr i64 %17 to i8*
%19 = icmp eq i64 %17, 0
br i1 %19, label %26, label %20
20: ; preds = %15
%21 = tail call i32 @sprintf(i8* %18, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %5, i8* %2, i8* %0)
%22 = icmp eq i32 %3, 0
%23 = zext i1 %22 to i32
%24 = tail call i32 @PHYSFS_addToSearchPath(i8* %18, i32 %23)
%25 = tail call i32 @__PHYSFS_smallFree(i8* %18)
br label %26
26: ; preds = %20, %15
ret void
}