#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 *,
                            char const *);
int strlen(char *);
char *fnc_ipc_name(const char *firstname, const char *lastname) {
  char *dir, *dst, *slash;
  if ((dst = malloc(4096)) == NULL)
    return (NULL);
  if ((dir = getenv("PX_IPC_NAME")) == NULL) {
    dir = "";
  }
  slash = (strlen(dir) && (dir[strlen(dir) - 1] == '/')) ? "" : "/";
  snprintf(dst, 4096, "%s%s%s.%s", dir, slash, firstname, lastname);
  return (dst);
}


x86 assembly (clang, -O0):
<fnc_ipc_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    $0x1000,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1175 <fnc_ipc_name+0x35>
movq   $0x0,-0x8(%rbp)
jmp    122a <fnc_ipc_name+0xea>
lea    0xe84(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    119a <fnc_ipc_name+0x5a>
lea    0xe77(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x31(%rbp)
je     11dd <fnc_ipc_name+0x9d>
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
sete   %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%dl
lea    0xe25(%rip),%rax
lea    0xe1f(%rip),%rcx
test   $0x1,%dl
cmovne %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    -0x30(%rbp),%r8
mov    -0x10(%rbp),%r9
mov    -0x18(%rbp),%rax
mov    $0x1000,%esi
lea    0xdf5(%rip),%rdx
mov    %rax,(%rsp)
call   1050 <snprintf@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fnc_ipc_name>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r15
mov    %rdi,%r14
mov    $0x1000,%edi
call   1060 <malloc@plt>
mov    %rax,%r12
test   %rax,%rax
je     11cf <fnc_ipc_name+0x8f>
lea    0xe94(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
test   %rax,%rax
lea    0xe8f(%rip),%r13
cmove  %r13,%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
je     11aa <fnc_ipc_name+0x6a>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
cmpb   $0x2f,-0x1(%rax,%rbx,1)
lea    0xe68(%rip),%r8
cmove  %r13,%r8
jmp    11b1 <fnc_ipc_name+0x71>
lea    0xe5b(%rip),%r8
mov    %r15,(%rsp)
lea    0xe52(%rip),%rdx
mov    %r12,%rdi
mov    $0x1000,%esi
mov    %rbx,%rcx
mov    %r14,%r9
call   1050 <snprintf@plt>
mov    %r12,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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