#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
char *malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *strdup(char *);
char *cached_filename(char *buf, int quality) {
  char *str;
  char *retval = malloc(sizeof(buf) + 4);
  char quality_s[3];
  str = strdup(buf);
  sprintf(quality_s, "%d", quality);
  strcpy(retval, str);
  strcat(retval, "-");
  strcat(retval, quality_s);
  return retval;
}


x86 assembly (clang, -O0):
<cached_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    $0xc,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x18(%rbp)
lea    -0x23(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xe78(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rdi
lea    0xe5e(%rip),%rsi
call   1050 <strcat@plt>
mov    -0x20(%rbp),%rdi
lea    -0x23(%rbp),%rsi
call   1050 <strcat@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cached_filename>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%rbx
mov    $0xc,%edi
call   1040 <malloc@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1070 <strdup@plt>
mov    %rax,%rbx
lea    0xe84(%rip),%rsi
lea    0x5(%rsp),%r15
mov    %r15,%rdi
mov    %r14d,%edx
call   1060 <sprintf@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
lea    0xe65(%rip),%rsi
mov    %rbp,%rdi
call   1050 <strcat@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
call   1050 <strcat@plt>
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [2 x i8] c"-\00"
define i8* @cached_filename(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca [3 x i8]
store i8* %0, i8** %3
store i32 %1, i32* %4
%8 = call i8* @malloc(i32 12)
store i8* %8, i8** %6
%9 = load i8*, i8** %3
%10 = call i8* @strdup(i8* %9)
store i8* %10, i8** %5
%11 = getelementptr inbounds [3 x i8], [3 x i8]* %7, i64 0, i64 0
%12 = load i32, i32* %4
%13 = call i32 @sprintf(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = load i8*, i8** %6
%15 = load i8*, i8** %5
%16 = call i32 @strcpy(i8* %14, i8* %15)
%17 = load i8*, i8** %6
%18 = call i32 @strcat(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%19 = load i8*, i8** %6
%20 = getelementptr inbounds [3 x i8], [3 x i8]* %7, i64 0, i64 0
%21 = call i32 @strcat(i8* %19, i8* %20)
%22 = load i8*, i8** %6
ret i8* %22
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [2 x i8] c"-\00"
define i8* @cached_filename(i8* nocapture %0, i32 %1) {
%3 = alloca [3 x i8]
%4 = tail call dereferenceable_or_null(12) i8* @malloc(i32 12)
%5 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%6 = tail call i8* @strdup(i8* %0)
%7 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %1)
%8 = tail call i32 @strcpy(i8* %4, i8* %6)
%9 = tail call i32 @strcat(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 @strcat(i8* %4, i8* %5)
ret i8* %4
}