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

/* Variables and functions */
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ getsockname(int, struct sockaddr *, int /*<<< orphan*/ *);
int /*<<< orphan*/ unlink(scalar_t__ *);
int lxc_af_unix_close(int fd) {
  struct sockaddr_un addr;
  socklen_t addrlen;
  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)
mov    -0x4(%rbp),%edi
lea    -0x10(%rbp),%rsi
lea    -0x14(%rbp),%rdx
call   1050 <getsockname@plt>
cmp    $0x0,%eax
jne    116b <lxc_af_unix_close+0x3b>
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     116b <lxc_af_unix_close+0x3b>
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
mov    %rsp,%rsi
lea    0xc(%rsp),%rdx
call   1050 <getsockname@plt>
test   %eax,%eax
jne    1157 <lxc_af_unix_close+0x27>
mov    (%rsp),%rdi
cmpq   $0x0,(%rdi)
je     1157 <lxc_af_unix_close+0x27>
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
%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*
%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
}