#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);
int /*<<< orphan*/ shutdown_socket(int, int /*<<< orphan*/ *);
int shutdown_server(int srv_socket, int max_fd, fd_set *active_fd_set) {
  int i;
  for (i = 0; i <= max_fd; i++) {
    if (i == srv_socket) {
      continue;
    } else if (FD_ISSET(i, active_fd_set)) {
      shutdown_socket(i, active_fd_set);
    }
  }
  if (FD_ISSET(srv_socket, active_fd_set)) {
    FD_CLR(srv_socket, active_fd_set);
  }
  close(srv_socket);
  printf("(Socket %d): Successfully closed server socket.\n", srv_socket);
  return 0;
}


x86 assembly (clang, -O0):
<shutdown_server>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     11c0 <shutdown_server+0x70>
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jne    1186 <shutdown_server+0x36>
jmp    11b2 <shutdown_server+0x62>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
je     11a8 <shutdown_server+0x58>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1050 <shutdown_socket@plt>
jmp    11ad <shutdown_server+0x5d>
jmp    11b2 <shutdown_server+0x62>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1169 <shutdown_server+0x19>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
je     11e2 <shutdown_server+0x92>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1070 <FD_CLR@plt>
mov    -0x4(%rbp),%edi
call   1060 <close@plt>
mov    -0x4(%rbp),%esi
lea    0xe0c(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shutdown_server>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %edi,%r15d
test   %esi,%esi
js     1197 <shutdown_server+0x47>
mov    %esi,%ebp
add    $0x1,%ebp
xor    %ebx,%ebx
jmp    1177 <shutdown_server+0x27>
nopw   0x0(%rax,%rax,1)
add    $0x1,%ebx
cmp    %ebx,%ebp
je     1197 <shutdown_server+0x47>
cmp    %ebx,%r15d
je     1170 <shutdown_server+0x20>
mov    %ebx,%edi
mov    %r14,%rsi
call   1030 <FD_ISSET@plt>
test   %rax,%rax
je     1170 <shutdown_server+0x20>
mov    %ebx,%edi
mov    %r14,%rsi
call   1050 <shutdown_socket@plt>
jmp    1170 <shutdown_server+0x20>
mov    %r15d,%edi
mov    %r14,%rsi
call   1030 <FD_ISSET@plt>
test   %rax,%rax
je     11b2 <shutdown_server+0x62>
mov    %r15d,%edi
mov    %r14,%rsi
call   1070 <FD_CLR@plt>
mov    %r15d,%edi
call   1060 <close@plt>
lea    0xe3f(%rip),%rdi
mov    %r15d,%esi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [49 x i8] c"(Socket %d): Successfully closed server socket.\0A\00"
define i32 @shutdown_server(i32 %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32* %2, i32** %6
store i32 0, i32* %7
br label %8
8: ; preds = %28, %3
%9 = load i32, i32* %7
%10 = load i32, i32* %5
%11 = icmp sle i32 %9, %10
br i1 %11, label %12, label %31
12: ; preds = %8
%13 = load i32, i32* %7
%14 = load i32, i32* %4
%15 = icmp eq i32 %13, %14
br i1 %15, label %16, label %17
16: ; preds = %12
br label %28
17: ; preds = %12
%18 = load i32, i32* %7
%19 = load i32*, i32** %6
%20 = call i64 @FD_ISSET(i32 %18, i32* %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %17
%23 = load i32, i32* %7
%24 = load i32*, i32** %6
%25 = call i32 @shutdown_socket(i32 %23, i32* %24)
br label %26
26: ; preds = %22, %17
br label %27
27: ; preds = %26
br label %28
28: ; preds = %27, %16
%29 = load i32, i32* %7
%30 = add nsw i32 %29, 1
store i32 %30, i32* %7
br label %8
31: ; preds = %8
%32 = load i32, i32* %4
%33 = load i32*, i32** %6
%34 = call i64 @FD_ISSET(i32 %32, i32* %33)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %40
36: ; preds = %31
%37 = load i32, i32* %4
%38 = load i32*, i32** %6
%39 = call i32 @FD_CLR(i32 %37, i32* %38)
br label %40
40: ; preds = %36, %31
%41 = load i32, i32* %4
%42 = call i32 @close(i32 %41)
%43 = load i32, i32* %4
%44 = call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i32 %43)
ret i32 0
}

LLVM IR (-O2):
@.str = [49 x i8] c"(Socket %d): Successfully closed server socket.\0A\00"
define i32 @shutdown_server(i32 %0, i32 %1, i32* %2) {
%4 = icmp slt i32 %1, 0
br i1 %4, label %16, label %5
5: ; preds = %3, %13
%6 = phi i32 [ %14, %13 ], [ 0, %3 ]
%7 = icmp eq i32 %6, %0
br i1 %7, label %13, label %8
8: ; preds = %5
%9 = tail call i64 @FD_ISSET(i32 %6, i32* %2)
%10 = icmp eq i64 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %8
%12 = tail call i32 @shutdown_socket(i32 %6, i32* %2)
br label %13
13: ; preds = %11, %8, %5
%14 = add nuw i32 %6, 1
%15 = icmp eq i32 %6, %1
br i1 %15, label %16, label %5
16: ; preds = %13, %3
%17 = tail call i64 @FD_ISSET(i32 %0, i32* %2)
%18 = icmp eq i64 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %16
%20 = tail call i32 @FD_CLR(i32 %0, i32* %2)
br label %21
21: ; preds = %19, %16
%22 = tail call i32 @close(i32 %0)
%23 = tail call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i32 %0)
ret i32 0
}