#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*/ fprintf(int /*<<< orphan*/, char *);
char *getenv(char *);
char *malloc(size_t);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
size_t strlen(char *);
char *get_lockfile_path() {
  char *path = NULL;
  char *env = NULL;
  size_t len = 0;
  env = getenv("HOME");
  if (env == NULL) {
    fprintf(stderr, "Failed to get home path\n");
    return NULL;
  }
  len = strlen(env);
  path = malloc((len + 13) * sizeof(char));
  if (path == NULL) {
    fprintf(stderr, "Malloc failed\n");
    return NULL;
  }
  strcpy(path, env);
  strcat(path, "/.steel_open");
  return path;
}


x86 assembly (clang, -O0):
<get_lockfile_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
lea    0xe79(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11bd <get_lockfile_path+0x5d>
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
lea    0xe5a(%rip),%rsi
call   1060 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1231 <get_lockfile_path+0xd1>
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
add    $0xd,%rdi
shl    $0x0,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    120c <get_lockfile_path+0xac>
mov    0x2def(%rip),%rax
mov    (%rax),%edi
lea    0xe24(%rip),%rsi
call   1060 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1231 <get_lockfile_path+0xd1>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x10(%rbp),%rdi
lea    0xe09(%rip),%rsi
call   1080 <strcat@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_lockfile_path>:
push   %r14
push   %rbx
push   %rax
lea    0xe95(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11ad <get_lockfile_path+0x4d>
mov    %rax,%r14
mov    %rax,%rdi
call   1050 <strlen@plt>
lea    0xd(%rax),%rdi
call   1070 <malloc@plt>
test   %rax,%rax
je     11bf <get_lockfile_path+0x5f>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
lea    0xe8a(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcat@plt>
jmp    11d6 <get_lockfile_path+0x76>
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
lea    0xe48(%rip),%rsi
jmp    11cf <get_lockfile_path+0x6f>
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
lea    0xe4f(%rip),%rsi
call   1060 <fprintf@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [5 x i8] c"HOME\00"
@stderr = global i32 0
@.str.1 = [25 x i8] c"Failed to get home path\0A\00"
@.str.2 = [15 x i8] c"Malloc failed\0A\00"
@.str.3 = [13 x i8] c"/.steel_open\00"
define i8* @get_lockfile_path() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
store i8* null, i8** %2
store i8* null, i8** %3
store i64 0, i64* %4
%5 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %5, i8** %3
%6 = load i8*, i8** %3
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = load i32, i32* @stderr
%10 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
store i8* null, i8** %1
br label %30
11: ; preds = %0
%12 = load i8*, i8** %3
%13 = call i64 @strlen(i8* %12)
store i64 %13, i64* %4
%14 = load i64, i64* %4
%15 = add i64 %14, 13
%16 = mul i64 %15, 1
%17 = call i8* @malloc(i64 %16)
store i8* %17, i8** %2
%18 = load i8*, i8** %2
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %23
20: ; preds = %11
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
store i8* null, i8** %1
br label %30
23: ; preds = %11
%24 = load i8*, i8** %2
%25 = load i8*, i8** %3
%26 = call i32 @strcpy(i8* %24, i8* %25)
%27 = load i8*, i8** %2
%28 = call i32 @strcat(i8* %27, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%29 = load i8*, i8** %2
store i8* %29, i8** %1
br label %30
30: ; preds = %23, %20, %8
%31 = load i8*, i8** %1
ret i8* %31
}

LLVM IR (-O2):
@.str = [5 x i8] c"HOME\00"
@stderr = global i32 0
@.str.1 = [25 x i8] c"Failed to get home path\0A\00"
@.str.2 = [15 x i8] c"Malloc failed\0A\00"
@.str.3 = [13 x i8] c"/.steel_open\00"
define i8* @get_lockfile_path() {
%1 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i8* %1, null
br i1 %2, label %3, label %6
3: ; preds = %0
%4 = load i32, i32* @stderr
%5 = tail call i32 @fprintf(i32 %4, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
br label %17
6: ; preds = %0
%7 = tail call i64 @strlen(i8* %1)
%8 = add i64 %7, 13
%9 = tail call i8* @malloc(i64 %8)
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %14
11: ; preds = %6
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
br label %17
14: ; preds = %6
%15 = tail call i32 @strcpy(i8* %9, i8* %1)
%16 = tail call i32 @strcat(i8* %9, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br label %17
17: ; preds = %14, %11, %3
%18 = phi i8* [ null, %3 ], [ null, %11 ], [ %9, %14 ]
ret i8* %18
}