#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 {
  int /*<<< orphan*/ sun_path;
};
struct sockaddr_storage {
  int dummy;
};
typedef scalar_t__ sa_family_t;

/* Variables and functions */
scalar_t__ AF_UNIX;
scalar_t__ close(int);
int remove(int /*<<< orphan*/);
int close_listening_socket(int listenfd, sa_family_t family,
                           struct sockaddr_storage *sock_addr) {
  if (close(listenfd))
    return -1;
  if (family == AF_UNIX) {
    return remove(((struct sockaddr_un *)sock_addr)->sun_path);
  }
  return 0;
}


x86 assembly (clang, -O0):
<close_listening_socket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
cmp    $0x0,%rax
je     1151 <close_listening_socket+0x31>
movl   $0xffffffff,-0x4(%rbp)
jmp    117f <close_listening_socket+0x5f>
mov    -0x10(%rbp),%rax
mov    0x2e8c(%rip),%rcx
cmp    (%rcx),%rax
jne    1178 <close_listening_socket+0x58>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1030 <remove@plt>
mov    %eax,-0x4(%rbp)
jmp    117f <close_listening_socket+0x5f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<close_listening_socket>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
call   1040 <close@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
jne    1159 <close_listening_socket+0x39>
mov    0x2ea5(%rip),%rcx
xor    %eax,%eax
cmp    %rbx,(%rcx)
jne    1159 <close_listening_socket+0x39>
mov    (%r14),%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <remove@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
%struct.sockaddr_storage = type { i32 }
@AF_UNIX = global i64 0
define i32 @close_listening_socket(i32 %0, i64 %1, %struct.sockaddr_storage* nocapture %2) {
%4 = tail call i64 @close(i32 %0)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %13
6: ; preds = %3
%7 = load i64, i64* @AF_UNIX
%8 = icmp eq i64 %7, %1
br i1 %8, label %9, label %13
9: ; preds = %6
%10 = getelementptr %struct.sockaddr_storage, %struct.sockaddr_storage* %2, i64 0, i32 0
%11 = load i32, i32* %10
%12 = tail call i32 @remove(i32 %11)
br label %13
13: ; preds = %6, %3, %9
%14 = phi i32 [ %12, %9 ], [ -1, %3 ], [ 0, %6 ]
ret i32 %14
}