#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 */
char *FindExt(char const *);
int /*<<< orphan*/ memcpy(char *, char const *, int);
int /*<<< orphan*/ strcat(char *, char const *);
int /*<<< orphan*/ strcpy(char *, char const *);
scalar_t__ strlen(char const *);
char *xmalloc(scalar_t__);
char *MakeFilename(const char *Origin, const char *Ext) {
  char *Out;
  const char *P = FindExt(Origin);
  if (P == 0) {
    Out = xmalloc(strlen(Origin) + strlen(Ext) + 1);
    strcpy(Out, Origin);
    strcat(Out, Ext);
  } else {
    Out = xmalloc(P - Origin + strlen(Ext) + 1);
    memcpy(Out, Origin, P - Origin);
    strcpy(Out + (P - Origin), Ext);
  }
  return Out;
}


x86 assembly (clang, -O0):
<MakeFilename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <FindExt@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11d1 <MakeFilename+0x71>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x28(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
call   1050 <xmalloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1080 <strcat@plt>
jmp    1232 <MakeFilename+0xd2>
mov    -0x20(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x30(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
call   1050 <xmalloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1070 <memcpy@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MakeFilename>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
call   1060 <FindExt@plt>
test   %rax,%rax
je     11b3 <MakeFilename+0x53>
mov    %rax,%rbx
sub    %r15,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    (%rbx,%rax,1),%rdi
add    $0x1,%rdi
call   1050 <xmalloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1070 <memcpy@plt>
add    %r12,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
jmp    11ec <MakeFilename+0x8c>
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    (%rbx,%rax,1),%rdi
add    $0x1,%rdi
call   1050 <xmalloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
mov    %r12,%rdi
mov    %r14,%rsi
call   1080 <strcat@plt>
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @MakeFilename(i8* %0, i8* %1) {
%3 = tail call i8* @FindExt(i8* %0)
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %13
5: ; preds = %2
%6 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%7 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%8 = add i64 %6, 1
%9 = add i64 %8, %7
%10 = tail call i8* @xmalloc(i64 %9)
%11 = tail call i32 @strcpy(i8* %10, i8* %0)
%12 = tail call i32 @strcat(i8* %10, i8* %1)
br label %25
13: ; preds = %2
%14 = ptrtoint i8* %3 to i64
%15 = ptrtoint i8* %0 to i64
%16 = sub i64 %14, %15
%17 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%18 = add i64 %16, 1
%19 = add i64 %18, %17
%20 = tail call i8* @xmalloc(i64 %19)
%21 = trunc i64 %16 to i32
%22 = tail call i32 @memcpy(i8* %20, i8* %0, i32 %21)
%23 = getelementptr inbounds i8, i8* %20, i64 %16
%24 = tail call i32 @strcpy(i8* %23, i8* %1)
br label %25
25: ; preds = %13, %5
%26 = phi i8* [ %10, %5 ], [ %20, %13 ]
ret i8* %26
}