#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 sockaddr_in {
  int dummy;
};
struct sockaddr {
  int dummy;
};
struct pollfd {
  int fd;
  int events;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ close(int);
int client_in(int lsn_sock, struct pollfd *set, int *set_pos) {
  int sock;
  struct sockaddr_in addr;
  socklen_t len = sizeof(addr);
  int i;
  sock = accept(lsn_sock, (struct sockaddr *)&addr, &len);
  for (i = 1; i < 100; i++) {
    if (set[i].fd < 0) {
      set[i].fd = sock;
      break;
    }
  }
  if (i == 100) {
    close(sock);
    return -1;
  }
  set[i].events = 0x040;
  if (i > *set_pos)
    *set_pos = i;
  return sock;
}


x86 assembly (clang, -O0):
<client_in>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x4,-0x24(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
lea    -0x24(%rbp),%rdx
call   1040 <accept@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x1,-0x28(%rbp)
cmpl   $0x64,-0x28(%rbp)
jge    1196 <client_in+0x76>
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,8)
jge    1183 <client_in+0x63>
mov    -0x1c(%rbp),%edx
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    %edx,(%rax,%rcx,8)
jmp    1196 <client_in+0x76>
jmp    1188 <client_in+0x68>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1154 <client_in+0x34>
cmpl   $0x64,-0x28(%rbp)
jne    11b4 <client_in+0x94>
mov    -0x1c(%rbp),%edi
call   1030 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e2 <client_in+0xc2>
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
movl   $0x40,0x4(%rax,%rcx,8)
mov    -0x28(%rbp),%eax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%eax
jle    11dc <client_in+0xbc>
mov    -0x28(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<client_in>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
movl   $0x4,0xc(%rsp)
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rdx
call   1040 <accept@plt>
mov    $0x3,%ecx
nopl   0x0(%rax)
cmpl   $0x0,-0x10(%rbx,%rcx,8)
js     117c <client_in+0x5c>
cmpl   $0x0,-0x8(%rbx,%rcx,8)
js     1182 <client_in+0x62>
cmpl   $0x0,(%rbx,%rcx,8)
js     1186 <client_in+0x66>
add    $0x3,%rcx
cmp    $0x66,%rcx
jne    1150 <client_in+0x30>
mov    %eax,%edi
call   1030 <close@plt>
mov    $0xffffffff,%eax
jmp    119b <client_in+0x7b>
add    $0xfffffffffffffffe,%rcx
jmp    1186 <client_in+0x66>
add    $0xffffffffffffffff,%rcx
mov    %ecx,%edx
mov    %eax,(%rbx,%rdx,8)
movl   $0x40,0x4(%rbx,%rdx,8)
cmp    %ecx,(%r14)
jge    119b <client_in+0x7b>
mov    %ecx,(%r14)
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.pollfd = type { i32, i32 }
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
define i32 @client_in(i32 %0, %struct.pollfd* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.pollfd*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca %struct.sockaddr_in
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %5
store %struct.pollfd* %1, %struct.pollfd** %6
store i32* %2, i32** %7
store i32 4, i32* %10
%12 = load i32, i32* %5
%13 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%14 = call i32 @accept(i32 %12, %struct.sockaddr* %13, i32* %10)
store i32 %14, i32* %8
store i32 1, i32* %11
br label %15
15: ; preds = %34, %3
%16 = load i32, i32* %11
%17 = icmp slt i32 %16, 100
br i1 %17, label %18, label %37
18: ; preds = %15
%19 = load %struct.pollfd*, %struct.pollfd** %6
%20 = load i32, i32* %11
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %19, i64 %21
%23 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %22, i32 0, i32 0
%24 = load i32, i32* %23
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %33
26: ; preds = %18
%27 = load i32, i32* %8
%28 = load %struct.pollfd*, %struct.pollfd** %6
%29 = load i32, i32* %11
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %28, i64 %30
%32 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %31, i32 0, i32 0
store i32 %27, i32* %32
br label %37
33: ; preds = %18
br label %34
34: ; preds = %33
%35 = load i32, i32* %11
%36 = add nsw i32 %35, 1
store i32 %36, i32* %11
br label %15
37: ; preds = %26, %15
%38 = load i32, i32* %11
%39 = icmp eq i32 %38, 100
br i1 %39, label %40, label %43
40: ; preds = %37
%41 = load i32, i32* %8
%42 = call i32 @close(i32 %41)
store i32 -1, i32* %4
br label %58
43: ; preds = %37
%44 = load %struct.pollfd*, %struct.pollfd** %6
%45 = load i32, i32* %11
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %44, i64 %46
%48 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %47, i32 0, i32 1
store i32 64, i32* %48
%49 = load i32, i32* %11
%50 = load i32*, i32** %7
%51 = load i32, i32* %50
%52 = icmp sgt i32 %49, %51
br i1 %52, label %53, label %56
53: ; preds = %43
%54 = load i32, i32* %11
%55 = load i32*, i32** %7
store i32 %54, i32* %55
br label %56
56: ; preds = %53, %43
%57 = load i32, i32* %8
store i32 %57, i32* %4
br label %58
58: ; preds = %56, %40
%59 = load i32, i32* %4
ret i32 %59
}

LLVM IR (-O2):
%struct.pollfd = type { i32, i32 }
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
define i32 @client_in(i32 %0, %struct.pollfd* nocapture %1, i32* nocapture %2) {
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = bitcast %struct.sockaddr_in* %4 to i8*
%7 = bitcast i32* %5 to i8*
store i32 4, i32* %5
%8 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%9 = call i32 @accept(i32 %0, %struct.sockaddr* %8, i32* %5)
br label %10
10: ; preds = %25, %3
%11 = phi i64 [ 1, %3 ], [ %26, %25 ]
%12 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %1, i64 %11, i32 0
%13 = load i32, i32* %12
%14 = icmp slt i32 %13, 0
br i1 %14, label %30, label %15
15: ; preds = %10
%16 = add nuw nsw i64 %11, 1
%17 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %1, i64 %16, i32 0
%18 = load i32, i32* %17
%19 = icmp slt i32 %18, 0
br i1 %19, label %30, label %20
20: ; preds = %15
%21 = add nuw nsw i64 %11, 2
%22 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %1, i64 %21, i32 0
%23 = load i32, i32* %22
%24 = icmp slt i32 %23, 0
br i1 %24, label %30, label %25
25: ; preds = %20
%26 = add nuw nsw i64 %11, 3
%27 = icmp eq i64 %26, 100
br i1 %27, label %28, label %10
28: ; preds = %25
%29 = call i32 @close(i32 %9)
br label %40
30: ; preds = %20, %15, %10
%31 = phi i64 [ %11, %10 ], [ %16, %15 ], [ %21, %20 ]
%32 = trunc i64 %31 to i32
%33 = and i64 %31, 4294967295
%34 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %1, i64 %33, i32 0
store i32 %9, i32* %34
%35 = and i64 %31, 4294967295
%36 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %1, i64 %35, i32 1
store i32 64, i32* %36
%37 = load i32, i32* %2
%38 = icmp slt i32 %37, %32
br i1 %38, label %39, label %40
39: ; preds = %30
store i32 %32, i32* %2
br label %40
40: ; preds = %30, %39, %28
%41 = phi i32 [ -1, %28 ], [ %9, %39 ], [ %9, %30 ]
ret i32 %41
}