#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 {
  int tv_sec;
};
typedef int /*<<< orphan*/ fd_set;

/* Variables and functions */
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SETSIZE;
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int accept(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ errno;
int select(int /*<<< orphan*/, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int /*<<< orphan*/ test_msg(char *, char *, int, int /*<<< orphan*/,
                            int /*<<< orphan*/);
int accept_one_conn(int sock) {
  int acc_sock;
  fd_set fds;
  struct timeval timeout = {
      .tv_sec = 100,
  };
  FD_ZERO(&fds);
  FD_SET(sock, &fds);
  switch (select(FD_SETSIZE, &fds, NULL, NULL, &timeout)) {
  case 1:
    break;
  case 0:
    test_msg("ERR: %s:%d: "
             "timeout accepting a connection"
             " (errno = %d (%s))\n",
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/LK4D4/criu/refs/heads/master/test/zdtm/"
             "live/streaming/unix_sock.c",
             93, errno, strerror(errno));
    return -1;
  default:
    test_msg("ERR: %s:%d: "
             "error while waiting for a connection: %m"
             " (errno = %d (%s))\n",
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/LK4D4/criu/refs/heads/master/test/zdtm/"
             "live/streaming/unix_sock.c",
             96, errno, strerror(errno));
    return -1;
  }
  acc_sock = accept(sock, NULL, NULL);
  if (acc_sock < 0)
    test_msg("ERR: %s:%d: "
             "error accepting a connection: %m"
             " (errno = %d (%s))\n",
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/LK4D4/criu/refs/heads/master/test/zdtm/"
             "live/streaming/unix_sock.c",
             102, errno, strerror(errno));
  return acc_sock;
}


x86 assembly (clang, -O0):
<accept_one_conn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    0xe8f(%rip),%eax
mov    %eax,-0x18(%rbp)
lea    -0x10(%rbp),%rdi
mov    %rdi,-0x28(%rbp)
call   1040 <FD_ZERO@plt>
mov    -0x28(%rbp),%rsi
mov    -0x8(%rbp),%edi
call   1080 <FD_SET@plt>
mov    -0x28(%rbp),%rsi
mov    0x2e48(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x18(%rbp),%r8
mov    %rcx,%rdx
call   1050 <select@plt>
mov    %eax,%ecx
mov    %ecx,-0x1c(%rbp)
test   %eax,%eax
je     11d2 <accept_one_conn+0x72>
jmp    11bc <accept_one_conn+0x5c>
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
jne    1216 <accept_one_conn+0xb6>
jmp    11cd <accept_one_conn+0x6d>
jmp    125a <accept_one_conn+0xfa>
mov    0x2dff(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x2c(%rbp),%ecx
mov    %eax,%r8d
lea    0xe0b(%rip),%rdi
lea    0xe42(%rip),%rsi
mov    $0x5d,%edx
call   1030 <test_msg@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b4 <accept_one_conn+0x154>
mov    0x2dbb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    0x2daf(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x30(%rbp),%ecx
mov    %eax,%r8d
lea    0xea1(%rip),%rdi
lea    0xdfe(%rip),%rsi
mov    $0x60,%edx
call   1030 <test_msg@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b4 <accept_one_conn+0x154>
mov    -0x8(%rbp),%edi
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rsi
call   1060 <accept@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    12ae <accept_one_conn+0x14e>
mov    0x2d5b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x2d4f(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x34(%rbp),%ecx
mov    %eax,%r8d
lea    0xe89(%rip),%rdi
lea    0xd9e(%rip),%rsi
mov    $0x66,%edx
call   1030 <test_msg@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<accept_one_conn>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
movl   $0x64,(%rsp)
lea    0x4(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <FD_ZERO@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1080 <FD_SET@plt>
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%r8
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1050 <select@plt>
cmp    $0x1,%eax
je     11c9 <accept_one_conn+0x69>
test   %eax,%eax
jne    1209 <accept_one_conn+0xa9>
mov    0x2e2d(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   1070 <strerror@plt>
lea    0xe45(%rip),%rdi
lea    0xe7c(%rip),%rsi
mov    $0x5d,%edx
jmp    122c <accept_one_conn+0xcc>
mov    %ebp,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <accept@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    123b <accept_one_conn+0xdb>
mov    0x2df7(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1070 <strerror@plt>
lea    0xf31(%rip),%rdi
lea    0xe46(%rip),%rsi
mov    $0x66,%edx
mov    %ebp,%ecx
mov    %eax,%r8d
call   1030 <test_msg@plt>
jmp    123b <accept_one_conn+0xdb>
mov    0x2dc8(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   1070 <strerror@plt>
lea    0xeba(%rip),%rdi
lea    0xe17(%rip),%rsi
mov    $0x60,%edx
mov    %ebx,%ecx
mov    %eax,%r8d
call   1030 <test_msg@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32 }
@__const.accept_one_conn.timeout = %struct.timeval { i32 100 }
@FD_SETSIZE = global i32 0
@.str = [62 x i8] c"ERR: %s:%d: timeout accepting a connection (errno = %d (%s))\0A\00"
@.str.1 = [156 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/LK4D4/criu/refs/heads/master/test/zdtm/live/streaming/unix_sock.c\00"
@errno = global i32 0
@.str.2 = [72 x i8] c"ERR: %s:%d: error while waiting for a connection: %m (errno = %d (%s))\0A\00"
@.str.3 = [64 x i8] c"ERR: %s:%d: error accepting a connection: %m (errno = %d (%s))\0A\00"
define i32 @accept_one_conn(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.timeval
store i32 %0, i32* %3
%7 = bitcast %struct.timeval* %6 to i8*
%8 = call i32 @FD_ZERO(i32* %5)
%9 = load i32, i32* %3
%10 = call i32 @FD_SET(i32 %9, i32* %5)
%11 = load i32, i32* @FD_SETSIZE
%12 = call i32 @select(i32 %11, i32* %5, i32* null, i32* null, %struct.timeval* %6)
switch i32 %12, label %19 [
i32 1, label %13
i32 0, label %14
]
13: ; preds = %1
br label %24
14: ; preds = %1
%15 = load i32, i32* @errno
%16 = load i32, i32* @errno
%17 = call i32 @strerror(i32 %16)
%18 = call i32 @test_msg(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([156 x i8], [156 x i8]* @.str.1, i64 0, i64 0), i32 93, i32 %15, i32 %17)
store i32 -1, i32* %2
br label %36
19: ; preds = %1
%20 = load i32, i32* @errno
%21 = load i32, i32* @errno
%22 = call i32 @strerror(i32 %21)
%23 = call i32 @test_msg(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([156 x i8], [156 x i8]* @.str.1, i64 0, i64 0), i32 96, i32 %20, i32 %22)
store i32 -1, i32* %2
br label %36
24: ; preds = %13
%25 = load i32, i32* %3
%26 = call i32 @accept(i32 %25, i32* null, i32* null)
store i32 %26, i32* %4
%27 = load i32, i32* %4
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %34
29: ; preds = %24
%30 = load i32, i32* @errno
%31 = load i32, i32* @errno
%32 = call i32 @strerror(i32 %31)
%33 = call i32 @test_msg(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([156 x i8], [156 x i8]* @.str.1, i64 0, i64 0), i32 102, i32 %30, i32 %32)
br label %34
34: ; preds = %29, %24
%35 = load i32, i32* %4
store i32 %35, i32* %2
br label %36
36: ; preds = %34, %19, %14
%37 = load i32, i32* %2
ret i32 %37
}

LLVM IR (-O2):
%struct.timeval = type { i32 }
@FD_SETSIZE = global i32 0
@.str = [62 x i8] c"ERR: %s:%d: timeout accepting a connection (errno = %d (%s))\0A\00"
@.str.1 = [156 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/LK4D4/criu/refs/heads/master/test/zdtm/live/streaming/unix_sock.c\00"
@errno = global i32 0
@.str.2 = [72 x i8] c"ERR: %s:%d: error while waiting for a connection: %m (errno = %d (%s))\0A\00"
@.str.3 = [64 x i8] c"ERR: %s:%d: error accepting a connection: %m (errno = %d (%s))\0A\00"
define i32 @accept_one_conn(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.timeval
%4 = bitcast i32* %2 to i8*
%5 = bitcast %struct.timeval* %3 to i8*
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
store i32 100, i32* %6
%7 = call i32 @FD_ZERO(i32* %2)
%8 = call i32 @FD_SET(i32 %0, i32* %2)
%9 = load i32, i32* @FD_SETSIZE
%10 = call i32 @select(i32 %9, i32* %2, i32* null, i32* null, %struct.timeval* %3)
switch i32 %10, label %15 [
i32 1, label %19
i32 0, label %11
]
11: ; preds = %1
%12 = load i32, i32* @errno
%13 = call i32 @strerror(i32 %12)
%14 = call i32 @test_msg(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([156 x i8], [156 x i8]* @.str.1, i64 0, i64 0), i32 93, i32 %12, i32 %13)
br label %26
15: ; preds = %1
%16 = load i32, i32* @errno
%17 = call i32 @strerror(i32 %16)
%18 = call i32 @test_msg(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([156 x i8], [156 x i8]* @.str.1, i64 0, i64 0), i32 96, i32 %16, i32 %17)
br label %26
19: ; preds = %1
%20 = call i32 @accept(i32 %0, i32* null, i32* null)
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %19
%23 = load i32, i32* @errno
%24 = call i32 @strerror(i32 %23)
%25 = call i32 @test_msg(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([156 x i8], [156 x i8]* @.str.1, i64 0, i64 0), i32 102, i32 %23, i32 %24)
br label %26
26: ; preds = %19, %22, %15, %11
%27 = phi i32 [ -1, %15 ], [ -1, %11 ], [ %20, %22 ], [ %20, %19 ]
ret i32 %27
}