#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;
};
typedef int socklen_t;

/* Variables and functions */
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int accept_one(int sd, int *isopen, int *cd, int ncons) {
  int ci;
  struct sockaddr_in client_addr;
  socklen_t client_addrlen = sizeof(struct sockaddr);
  for (ci = 0; ci < ncons; ci++)
    if (!isopen[ci])
      break;
  if ((cd[ci] = accept(sd, (struct sockaddr *)&client_addr, &client_addrlen)) <
      0) {
    perror("accept");
    exit(errno);
  };
  ;
  return ci;
}


x86 assembly (clang, -O0):
<accept_one>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0x4,-0x2c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    118a <accept_one+0x5a>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jne    1177 <accept_one+0x47>
jmp    118a <accept_one+0x5a>
jmp    117c <accept_one+0x4c>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1154 <accept_one+0x24>
mov    -0x4(%rbp),%edi
lea    -0x28(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
call   1040 <accept@plt>
mov    -0x18(%rbp),%rcx
movslq -0x20(%rbp),%rdx
mov    %eax,(%rcx,%rdx,4)
cmp    $0x0,%eax
jge    11c8 <accept_one+0x98>
lea    0xe4b(%rip),%rdi
call   1030 <perror@plt>
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x20(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<accept_one>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
movl   $0x4,0xc(%rsp)
test   %ecx,%ecx
jle    1163 <accept_one+0x33>
mov    %ecx,%eax
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
cmpl   $0x0,(%rsi,%rbx,4)
je     1165 <accept_one+0x35>
add    $0x1,%rbx
cmp    %rbx,%rax
jne    1150 <accept_one+0x20>
mov    %eax,%ebx
jmp    1165 <accept_one+0x35>
xor    %ebx,%ebx
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rdx
call   1040 <accept@plt>
mov    %ebx,%ecx
mov    %eax,(%r14,%rcx,4)
test   %eax,%eax
js     1188 <accept_one+0x58>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe71(%rip),%rdi
call   1030 <perror@plt>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [7 x i8] c"accept\00"
@errno = global i32 0
define i32 @accept_one(i32 %0, i32* %1, i32* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.sockaddr_in
%11 = alloca i32
store i32 %0, i32* %5
store i32* %1, i32** %6
store i32* %2, i32** %7
store i32 %3, i32* %8
store i32 4, i32* %11
store i32 0, i32* %9
br label %12
12: ; preds = %25, %4
%13 = load i32, i32* %9
%14 = load i32, i32* %8
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %28
16: ; preds = %12
%17 = load i32*, i32** %6
%18 = load i32, i32* %9
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i32, i32* %17, i64 %19
%21 = load i32, i32* %20
%22 = icmp ne i32 %21, 0
br i1 %22, label %24, label %23
23: ; preds = %16
br label %28
24: ; preds = %16
br label %25
25: ; preds = %24
%26 = load i32, i32* %9
%27 = add nsw i32 %26, 1
store i32 %27, i32* %9
br label %12
28: ; preds = %23, %12
%29 = load i32, i32* %5
%30 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%31 = call i32 @accept(i32 %29, %struct.sockaddr* %30, i32* %11)
%32 = load i32*, i32** %7
%33 = load i32, i32* %9
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i32, i32* %32, i64 %34
store i32 %31, i32* %35
%36 = icmp slt i32 %31, 0
br i1 %36, label %37, label %41
37: ; preds = %28
%38 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%39 = load i32, i32* @errno
%40 = call i32 @exit(i32 %39)
unreachable
41: ; preds = %28
%42 = load i32, i32* %9
ret i32 %42
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [7 x i8] c"accept\00"
@errno = global i32 0
define i32 @accept_one(i32 %0, i32* nocapture %1, i32* nocapture writeonly %2, i32 %3) {
%5 = alloca %struct.sockaddr_in
%6 = alloca i32
%7 = bitcast %struct.sockaddr_in* %5 to i8*
%8 = bitcast i32* %6 to i8*
store i32 4, i32* %6
%9 = icmp sgt i32 %3, 0
br i1 %9, label %10, label %22
10: ; preds = %4
%11 = zext i32 %3 to i64
br label %12
12: ; preds = %10, %17
%13 = phi i64 [ 0, %10 ], [ %18, %17 ]
%14 = getelementptr inbounds i32, i32* %1, i64 %13
%15 = load i32, i32* %14
%16 = icmp eq i32 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %12
%18 = add nuw nsw i64 %13, 1
%19 = icmp eq i64 %18, %11
br i1 %19, label %22, label %12
20: ; preds = %12
%21 = trunc i64 %13 to i32
br label %22
22: ; preds = %17, %20, %4
%23 = phi i32 [ 0, %4 ], [ %21, %20 ], [ %3, %17 ]
%24 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%25 = call i32 @accept(i32 %0, %struct.sockaddr* %24, i32* %6)
%26 = zext i32 %23 to i64
%27 = getelementptr inbounds i32, i32* %2, i64 %26
store i32 %25, i32* %27
%28 = icmp slt i32 %25, 0
br i1 %28, label %29, label %33
29: ; preds = %22
%30 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%31 = load i32, i32* @errno
%32 = call i32 @exit(i32 %31)
unreachable
33: ; preds = %22
ret i32 %23
}