#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*/ close(int);
int /*<<< orphan*/ printf(char *, int);
scalar_t__ send(int, char *, int, int /*<<< orphan*/);
void ts_broadcast(char c, fd_set *fd_set, int *client_socket) {
  int i = -1;
  for (i = 1; i <= client_socket[0]; i++) {
    if (send(client_socket[i], &c, 1, 0) < 0) {
      if (0 > 1)
        printf("DEBUG: failed to send data to client, closing it (%i).\n",
               client_socket[i]);
      close(client_socket[i]);
      FD_CLR(client_socket[i], fd_set);
      if (i == client_socket[0]) {
        client_socket[0]--;
      } else {
        client_socket[i] = client_socket[client_socket[0]];
        client_socket[0]--;
        i--;
      }
    }
  }
}


x86 assembly (clang, -O0):
<ts_broadcast>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%eax
jg     1210 <ts_broadcast+0xe0>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
lea    -0x1(%rbp),%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1030 <send@plt>
cmp    $0x0,%rax
jge    11fd <ts_broadcast+0xcd>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
call   1040 <close@plt>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
mov    -0x10(%rbp),%rsi
call   1050 <FD_CLR@plt>
mov    -0x1c(%rbp),%eax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%eax
jne    11cb <ts_broadcast+0x9b>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0xffffffff,%ecx
mov    %ecx,(%rax)
jmp    11f8 <ts_broadcast+0xc8>
mov    -0x18(%rbp),%rax
mov    -0x18(%rbp),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0xffffffff,%ecx
mov    %ecx,(%rax)
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    11fd <ts_broadcast+0xcd>
jmp    1202 <ts_broadcast+0xd2>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1154 <ts_broadcast+0x24>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ts_broadcast>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %dil,0xf(%rsp)
cmpl   $0x0,(%rdx)
jle    11c9 <ts_broadcast+0x99>
mov    %rdx,%r12
mov    %rsi,%r14
mov    $0x1,%ebx
lea    0xf(%rsp),%r15
jmp    116d <ts_broadcast+0x3d>
nopl   (%rax)
mov    (%r12),%eax
lea    0x1(%rbx),%ecx
cmp    %eax,%ebx
mov    %ecx,%ebx
jge    11c9 <ts_broadcast+0x99>
movslq %ebx,%r13
mov    (%r12,%r13,4),%edi
mov    %r15,%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1030 <send@plt>
test   %rax,%rax
jns    1160 <ts_broadcast+0x30>
mov    (%r12,%r13,4),%edi
call   1040 <close@plt>
mov    (%r12,%r13,4),%edi
mov    %r14,%rsi
call   1050 <FD_CLR@plt>
movslq (%r12),%rax
cmp    %eax,%r13d
je     11c2 <ts_broadcast+0x92>
mov    (%r12,%rax,4),%eax
mov    %eax,(%r12,%r13,4)
mov    (%r12),%eax
add    $0xffffffff,%eax
mov    %eax,(%r12)
add    $0xffffffff,%r13d
mov    %r13d,%ebx
jmp    1164 <ts_broadcast+0x34>
add    $0xffffffff,%ebx
mov    %ebx,(%r12)
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @ts_broadcast(i8 signext %0, i32* %1, i32* %2) {
%4 = alloca i8
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
store i8 %0, i8* %4
store i32* %1, i32** %5
store i32* %2, i32** %6
store i32 -1, i32* %7
store i32 1, i32* %7
br label %8
8: ; preds = %66, %3
%9 = load i32, i32* %7
%10 = load i32*, i32** %6
%11 = getelementptr inbounds i32, i32* %10, i64 0
%12 = load i32, i32* %11
%13 = icmp sle i32 %9, %12
br i1 %13, label %14, label %69
14: ; preds = %8
%15 = load i32*, i32** %6
%16 = load i32, i32* %7
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i32, i32* %15, i64 %17
%19 = load i32, i32* %18
%20 = call i64 @send(i32 %19, i8* %4, i32 1, i32 0)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %65
22: ; preds = %14
%23 = load i32*, i32** %6
%24 = load i32, i32* %7
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32, i32* %23, i64 %25
%27 = load i32, i32* %26
%28 = call i32 @close(i32 %27)
%29 = load i32*, i32** %6
%30 = load i32, i32* %7
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i32, i32* %29, i64 %31
%33 = load i32, i32* %32
%34 = load i32*, i32** %5
%35 = call i32 @FD_CLR(i32 %33, i32* %34)
%36 = load i32, i32* %7
%37 = load i32*, i32** %6
%38 = getelementptr inbounds i32, i32* %37, i64 0
%39 = load i32, i32* %38
%40 = icmp eq i32 %36, %39
br i1 %40, label %41, label %46
41: ; preds = %22
%42 = load i32*, i32** %6
%43 = getelementptr inbounds i32, i32* %42, i64 0
%44 = load i32, i32* %43
%45 = add nsw i32 %44, -1
store i32 %45, i32* %43
br label %64
46: ; preds = %22
%47 = load i32*, i32** %6
%48 = load i32*, i32** %6
%49 = getelementptr inbounds i32, i32* %48, i64 0
%50 = load i32, i32* %49
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i32, i32* %47, i64 %51
%53 = load i32, i32* %52
%54 = load i32*, i32** %6
%55 = load i32, i32* %7
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i32, i32* %54, i64 %56
store i32 %53, i32* %57
%58 = load i32*, i32** %6
%59 = getelementptr inbounds i32, i32* %58, i64 0
%60 = load i32, i32* %59
%61 = add nsw i32 %60, -1
store i32 %61, i32* %59
%62 = load i32, i32* %7
%63 = add nsw i32 %62, -1
store i32 %63, i32* %7
br label %64
64: ; preds = %46, %41
br label %65
65: ; preds = %64, %14
br label %66
66: ; preds = %65
%67 = load i32, i32* %7
%68 = add nsw i32 %67, 1
store i32 %68, i32* %7
br label %8
69: ; preds = %8
ret void
}

