#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*/ strchr(char *, char);
int /*<<< orphan*/ strcpy(char *, char const *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
char *strrchr(char const *, char);
char *ConstructOutputName(const char *infile, char *outfile, char *ext) {
  char *end = strrchr(infile, '.');
  if (end && !strchr(end, '/') && !strchr(end, '\\')) {
    strncpy(outfile, infile, end - infile);
    outfile[end - infile] = '\0';
  } else
    strcpy(outfile, infile);
  strcat(outfile, ext);
  return outfile;
}


x86 assembly (clang, -O0):
<ConstructOutputName>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2e,%esi
call   1060 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11e1 <ConstructOutputName+0x91>
mov    -0x20(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strchr@plt>
cmp    $0x0,%eax
jne    11e1 <ConstructOutputName+0x91>
mov    -0x20(%rbp),%rdi
mov    $0x5c,%esi
call   1050 <strchr@plt>
cmp    $0x0,%eax
jne    11e1 <ConstructOutputName+0x91>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    -0x8(%rbp),%rdx
sub    %rdx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    11ee <ConstructOutputName+0x9e>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ConstructOutputName>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%r15
mov    $0x2e,%esi
call   1060 <strrchr@plt>
test   %rax,%rax
je     1195 <ConstructOutputName+0x45>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x2f,%esi
call   1050 <strchr@plt>
test   %eax,%eax
jne    1195 <ConstructOutputName+0x45>
mov    %rbx,%rdi
mov    $0x5c,%esi
call   1050 <strchr@plt>
test   %eax,%eax
je     11ba <ConstructOutputName+0x6a>
mov    %r12,%rdi
mov    %r15,%rsi
call   1040 <strcpy@plt>
mov    %r12,%rdi
mov    %r14,%rsi
call   1070 <strcat@plt>
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
sub    %r15,%rbx
mov    %r12,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1030 <strncpy@plt>
movb   $0x0,(%r12,%rbx,1)
jmp    11a0 <ConstructOutputName+0x50>

LLVM IR (-O0):
define i8* @ConstructOutputName(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%8 = load i8*, i8** %4
%9 = call i8* @strrchr(i8* %8, i8 signext 46)
store i8* %9, i8** %7
%10 = load i8*, i8** %7
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %37
12: ; preds = %3
%13 = load i8*, i8** %7
%14 = call i32 @strchr(i8* %13, i8 signext 47)
%15 = icmp ne i32 %14, 0
br i1 %15, label %37, label %16
16: ; preds = %12
%17 = load i8*, i8** %7
%18 = call i32 @strchr(i8* %17, i8 signext 92)
%19 = icmp ne i32 %18, 0
br i1 %19, label %37, label %20
20: ; preds = %16
%21 = load i8*, i8** %5
%22 = load i8*, i8** %4
%23 = load i8*, i8** %7
%24 = load i8*, i8** %4
%25 = ptrtoint i8* %23 to i64
%26 = ptrtoint i8* %24 to i64
%27 = sub i64 %25, %26
%28 = trunc i64 %27 to i32
%29 = call i32 @strncpy(i8* %21, i8* %22, i32 %28)
%30 = load i8*, i8** %5
%31 = load i8*, i8** %7
%32 = load i8*, i8** %4
%33 = ptrtoint i8* %31 to i64
%34 = ptrtoint i8* %32 to i64
%35 = sub i64 %33, %34
%36 = getelementptr inbounds i8, i8* %30, i64 %35
store i8 0, i8* %36
br label %41
37: ; preds = %16, %12, %3
%38 = load i8*, i8** %5
%39 = load i8*, i8** %4
%40 = call i32 @strcpy(i8* %38, i8* %39)
br label %41
41: ; preds = %37, %20
%42 = load i8*, i8** %5
%43 = load i8*, i8** %6
%44 = call i32 @strcat(i8* %42, i8* %43)
%45 = load i8*, i8** %5
ret i8* %45
}

LLVM IR (-O2):
define i8* @ConstructOutputName(i8* %0, i8* returned %1, i8* %2) {
%4 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 46)
%5 = icmp eq i8* %4, null
br i1 %5, label %19, label %6
6: ; preds = %3
%7 = tail call i32 @strchr(i8* %4, i8 signext 47)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %19
9: ; preds = %6
%10 = tail call i32 @strchr(i8* %4, i8 signext 92)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %19
12: ; preds = %9
%13 = ptrtoint i8* %4 to i64
%14 = ptrtoint i8* %0 to i64
%15 = sub i64 %13, %14
%16 = trunc i64 %15 to i32
%17 = tail call i32 @strncpy(i8* %1, i8* %0, i32 %16)
%18 = getelementptr inbounds i8, i8* %1, i64 %15
store i8 0, i8* %18
br label %21
19: ; preds = %9, %6, %3
%20 = tail call i32 @strcpy(i8* %1, i8* %0)
br label %21
21: ; preds = %19, %12
%22 = tail call i32 @strcat(i8* %1, i8* %2)
ret i8* %1
}