#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 Utils_StrChr(char *, int, int, char);
int /*<<< orphan*/ memcpy(char *, char *, unsigned int);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *, ...);
scalar_t__ strlen(char *);
void Utils_StrAppend(char *oldname, char *append, char *newname) {
  char prefix[128] = {0};
  char sufix[128] = {0};
  int pos;
  int len;
  len = (int)strlen(oldname);
  pos = Utils_StrChr(oldname, 1, len + 1, '.');
  if (pos != 0) {
    memcpy(prefix, oldname, (unsigned int)pos - 1);
    memcpy(sufix, &oldname[pos], (unsigned int)((int)len - pos));
    sprintf(newname, "%s_%s.%s", prefix, append, sufix);
  } else {
    sprintf(newname, "%s_%s", oldname, append);
  }
}


x86 assembly (clang, -O0):
<Utils_StrAppend>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0xa0(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1040 <memset@plt>
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1040 <memset@plt>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x128(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x128(%rbp),%edx
add    $0x1,%edx
mov    $0x1,%esi
mov    $0x2e,%ecx
call   1060 <Utils_StrChr@plt>
mov    %eax,-0x124(%rbp)
cmpl   $0x0,-0x124(%rbp)
je     1233 <Utils_StrAppend+0xe3>
lea    -0xa0(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x124(%rbp),%edx
sub    $0x1,%edx
call   1050 <memcpy@plt>
lea    -0x120(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movslq -0x124(%rbp),%rax
add    %rax,%rsi
mov    -0x128(%rbp),%edx
sub    -0x124(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0x18(%rbp),%rdi
lea    -0xa0(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    -0x120(%rbp),%r8
lea    0xdd9(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
jmp    124d <Utils_StrAppend+0xfd>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xdc3(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Utils_StrAppend>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%r12
xorps  %xmm0,%xmm0
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
call   1030 <strlen@plt>
mov    %rax,%r13
lea    0x1(%rax),%edx
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x2e,%ecx
call   1050 <Utils_StrChr@plt>
test   %eax,%eax
je     1240 <Utils_StrAppend+0x100>
mov    %eax,%ebx
lea    -0x1(%rbx),%edx
lea    0x80(%rsp),%rbp
mov    %rbp,%rdi
mov    %r12,%rsi
call   1040 <memcpy@plt>
movslq %ebx,%rsi
add    %r12,%rsi
sub    %ebx,%r13d
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %r13d,%edx
call   1040 <memcpy@plt>
lea    0xde5(%rip),%rsi
mov    %r15,%rdi
mov    %rbp,%rdx
mov    %r14,%rcx
mov    %rbx,%r8
xor    %eax,%eax
call   1060 <sprintf@plt>
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdc2(%rip),%rsi
mov    %r15,%rdi
mov    %r12,%rdx
mov    %r14,%rcx
xor    %eax,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <sprintf@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"%s_%s.%s\00"
@.str.1 = [6 x i8] c"%s_%s\00"
define void @Utils_StrAppend(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca [128 x i8]
%8 = alloca [128 x i8]
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%11 = bitcast [128 x i8]* %7 to i8*
%12 = bitcast [128 x i8]* %8 to i8*
%13 = load i8*, i8** %4
%14 = call i64 @strlen(i8* %13)
%15 = trunc i64 %14 to i32
store i32 %15, i32* %10
%16 = load i8*, i8** %4
%17 = load i32, i32* %10
%18 = add nsw i32 %17, 1
%19 = call i32 @Utils_StrChr(i8* %16, i32 1, i32 %18, i8 signext 46)
store i32 %19, i32* %9
%20 = load i32, i32* %9
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %42
22: ; preds = %3
%23 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%24 = load i8*, i8** %4
%25 = load i32, i32* %9
%26 = sub i32 %25, 1
%27 = call i32 @memcpy(i8* %23, i8* %24, i32 %26)
%28 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%29 = load i8*, i8** %4
%30 = load i32, i32* %9
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
%33 = load i32, i32* %10
%34 = load i32, i32* %9
%35 = sub nsw i32 %33, %34
%36 = call i32 @memcpy(i8* %28, i8* %32, i32 %35)
%37 = load i8*, i8** %6
%38 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%39 = load i8*, i8** %5
%40 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%41 = call i32 (i8*, i8*, i8*, i8*, ...) @sprintf(i8* %37, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %38, i8* %39, i8* %40)
br label %47
42: ; preds = %3
%43 = load i8*, i8** %6
%44 = load i8*, i8** %4
%45 = load i8*, i8** %5
%46 = call i32 (i8*, i8*, i8*, i8*, ...) @sprintf(i8* %43, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %44, i8* %45)
br label %47
47: ; preds = %42, %22
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"%s_%s.%s\00"
@.str.1 = [6 x i8] c"%s_%s\00"
define void @Utils_StrAppend(i8* %0, i8* %1, i8* nocapture writeonly %2) {
%4 = alloca [128 x i8]
%5 = alloca [128 x i8]
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%8 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%9 = trunc i64 %8 to i32
%10 = add nsw i32 %9, 1
%11 = tail call i32 @Utils_StrChr(i8* %0, i32 1, i32 %10, i8 signext 46)
%12 = icmp eq i32 %11, 0
br i1 %12, label %21, label %13
13: ; preds = %3
%14 = add i32 %11, -1
%15 = call i32 @memcpy(i8* %6, i8* %0, i32 %14)
%16 = sext i32 %11 to i64
%17 = getelementptr inbounds i8, i8* %0, i64 %16
%18 = sub nsw i32 %9, %11
%19 = call i32 @memcpy(i8* %7, i8* %17, i32 %18)
%20 = call i32 (i8*, i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %2, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %6, i8* %1, i8* %7)
br label %23
21: ; preds = %3
%22 = tail call i32 (i8*, i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %2, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %1)
br label %23
23: ; preds = %21, %13
ret void
}