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

/* Variables and functions */
int /*<<< orphan*/ FD_CLR(int, int /*<<< orphan*/ *);
scalar_t__ FD_ISSET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ printf(char *, ...);
int shutdown_socket(int dst_socket, fd_set *active_fd_set) {
  if (dst_socket < 0 || active_fd_set == NULL) {
    printf("Socket or socket set incorrect.\n");
    return -1;
  }
  if (FD_ISSET(dst_socket, active_fd_set)) {
    FD_CLR(dst_socket, active_fd_set);
  }
  close(dst_socket);
  printf("(Socket %d): Successfully closed client socket.\n", dst_socket);
  return 0;
}


x86 assembly (clang, -O0):
<shutdown_socket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     1164 <shutdown_socket+0x24>
cmpq   $0x0,-0x10(%rbp)
jne    117e <shutdown_socket+0x3e>
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c0 <shutdown_socket+0x80>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
je     11a0 <shutdown_socket+0x60>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1060 <FD_CLR@plt>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
mov    -0x8(%rbp),%esi
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shutdown_socket>:
push   %rbp
push   %r14
push   %rbx
test   %edi,%edi
js     1194 <shutdown_socket+0x44>
mov    %rsi,%r14
test   %rsi,%rsi
je     1194 <shutdown_socket+0x44>
mov    %edi,%ebx
mov    %r14,%rsi
call   1040 <FD_ISSET@plt>
test   %rax,%rax
je     1179 <shutdown_socket+0x29>
mov    %ebx,%edi
mov    %r14,%rsi
call   1070 <FD_CLR@plt>
mov    %ebx,%edi
call   1060 <close@plt>
lea    0xe79(%rip),%rdi
xor    %ebp,%ebp
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11a5 <shutdown_socket+0x55>
lea    0xe96(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [33 x i8] c"Socket or socket set incorrect.\0A\00"
@.str.1 = [49 x i8] c"(Socket %d): Successfully closed client socket.\0A\00"
define i32 @shutdown_socket(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
store i32 %0, i32* %4
store i32* %1, i32** %5
%6 = load i32, i32* %4
%7 = icmp slt i32 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = load i32*, i32** %5
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %8, %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %27
13: ; preds = %8
%14 = load i32, i32* %4
%15 = load i32*, i32** %5
%16 = call i64 @FD_ISSET(i32 %14, i32* %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %13
%19 = load i32, i32* %4
%20 = load i32*, i32** %5
%21 = call i32 @FD_CLR(i32 %19, i32* %20)
br label %22
22: ; preds = %18, %13
%23 = load i32, i32* %4
%24 = call i32 @close(i32 %23)
%25 = load i32, i32* %4
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0), i32 %25)
store i32 0, i32* %3
br label %27
27: ; preds = %22, %11
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
@.str.1 = [49 x i8] c"(Socket %d): Successfully closed client socket.\0A\00"
@str = [32 x i8] c"Socket or socket set incorrect.\00"
define i32 @shutdown_socket(i32 %0, i32* %1) {
%3 = icmp slt i32 %0, 0
%4 = icmp eq i32* %1, null
%5 = or i1 %3, %4
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
br label %16
8: ; preds = %2
%9 = tail call i64 @FD_ISSET(i32 %0, i32* %1)
%10 = icmp eq i64 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %8
%12 = tail call i32 @FD_CLR(i32 %0, i32* %1)
br label %13
13: ; preds = %11, %8
%14 = tail call i32 @close(i32 %0)
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0), i32 %0)
br label %16
16: ; preds = %13, %6
%17 = phi i32 [ -1, %6 ], [ 0, %13 ]
ret i32 %17
}