#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 timeval {
  scalar_t__ tv_usec;
  scalar_t__ tv_sec;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ sockAddr;
typedef int /*<<< orphan*/ fd_set;

/* Variables and functions */
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ myfprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ openAInterface(int, struct sockaddr *);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
int /*<<< orphan*/ stderr;
void getConnections(int sock) {
  fd_set fdsr;
  int fd = 0;
  struct timeval tv;
  struct sockaddr sockAddr;
  socklen_t socklen = sizeof(sockAddr);
  tv.tv_sec = tv.tv_usec = 0;
  fflush(NULL);
  FD_ZERO(&fdsr);
  FD_SET(sock, &fdsr);
  if (select(sock + 1, &fdsr, NULL, NULL, &tv) == 1 &&
      ((fd = accept(sock, &sockAddr, &socklen)) >= 0)) {
    openAInterface(fd, &sockAddr);
  } else if (fd < 0)
    myfprintf(stderr, "Problems accept()'ing\n");
}


x86 assembly (clang, -O0):
<getConnections>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x4,-0x2c(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x18(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <fflush@plt>
lea    -0x8(%rbp),%rdi
call   1040 <FD_ZERO@plt>
mov    -0x4(%rbp),%edi
lea    -0x8(%rbp),%rsi
call   1090 <FD_SET@plt>
mov    -0x4(%rbp),%edi
add    $0x1,%edi
lea    -0x8(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x20(%rbp),%r8
mov    %rcx,%rdx
call   1050 <select@plt>
cmp    $0x1,%eax
jne    1207 <getConnections+0x97>
mov    -0x4(%rbp),%edi
lea    -0x28(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
call   1080 <accept@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jl     1207 <getConnections+0x97>
mov    -0xc(%rbp),%edi
lea    -0x28(%rbp),%rsi
call   1070 <openAInterface@plt>
jmp    122b <getConnections+0xbb>
cmpl   $0x0,-0xc(%rbp)
jge    1226 <getConnections+0xb6>
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
lea    0xddf(%rip),%rsi
call   1030 <myfprintf@plt>
jmp    122b <getConnections+0xbb>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getConnections>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %edi,%ebx
movl   $0x4,0x8(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
xor    %edi,%edi
call   1060 <fflush@plt>
lea    0xc(%rsp),%r14
mov    %r14,%rdi
call   1040 <FD_ZERO@plt>
mov    %ebx,%edi
mov    %r14,%rsi
call   1090 <FD_SET@plt>
lea    0x1(%rbx),%edi
lea    0x10(%rsp),%r8
mov    %r14,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1050 <select@plt>
cmp    $0x1,%eax
jne    11f4 <getConnections+0x84>
mov    %rsp,%rsi
lea    0x8(%rsp),%rdx
mov    %ebx,%edi
call   1080 <accept@plt>
test   %eax,%eax
js     11df <getConnections+0x6f>
mov    %rsp,%rsi
mov    %eax,%edi
call   1070 <openAInterface@plt>
jmp    11f4 <getConnections+0x84>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
lea    0xe11(%rip),%rsi
call   1030 <myfprintf@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [23 x i8] c"Problems accept()'ing\0A\00"
define void @getConnections(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.timeval
%6 = alloca %struct.sockaddr
%7 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %4
store i32 4, i32* %7
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
store i64 0, i64* %8
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
store i64 0, i64* %9
%10 = call i32 @fflush(i32* null)
%11 = call i32 @FD_ZERO(i32* %3)
%12 = load i32, i32* %2
%13 = call i32 @FD_SET(i32 %12, i32* %3)
%14 = load i32, i32* %2
%15 = add nsw i32 %14, 1
%16 = call i32 @select(i32 %15, i32* %3, i32* null, i32* null, %struct.timeval* %5)
%17 = icmp eq i32 %16, 1
br i1 %17, label %18, label %25
18: ; preds = %1
%19 = load i32, i32* %2
%20 = call i32 @accept(i32 %19, %struct.sockaddr* %6, i32* %7)
store i32 %20, i32* %4
%21 = icmp sge i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = load i32, i32* %4
%24 = call i32 @openAInterface(i32 %23, %struct.sockaddr* %6)
br label %32
25: ; preds = %18, %1
%26 = load i32, i32* %4
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = load i32, i32* @stderr
%30 = call i32 @myfprintf(i32 %29, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %31
31: ; preds = %28, %25
br label %32
32: ; preds = %31, %22
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [23 x i8] c"Problems accept()'ing\0A\00"
define void @getConnections(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.timeval
%4 = alloca %struct.sockaddr
%5 = alloca i32
%6 = bitcast i32* %2 to i8*
%7 = bitcast %struct.timeval* %3 to i8*
%8 = bitcast %struct.sockaddr* %4 to i8*
%9 = bitcast i32* %5 to i8*
store i32 4, i32* %5
%10 = bitcast %struct.timeval* %3 to i8*
%11 = tail call i32 @fflush(i32* null)
%12 = call i32 @FD_ZERO(i32* %2)
%13 = call i32 @FD_SET(i32 %0, i32* %2)
%14 = add nsw i32 %0, 1
%15 = call i32 @select(i32 %14, i32* %2, i32* null, i32* null, %struct.timeval* %3)
%16 = icmp eq i32 %15, 1
br i1 %16, label %17, label %25
17: ; preds = %1
%18 = call i32 @accept(i32 %0, %struct.sockaddr* %4, i32* %5)
%19 = icmp sgt i32 %18, -1
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = call i32 @openAInterface(i32 %18, %struct.sockaddr* %4)
br label %25
22: ; preds = %17
%23 = load i32, i32* @stderr
%24 = call i32 @myfprintf(i32 %23, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %25
25: ; preds = %1, %22, %20
ret void
}