#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 */
struct pollfd {
  int fd;
  int events;
  int revents;
};

/* Variables and functions */
int client_in(int, struct pollfd *, int *);
int poll(struct pollfd *, int, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ recv_data(int, struct pollfd *, int);
void svr_loop(int lsn_sock) {
  struct pollfd set[100];
  int fds;
  int set_pos = 0;
  int sock;
  int i;
  set[0].fd = lsn_sock;
  set[0].events = 0x040;
  for (i = 1; i < 100; i++)
    set[i].fd = -1;
  while (1) {
    fds = poll(set, set_pos + 1, -1);
    if (set[0].revents & 0x040) {
      sock = client_in(lsn_sock, set, &set_pos);
      if (sock == -1)
        continue;
      printf("client in\n");
      if (--fds <= 0)
        continue;
    }
    recv_data(fds, set, set_pos);
  }
}


x86 assembly (clang, -O0):
<svr_loop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4d0,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x4c8(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x4c0(%rbp)
movl   $0x40,-0x4bc(%rbp)
movl   $0x1,-0x4d0(%rbp)
cmpl   $0x64,-0x4d0(%rbp)
jge    11b1 <svr_loop+0x71>
movslq -0x4d0(%rbp),%rcx
lea    -0x4c0(%rbp),%rax
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
movl   $0xffffffff,(%rax)
mov    -0x4d0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4d0(%rbp)
jmp    1175 <svr_loop+0x35>
jmp    11b6 <svr_loop+0x76>
lea    -0x4c0(%rbp),%rdi
mov    -0x4c8(%rbp),%esi
add    $0x1,%esi
mov    $0xffffffff,%edx
call   1060 <poll@plt>
mov    %eax,-0x4c4(%rbp)
mov    -0x4b8(%rbp),%eax
and    $0x40,%eax
cmp    $0x0,%eax
je     1244 <svr_loop+0x104>
mov    -0x4(%rbp),%edi
lea    -0x4c0(%rbp),%rsi
lea    -0x4c8(%rbp),%rdx
call   1030 <client_in@plt>
mov    %eax,-0x4cc(%rbp)
cmpl   $0xffffffff,-0x4cc(%rbp)
jne    1216 <svr_loop+0xd6>
jmp    11b6 <svr_loop+0x76>
lea    0xde3(%rip),%rdi
call   1050 <printf@plt>
mov    -0x4c4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x4c4(%rbp)
cmp    $0x0,%eax
jg     123f <svr_loop+0xff>
jmp    11b6 <svr_loop+0x76>
jmp    1244 <svr_loop+0x104>
mov    -0x4c4(%rbp),%edi
lea    -0x4c0(%rbp),%rsi
mov    -0x4c8(%rbp),%edx
call   1040 <recv_data@plt>
jmp    11b6 <svr_loop+0x76>

x86 assembly (clang, -O2):
<svr_loop>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x4c0,%rsp
mov    %edi,%r12d
movl   $0x0,0xc(%rsp)
mov    %edi,0x10(%rsp)
movl   $0x40,0x14(%rsp)
mov    $0x24,%eax
nopl   0x0(%rax,%rax,1)
movl   $0xffffffff,-0x8(%rsp,%rax,1)
ff
movl   $0xffffffff,0x4(%rsp,%rax,1)
ff
movl   $0xffffffff,0x10(%rsp,%rax,1)
ff
add    $0x24,%rax
cmp    $0x4c8,%rax
jne    1170 <svr_loop+0x30>
xor    %esi,%esi
lea    0x10(%rsp),%rbx
lea    0xc(%rsp),%r14
lea    0xe59(%rip),%r15
jmp    11c2 <svr_loop+0x82>
nopl   0x0(%rax)
mov    0xc(%rsp),%edx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1050 <recv_data@plt>
mov    0xc(%rsp),%esi
add    $0x1,%esi
mov    %rbx,%rdi
mov    $0xffffffff,%edx
call   1060 <poll@plt>
mov    %eax,%ebp
testb  $0x40,0x18(%rsp)
je     11b0 <svr_loop+0x70>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1040 <client_in@plt>
cmp    $0xffffffff,%eax
je     11be <svr_loop+0x7e>
mov    %r15,%rdi
call   1030 <puts@plt>
cmp    $0x2,%ebp
jl     11be <svr_loop+0x7e>
add    $0xffffffff,%ebp
jmp    11b0 <svr_loop+0x70>

LLVM IR (-O0):
%struct.pollfd = type { i32, i32, i32 }
@.str = [11 x i8] c"client in\0A\00"
define void @svr_loop(i32 %0) {
%2 = alloca i32
%3 = alloca [100 x %struct.pollfd]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %5
%8 = load i32, i32* %2
%9 = getelementptr inbounds [100 x %struct.pollfd], [100 x %struct.pollfd]* %3, i64 0, i64 0
%10 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %9, i32 0, i32 0
store i32 %8, i32* %10
%11 = getelementptr inbounds [100 x %struct.pollfd], [100 x %struct.pollfd]* %3, i64 0, i64 0
%12 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %11, i32 0, i32 1
store i32 64, i32* %12
store i32 1, i32* %7
br label %13
13: ; preds = %21, %1
%14 = load i32, i32* %7
%15 = icmp slt i32 %14, 100
br i1 %15, label %16, label %24
16: ; preds = %13
%17 = load i32, i32* %7
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [100 x %struct.pollfd], [100 x %struct.pollfd]* %3, i64 0, i64 %18
%20 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %19, i32 0, i32 0
store i32 -1, i32* %20
br label %21
21: ; preds = %16
%22 = load i32, i32* %7
%23 = add nsw i32 %22, 1
store i32 %23, i32* %7
br label %13
24: ; preds = %13
br label %25
25: ; preds = %24, %41, %47, %49
%26 = getelementptr inbounds [100 x %struct.pollfd], [100 x %struct.pollfd]* %3, i64 0, i64 0
%27 = load i32, i32* %5
%28 = add nsw i32 %27, 1
%29 = call i32 @poll(%struct.pollfd* %26, i32 %28, i32 -1)
store i32 %29, i32* %4
%30 = getelementptr inbounds [100 x %struct.pollfd], [100 x %struct.pollfd]* %3, i64 0, i64 0
%31 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %30, i32 0, i32 2
%32 = load i32, i32* %31
%33 = and i32 %32, 64
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %49
35: ; preds = %25
%36 = load i32, i32* %2
%37 = getelementptr inbounds [100 x %struct.pollfd], [100 x %struct.pollfd]* %3, i64 0, i64 0
%38 = call i32 @client_in(i32 %36, %struct.pollfd* %37, i32* %5)
store i32 %38, i32* %6
%39 = load i32, i32* %6
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %42
41: ; preds = %35
br label %25
42: ; preds = %35
%43 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%44 = load i32, i32* %4
%45 = add nsw i32 %44, -1
store i32 %45, i32* %4
%46 = icmp sle i32 %45, 0
br i1 %46, label %47, label %48
47: ; preds = %42
br label %25
48: ; preds = %42
br label %49
49: ; preds = %48, %25
%50 = load i32, i32* %4
%51 = getelementptr inbounds [100 x %struct.pollfd], [100 x %struct.pollfd]* %3, i64 0, i64 0
%52 = load i32, i32* %5
%53 = call i32 @recv_data(i32 %50, %struct.pollfd* %51, i32 %52)
br label %25
}

LLVM IR (-O2):
%struct.pollfd = type { i32, i32, i32 }
@str = [10 x i8] c"client in\00"
define void @svr_loop(i32 %0) {
%2 = alloca [100 x %struct.pollfd]
%3 = alloca i32
%4 = bitcast [100 x %struct.pollfd]* %2 to i8*
%5 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%6 = getelementptr inbounds [100 x %struct.pollfd], [100 x %struct.pollfd]* %2, i64 0, i64 0, i32 0
store i32 %0, i32* %6
%7 = getelementptr inbounds [100 x %struct.pollfd], [100 x %struct.pollfd]* %2, i64 0, i64 0, i32 1
store i32 64, i32* %7
br label %11
8: ; preds = %11
%9 = getelementptr inbounds [100 x %struct.pollfd], [100 x %struct.pollfd]* %2, i64 0, i64 0
%10 = getelementptr inbounds [100 x %struct.pollfd], [100 x %struct.pollfd]* %2, i64 0, i64 0, i32 2
br label %20
11: ; preds = %11, %1
%12 = phi i64 [ 1, %1 ], [ %18, %11 ]
%13 = getelementptr inbounds [100 x %struct.pollfd], [100 x %struct.pollfd]* %2, i64 0, i64 %12, i32 0
store i32 -1, i32* %13
%14 = add nuw nsw i64 %12, 1
%15 = getelementptr inbounds [100 x %struct.pollfd], [100 x %struct.pollfd]* %2, i64 0, i64 %14, i32 0
store i32 -1, i32* %15
%16 = add nuw nsw i64 %12, 2
%17 = getelementptr inbounds [100 x %struct.pollfd], [100 x %struct.pollfd]* %2, i64 0, i64 %16, i32 0
store i32 -1, i32* %17
%18 = add nuw nsw i64 %12, 3
%19 = icmp eq i64 %18, 100
br i1 %19, label %8, label %11
20: ; preds = %38, %8
%21 = phi i32 [ %39, %38 ], [ 0, %8 ]
%22 = add nsw i32 %21, 1
%23 = call i32 @poll(%struct.pollfd* %9, i32 %22, i32 -1)
%24 = load i32, i32* %10
%25 = and i32 %24, 64
%26 = icmp eq i32 %25, 0
br i1 %26, label %34, label %27
27: ; preds = %20
%28 = call i32 @client_in(i32 %0, %struct.pollfd* %9, i32* %3)
%29 = icmp eq i32 %28, -1
br i1 %29, label %38, label %30
30: ; preds = %27
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
%32 = add nsw i32 %23, -1
%33 = icmp slt i32 %23, 2
br i1 %33, label %38, label %34
34: ; preds = %30, %20
%35 = phi i32 [ %32, %30 ], [ %23, %20 ]
%36 = load i32, i32* %3
%37 = call i32 @recv_data(i32 %35, %struct.pollfd* %9, i32 %36)
br label %38
38: ; preds = %34, %27, %30
%39 = load i32, i32* %3
br label %20
}