#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *getCombinedFilename(char *fName) {
  char *sortedName = "sorted_";
  char *combinedName = "combined_";
  int chopLength = strlen(sortedName);
  char *choppedName = (char *)malloc(strlen(fName) - strlen(sortedName));
  int j = chopLength;
  int i = 0;
  for (i = 0; i <= strlen(choppedName); i++) {
    choppedName[i] = fName[j];
    j++;
  }
  char *newName = (char *)malloc(strlen(combinedName) + strlen(choppedName));
  strcpy(newName, combinedName);
  strcat(newName, choppedName);
  return newName;
}


x86 assembly (clang, -O0):
<getCombinedFilename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xead(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xeaa(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x3c(%rbp),%edi
sub    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%eax
cmp    %ecx,%eax
jg     11ee <getCombinedFilename+0xae>
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x28(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11a5 <getCombinedFilename+0x65>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x44(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x44(%rbp),%edi
add    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1060 <strcat@plt>
mov    -0x38(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getCombinedFilename>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xeaf(%rip),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%r15d
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <strlen@plt>
sub    %eax,%ebp
mov    %ebp,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
js     11bd <getCombinedFilename+0x7d>
movslq %r15d,%rax
add    %rax,%r14
mov    $0xffffffffffffffff,%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl 0x1(%r14,%rbp,1),%eax
mov    %al,0x1(%rbx,%rbp,1)
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
add    $0x1,%rbp
cmp    %rax,%rbp
jl     11a0 <getCombinedFilename+0x60>
lea    0xe44(%rip),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <strlen@plt>
add    %eax,%ebp
mov    %ebp,%edi
call   1050 <malloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1060 <strcat@plt>
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [8 x i8] c"sorted_\00"
@.str.1 = [10 x i8] c"combined_\00"
define i8* @getCombinedFilename(i8* %0) {
%2 = tail call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 @strlen(i8* %0)
%4 = tail call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%5 = sub nsw i32 %3, %4
%6 = tail call i64 @malloc(i32 %5)
%7 = inttoptr i64 %6 to i8*
%8 = tail call i32 @strlen(i8* %7)
%9 = icmp slt i32 %8, 0
br i1 %9, label %23, label %10
10: ; preds = %1
%11 = sext i32 %2 to i64
br label %12
12: ; preds = %10, %12
%13 = phi i64 [ 0, %10 ], [ %19, %12 ]
%14 = phi i64 [ %11, %10 ], [ %18, %12 ]
%15 = getelementptr inbounds i8, i8* %0, i64 %14
%16 = load i8, i8* %15
%17 = getelementptr inbounds i8, i8* %7, i64 %13
store i8 %16, i8* %17
%18 = add nsw i64 %14, 1
%19 = add nuw nsw i64 %13, 1
%20 = tail call i32 @strlen(i8* %7)
%21 = sext i32 %20 to i64
%22 = icmp slt i64 %13, %21
br i1 %22, label %12, label %23
23: ; preds = %12, %1
%24 = tail call i32 @strlen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%25 = tail call i32 @strlen(i8* %7)
%26 = add nsw i32 %25, %24
%27 = tail call i64 @malloc(i32 %26)
%28 = inttoptr i64 %27 to i8*
%29 = tail call i32 @strcpy(i8* %28, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%30 = tail call i32 @strcat(i8* %28, i8* %7)
ret i8* %28
}