#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 *getenv(char *);
char *malloc(scalar_t__);
int /*<<< orphan*/ strcat(char *, char const *);
int /*<<< orphan*/ strcpy(char *, char const *);
char *strdup(char const *);
scalar_t__ strlen(char const *);
char *mangle_filename(const char *orig_filename) {
  const char *prefix;
  char *filename = 0;
  prefix = getenv("GCOV_PREFIX");
  if (!prefix)
    return strdup(orig_filename);
  filename = malloc(strlen(prefix) + 1 + strlen(orig_filename) + 1);
  strcpy(filename, prefix);
  strcat(filename, "/");
  strcat(filename, orig_filename);
  return filename;
}


x86 assembly (clang, -O0):
<mangle_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
lea    0xe85(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11a1 <mangle_filename+0x41>
mov    -0x10(%rbp),%rdi
call   1080 <strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    1201 <mangle_filename+0xa1>
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x28(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x20(%rbp),%rdi
lea    0xe25(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mangle_filename>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xe8e(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11d6 <mangle_filename+0x76>
mov    %rax,%r12
mov    %rax,%rdi
call   1050 <strlen@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    (%r15,%rax,1),%rdi
add    $0x2,%rdi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r12,%rsi
call   1040 <strcpy@plt>
lea    0xe58(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <strcat@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1080 <strdup@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"GCOV_PREFIX\00"
@.str.1 = [2 x i8] c"/\00"
define i8* @mangle_filename(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
store i8* null, i8** %5
%6 = call i8* @getenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i8* %6, i8** %4
%7 = load i8*, i8** %4
%8 = icmp ne i8* %7, null
br i1 %8, label %12, label %9
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = call i8* @strdup(i8* %10)
store i8* %11, i8** %2
br label %30
12: ; preds = %1
%13 = load i8*, i8** %4
%14 = call i64 @strlen(i8* %13)
%15 = add nsw i64 %14, 1
%16 = load i8*, i8** %3
%17 = call i64 @strlen(i8* %16)
%18 = add nsw i64 %15, %17
%19 = add nsw i64 %18, 1
%20 = call i8* @malloc(i64 %19)
store i8* %20, i8** %5
%21 = load i8*, i8** %5
%22 = load i8*, i8** %4
%23 = call i32 @strcpy(i8* %21, i8* %22)
%24 = load i8*, i8** %5
%25 = call i32 @strcat(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%26 = load i8*, i8** %5
%27 = load i8*, i8** %3
%28 = call i32 @strcat(i8* %26, i8* %27)
%29 = load i8*, i8** %5
store i8* %29, i8** %2
br label %30
30: ; preds = %12, %9
%31 = load i8*, i8** %2
ret i8* %31
}

LLVM IR (-O2):
@.str = [12 x i8] c"GCOV_PREFIX\00"
@.str.1 = [2 x i8] c"/\00"
define i8* @mangle_filename(i8* %0) {
%2 = tail call i8* @getenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i8* %2, null
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i8* @strdup(i8* %0)
br label %15
6: ; preds = %1
%7 = tail call i64 @strlen(i8* %2)
%8 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%9 = add i64 %7, 2
%10 = add i64 %9, %8
%11 = tail call i8* @malloc(i64 %10)
%12 = tail call i32 @strcpy(i8* %11, i8* %2)
%13 = tail call i32 @strcat(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%14 = tail call i32 @strcat(i8* %11, i8* %0)
br label %15
15: ; preds = %6, %4
%16 = phi i8* [ %11, %6 ], [ %5, %4 ]
ret i8* %16
}