#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 */
typedef int /*<<< orphan*/ uint8_t;
typedef int /*<<< orphan*/ uint64_t;
typedef int uint32_t;
struct timeval {
  int tv_sec;
  int tv_usec;
};
typedef int /*<<< orphan*/ ssize_t;
typedef int /*<<< orphan*/ socklen_t;
typedef int int32_t;
typedef int /*<<< orphan*/ fd_set;

/* Variables and functions */
int EAGAIN;
int ETIMEDOUT;
int EWOULDBLOCK;
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ MSG_DONTWAIT;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_RCVTIMEO;
int errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ printf(char *, int, int);
scalar_t__ recv(int, int /*<<< orphan*/ *, size_t, int /*<<< orphan*/);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
int /*<<< orphan*/ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              struct timeval *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
char *strerror(int);
ssize_t tcp_recv_from(int32_t sockfd, uint8_t *buf, int32_t start, size_t max,
                      uint32_t wr_us, uint32_t r_us) {
  struct timeval timeout, timeout_r;
  fd_set readfds;
  int nfds, ret;
  fprintf(stdout, "+%d: fd: %d buf: %llx start: %d max: %zu\n", 112, sockfd,
          (uint64_t)buf, start, max);
  printf("wr_us: %u r_us: %u\n", wr_us, r_us);
  timeout.tv_sec = wr_us / 1e6;
  timeout.tv_usec = wr_us % (int)1e6;
  FD_ZERO(&readfds);
  FD_SET((int)sockfd, &readfds);
  nfds = (int)sockfd + 1;
  ret = select(nfds, &readfds, NULL, NULL, &timeout);
  if (-1 == ret) {
    ret = errno;
    goto select_fail;
  } else if (0 == ret) {
    ret = ETIMEDOUT;
    goto select_to;
  }
  timeout_r.tv_sec = r_us / 1e6;
  timeout_r.tv_usec = r_us % (int)1e6;
  setsockopt((int)sockfd, SOL_SOCKET, SO_RCVTIMEO, &timeout_r,
             (socklen_t)sizeof(struct timeval));
  ret = (int)recv((int)sockfd, buf + (int)start, max, MSG_DONTWAIT);
  if ((ret < 0) && (EAGAIN == errno)) {
    ret = ETIMEDOUT;
    goto recv_to;
  } else if ((ret < 0) && (EWOULDBLOCK == errno)) {
    ret = errno;
    goto recv_fail;
  } else if (ret < 0) {
    ret = errno;
    goto recv_fail;
  }
  return (ssize_t)ret;
recv_fail:
  fprintf(stderr, "%s +%d: recv fail: %s\n",
          "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
          "2022-01-22/02-19-57/repos/iamyuiwong/swift-socket/refs/heads/master/"
          "socket/tcp.c",
          163, strerror(ret));
  return (ssize_t)-ret;
recv_to:
  fprintf(stderr, "%s +%d: recv timeout: %s\n",
          "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
          "2022-01-22/02-19-57/repos/iamyuiwong/swift-socket/refs/heads/master/"
          "socket/tcp.c",
          169, strerror(ret));
  return (ssize_t)-ret;
select_to:
  fprintf(stderr, "%s +%d: select timeout: %s\n",
          "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
          "2022-01-22/02-19-57/repos/iamyuiwong/swift-socket/refs/heads/master/"
          "socket/tcp.c",
          175, strerror(ret));
  return (ssize_t)-ret;
select_fail:
  fprintf(stderr, "%s +%d: select fail: %s\n",
          "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
          "2022-01-22/02-19-57/repos/iamyuiwong/swift-socket/refs/heads/master/"
          "socket/tcp.c",
          181, strerror(ret));
  return (ssize_t)-ret;
}


