#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 int /*<<< orphan*/ oldPath;

/* Variables and functions */
int /*<<< orphan*/ com_snprintf(char *, int const, char *, char *,
                                char const *);
int /*<<< orphan*/ com_strlcpy(char *, char *, int);
int strlen(char *);
void FS_DefaultExtension(char *path, const int maxSize, const char *extension) {
  char oldPath[128];
  char *src;
  src = path + strlen(path) - 1;
  while (*src != '/' && src != path) {
    if (*src == '.') {
      return;
    }
    src--;
  }
  com_strlcpy(oldPath, path, sizeof(oldPath));
  com_snprintf(path, maxSize, "%s%s", oldPath, extension);
}


x86 assembly (clang, -O0):
<FS_DefaultExtension>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0xb0(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0xb0(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0xa8(%rbp)
mov    -0xa8(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x2f,%ecx
mov    %al,-0xb1(%rbp)
je     11a3 <FS_DefaultExtension+0x73>
mov    -0xa8(%rbp),%rax
cmp    -0x8(%rbp),%rax
setne  %al
mov    %al,-0xb1(%rbp)
mov    -0xb1(%rbp),%al
test   $0x1,%al
jne    11b6 <FS_DefaultExtension+0x86>
jmp    11e5 <FS_DefaultExtension+0xb5>
mov    -0xa8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    11ce <FS_DefaultExtension+0x9e>
jmp    1218 <FS_DefaultExtension+0xe8>
mov    -0xa8(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0xa8(%rbp)
jmp    1174 <FS_DefaultExtension+0x44>
lea    -0xa0(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x80,%edx
call   1050 <com_strlcpy@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
lea    -0xa0(%rbp),%rcx
mov    -0x18(%rbp),%r8
lea    0xded(%rip),%rdx
call   1040 <com_snprintf@plt>
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FS_DefaultExtension>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x88,%rsp
mov    %rdx,%r14
mov    %esi,%ebp
mov    %rdi,%rbx
call   1030 <strlen@plt>
cltq
add    $0xffffffffffffffff,%rax
movzbl (%rbx,%rax,1),%ecx
cmp    $0x2f,%cl
je     1169 <FS_DefaultExtension+0x39>
test   %rax,%rax
je     1169 <FS_DefaultExtension+0x39>
add    $0xffffffffffffffff,%rax
cmp    $0x2e,%cl
jne    1150 <FS_DefaultExtension+0x20>
jmp    1193 <FS_DefaultExtension+0x63>
mov    %rsp,%r15
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x80,%edx
call   1050 <com_strlcpy@plt>
lea    0xe7d(%rip),%rdx
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r15,%rcx
mov    %r14,%r8
call   1040 <com_snprintf@plt>
add    $0x88,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [5 x i8] c"%s%s\00"
define void @FS_DefaultExtension(i8* %0, i32 %1, i8* %2) {
%4 = alloca [128 x i8]
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%6 = tail call i32 @strlen(i8* %0)
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %0, i64 %7
br label %9
9: ; preds = %16, %3
%10 = phi i8* [ %8, %3 ], [ %11, %16 ]
%11 = getelementptr inbounds i8, i8* %10, i64 -1
%12 = load i8, i8* %11
%13 = icmp ne i8 %12, 47
%14 = icmp ne i8* %11, %0
%15 = and i1 %13, %14
br i1 %15, label %16, label %18
16: ; preds = %9
%17 = icmp eq i8 %12, 46
br i1 %17, label %21, label %9
18: ; preds = %9
%19 = call i32 @com_strlcpy(i8* %5, i8* %0, i32 128)
%20 = call i32 @com_snprintf(i8* %0, i32 %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %5, i8* %2)
br label %21
21: ; preds = %16, %18
ret void
}