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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
char *get_lockfile_path();
int /*<<< orphan*/ getline(char **, size_t *, int /*<<< orphan*/ *);
char *malloc(size_t);
int /*<<< orphan*/ stderr;
char *read_path_from_lockfile() {
  char *lockfile = NULL;
  FILE *fp = NULL;
  char *data = NULL;
  char *line = NULL;
  size_t len = 256;
  data = malloc(len * sizeof(char));
  if (data == NULL) {
    fprintf(stderr, "Malloc failed.\n");
    return NULL;
  }
  lockfile = get_lockfile_path();
  if (lockfile == NULL) {
    free(data);
    return NULL;
  }
  fp = fopen(lockfile, "r");
  if (!fp) {
    free(data);
    free(lockfile);
    return NULL;
  }
  line = data;
  getline(&line, &len, fp);
  fclose(fp);
  free(lockfile);
  return line;
}


x86 assembly (clang, -O0):
<read_path_from_lockfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x100,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
shl    $0x0,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11de <read_path_from_lockfile+0x6e>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
lea    0xe34(%rip),%rsi
call   1060 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    127b <read_path_from_lockfile+0x10b>
mov    $0x0,%al
call   1040 <get_lockfile_path@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    120a <read_path_from_lockfile+0x9a>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    127b <read_path_from_lockfile+0x10b>
mov    -0x10(%rbp),%rdi
lea    0xdfb(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1248 <read_path_from_lockfile+0xd8>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    127b <read_path_from_lockfile+0x10b>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdx
lea    -0x28(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1090 <getline@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_path_from_lockfile>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
movq   $0x100,0x8(%rsp)
mov    $0x100,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     11e4 <read_path_from_lockfile+0x74>
mov    %rax,%rbx
xor    %eax,%eax
call   1040 <get_lockfile_path@plt>
test   %rax,%rax
je     11fb <read_path_from_lockfile+0x8b>
mov    %rax,%r14
lea    0xe66(%rip),%rsi
mov    %rax,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     1200 <read_path_from_lockfile+0x90>
mov    %rax,%r15
mov    %rbx,(%rsp)
mov    %rsp,%rdi
lea    0x8(%rsp),%rsi
mov    %rax,%rdx
call   1090 <getline@plt>
mov    %r15,%rdi
call   1050 <fclose@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    (%rsp),%rax
jmp    1212 <read_path_from_lockfile+0xa2>
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
lea    0xe0c(%rip),%rsi
call   1060 <fprintf@plt>
jmp    1210 <read_path_from_lockfile+0xa0>
mov    %rbx,%rdi
jmp    120b <read_path_from_lockfile+0x9b>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [16 x i8] c"Malloc failed.\0A\00"
@.str.1 = [2 x i8] c"r\00"
define i8* @read_path_from_lockfile() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
store i8* null, i8** %2
store i32* null, i32** %3
store i8* null, i8** %4
store i8* null, i8** %5
store i64 256, i64* %6
%7 = load i64, i64* %6
%8 = mul i64 %7, 1
%9 = call i8* @malloc(i64 %8)
store i8* %9, i8** %4
%10 = load i8*, i8** %4
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %15
12: ; preds = %0
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %1
br label %41
15: ; preds = %0
%16 = call i8* (...) @get_lockfile_path()
store i8* %16, i8** %2
%17 = load i8*, i8** %2
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %22
19: ; preds = %15
%20 = load i8*, i8** %4
%21 = call i32 @free(i8* %20)
store i8* null, i8** %1
br label %41
22: ; preds = %15
%23 = load i8*, i8** %2
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %24, i32** %3
%25 = load i32*, i32** %3
%26 = icmp ne i32* %25, null
br i1 %26, label %32, label %27
27: ; preds = %22
%28 = load i8*, i8** %4
%29 = call i32 @free(i8* %28)
%30 = load i8*, i8** %2
%31 = call i32 @free(i8* %30)
store i8* null, i8** %1
br label %41
32: ; preds = %22
%33 = load i8*, i8** %4
store i8* %33, i8** %5
%34 = load i32*, i32** %3
%35 = call i32 @getline(i8** %5, i64* %6, i32* %34)
%36 = load i32*, i32** %3
%37 = call i32 @fclose(i32* %36)
%38 = load i8*, i8** %2
%39 = call i32 @free(i8* %38)
%40 = load i8*, i8** %5
store i8* %40, i8** %1
br label %41
41: ; preds = %32, %27, %19, %12
%42 = load i8*, i8** %1
ret i8* %42
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [16 x i8] c"Malloc failed.\0A\00"
@.str.1 = [2 x i8] c"r\00"
define i8* @read_path_from_lockfile() {
%1 = alloca i8*
%2 = alloca i64
%3 = bitcast i8** %1 to i8*
%4 = bitcast i64* %2 to i8*
store i64 256, i64* %2
%5 = tail call dereferenceable_or_null(256) i8* @malloc(i64 256)
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %26
10: ; preds = %0
%11 = tail call i8* (...) @get_lockfile_path()
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = tail call i32 @free(i8* %5)
br label %26
15: ; preds = %10
%16 = tail call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = tail call i32 @free(i8* %5)
%20 = tail call i32 @free(i8* %11)
br label %26
21: ; preds = %15
store i8* %5, i8** %1
%22 = call i32 @getline(i8** %1, i64* %2, i32* %16)
%23 = call i32 @fclose(i32* %16)
%24 = call i32 @free(i8* %11)
%25 = load i8*, i8** %1
br label %26
26: ; preds = %21, %18, %13, %7
%27 = phi i8* [ null, %7 ], [ null, %13 ], [ %25, %21 ], [ null, %18 ]
ret i8* %27
}