#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  char *pw_dir;
};

/* Variables and functions */
int /*<<< orphan*/ errno;
TYPE_1__ *getpwuid(int /*<<< orphan*/);
int /*<<< orphan*/ getuid();
int /*<<< orphan*/ log_error(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ log_message(char *, int);
int /*<<< orphan*/ sprintf(char *, char *, char const *);
int unlink(char *);
int remove_lock() {
  char lock_file[1024];
  const char *home_dir = getpwuid(getuid())->pw_dir;
  sprintf(lock_file, "%s/streams.lock", home_dir);
  if (unlink(lock_file) == -1) {
    log_error("Could not delete lock file in home directory", 1, errno);
    return 1;
  }
  log_message("Lock file removed", 7);
  return 0;
}


x86 assembly (clang, -O0):
<remove_lock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    $0x0,%al
call   1060 <getuid@plt>
mov    %eax,%edi
call   1050 <getpwuid@plt>
mov    (%rax),%rax
mov    %rax,-0x418(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x418(%rbp),%rdx
lea    0xe68(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0x410(%rbp),%rdi
call   1030 <unlink@plt>
cmp    $0xffffffff,%eax
jne    11d8 <remove_lock+0x78>
mov    0x2e27(%rip),%rax
mov    (%rax),%edx
lea    0xe4e(%rip),%rdi
mov    $0x1,%esi
call   1040 <log_error@plt>
movl   $0x1,-0x4(%rbp)
jmp    11f0 <remove_lock+0x90>
lea    0xe5e(%rip),%rdi
mov    $0x7,%esi
call   1070 <log_message@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remove_lock>:
push   %rbp
push   %rbx
sub    $0x408,%rsp
xor    %ebp,%ebp
xor    %eax,%eax
call   1060 <getuid@plt>
mov    %eax,%edi
call   1050 <getpwuid@plt>
mov    (%rax),%rdx
lea    0xe7d(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1080 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <unlink@plt>
cmp    $0xffffffff,%eax
je     11ae <remove_lock+0x4e>
lea    0xe9b(%rip),%rdi
mov    $0x7,%esi
call   1070 <log_message@plt>
jmp    11cd <remove_lock+0x6d>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edx
lea    0xe52(%rip),%rdi
mov    $0x1,%ebp
mov    $0x1,%esi
call   1040 <log_error@plt>
mov    %ebp,%eax
add    $0x408,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_2__ = type { i8* }
@.str = [16 x i8] c"%s/streams.lock\00"
@.str.1 = [45 x i8] c"Could not delete lock file in home directory\00"
@errno = global i32 0
@.str.2 = [18 x i8] c"Lock file removed\00"
define i32 @remove_lock() {
%1 = alloca i32
%2 = alloca [1024 x i8]
%3 = alloca i8*
%4 = call i32 (...) @getuid()
%5 = call %struct.TYPE_2__* @getpwuid(i32 %4)
%6 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %5, i32 0, i32 0
%7 = load i8*, i8** %6
store i8* %7, i8** %3
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%9 = load i8*, i8** %3
%10 = call i32 @sprintf(i8* %8, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%12 = call i32 @unlink(i8* %11)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %17
14: ; preds = %0
%15 = load i32, i32* @errno
%16 = call i32 @log_error(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i32 1, i32 %15)
store i32 1, i32* %1
br label %19
17: ; preds = %0
%18 = call i32 @log_message(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 7)
store i32 0, i32* %1
br label %19
19: ; preds = %17, %14
%20 = load i32, i32* %1
ret i32 %20
}

LLVM IR (-O2):
%struct.TYPE_2__ = type { i8* }
@.str = [16 x i8] c"%s/streams.lock\00"
@.str.1 = [45 x i8] c"Could not delete lock file in home directory\00"
@errno = global i32 0
@.str.2 = [18 x i8] c"Lock file removed\00"
define i32 @remove_lock() {
%1 = alloca [1024 x i8]
%2 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (...) @getuid()
%4 = tail call %struct.TYPE_2__* @getpwuid(i32 %3)
%5 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %4, i64 0, i32 0
%6 = load i8*, i8** %5
%7 = call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = call i32 @unlink(i8* %2)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = load i32, i32* @errno
%12 = tail call i32 @log_error(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i32 1, i32 %11)
br label %15
13: ; preds = %0
%14 = tail call i32 @log_message(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 7)
br label %15
15: ; preds = %13, %10
%16 = phi i32 [ 1, %10 ], [ 0, %13 ]
ret i32 %16
}