#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*/ strcat(char *, char const *);
int strlen(char const *);
char *_pico_setfext(char *path, const char *ext) {
  char *src;
  int remfext = 0;
  src = path + (strlen(path) - 1);
  if (ext == NULL) {
    ext = "";
  }
  if (strlen(ext) < 1) {
    remfext = 1;
  }
  if (strlen(path) < 1) {
    return path;
  }
  while ((src--) != path) {
    if (*src == '/' || *src == '\\') {
      return path;
    }
    if (*src == '.') {
      if (remfext) {
        *src = '\0';
        return path;
      }
      *(++src) = '\0';
      break;
    }
  }
  strcat(path, ext);
  return path;
}


x86 assembly (clang, -O0):
<_pico_setfext>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1171 <_pico_setfext+0x51>
lea    0xe93(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x1,%eax
jge    118a <_pico_setfext+0x6a>
movl   $0x1,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x1,%eax
jge    11a9 <_pico_setfext+0x89>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1254 <_pico_setfext+0x134>
jmp    11ae <_pico_setfext+0x8e>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x20(%rbp)
cmp    -0x10(%rbp),%rax
je     123f <_pico_setfext+0x11f>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     11e7 <_pico_setfext+0xc7>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5c,%eax
jne    11f4 <_pico_setfext+0xd4>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1254 <_pico_setfext+0x134>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    123a <_pico_setfext+0x11a>
cmpl   $0x0,-0x24(%rbp)
je     1222 <_pico_setfext+0x102>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1254 <_pico_setfext+0x134>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x0,0x1(%rax)
jmp    123f <_pico_setfext+0x11f>
jmp    11ae <_pico_setfext+0x8e>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcat@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_pico_setfext>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%rbp
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %eax,%r12d
test   %rbp,%rbp
lea    0xec0(%rip),%r14
cmovne %rbp,%r14
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %eax,%r15d
mov    %rbx,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    11a2 <_pico_setfext+0x82>
add    $0xffffffff,%r12d
movslq %r12d,%rax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
test   %rax,%rax
je     1197 <_pico_setfext+0x77>
movzbl -0x1(%rbx,%rax,1),%ecx
cmp    $0x5c,%cl
je     11a2 <_pico_setfext+0x82>
cmp    $0x2f,%cl
je     11a2 <_pico_setfext+0x82>
add    $0xffffffffffffffff,%rax
cmp    $0x2e,%cl
jne    1170 <_pico_setfext+0x50>
test   %r15d,%r15d
jle    11ae <_pico_setfext+0x8e>
movb   $0x0,0x1(%rbx,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <strcat@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
movb   $0x0,(%rbx,%rax,1)
jmp    11a2 <_pico_setfext+0x82>

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

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
define i8* @_pico_setfext(i8* returned %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = icmp eq i8* %1, null
%5 = select i1 %4, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* %1
%6 = tail call i32 @strlen(i8* %5)
%7 = icmp slt i32 %6, 1
%8 = tail call i32 @strlen(i8* %0)
%9 = icmp slt i32 %8, 1
br i1 %9, label %25, label %10
10: ; preds = %2
%11 = add nsw i32 %3, -1
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %0, i64 %12
br label %14
14: ; preds = %10, %18
%15 = phi i8* [ %16, %18 ], [ %13, %10 ]
%16 = getelementptr inbounds i8, i8* %15, i64 -1
%17 = icmp eq i8* %15, %0
br i1 %17, label %23, label %18
18: ; preds = %14
%19 = load i8, i8* %16
switch i8 %19, label %14 [
i8 47, label %25
i8 92, label %25
i8 46, label %20
]
20: ; preds = %18
br i1 %7, label %21, label %22
21: ; preds = %20
store i8 0, i8* %16
br label %25
22: ; preds = %20
store i8 0, i8* %15
br label %23
23: ; preds = %14, %22
%24 = tail call i32 @strcat(i8* %0, i8* %5)
br label %25
25: ; preds = %18, %18, %2, %23, %21
ret i8* %0
}