#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 */
scalar_t__ FD_ISSET(int, int /*<<< orphan*/ *);
scalar_t__ close_client(int *, int, int /*<<< orphan*/ *);
scalar_t__ recv(int, void *, int, int /*<<< orphan*/);
int ts_receive(unsigned char *c, fd_set *fd_read, fd_set *fd_active,
               int *client_socket) {
  int i;
  for (i = 1; i <= client_socket[0]; i++) {
    if (FD_ISSET(client_socket[i], fd_read)) {
      if (recv(client_socket[i], c, 1, 0) <= 0) {
        if (close_client(client_socket, i, fd_active)) {
          i--;
        }
      } else {
        if (*c == 255) {
          char devNull[2];
          if (recv(client_socket[i], (void *)devNull, 2, 0) <= 0) {
            close_client(client_socket, i, fd_active);
          }
          return 1;
        }
        return 0;
      }
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<ts_receive>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    -0x28(%rbp),%rcx
cmp    (%rcx),%eax
jg     1240 <ts_receive+0x110>
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
mov    -0x18(%rbp),%rsi
call   1050 <FD_ISSET@plt>
cmp    $0x0,%rax
je     122d <ts_receive+0xfd>
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
mov    -0x10(%rbp),%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cmp    $0x0,%rax
jg     11c9 <ts_receive+0x99>
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   1040 <close_client@plt>
cmp    $0x0,%rax
je     11c4 <ts_receive+0x94>
mov    -0x2c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x2c(%rbp)
jmp    1228 <ts_receive+0xf8>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
cmp    $0xff,%eax
jne    121c <ts_receive+0xec>
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
lea    -0x2e(%rbp),%rsi
mov    $0x2,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cmp    $0x0,%rax
jg     1210 <ts_receive+0xe0>
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   1040 <close_client@plt>
movl   $0x1,-0x4(%rbp)
jmp    1247 <ts_receive+0x117>
movl   $0x0,-0x4(%rbp)
jmp    1247 <ts_receive+0x117>
jmp    122d <ts_receive+0xfd>
jmp    1232 <ts_receive+0x102>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    114f <ts_receive+0x1f>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ts_receive>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmpl   $0x0,(%rcx)
jle    11dc <ts_receive+0xac>
mov    %rcx,%r15
mov    %rdx,%r14
mov    %rsi,%r13
mov    %rdi,%r12
mov    $0x1,%ebx
jmp    116a <ts_receive+0x3a>
nopw   0x0(%rax,%rax,1)
lea    0x1(%rbx),%eax
cmp    (%r15),%ebx
mov    %eax,%ebx
jge    11dc <ts_receive+0xac>
movslq %ebx,%rbp
mov    (%r15,%rbp,4),%edi
mov    %r13,%rsi
call   1050 <FD_ISSET@plt>
test   %rax,%rax
je     1160 <ts_receive+0x30>
mov    (%r15,%rbp,4),%edi
mov    %r12,%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %rax,%rax
jg     11ac <ts_receive+0x7c>
mov    %r15,%rdi
mov    %ebx,%esi
mov    %r14,%rdx
call   1040 <close_client@plt>
cmp    $0x1,%rax
adc    $0xffffffff,%ebx
jmp    1160 <ts_receive+0x30>
xor    %eax,%eax
cmpb   $0xff,(%r12)
jne    11e1 <ts_receive+0xb1>
mov    (%r15,%rbp,4),%edi
lea    0x6(%rsp),%rsi
mov    $0x2,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %rax,%rax
jg     11dc <ts_receive+0xac>
mov    %r15,%rdi
mov    %ebx,%esi
mov    %r14,%rdx
call   1040 <close_client@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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