#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*/ *);
int /*<<< orphan*/ UNLLog(int, char *, int);
int /*<<< orphan*/ close(int);
int close_client(int *client_socket, int i, fd_set *fd_active) {
  UNLLog(1, "Failed to receive data from client, closing it (%i).\n",
         client_socket[i]);
  close(client_socket[i]);
  FD_CLR(client_socket[i], fd_active);
  if (i == client_socket[0]) {
    client_socket[0]--;
    return 0;
  } else {
    client_socket[i] = client_socket[client_socket[0]];
    client_socket[0]--;
    return 1;
  }
}


x86 assembly (clang, -O0):
<close_client>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    $0x1,%edi
lea    0xea6(%rip),%rsi
call   1040 <UNLLog@plt>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
call   1030 <close@plt>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
mov    -0x20(%rbp),%rsi
call   1050 <FD_CLR@plt>
mov    -0x14(%rbp),%eax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%eax
jne    11a9 <close_client+0x79>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0xffffffff,%ecx
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    11d4 <close_client+0xa4>
mov    -0x10(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0xffffffff,%ecx
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<close_client>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %esi,%r15d
mov    %rdi,%rbx
movslq %esi,%rbp
mov    (%rdi,%rbp,4),%edx
lea    0xeb3(%rip),%rsi
mov    $0x1,%edi
call   1040 <UNLLog@plt>
mov    (%rbx,%rbp,4),%edi
call   1030 <close@plt>
mov    (%rbx,%rbp,4),%edi
mov    %r14,%rsi
call   1050 <FD_CLR@plt>
movslq (%rbx),%rcx
xor    %eax,%eax
cmp    %ebp,%ecx
je     1181 <close_client+0x51>
mov    (%rbx,%rcx,4),%eax
mov    %eax,(%rbx,%rbp,4)
mov    (%rbx),%r15d
mov    $0x1,%eax
add    $0xffffffff,%r15d
mov    %r15d,(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [54 x i8] c"Failed to receive data from client, closing it (%i).\0A\00"
define i32 @close_client(i32* %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32*
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32* %2, i32** %7
%8 = load i32*, i32** %5
%9 = load i32, i32* %6
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i32, i32* %8, i64 %10
%12 = load i32, i32* %11
%13 = call i32 @UNLLog(i32 1, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = load i32*, i32** %5
%15 = load i32, i32* %6
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i32, i32* %14, i64 %16
%18 = load i32, i32* %17
%19 = call i32 @close(i32 %18)
%20 = load i32*, i32** %5
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %20, i64 %22
%24 = load i32, i32* %23
%25 = load i32*, i32** %7
%26 = call i32 @FD_CLR(i32 %24, i32* %25)
%27 = load i32, i32* %6
%28 = load i32*, i32** %5
%29 = getelementptr inbounds i32, i32* %28, i64 0
%30 = load i32, i32* %29
%31 = icmp eq i32 %27, %30
br i1 %31, label %32, label %37
32: ; preds = %3
%33 = load i32*, i32** %5
%34 = getelementptr inbounds i32, i32* %33, i64 0
%35 = load i32, i32* %34
%36 = add nsw i32 %35, -1
store i32 %36, i32* %34
store i32 0, i32* %4
br label %53
37: ; preds = %3
%38 = load i32*, i32** %5
%39 = load i32*, i32** %5
%40 = getelementptr inbounds i32, i32* %39, i64 0
%41 = load i32, i32* %40
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i32, i32* %38, i64 %42
%44 = load i32, i32* %43
%45 = load i32*, i32** %5
%46 = load i32, i32* %6
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i32, i32* %45, i64 %47
store i32 %44, i32* %48
%49 = load i32*, i32** %5
%50 = getelementptr inbounds i32, i32* %49, i64 0
%51 = load i32, i32* %50
%52 = add nsw i32 %51, -1
store i32 %52, i32* %50
store i32 1, i32* %4
br label %53
53: ; preds = %37, %32
%54 = load i32, i32* %4
ret i32 %54
}

LLVM IR (-O2):
@.str = [54 x i8] c"Failed to receive data from client, closing it (%i).\0A\00"
define i32 @close_client(i32* nocapture %0, i32 %1, i32* %2) {
%4 = sext i32 %1 to i64
%5 = getelementptr inbounds i32, i32* %0, i64 %4
%6 = load i32, i32* %5
%7 = tail call i32 @UNLLog(i32 1, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = load i32, i32* %5
%9 = tail call i32 @close(i32 %8)
%10 = load i32, i32* %5
%11 = tail call i32 @FD_CLR(i32 %10, i32* %2)
%12 = load i32, i32* %0
%13 = icmp eq i32 %12, %1
br i1 %13, label %19, label %14
14: ; preds = %3
%15 = sext i32 %12 to i64
%16 = getelementptr inbounds i32, i32* %0, i64 %15
%17 = load i32, i32* %16
store i32 %17, i32* %5
%18 = load i32, i32* %0
br label %19
19: ; preds = %3, %14
%20 = phi i32 [ %18, %14 ], [ %1, %3 ]
%21 = phi i32 [ 1, %14 ], [ 0, %3 ]
%22 = add nsw i32 %20, -1
store i32 %22, i32* %0
ret i32 %21
}