#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(int);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *, char const *);
int strlen(char *);
char *px_ipc_name(const char *name) {
  char *dst;
  char *dir;
  char *slash;
  dst = malloc((20));
  if (NULL == dst) {
    return NULL;
  }
  dir = getenv("PX_IPC_NAME");
  if (NULL == dir) {
    dir = "tests";
  }
  slash = ('/' == dir[strlen(dir) - 1]) ? "" : "/";
  snprintf(dst, (20), "%s%s%s", dir, slash, name);
  return dst;
}


x86 assembly (clang, -O0):
<px_ipc_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x14,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
jne    1173 <px_ipc_name+0x33>
movq   $0x0,-0x8(%rbp)
jmp    1201 <px_ipc_name+0xc1>
lea    0xe86(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmp    -0x20(%rbp),%rax
jne    119a <px_ipc_name+0x5a>
lea    0xe76(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%esi
mov    $0x2f,%edx
lea    0xe4b(%rip),%rax
lea    0xe45(%rip),%rcx
cmp    %esi,%edx
cmove  %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
mov    -0x10(%rbp),%r9
mov    $0x14,%esi
lea    0xe20(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<px_ipc_name>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
mov    $0x14,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
test   %rax,%rax
je     11af <px_ipc_name+0x6f>
lea    0xe9f(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
lea    0xe9c(%rip),%rbx
cmovne %rax,%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
cmpb   $0x2f,-0x1(%rax,%rbx,1)
lea    0xe89(%rip),%rax
lea    0xe81(%rip),%r8
cmove  %rax,%r8
lea    0xe78(%rip),%rdx
mov    %r15,%rdi
mov    $0x14,%esi
mov    %rbx,%rcx
mov    %r14,%r9
call   1050 <snprintf@plt>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [12 x i8] c"PX_IPC_NAME\00"
@.str.1 = [6 x i8] c"tests\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [2 x i8] c"/\00"
@.str.4 = [7 x i8] c"%s%s%s\00"
define i8* @px_ipc_name(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %3
%7 = call i8* @malloc(i32 20)
store i8* %7, i8** %4
%8 = load i8*, i8** %4
%9 = icmp eq i8* null, %8
br i1 %9, label %10, label %11
10: ; preds = %1
store i8* null, i8** %2
br label %34
11: ; preds = %1
%12 = call i8* @getenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i8* %12, i8** %5
%13 = load i8*, i8** %5
%14 = icmp eq i8* null, %13
br i1 %14, label %15, label %16
15: ; preds = %11
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8** %5
br label %16
16: ; preds = %15, %11
%17 = load i8*, i8** %5
%18 = load i8*, i8** %5
%19 = call i32 @strlen(i8* %18)
%20 = sub nsw i32 %19, 1
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %17, i64 %21
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 47, %24
%26 = zext i1 %25 to i64
%27 = select i1 %25, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0)
store i8* %27, i8** %6
%28 = load i8*, i8** %4
%29 = load i8*, i8** %5
%30 = load i8*, i8** %6
%31 = load i8*, i8** %3
%32 = call i32 @snprintf(i8* %28, i32 20, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %29, i8* %30, i8* %31)
%33 = load i8*, i8** %4
store i8* %33, i8** %2
br label %34
34: ; preds = %16, %10
%35 = load i8*, i8** %2
ret i8* %35
}

LLVM IR (-O2):
@.str = [12 x i8] c"PX_IPC_NAME\00"
@.str.1 = [6 x i8] c"tests\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [2 x i8] c"/\00"
@.str.4 = [7 x i8] c"%s%s%s\00"
define i8* @px_ipc_name(i8* %0) {
%2 = tail call dereferenceable_or_null(20) i8* @malloc(i32 20)
%3 = icmp eq i8* %2, null
br i1 %3, label %16, label %4
4: ; preds = %1
%5 = tail call i8* @getenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i8* %5, null
%7 = select i1 %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %5
%8 = tail call i32 @strlen(i8* %7)
%9 = add nsw i32 %8, -1
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %7, i64 %10
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 47
%14 = select i1 %13, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0)
%15 = tail call i32 @snprintf(i8* %2, i32 20, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %7, i8* %14, i8* %0)
br label %16
16: ; preds = %1, %4
ret i8* %2
}