x86 assembly (clang, -O0):
<tcp_recv_from>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9d,-0x28(%rbp)
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %eax,%r8d
mov    -0x14(%rbp),%r9d
mov    -0x20(%rbp),%rax
lea    0xe48(%rip),%rsi
mov    $0x70,%edx
mov    %rax,(%rsp)
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x24(%rbp),%esi
mov    -0x28(%rbp),%edx
lea    0xe55(%rip),%rdi
call   1050 <printf@plt>
cvtsi2sdl -0x24(%rbp),%xmm0
movsd  0xe11(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x30(%rbp)
mov    -0x24(%rbp),%eax
mov    $0xf4240,%ecx
cltd
idiv   %ecx
mov    %edx,-0x2c(%rbp)
lea    -0x3c(%rbp),%rdi
call   1070 <FD_ZERO@plt>
mov    -0x8(%rbp),%edi
lea    -0x3c(%rbp),%rsi
call   10a0 <FD_SET@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%edi
lea    -0x3c(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x30(%rbp),%r8
mov    %rcx,%rdx
call   1080 <select@plt>
mov    %eax,-0x44(%rbp)
mov    $0xffffffff,%eax
cmp    -0x44(%rbp),%eax
jne    125f <tcp_recv_from+0xdf>
mov    0x2d73(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
jmp    144a <tcp_recv_from+0x2ca>
xor    %eax,%eax
cmp    -0x44(%rbp),%eax
jne    127b <tcp_recv_from+0xfb>
mov    0x2d3f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
jmp    1409 <tcp_recv_from+0x289>
jmp    1280 <tcp_recv_from+0x100>
cvtsi2sdl -0x28(%rbp),%xmm0
movsd  0xd73(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x38(%rbp)
mov    -0x28(%rbp),%eax
mov    $0xf4240,%ecx
cltd
idiv   %ecx
mov    %edx,-0x34(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2d38(%rip),%rax
mov    (%rax),%esi
mov    0x2d1f(%rip),%rax
mov    (%rax),%edx
lea    -0x38(%rbp),%rcx
mov    $0x8,%r8d
call   1040 <setsockopt@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
mov    -0x20(%rbp),%rdx
mov    0x2cd1(%rip),%rax
mov    (%rax),%ecx
call   1030 <recv@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jge    1324 <tcp_recv_from+0x1a4>
mov    0x2c96(%rip),%rax
mov    (%rax),%eax
mov    0x2cbd(%rip),%rcx
cmp    (%rcx),%eax
jne    1324 <tcp_recv_from+0x1a4>
mov    0x2c96(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
jmp    13c8 <tcp_recv_from+0x248>
cmpl   $0x0,-0x44(%rbp)
jge    1357 <tcp_recv_from+0x1d7>
mov    0x2c8b(%rip),%rax
mov    (%rax),%eax
mov    0x2c8a(%rip),%rcx
cmp    (%rcx),%eax
jne    1357 <tcp_recv_from+0x1d7>
mov    0x2c7b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
jmp    1387 <tcp_recv_from+0x207>
cmpl   $0x0,-0x44(%rbp)
jge    1372 <tcp_recv_from+0x1f2>
mov    0x2c60(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
jmp    1387 <tcp_recv_from+0x207>
jmp    1377 <tcp_recv_from+0x1f7>
jmp    137c <tcp_recv_from+0x1fc>
mov    -0x44(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1486 <tcp_recv_from+0x306>
mov    0x2c42(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
mov    -0x44(%rbp),%edi
call   1090 <strerror@plt>
mov    -0x48(%rbp),%edi
mov    %rax,%r8
lea    0xc9e(%rip),%rsi
lea    0xcae(%rip),%rdx
mov    $0xa3,%ecx
mov    $0x0,%al
call   1060 <fprintf@plt>
xor    %eax,%eax
sub    -0x44(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1486 <tcp_recv_from+0x306>
mov    0x2c01(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x44(%rbp),%edi
call   1090 <strerror@plt>
mov    -0x4c(%rbp),%edi
mov    %rax,%r8
lea    0xd05(%rip),%rsi
lea    0xc6d(%rip),%rdx
mov    $0xa9,%ecx
mov    $0x0,%al
call   1060 <fprintf@plt>
xor    %eax,%eax
sub    -0x44(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1486 <tcp_recv_from+0x306>
mov    0x2bc0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x50(%rbp)
mov    -0x44(%rbp),%edi
call   1090 <strerror@plt>
mov    -0x50(%rbp),%edi
mov    %rax,%r8
lea    0xcde(%rip),%rsi
lea    0xc2c(%rip),%rdx
mov    $0xaf,%ecx
mov    $0x0,%al
call   1060 <fprintf@plt>
xor    %eax,%eax
sub    -0x44(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1486 <tcp_recv_from+0x306>
mov    0x2b7f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
mov    -0x44(%rbp),%edi
call   1090 <strerror@plt>
mov    -0x54(%rbp),%edi
mov    %rax,%r8
lea    0xcb9(%rip),%rsi
lea    0xbeb(%rip),%rdx
mov    $0xb5,%ecx
mov    $0x0,%al
call   1060 <fprintf@plt>
xor    %eax,%eax
sub    -0x44(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tcp_recv_from>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9d,%r13d
mov    %r8d,%ebp
mov    %rcx,%r14
mov    %edx,%r12d
mov    %rsi,%r15
mov    %edi,%ebx
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
mov    %rcx,(%rsp)
lea    0xe55(%rip),%rsi
mov    $0x70,%edx
mov    %ebx,%ecx
mov    %r15d,%r8d
mov    %r12d,%r9d
xor    %eax,%eax
call   1060 <fprintf@plt>
lea    0xe64(%rip),%rdi
mov    %ebp,%esi
mov    %r13d,%edx
call   1050 <printf@plt>
cvtsi2sd %ebp,%xmm0
divsd  0xe1c(%rip),%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,0x18(%rsp)
movslq %ebp,%rax
imul   $0x431bde83,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x32,%rcx
add    %edx,%ecx
imul   $0xf4240,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,0x1c(%rsp)
lea    0x24(%rsp),%rbp
mov    %rbp,%rdi
call   1070 <FD_ZERO@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
call   10a0 <FD_SET@plt>
lea    0x1(%rbx),%edi
lea    0x18(%rsp),%r8
mov    %rbp,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1080 <select@plt>
test   %eax,%eax
je     1273 <tcp_recv_from+0xf3>
cmp    $0xffffffff,%eax
jne    12b2 <tcp_recv_from+0x132>
mov    0x2d7e(%rip),%rax
mov    (%rax),%ebx
mov    0x2d7d(%rip),%rax
mov    (%rax),%ebp
mov    %ebx,%edi
call   1090 <strerror@plt>
lea    0xec1(%rip),%rsi
lea    0xdf3(%rip),%rdx
mov    %ebp,%edi
mov    $0xb5,%ecx
jmp    12a1 <tcp_recv_from+0x121>
mov    0x2d3e(%rip),%rax
mov    (%rax),%ebx
mov    0x2d4d(%rip),%rax
mov    (%rax),%ebp
mov    %ebx,%edi
call   1090 <strerror@plt>
lea    0xe75(%rip),%rsi
lea    0xdc3(%rip),%rdx
mov    %ebp,%edi
mov    $0xaf,%ecx
mov    %rax,%r8
xor    %eax,%eax
call   1060 <fprintf@plt>
neg    %ebx
jmp    1334 <tcp_recv_from+0x1b4>
xorps  %xmm0,%xmm0
cvtsi2sd %r13d,%xmm0
divsd  0xd3e(%rip),%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,0x10(%rsp)
movslq %r13d,%rax
imul   $0x431bde83,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x32,%rax
add    %ecx,%eax
imul   $0xf4240,%eax,%eax
sub    %eax,%r13d
mov    %r13d,0x14(%rsp)
mov    0x2cf2(%rip),%rax
mov    (%rax),%esi
mov    0x2cd9(%rip),%rax
mov    (%rax),%edx
lea    0x10(%rsp),%rcx
mov    %ebx,%edi
mov    $0x8,%r8d
call   1040 <setsockopt@plt>
movslq %r12d,%rax
lea    (%r15,%rax,4),%rsi
mov    0x2c9f(%rip),%rax
mov    (%rax),%ecx
mov    %ebx,%edi
mov    %r14,%rdx
call   1030 <recv@plt>
mov    %rax,%rbx
test   %ebx,%ebx
js     1345 <tcp_recv_from+0x1c5>
mov    %ebx,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2c54(%rip),%rax
mov    0x2c75(%rip),%rcx
mov    (%rcx),%ebx
cmp    %ebx,(%rax)
jne    138c <tcp_recv_from+0x20c>
mov    0x2c58(%rip),%rax
mov    (%rax),%ebx
mov    0x2c67(%rip),%rax
mov    (%rax),%ebp
mov    %ebx,%edi
call   1090 <strerror@plt>
lea    0xd75(%rip),%rsi
lea    0xcdd(%rip),%rdx
mov    %ebp,%edi
mov    $0xa9,%ecx
jmp    12a1 <tcp_recv_from+0x121>
mov    0x2c3d(%rip),%rax
mov    (%rax),%ebp
mov    %ebx,%edi
call   1090 <strerror@plt>
lea    0xca3(%rip),%rsi
lea    0xcb3(%rip),%rdx
mov    %ebp,%edi
mov    $0xa3,%ecx
jmp    12a1 <tcp_recv_from+0x121>

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@stdout = global i32 0
@.str = [42 x i8] c"+%d: fd: %d buf: %llx start: %d max: %zu\0A\00"
@.str.1 = [20 x i8] c"wr_us: %u r_us: %u\0A\00"
@errno = global i32 0
@ETIMEDOUT = global i32 0
@SOL_SOCKET = global i32 0
@SO_RCVTIMEO = global i32 0
@MSG_DONTWAIT = global i32 0
@EAGAIN = global i32 0
@EWOULDBLOCK = global i32 0
@stderr = global i32 0
@.str.2 = [23 x i8] c"%s +%d: recv fail: %s\0A\00"
@.str.3 = [145 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/iamyuiwong/swift-socket/refs/heads/master/socket/tcp.c\00"
@.str.4 = [26 x i8] c"%s +%d: recv timeout: %s\0A\00"
@.str.5 = [28 x i8] c"%s +%d: select timeout: %s\0A\00"
@.str.6 = [25 x i8] c"%s +%d: select fail: %s\0A\00"
define i32 @tcp_recv_from(i32 %0, i32* %1, i32 %2, i64 %3, i32 %4, i32 %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i64
%12 = alloca i32
%13 = alloca i32
%14 = alloca %struct.timeval
%15 = alloca %struct.timeval
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
store i32 %0, i32* %8
store i32* %1, i32** %9
store i32 %2, i32* %10
store i64 %3, i64* %11
store i32 %4, i32* %12
store i32 %5, i32* %13
%19 = load i32, i32* @stdout
%20 = load i32, i32* %8
%21 = load i32*, i32** %9
%22 = ptrtoint i32* %21 to i32
%23 = load i32, i32* %10
%24 = load i64, i64* %11
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 112, i32 %20, i32 %22, i32 %23, i64 %24)
%26 = load i32, i32* %12
%27 = load i32, i32* %13
%28 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %26, i32 %27)
%29 = load i32, i32* %12
%30 = sitofp i32 %29 to double
%31 = fdiv double %30, 1.000000e+06
%32 = fptosi double %31 to i32
%33 = getelementptr inbounds %struct.timeval, %struct.timeval* %14, i32 0, i32 0
store i32 %32, i32* %33
%34 = load i32, i32* %12
%35 = srem i32 %34, 1000000
%36 = getelementptr inbounds %struct.timeval, %struct.timeval* %14, i32 0, i32 1
store i32 %35, i32* %36
%37 = call i32 @FD_ZERO(i32* %16)
%38 = load i32, i32* %8
%39 = call i32 @FD_SET(i32 %38, i32* %16)
%40 = load i32, i32* %8
%41 = add nsw i32 %40, 1
store i32 %41, i32* %17
%42 = load i32, i32* %17
%43 = call i32 @select(i32 %42, i32* %16, i32* null, i32* null, %struct.timeval* %14)
store i32 %43, i32* %18
%44 = load i32, i32* %18
%45 = icmp eq i32 -1, %44
br i1 %45, label %46, label %48
46: ; preds = %6
%47 = load i32, i32* @errno
store i32 %47, i32* %18
br label %123
48: ; preds = %6
%49 = load i32, i32* %18
%50 = icmp eq i32 0, %49
br i1 %50, label %51, label %53
51: ; preds = %48
%52 = load i32, i32* @ETIMEDOUT
store i32 %52, i32* %18
br label %116
53: ; preds = %48
br label %54
54: ; preds = %53
%55 = load i32, i32* %13
%56 = sitofp i32 %55 to double
%57 = fdiv double %56, 1.000000e+06
%58 = fptosi double %57 to i32
%59 = getelementptr inbounds %struct.timeval, %struct.timeval* %15, i32 0, i32 0
store i32 %58, i32* %59
%60 = load i32, i32* %13
%61 = srem i32 %60, 1000000
%62 = getelementptr inbounds %struct.timeval, %struct.timeval* %15, i32 0, i32 1
store i32 %61, i32* %62
%63 = load i32, i32* %8
%64 = load i32, i32* @SOL_SOCKET
%65 = load i32, i32* @SO_RCVTIMEO
%66 = call i32 @setsockopt(i32 %63, i32 %64, i32 %65, %struct.timeval* %15, i32 8)
%67 = load i32, i32* %8
%68 = load i32*, i32** %9
%69 = load i32, i32* %10
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i32, i32* %68, i64 %70
%72 = load i64, i64* %11
%73 = load i32, i32* @MSG_DONTWAIT
%74 = call i64 @recv(i32 %67, i32* %71, i64 %72, i32 %73)
%75 = trunc i64 %74 to i32
store i32 %75, i32* %18
%76 = load i32, i32* %18
%77 = icmp slt i32 %76, 0
br i1 %77, label %78, label %84
78: ; preds = %54
%79 = load i32, i32* @EAGAIN
%80 = load i32, i32* @errno
%81 = icmp eq i32 %79, %80
br i1 %81, label %82, label %84
82: ; preds = %78
%83 = load i32, i32* @ETIMEDOUT
store i32 %83, i32* %18
br label %109
84: ; preds = %78, %54
%85 = load i32, i32* %18
%86 = icmp slt i32 %85, 0
br i1 %86, label %87, label %93
87: ; preds = %84
%88 = load i32, i32* @EWOULDBLOCK
%89 = load i32, i32* @errno
%90 = icmp eq i32 %88, %89
br i1 %90, label %91, label %93
91: ; preds = %87
%92 = load i32, i32* @errno
store i32 %92, i32* %18
br label %102
93: ; preds = %87, %84
%94 = load i32, i32* %18
%95 = icmp slt i32 %94, 0
br i1 %95, label %96, label %98
96: ; preds = %93
%97 = load i32, i32* @errno
store i32 %97, i32* %18
br label %102
98: ; preds = %93
br label %99
99: ; preds = %98
br label %100
100: ; preds = %99
%101 = load i32, i32* %18
store i32 %101, i32* %7
br label %130
102: ; preds = %96, %91
%103 = load i32, i32* @stderr
%104 = load i32, i32* %18
%105 = call i8* @strerror(i32 %104)
%106 = call i32 (i32, i8*, ...) @fprintf(i32 %103, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([145 x i8], [145 x i8]* @.str.3, i64 0, i64 0), i32 163, i8* %105)
%107 = load i32, i32* %18
%108 = sub nsw i32 0, %107
store i32 %108, i32* %7
br label %130
109: ; preds = %82
%110 = load i32, i32* @stderr
%111 = load i32, i32* %18
%112 = call i8* @strerror(i32 %111)
%113 = call i32 (i32, i8*, ...) @fprintf(i32 %110, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([145 x i8], [145 x i8]* @.str.3, i64 0, i64 0), i32 169, i8* %112)
%114 = load i32, i32* %18
%115 = sub nsw i32 0, %114
store i32 %115, i32* %7
br label %130
116: ; preds = %51
%117 = load i32, i32* @stderr
%118 = load i32, i32* %18
%119 = call i8* @strerror(i32 %118)
%120 = call i32 (i32, i8*, ...) @fprintf(i32 %117, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([145 x i8], [145 x i8]* @.str.3, i64 0, i64 0), i32 175, i8* %119)
%121 = load i32, i32* %18
%122 = sub nsw i32 0, %121
store i32 %122, i32* %7
br label %130
123: ; preds = %46
%124 = load i32, i32* @stderr
%125 = load i32, i32* %18
%126 = call i8* @strerror(i32 %125)
%127 = call i32 (i32, i8*, ...) @fprintf(i32 %124, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([145 x i8], [145 x i8]* @.str.3, i64 0, i64 0), i32 181, i8* %126)
%128 = load i32, i32* %18
%129 = sub nsw i32 0, %128
store i32 %129, i32* %7
br label %130
130: ; preds = %123, %116, %109, %102, %100
%131 = load i32, i32* %7
ret i32 %131
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@stdout = global i32 0
@.str = [42 x i8] c"+%d: fd: %d buf: %llx start: %d max: %zu\0A\00"
@.str.1 = [20 x i8] c"wr_us: %u r_us: %u\0A\00"
@errno = global i32 0
@ETIMEDOUT = global i32 0
@SOL_SOCKET = global i32 0
@SO_RCVTIMEO = global i32 0
@MSG_DONTWAIT = global i32 0
@EAGAIN = global i32 0
@EWOULDBLOCK = global i32 0
@stderr = global i32 0
@.str.2 = [23 x i8] c"%s +%d: recv fail: %s\0A\00"
@.str.3 = [145 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/iamyuiwong/swift-socket/refs/heads/master/socket/tcp.c\00"
@.str.4 = [26 x i8] c"%s +%d: recv timeout: %s\0A\00"
@.str.5 = [28 x i8] c"%s +%d: select timeout: %s\0A\00"
@.str.6 = [25 x i8] c"%s +%d: select fail: %s\0A\00"
define i32 @tcp_recv_from(i32 %0, i32* %1, i32 %2, i64 %3, i32 %4, i32 %5) {
%7 = alloca %struct.timeval
%8 = alloca %struct.timeval
%9 = alloca i32
%10 = bitcast %struct.timeval* %7 to i8*
%11 = bitcast %struct.timeval* %8 to i8*
%12 = bitcast i32* %9 to i8*
%13 = load i32, i32* @stdout
%14 = ptrtoint i32* %1 to i64
%15 = trunc i64 %14 to i32
%16 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 112, i32 %0, i32 %15, i32 %2, i64 %3)
%17 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %4, i32 %5)
%18 = sitofp i32 %4 to double
%19 = fdiv double %18, 1.000000e+06
%20 = fptosi double %19 to i32
%21 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i64 0, i32 0
store i32 %20, i32* %21
%22 = srem i32 %4, 1000000
%23 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i64 0, i32 1
store i32 %22, i32* %23
%24 = call i32 @FD_ZERO(i32* %9)
%25 = call i32 @FD_SET(i32 %0, i32* %9)
%26 = add nsw i32 %0, 1
%27 = call i32 @select(i32 %26, i32* %9, i32* null, i32* null, %struct.timeval* %7)
switch i32 %27, label %40 [
i32 -1, label %28
i32 0, label %34
]
28: ; preds = %6
%29 = load i32, i32* @errno
%30 = load i32, i32* @stderr
%31 = call i8* @strerror(i32 %29)
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([145 x i8], [145 x i8]* @.str.3, i64 0, i64 0), i32 181, i8* %31)
%33 = sub nsw i32 0, %29
br label %71
34: ; preds = %6
%35 = load i32, i32* @ETIMEDOUT
%36 = load i32, i32* @stderr
%37 = call i8* @strerror(i32 %35)
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([145 x i8], [145 x i8]* @.str.3, i64 0, i64 0), i32 175, i8* %37)
%39 = sub nsw i32 0, %35
br label %71
40: ; preds = %6
%41 = sitofp i32 %5 to double
%42 = fdiv double %41, 1.000000e+06
%43 = fptosi double %42 to i32
%44 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i64 0, i32 0
store i32 %43, i32* %44
%45 = srem i32 %5, 1000000
%46 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i64 0, i32 1
store i32 %45, i32* %46
%47 = load i32, i32* @SOL_SOCKET
%48 = load i32, i32* @SO_RCVTIMEO
%49 = call i32 @setsockopt(i32 %0, i32 %47, i32 %48, %struct.timeval* %8, i32 8)
%50 = sext i32 %2 to i64
%51 = getelementptr inbounds i32, i32* %1, i64 %50
%52 = load i32, i32* @MSG_DONTWAIT
%53 = call i64 @recv(i32 %0, i32* %51, i64 %3, i32 %52)
%54 = trunc i64 %53 to i32
%55 = icmp slt i32 %54, 0
br i1 %55, label %56, label %71
56: ; preds = %40
%57 = load i32, i32* @EAGAIN
%58 = load i32, i32* @errno
%59 = icmp eq i32 %57, %58
br i1 %59, label %60, label %66
60: ; preds = %56
%61 = load i32, i32* @ETIMEDOUT
%62 = load i32, i32* @stderr
%63 = call i8* @strerror(i32 %61)
%64 = call i32 (i32, i8*, ...) @fprintf(i32 %62, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([145 x i8], [145 x i8]* @.str.3, i64 0, i64 0), i32 169, i8* %63)
%65 = sub nsw i32 0, %61
br label %71
66: ; preds = %56
%67 = load i32, i32* @stderr
%68 = call i8* @strerror(i32 %58)
%69 = call i32 (i32, i8*, ...) @fprintf(i32 %67, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([145 x i8], [145 x i8]* @.str.3, i64 0, i64 0), i32 163, i8* %68)
%70 = sub nsw i32 0, %58
br label %71
71: ; preds = %40, %28, %34, %60, %66
%72 = phi i32 [ %33, %28 ], [ %39, %34 ], [ %65, %60 ], [ %70, %66 ], [ %54, %40 ]
ret i32 %72
}