#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 *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
void new_ext(char *filename, char *extname, char *newname) {
  int found, dotpos;
  dotpos = strlen(filename);
  found = 0;
  do {
    switch (filename[dotpos]) {
    case '.':
      found = 1;
      break;
    case '\\':
    case '/':
    case ':':
      found = -1;
      break;
    default:
      dotpos--;
      if (dotpos < 0)
        found = -1;
      break;
    }
  } while (found == 0);
  if (found == -1)
    strcpy(newname, filename);
  if (found == 1) {
    strncpy(newname, filename, dotpos);
    newname[dotpos] = '\0';
  }
  strcat(newname, extname);
}


x86 assembly (clang, -O0):
<new_ext>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x24(%rbp)
sub    $0x2e,%eax
je     11b7 <new_ext+0x77>
jmp    1184 <new_ext+0x44>
mov    -0x24(%rbp),%eax
sub    $0x2f,%eax
je     11c3 <new_ext+0x83>
jmp    1195 <new_ext+0x55>
mov    -0x24(%rbp),%eax
sub    $0x3a,%eax
je     11c3 <new_ext+0x83>
jmp    11a6 <new_ext+0x66>
mov    -0x24(%rbp),%eax
sub    $0x5c,%eax
je     11c3 <new_ext+0x83>
jmp    11cf <new_ext+0x8f>
movl   $0x1,-0x1c(%rbp)
jmp    11ee <new_ext+0xae>
movl   $0xffffffff,-0x1c(%rbp)
jmp    11ee <new_ext+0xae>
mov    -0x20(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    11e9 <new_ext+0xa9>
movl   $0xffffffff,-0x1c(%rbp)
jmp    11ee <new_ext+0xae>
jmp    11f3 <new_ext+0xb3>
cmpl   $0x0,-0x1c(%rbp)
je     1167 <new_ext+0x27>
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1214 <new_ext+0xd4>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
cmpl   $0x1,-0x1c(%rbp)
jne    123a <new_ext+0xfa>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strcat@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<new_ext>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%r12
call   1050 <strlen@plt>
movslq %eax,%rcx
mov    %rcx,%rbx
shl    $0x20,%rbx
add    $0x1,%rcx
movabs $0xffffffff00000000,%rdx
ff ff ff
jmp    117c <new_ext+0x3c>
add    %rdx,%rbx
add    $0xffffffff,%eax
add    $0xffffffffffffffff,%rcx
jle    11aa <new_ext+0x6a>
movsbl -0x1(%r12,%rcx,1),%esi
cmp    $0x39,%esi
jg     11a0 <new_ext+0x60>
cmp    $0x2e,%esi
je     11b7 <new_ext+0x77>
cmp    $0x2f,%esi
jne    1170 <new_ext+0x30>
jmp    11aa <new_ext+0x6a>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmp    $0x3a,%esi
je     11aa <new_ext+0x6a>
cmp    $0x5c,%esi
jne    1170 <new_ext+0x30>
mov    %r15,%rdi
mov    %r12,%rsi
call   1040 <strcpy@plt>
jmp    11cd <new_ext+0x8d>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %eax,%edx
call   1030 <strncpy@plt>
sar    $0x20,%rbx
movb   $0x0,(%r15,%rbx,1)
mov    %r15,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1060 <strcat@plt>

LLVM IR (-O0):
define void @new_ext(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%9 = load i8*, i8** %4
%10 = call i32 @strlen(i8* %9)
store i32 %10, i32* %8
store i32 0, i32* %7
br label %11
11: ; preds = %28, %3
%12 = load i8*, i8** %4
%13 = load i32, i32* %8
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %12, i64 %14
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
switch i32 %17, label %20 [
i32 46, label %18
i32 92, label %19
i32 47, label %19
i32 58, label %19
]
18: ; preds = %11
store i32 1, i32* %7
br label %27
19: ; preds = %11, %11, %11
store i32 -1, i32* %7
br label %27
20: ; preds = %11
%21 = load i32, i32* %8
%22 = add nsw i32 %21, -1
store i32 %22, i32* %8
%23 = load i32, i32* %8
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %20
store i32 -1, i32* %7
br label %26
26: ; preds = %25, %20
br label %27
27: ; preds = %26, %19, %18
br label %28
28: ; preds = %27
%29 = load i32, i32* %7
%30 = icmp eq i32 %29, 0
br i1 %30, label %11, label %31
31: ; preds = %28
%32 = load i32, i32* %7
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %38
34: ; preds = %31
%35 = load i8*, i8** %6
%36 = load i8*, i8** %4
%37 = call i32 @strcpy(i8* %35, i8* %36)
br label %38
38: ; preds = %34, %31
%39 = load i32, i32* %7
%40 = icmp eq i32 %39, 1
br i1 %40, label %41, label %50
41: ; preds = %38
%42 = load i8*, i8** %6
%43 = load i8*, i8** %4
%44 = load i32, i32* %8
%45 = call i32 @strncpy(i8* %42, i8* %43, i32 %44)
%46 = load i8*, i8** %6
%47 = load i32, i32* %8
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %46, i64 %48
store i8 0, i8* %49
br label %50
50: ; preds = %41, %38
%51 = load i8*, i8** %6
%52 = load i8*, i8** %5
%53 = call i32 @strcat(i8* %51, i8* %52)
ret void
}

LLVM IR (-O2):
define void @new_ext(i8* %0, i8* %1, i8* %2) {
%4 = tail call i32 @strlen(i8* %0)
%5 = sext i32 %4 to i64
br label %6
6: ; preds = %11, %3
%7 = phi i64 [ %12, %11 ], [ %5, %3 ]
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
switch i32 %10, label %11 [
i32 46, label %16
i32 92, label %14
i32 47, label %14
i32 58, label %14
]
11: ; preds = %6
%12 = add nsw i64 %7, -1
%13 = icmp slt i64 %7, 1
br i1 %13, label %14, label %6
14: ; preds = %11, %6, %6, %6
%15 = tail call i32 @strcpy(i8* %2, i8* %0)
br label %22
16: ; preds = %6
%17 = trunc i64 %7 to i32
%18 = tail call i32 @strncpy(i8* %2, i8* %0, i32 %17)
%19 = shl i64 %7, 32
%20 = ashr exact i64 %19, 32
%21 = getelementptr inbounds i8, i8* %2, i64 %20
store i8 0, i8* %21
br label %22
22: ; preds = %14, %16
%23 = tail call i32 @strcat(i8* %2, i8* %1)
ret void
}