#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(size_t const);
int /*<<< orphan*/ memcpy(char *, char const *, size_t const);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
size_t strlen(char const *);
char *GetPluginStateDir(int instance, const char *dir) {
  if (dir == NULL)
    return NULL;
  char effidstr[24] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  snprintf(effidstr, 23, "effect-%d", instance);
  const size_t current_path_size = strlen(dir);
  const size_t effidstr_size = strlen(effidstr);
  char *newpath, *buf;
  newpath = buf = malloc(current_path_size + effidstr_size + 2);
  if (newpath == NULL)
    return NULL;
  memcpy(buf, dir, current_path_size);
  buf += current_path_size;
  *buf++ = '/';
  memcpy(buf, effidstr, effidstr_size);
  buf += effidstr_size;
  *buf = '\0';
  return newpath;
}


x86 assembly (clang, -O0):
<GetPluginStateDir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1177 <GetPluginStateDir+0x27>
movq   $0x0,-0x8(%rbp)
jmp    1245 <GetPluginStateDir+0xf5>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1050 <memset@plt>
lea    -0x30(%rbp),%rdi
mov    -0xc(%rbp),%ecx
mov    $0x17,%esi
lea    0xe66(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x38(%rbp)
lea    -0x30(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%rdi
add    -0x40(%rbp),%rdi
add    $0x2,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x50(%rbp)
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    11ea <GetPluginStateDir+0x9a>
movq   $0x0,-0x8(%rbp)
jmp    1245 <GetPluginStateDir+0xf5>
mov    -0x50(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x38(%rbp),%rdx
call   1060 <memcpy@plt>
mov    -0x38(%rbp),%rax
add    -0x50(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x50(%rbp)
movb   $0x2f,(%rax)
mov    -0x50(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    -0x40(%rbp),%rdx
call   1060 <memcpy@plt>
mov    -0x40(%rbp),%rax
add    -0x50(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x48(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetPluginStateDir>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
test   %rsi,%rsi
je     11dd <GetPluginStateDir+0x9d>
mov    %rsi,%r14
mov    %edi,%ecx
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movq   $0x0,0x10(%rsp)
lea    0xe90(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x17,%esi
call   1040 <snprintf@plt>
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %rax,%r12
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %rax,%r15
lea    (%r12,%rax,1),%rdi
add    $0x2,%rdi
call   1060 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11df <GetPluginStateDir+0x9f>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
call   1050 <memcpy@plt>
lea    (%rbx,%r12,1),%r14
lea    (%rbx,%r12,1),%rdi
add    $0x1,%rdi
movb   $0x2f,(%rbx,%r12,1)
mov    %rsp,%rsi
mov    %r15,%rdx
call   1050 <memcpy@plt>
movb   $0x0,0x1(%r15,%r14,1)
jmp    11df <GetPluginStateDir+0x9f>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [10 x i8] c"effect-%d\00"
define i8* @GetPluginStateDir(i32 %0, i8* %1) {
%3 = alloca [24 x i8]
%4 = icmp eq i8* %1, null
br i1 %4, label %21, label %5
5: ; preds = %2
%6 = getelementptr inbounds [24 x i8], [24 x i8]* %3, i64 0, i64 0
%7 = call i32 @snprintf(i8* %6, i32 23, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %0)
%8 = call i64 @strlen(i8* %1)
%9 = call i64 @strlen(i8* %6)
%10 = add i64 %8, 2
%11 = add i64 %10, %9
%12 = call i8* @malloc(i64 %11)
%13 = icmp eq i8* %12, null
br i1 %13, label %20, label %14
14: ; preds = %5
%15 = call i32 @memcpy(i8* %12, i8* %1, i64 %8)
%16 = getelementptr inbounds i8, i8* %12, i64 %8
%17 = getelementptr inbounds i8, i8* %16, i64 1
store i8 47, i8* %16
%18 = call i32 @memcpy(i8* %17, i8* %6, i64 %9)
%19 = getelementptr inbounds i8, i8* %17, i64 %9
store i8 0, i8* %19
br label %20
20: ; preds = %5, %14
br label %21
21: ; preds = %2, %20
%22 = phi i8* [ %12, %20 ], [ null, %2 ]
ret i8* %22
}