#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 *malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
int strlen(char *);
char *getVPTREEpath(char *idxpath, char component) {
  register int idxlen = strlen(idxpath);
  char *files[3] = {"database", "index", "metric"};
  register char *fullpath = malloc(
      sizeof(char) * (idxlen + strlen(files[(unsigned char)component]) + 2));
  sprintf(fullpath, "%s/%s", idxpath, files[(unsigned char)component]);
  return fullpath;
}


x86 assembly (clang, -O0):
<getVPTREEpath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x10(%rbp)
mov    0x2cab(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0x2ca8(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0x2ca5(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x3c(%rbp)
movzbl -0x9(%rbp),%eax
mov    -0x30(%rbp,%rax,8),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x3c(%rbp),%eax
add    %ecx,%eax
add    $0x2,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x8(%rbp),%rdx
movzbl -0x9(%rbp),%eax
mov    -0x30(%rbp,%rax,8),%rcx
lea    0xe60(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x38(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getVPTREEpath>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %rdi,%r14
call   1030 <strlen@plt>
mov    %eax,%r15d
movzbl %bl,%eax
lea    0x2cb1(%rip),%rcx
mov    (%rcx,%rax,8),%r12
mov    %r12,%rdi
call   1030 <strlen@plt>
lea    (%r15,%rax,1),%edi
add    $0x2,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
lea    0xea5(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
mov    %r12,%rcx
call   1050 <sprintf@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [9 x i8] c"database\00"
@.str.1 = [6 x i8] c"index\00"
@.str.2 = [7 x i8] c"metric\00"
@__const.getVPTREEpath.files = [3 x i8*] [i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i32 0, i32 0)]
@.str.3 = [6 x i8] c"%s/%s\00"
define i8* @getVPTREEpath(i8* %0, i8 signext %1) {
%3 = alloca i8*
%4 = alloca i8
%5 = alloca i32
%6 = alloca [3 x i8*]
%7 = alloca i8*
store i8* %0, i8** %3
store i8 %1, i8* %4
%8 = load i8*, i8** %3
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %5
%10 = bitcast [3 x i8*]* %6 to i8*
%11 = load i32, i32* %5
%12 = load i8, i8* %4
%13 = zext i8 %12 to i64
%14 = getelementptr inbounds [3 x i8*], [3 x i8*]* %6, i64 0, i64 %13
%15 = load i8*, i8** %14
%16 = call i32 @strlen(i8* %15)
%17 = add nsw i32 %11, %16
%18 = add nsw i32 %17, 2
%19 = sext i32 %18 to i64
%20 = mul i64 1, %19
%21 = trunc i64 %20 to i32
%22 = call i8* @malloc(i32 %21)
store i8* %22, i8** %7
%23 = load i8*, i8** %7
%24 = load i8*, i8** %3
%25 = load i8, i8* %4
%26 = zext i8 %25 to i64
%27 = getelementptr inbounds [3 x i8*], [3 x i8*]* %6, i64 0, i64 %26
%28 = load i8*, i8** %27
%29 = call i32 @sprintf(i8* %23, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %24, i8* %28)
%30 = load i8*, i8** %7
ret i8* %30
}

LLVM IR (-O2):
@.str = [9 x i8] c"database\00"
@.str.1 = [6 x i8] c"index\00"
@.str.2 = [7 x i8] c"metric\00"
@__const.getVPTREEpath.files = [3 x i8*] [i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i32 0, i32 0)]
@.str.3 = [6 x i8] c"%s/%s\00"
define noalias i8* @getVPTREEpath(i8* %0, i8 signext %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = zext i8 %1 to i64
%5 = getelementptr inbounds [3 x i8*], [3 x i8*]* @__const.getVPTREEpath.files, i64 0, i64 %4
%6 = load i8*, i8** %5
%7 = tail call i32 @strlen(i8* %6)
%8 = add i32 %3, 2
%9 = add i32 %8, %7
%10 = tail call i8* @malloc(i32 %9)
%11 = tail call i32 @sprintf(i8* dereferenceable(1) %10, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %0, i8* %6)
ret i8* %10
}