#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);
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) {
      UNLLog(1, "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     123c <ts_broadcast+0xfc>
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    1229 <ts_broadcast+0xe9>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    $0x1,%edi
lea    0xe51(%rip),%rsi
call   1050 <UNLLog@plt>
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   1060 <FD_CLR@plt>
mov    -0x1c(%rbp),%eax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%eax
jne    11f7 <ts_broadcast+0xb7>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0xffffffff,%ecx
mov    %ecx,(%rax)
jmp    1224 <ts_broadcast+0xe4>
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    1229 <ts_broadcast+0xe9>
jmp    122e <ts_broadcast+0xee>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1164 <ts_broadcast+0x24>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ts_broadcast>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %dil,0x7(%rsp)
cmpl   $0x0,(%rdx)
jle    11fd <ts_broadcast+0xbd>
mov    %rdx,%r13
mov    %rsi,%r14
mov    $0x1,%ebx
lea    0x7(%rsp),%r15
lea    0xe90(%rip),%r12
jmp    118d <ts_broadcast+0x4d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x0(%r13),%eax
lea    0x1(%rbx),%ecx
cmp    %eax,%ebx
mov    %ecx,%ebx
jge    11fd <ts_broadcast+0xbd>
movslq %ebx,%rbp
mov    0x0(%r13,%rbp,4),%edi
mov    %r15,%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1030 <send@plt>
test   %rax,%rax
jns    1180 <ts_broadcast+0x40>
mov    0x0(%r13,%rbp,4),%edx
mov    $0x1,%edi
mov    %r12,%rsi
call   1050 <UNLLog@plt>
mov    0x0(%r13,%rbp,4),%edi
call   1040 <close@plt>
mov    0x0(%r13,%rbp,4),%edi
mov    %r14,%rsi
call   1060 <FD_CLR@plt>
movslq 0x0(%r13),%rax
cmp    %eax,%ebp
je     11f6 <ts_broadcast+0xb6>
mov    0x0(%r13,%rax,4),%eax
mov    %eax,0x0(%r13,%rbp,4)
mov    0x0(%r13),%eax
add    $0xffffffff,%eax
mov    %eax,0x0(%r13)
add    $0xffffffff,%ebp
mov    %ebp,%ebx
jmp    1184 <ts_broadcast+0x44>
add    $0xffffffff,%ebx
mov    %ebx,0x0(%r13)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [49 x i8] c"Failed to send data to client, closing it (%i).\0A\00"
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 = %72, %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 %75
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 %71
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 @UNLLog(i32 1, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), 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 = call i32 @close(i32 %33)
%35 = load i32*, i32** %6
%36 = load i32, i32* %7
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i32, i32* %35, i64 %37
%39 = load i32, i32* %38
%40 = load i32*, i32** %5
%41 = call i32 @FD_CLR(i32 %39, i32* %40)
%42 = load i32, i32* %7
%43 = load i32*, i32** %6
%44 = getelementptr inbounds i32, i32* %43, i64 0
%45 = load i32, i32* %44
%46 = icmp eq i32 %42, %45
br i1 %46, label %47, label %52
47: ; preds = %22
%48 = load i32*, i32** %6
%49 = getelementptr inbounds i32, i32* %48, i64 0
%50 = load i32, i32* %49
%51 = add nsw i32 %50, -1
store i32 %51, i32* %49
br label %70
52: ; preds = %22
%53 = load i32*, i32** %6
%54 = load i32*, i32** %6
%55 = getelementptr inbounds i32, i32* %54, i64 0
%56 = load i32, i32* %55
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i32, i32* %53, i64 %57
%59 = load i32, i32* %58
%60 = load i32*, i32** %6
%61 = load i32, i32* %7
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i32, i32* %60, i64 %62
store i32 %59, i32* %63
%64 = load i32*, i32** %6
%65 = getelementptr inbounds i32, i32* %64, i64 0
%66 = load i32, i32* %65
%67 = add nsw i32 %66, -1
store i32 %67, i32* %65
%68 = load i32, i32* %7
%69 = add nsw i32 %68, -1
store i32 %69, i32* %7
br label %70
70: ; preds = %52, %47
br label %71
71: ; preds = %70, %14
br label %72
72: ; preds = %71
%73 = load i32, i32* %7
%74 = add nsw i32 %73, 1
store i32 %74, i32* %7
br label %8
75: ; preds = %8
ret void
}

LLVM IR (-O2):
@.str = [49 x i8] c"Failed to send data to client, closing it (%i).\0A\00"
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 %39, label %7
7: ; preds = %3, %34
%8 = phi i32 [ %37, %34 ], [ 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 %34
16: ; preds = %7
%17 = load i32, i32* %10
%18 = call i32 @UNLLog(i32 1, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i32 %17)
%19 = load i32, i32* %10
%20 = call i32 @close(i32 %19)
%21 = load i32, i32* %10
%22 = call i32 @FD_CLR(i32 %21, i32* %1)
%23 = load i32, i32* %2
%24 = icmp eq i32 %8, %23
br i1 %24, label %25, label %27
25: ; preds = %16
%26 = add nsw i32 %8, -1
store i32 %26, i32* %2
br label %39
27: ; preds = %16
%28 = sext i32 %23 to i64
%29 = getelementptr inbounds i32, i32* %2, i64 %28
%30 = load i32, i32* %29
store i32 %30, i32* %10
%31 = load i32, i32* %2
%32 = add nsw i32 %31, -1
store i32 %32, i32* %2
%33 = add nsw i32 %8, -1
br label %34
34: ; preds = %14, %27
%35 = phi i32 [ %32, %27 ], [ %15, %14 ]
%36 = phi i32 [ %33, %27 ], [ %8, %14 ]
%37 = add nsw i32 %36, 1
%38 = icmp slt i32 %36, %35
br i1 %38, label %7, label %39
39: ; preds = %34, %25, %3
ret void
}