#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 *, ...);
int /*<<< orphan*/ getenv(char *);
scalar_t__ geteuid();
char *getlockfilename() {
  char *lockfile;
  if (geteuid() == 0) {
    asprintf(&lockfile, "%s", "/var/run/gladbooks.pid");
  } else {
    asprintf(&lockfile, "%s/%s", getenv("HOME"), ".gladbooks.pid");
  }
  return lockfile;
}


x86 assembly (clang, -O0):
<getlockfilename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1040 <geteuid@plt>
cmp    $0x0,%rax
jne    1167 <getlockfilename+0x37>
lea    -0x8(%rbp),%rdi
lea    0xec6(%rip),%rsi
lea    0xea5(%rip),%rdx
mov    $0x0,%al
call   1050 <asprintf@plt>
jmp    118f <getlockfilename+0x5f>
lea    0xeaf(%rip),%rdi
call   1030 <getenv@plt>
movslq %eax,%rdx
lea    -0x8(%rbp),%rdi
lea    0xe96(%rip),%rsi
lea    0xe9a(%rip),%rcx
mov    $0x0,%al
call   1050 <asprintf@plt>
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getlockfilename>:
push   %rax
xor    %eax,%eax
call   1040 <geteuid@plt>
test   %rax,%rax
je     1166 <getlockfilename+0x36>
lea    0xed9(%rip),%rdi
call   1030 <getenv@plt>
movslq %eax,%rdx
lea    0xec4(%rip),%rsi
lea    0xec8(%rip),%rcx
mov    %rsp,%rdi
xor    %eax,%eax
call   1050 <asprintf@plt>
jmp    117e <getlockfilename+0x4e>
lea    0xead(%rip),%rsi
lea    0xe8c(%rip),%rdx
mov    %rsp,%rdi
xor    %eax,%eax
call   1050 <asprintf@plt>
mov    (%rsp),%rax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [23 x i8] c"/var/run/gladbooks.pid\00"
@.str.2 = [6 x i8] c"%s/%s\00"
@.str.3 = [5 x i8] c"HOME\00"
@.str.4 = [15 x i8] c".gladbooks.pid\00"
define i8* @getlockfilename() {
%1 = alloca i8*
%2 = call i64 (...) @geteuid()
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %6
4: ; preds = %0
%5 = call i32 (i8**, i8*, i8*, ...) @asprintf(i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %11
6: ; preds = %0
%7 = call i32 @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%8 = sext i32 %7 to i64
%9 = inttoptr i64 %8 to i8*
%10 = call i32 (i8**, i8*, i8*, ...) @asprintf(i8** %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %9, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
br label %11
11: ; preds = %6, %4
%12 = load i8*, i8** %1
ret i8* %12
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [23 x i8] c"/var/run/gladbooks.pid\00"
@.str.2 = [6 x i8] c"%s/%s\00"
@.str.3 = [5 x i8] c"HOME\00"
@.str.4 = [15 x i8] c".gladbooks.pid\00"
define i8* @getlockfilename() {
%1 = alloca i8*
%2 = bitcast i8** %1 to i8*
%3 = tail call i64 (...) @geteuid()
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = call i32 (i8**, i8*, i8*, ...) @asprintf(i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %12
7: ; preds = %0
%8 = tail call i32 @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%9 = sext i32 %8 to i64
%10 = inttoptr i64 %9 to i8*
%11 = call i32 (i8**, i8*, i8*, ...) @asprintf(i8** %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %10, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
br label %12
12: ; preds = %7, %5
%13 = load i8*, i8** %1
ret i8* %13
}