#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*/ pid_dir;

/* Variables and functions */
int /*<<< orphan*/ free(char *);
scalar_t__ snprintf(char *, size_t, char *, char const *, char const *);
int strlen(char const *);
char *xcalloc(size_t, int);
const char *local_pid_dir(const char *local_dir) {
  if (local_dir == NULL || *local_dir == '\0')
    return NULL;
  const char pid_dir[] = "/.nyx/pid";
  size_t len = strlen(local_dir) + (sizeof(pid_dir) / sizeof(pid_dir[0])) + 1;
  char *buffer = xcalloc(len, sizeof(char));
  if (snprintf(buffer, len - 1, "%s%s", local_dir, pid_dir) < 0) {
    free(buffer);
    return NULL;
  }
  return buffer;
}


x86 assembly (clang, -O0):
<local_pid_dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1167 <local_pid_dir+0x27>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1174 <local_pid_dir+0x34>
movq   $0x0,-0x8(%rbp)
jmp    11fb <local_pid_dir+0xbb>
mov    0xe85(%rip),%rax
mov    %rax,-0x1a(%rbp)
mov    0xe82(%rip),%ax
mov    %ax,-0x12(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cltq
add    $0xa,%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    $0x1,%esi
call   1060 <xcalloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
sub    $0x1,%rsi
mov    -0x10(%rbp),%rcx
lea    -0x1a(%rbp),%r8
lea    0xe3c(%rip),%rdx
call   1050 <snprintf@plt>
cmp    $0x0,%rax
jge    11f3 <local_pid_dir+0xb3>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    11fb <local_pid_dir+0xbb>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<local_pid_dir>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
test   %rdi,%rdi
je     11b0 <local_pid_dir+0x70>
mov    %rdi,%rbx
cmpb   $0x0,(%rdi)
je     11b0 <local_pid_dir+0x70>
movabs $0x69702f78796e2e2f,%rax
2f 70 69
mov    %rax,(%rsp)
movw   $0x64,0x8(%rsp)
mov    %rbx,%rdi
call   1040 <strlen@plt>
movslq %eax,%rdi
lea    0xa(%rdi),%r15
add    $0xb,%rdi
mov    $0x1,%esi
call   1060 <xcalloc@plt>
mov    %rax,%r14
lea    0xe78(%rip),%rdx
mov    %rsp,%r8
mov    %rax,%rdi
mov    %r15,%rsi
mov    %rbx,%rcx
call   1050 <snprintf@plt>
test   %rax,%rax
jns    11b3 <local_pid_dir+0x73>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.local_pid_dir.pid_dir = [10 x i8] c"/.nyx/pid\00"
@.str = [5 x i8] c"%s%s\00"
define i8* @local_pid_dir(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca [10 x i8]
%5 = alloca i64
%6 = alloca i8*
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = icmp eq i8* %7, null
br i1 %8, label %14, label %9
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %9, %1
store i8* null, i8** %2
br label %36
15: ; preds = %9
%16 = bitcast [10 x i8]* %4 to i8*
%17 = load i8*, i8** %3
%18 = call i32 @strlen(i8* %17)
%19 = sext i32 %18 to i64
%20 = add i64 %19, 10
%21 = add i64 %20, 1
store i64 %21, i64* %5
%22 = load i64, i64* %5
%23 = call i8* @xcalloc(i64 %22, i32 1)
store i8* %23, i8** %6
%24 = load i8*, i8** %6
%25 = load i64, i64* %5
%26 = sub i64 %25, 1
%27 = load i8*, i8** %3
%28 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%29 = call i64 @snprintf(i8* %24, i64 %26, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %27, i8* %28)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %15
%32 = load i8*, i8** %6
%33 = call i32 @free(i8* %32)
store i8* null, i8** %2
br label %36
34: ; preds = %15
%35 = load i8*, i8** %6
store i8* %35, i8** %2
br label %36
36: ; preds = %34, %31, %14
%37 = load i8*, i8** %2
ret i8* %37
}

LLVM IR (-O2):
@__const.local_pid_dir.pid_dir = [10 x i8] c"/.nyx/pid\00"
@.str = [5 x i8] c"%s%s\00"
define i8* @local_pid_dir(i8* %0) {
%2 = alloca [10 x i8]
%3 = icmp eq i8* %0, null
br i1 %3, label %20, label %4
4: ; preds = %1
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 0
br i1 %6, label %20, label %7
7: ; preds = %4
%8 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%9 = tail call i32 @strlen(i8* %0)
%10 = sext i32 %9 to i64
%11 = add nsw i64 %10, 10
%12 = add nsw i64 %10, 11
%13 = tail call i8* @xcalloc(i64 %12, i32 1)
%14 = call i64 @snprintf(i8* %13, i64 %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %8)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %7
%17 = call i32 @free(i8* %13)
br label %18
18: ; preds = %7, %16
%19 = phi i8* [ null, %16 ], [ %13, %7 ]
br label %20
20: ; preds = %1, %4, %18
%21 = phi i8* [ %19, %18 ], [ null, %4 ], [ null, %1 ]
ret i8* %21
}