LLVM IR (-O2):
define void @ts_broadcast(i8 signext %0, i32* %1, i32* nocapture %2) {
%4 = alloca i8
store i8 %0, i8* %4
%5 = load i32, i32* %2
%6 = icmp slt i32 %5, 1
br i1 %6, label %37, label %7
7: ; preds = %3, %32
%8 = phi i32 [ %35, %32 ], [ 1, %3 ]
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i32, i32* %2, i64 %9
%11 = load i32, i32* %10
%12 = call i64 @send(i32 %11, i8* %4, i32 1, i32 0)
%13 = icmp slt i64 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %7
%15 = load i32, i32* %2
br label %32
16: ; preds = %7
%17 = load i32, i32* %10
%18 = call i32 @close(i32 %17)
%19 = load i32, i32* %10
%20 = call i32 @FD_CLR(i32 %19, i32* %1)
%21 = load i32, i32* %2
%22 = icmp eq i32 %8, %21
br i1 %22, label %23, label %25
23: ; preds = %16
%24 = add nsw i32 %8, -1
store i32 %24, i32* %2
br label %37
25: ; preds = %16
%26 = sext i32 %21 to i64
%27 = getelementptr inbounds i32, i32* %2, i64 %26
%28 = load i32, i32* %27
store i32 %28, i32* %10
%29 = load i32, i32* %2
%30 = add nsw i32 %29, -1
store i32 %30, i32* %2
%31 = add nsw i32 %8, -1
br label %32
32: ; preds = %14, %25
%33 = phi i32 [ %30, %25 ], [ %15, %14 ]
%34 = phi i32 [ %31, %25 ], [ %8, %14 ]
%35 = add nsw i32 %34, 1
%36 = icmp slt i32 %34, %33
br i1 %36, label %7, label %37
37: ; preds = %32, %23, %3
ret void
}