#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 */
int /*<<< orphan*/ asprintf(char **, char *, char *, char *);
int /*<<< orphan*/ err(int, char *);
char *getenv(char *);
char *pidpath(char *daemon) {
  char *p;
  char *bh;
  bh = getenv("BOITHOHOME");
  if (bh == NULL)
    err(1, "BOITHOHOME not set");
  asprintf(&p, "%s/var/%s.gpid", bh, daemon);
  if (p == NULL)
    err(1, "asprintf()");
  return p;
}


x86 assembly (clang, -O0):
<pidpath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xebd(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1168 <pidpath+0x38>
mov    $0x1,%edi
lea    0xea8(%rip),%rsi
call   1040 <err@plt>
mov    -0x18(%rbp),%rdx
mov    -0x8(%rbp),%rcx
lea    -0x10(%rbp),%rdi
lea    0xea3(%rip),%rsi
call   1050 <asprintf@plt>
cmpq   $0x0,-0x10(%rbp)
jne    119c <pidpath+0x6c>
mov    $0x1,%edi
lea    0xe96(%rip),%rsi
call   1040 <err@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pidpath>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xec2(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    115c <pidpath+0x2c>
lea    0xeb9(%rip),%rsi
mov    $0x1,%edi
call   1040 <err@plt>
lea    0xebb(%rip),%rsi
mov    %rsp,%rdi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1050 <asprintf@plt>
mov    (%rsp),%rax
test   %rax,%rax
jne    118f <pidpath+0x5f>
lea    0xeac(%rip),%rsi
mov    $0x1,%edi
call   1040 <err@plt>
mov    (%rsp),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [11 x i8] c"BOITHOHOME\00"
@.str.1 = [19 x i8] c"BOITHOHOME not set\00"
@.str.2 = [15 x i8] c"%s/var/%s.gpid\00"
@.str.3 = [11 x i8] c"asprintf()\00"
define i8* @pidpath(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %2
%5 = call i8* @getenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store i8* %5, i8** %4
%6 = load i8*, i8** %4
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 @err(i32 1, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %10
10: ; preds = %8, %1
%11 = load i8*, i8** %4
%12 = load i8*, i8** %2
%13 = call i32 @asprintf(i8** %3, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %11, i8* %12)
%14 = load i8*, i8** %3
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %18
16: ; preds = %10
%17 = call i32 @err(i32 1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
br label %18
18: ; preds = %16, %10
%19 = load i8*, i8** %3
ret i8* %19
}

LLVM IR (-O2):
@.str = [11 x i8] c"BOITHOHOME\00"
@.str.1 = [19 x i8] c"BOITHOHOME not set\00"
@.str.2 = [15 x i8] c"%s/var/%s.gpid\00"
@.str.3 = [11 x i8] c"asprintf()\00"
define i8* @pidpath(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = tail call i8* @getenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %8
8: ; preds = %6, %1
%9 = call i32 @asprintf(i8** %2, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %4, i8* %0)
%10 = load i8*, i8** %2
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %15
12: ; preds = %8
%13 = call i32 @err(i32 1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%14 = load i8*, i8** %2
br label %15
15: ; preds = %12, %8
%16 = phi i8* [ %14, %12 ], [ %10, %8 ]
ret i8* %16
}