#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 */
struct sockaddr_un {
  scalar_t__ *sun_path;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ getsockname(int, struct sockaddr *, int *);
int /*<<< orphan*/ unlink(scalar_t__ *);
int lxc_af_unix_close(int fd) {
  struct sockaddr_un addr;
  socklen_t addrlen = sizeof(addr);
  if (!getsockname(fd, (struct sockaddr *)&addr, &addrlen) && addr.sun_path[0])
    unlink(addr.sun_path);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<lxc_af_unix_close>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x8,-0x14(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x10(%rbp),%rsi
lea    -0x14(%rbp),%rdx
call   1050 <getsockname@plt>
cmp    $0x0,%eax
jne    1172 <lxc_af_unix_close+0x42>
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     1172 <lxc_af_unix_close+0x42>
mov    -0x10(%rbp),%rdi
call   1030 <unlink@plt>
mov    -0x4(%rbp),%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lxc_af_unix_close>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
movl   $0x8,0x4(%rsp)
lea    0x8(%rsp),%rsi
lea    0x4(%rsp),%rdx
call   1050 <getsockname@plt>
test   %eax,%eax
jne    1162 <lxc_af_unix_close+0x32>
mov    0x8(%rsp),%rdi
cmpq   $0x0,(%rdi)
je     1162 <lxc_af_unix_close+0x32>
call   1030 <unlink@plt>
mov    %ebx,%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.sockaddr_un = type { i64* }
%struct.sockaddr = type { i32 }
define i32 @lxc_af_unix_close(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.sockaddr_un
%4 = alloca i32
store i32 %0, i32* %2
store i32 8, i32* %4
%5 = load i32, i32* %2
%6 = bitcast %struct.sockaddr_un* %3 to %struct.sockaddr*
%7 = call i32 @getsockname(i32 %5, %struct.sockaddr* %6, i32* %4)
%8 = icmp ne i32 %7, 0
br i1 %8, label %19, label %9
9: ; preds = %1
%10 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i32 0, i32 0
%11 = load i64*, i64** %10
%12 = getelementptr inbounds i64, i64* %11, i64 0
%13 = load i64, i64* %12
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %9
%16 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i32 0, i32 0
%17 = load i64*, i64** %16
%18 = call i32 @unlink(i64* %17)
br label %19
19: ; preds = %15, %9, %1
%20 = load i32, i32* %2
%21 = call i32 @close(i32 %20)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i64* }
%struct.sockaddr = type { i32 }
define i32 @lxc_af_unix_close(i32 %0) {
%2 = alloca %struct.sockaddr_un
%3 = alloca i32
%4 = bitcast %struct.sockaddr_un* %2 to i8*
%5 = bitcast i32* %3 to i8*
store i32 8, i32* %3
%6 = bitcast %struct.sockaddr_un* %2 to %struct.sockaddr*
%7 = call i32 @getsockname(i32 %0, %struct.sockaddr* %6, i32* %3)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %16
9: ; preds = %1
%10 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %2, i64 0, i32 0
%11 = load i64*, i64** %10
%12 = load i64, i64* %11
%13 = icmp eq i64 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %9
%15 = call i32 @unlink(i64* %11)
br label %16
16: ; preds = %14, %9, %1
%17 = call i32 @close(i32 %0)
ret i32 0
}