#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*/ strlcat(char *, char *, unsigned int);
int strlen(char *);
void COM_DefaultExtension(char *path, unsigned int pathlen, char *extension) {
  char *src;
  src = path + strlen(path) - 1;
  while (*src != '/' && src != path) {
    if (*src == '.')
      return;
    src--;
  }
  strlcat(path, extension, pathlen);
}


x86 assembly (clang, -O0):
<COM_DefaultExtension>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x2f,%ecx
mov    %al,-0x29(%rbp)
je     117b <COM_DefaultExtension+0x5b>
mov    -0x20(%rbp),%rax
cmp    -0x8(%rbp),%rax
setne  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    118b <COM_DefaultExtension+0x6b>
jmp    11b1 <COM_DefaultExtension+0x91>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    11a0 <COM_DefaultExtension+0x80>
jmp    11c1 <COM_DefaultExtension+0xa1>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    1158 <COM_DefaultExtension+0x38>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1030 <strlcat@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<COM_DefaultExtension>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %esi,%ebp
mov    %rdi,%rbx
call   1040 <strlen@plt>
cltq
add    $0xffffffffffffffff,%rax
nopw   0x0(%rax,%rax,1)
movzbl (%rbx,%rax,1),%ecx
cmp    $0x2f,%cl
je     115c <COM_DefaultExtension+0x3c>
test   %rax,%rax
je     115c <COM_DefaultExtension+0x3c>
add    $0xffffffffffffffff,%rax
cmp    $0x2e,%cl
jne    1140 <COM_DefaultExtension+0x20>
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <strlcat@plt>

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

LLVM IR (-O2):
define void @COM_DefaultExtension(i8* %0, i32 %1, i8* %2) {
%4 = tail call i32 @strlen(i8* %0)
%5 = sext i32 %4 to i64
%6 = getelementptr inbounds i8, i8* %0, i64 %5
br label %7
7: ; preds = %14, %3
%8 = phi i8* [ %6, %3 ], [ %9, %14 ]
%9 = getelementptr inbounds i8, i8* %8, i64 -1
%10 = load i8, i8* %9
%11 = icmp ne i8 %10, 47
%12 = icmp ne i8* %9, %0
%13 = and i1 %11, %12
br i1 %13, label %14, label %16
14: ; preds = %7
%15 = icmp eq i8 %10, 46
br i1 %15, label %18, label %7
16: ; preds = %7
%17 = tail call i32 @strlcat(i8* %0, i8* %2, i32 %1)
br label %18
18: ; preds = %14, %16
ret void
}