#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
typedef int /*<<< orphan*/ uint16_t;
struct timeval {
  int tv_sec;
  scalar_t__ tv_usec;
};
struct TYPE_2__ {
  void *s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  void *sin_port;
  void *sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ sa;
typedef int /*<<< orphan*/ fd_set;
typedef int /*<<< orphan*/ bufs;
typedef int /*<<< orphan*/ bufc;

/* Variables and functions */
void *AF_INET;
int /*<<< orphan*/ FD_CLR(int, int /*<<< orphan*/ *);
scalar_t__ FD_ISSET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ INADDR_LOOPBACK;
int /*<<< orphan*/ SOCK_DGRAM;
scalar_t__ bind(int, struct sockaddr *, int);
scalar_t__ close(int);
scalar_t__ getsockname(int, struct sockaddr *, int *);
void *htonl(int /*<<< orphan*/);
void *htons(int /*<<< orphan*/);
scalar_t__ memcmp(char *, char const *, int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ ntohs(void *);
int /*<<< orphan*/ printf(char *, char const *, char *);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int *);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
scalar_t__ sendto(int, char const *, int, int /*<<< orphan*/, struct sockaddr *,
                  int);
int socket(void *, int /*<<< orphan*/, int /*<<< orphan*/);
int _socket_udp(char const *progname) {
  int ret;
  int fds = -1;
  int fdc;
  struct sockaddr_in sa;
  uint16_t port;
  socklen_t salen;
  int nfds;
  fd_set rfds;
  fd_set wfds;
  struct timeval timeout;
  int res;
  char const bufc[14] = "DeforaOS libc";
  char bufs[14];
  printf("%s: Testing %s\n", progname, "UDP");
  if ((fds = socket(AF_INET, SOCK_DGRAM, 0)) < 0 ||
      (fdc = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
    if (fds >= 0)
      close(fds);
    return 2;
  }
  memset(&sa, 0, sizeof(sa));
  sa.sin_family = AF_INET;
  sa.sin_port = htons(0);
  sa.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
  salen = sizeof(sa);
  if (bind(fds, (struct sockaddr *)&sa, sizeof(sa)) != 0 ||
      getsockname(fds, (struct sockaddr *)&sa, &salen) != 0) {
    close(fdc);
    close(fds);
    return 3;
  }
  port = ntohs(sa.sin_port);
  nfds = fdc + 1;
  FD_ZERO(&rfds);
  FD_ZERO(&wfds);
  FD_SET(fdc, &wfds);
  for (ret = 0; ret == 0;) {
    timeout.tv_sec = 1;
    timeout.tv_usec = 0;
    if ((res = select(nfds, &rfds, &wfds, NULL, &timeout)) < 0)
      ret = 4;
    else if (res == 0)
      ret = 5;
    else if (FD_ISSET(fds, &rfds)) {
      if ((res = recvfrom(fds, bufs, sizeof(bufs), 0, (struct sockaddr *)&sa,
                          &salen)) < 0 ||
          res != sizeof(bufs))
        ret = 6;
      if (memcmp(bufs, bufc, sizeof(bufs)) != 0)
        ret = 7;
      break;
    } else if (FD_ISSET(fdc, &wfds)) {
      memset(&sa, 0, sizeof(sa));
      sa.sin_family = AF_INET;
      sa.sin_port = htons(port);
      sa.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
      if (sendto(fdc, bufc, sizeof(bufc), 0, (struct sockaddr *)&sa,
                 sizeof(sa)) < 0)
        ret = 8;
      FD_CLR(fdc, &wfds);
      nfds = fds + 1;
      FD_SET(fds, &rfds);
    } else
      ret = 9;
  }
  if (close(fdc) != 0)
    ret = 10;
  if (close(fds) != 0)
    ret = 11;
  return ret;
}


x86 assembly (clang, -O0):
<_socket_udp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0xffffffff,-0x18(%rbp)
mov    0xdd3(%rip),%rax
mov    %rax,-0x72(%rbp)
mov    0xdd1(%rip),%eax
mov    %eax,-0x6a(%rbp)
mov    0xdcb(%rip),%ax
mov    %ax,-0x66(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xdbe(%rip),%rdi
lea    0xdc7(%rip),%rdx
call   1050 <printf@plt>
mov    0x2d85(%rip),%rax
mov    (%rax),%rdi
mov    0x2d73(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1130 <socket@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jl     12a8 <_socket_udp+0x98>
mov    0x2d5f(%rip),%rax
mov    (%rax),%rdi
mov    0x2d4d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1130 <socket@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    12c6 <_socket_udp+0xb6>
cmpl   $0x0,-0x18(%rbp)
jl     12ba <_socket_udp+0xaa>
mov    -0x18(%rbp),%edi
call   1090 <close@plt>
movl   $0x2,-0x4(%rbp)
jmp    1565 <_socket_udp+0x355>
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1070 <memset@plt>
mov    0x2d0b(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
xor    %edi,%edi
call   1040 <htons@plt>
mov    %rax,-0x30(%rbp)
mov    0x2ce2(%rip),%rax
mov    (%rax),%edi
call   1060 <htonl@plt>
mov    %rax,-0x38(%rbp)
movl   $0x18,-0x40(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x38(%rbp),%rsi
mov    $0x18,%edx
call   10f0 <bind@plt>
cmp    $0x0,%rax
jne    133d <_socket_udp+0x12d>
mov    -0x18(%rbp),%edi
lea    -0x38(%rbp),%rsi
lea    -0x40(%rbp),%rdx
call   1100 <getsockname@plt>
cmp    $0x0,%rax
je     1359 <_socket_udp+0x149>
mov    -0x1c(%rbp),%edi
call   1090 <close@plt>
mov    -0x18(%rbp),%edi
call   1090 <close@plt>
movl   $0x3,-0x4(%rbp)
jmp    1565 <_socket_udp+0x355>
mov    -0x30(%rbp),%rdi
call   10e0 <ntohs@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
lea    -0x48(%rbp),%rdi
call   10b0 <FD_ZERO@plt>
lea    -0x4c(%rbp),%rdi
call   10b0 <FD_ZERO@plt>
mov    -0x1c(%rbp),%edi
lea    -0x4c(%rbp),%rsi
call   1120 <FD_SET@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    152d <_socket_udp+0x31d>
movl   $0x1,-0x60(%rbp)
movq   $0x0,-0x58(%rbp)
mov    -0x44(%rbp),%edi
lea    -0x48(%rbp),%rsi
lea    -0x4c(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x60(%rbp),%r8
call   10c0 <select@plt>
mov    %eax,-0x64(%rbp)
cmp    $0x0,%eax
jge    13dc <_socket_udp+0x1cc>
movl   $0x4,-0x14(%rbp)
jmp    1528 <_socket_udp+0x318>
cmpl   $0x0,-0x64(%rbp)
jne    13f2 <_socket_udp+0x1e2>
movl   $0x5,-0x14(%rbp)
jmp    1523 <_socket_udp+0x313>
mov    -0x18(%rbp),%edi
lea    -0x48(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
je     146c <_socket_udp+0x25c>
mov    -0x18(%rbp),%edi
lea    -0x80(%rbp),%rsi
lea    -0x38(%rbp),%r8
mov    $0xe,%edx
xor    %ecx,%ecx
lea    -0x40(%rbp),%r9
call   10d0 <recvfrom@plt>
mov    %eax,-0x64(%rbp)
cmp    $0x0,%eax
jl     143d <_socket_udp+0x22d>
movslq -0x64(%rbp),%rax
cmp    $0xe,%rax
je     1444 <_socket_udp+0x234>
movl   $0x6,-0x14(%rbp)
lea    -0x80(%rbp),%rdi
lea    -0x72(%rbp),%rsi
mov    $0xe,%edx
call   10a0 <memcmp@plt>
cmp    $0x0,%rax
je     1467 <_socket_udp+0x257>
movl   $0x7,-0x14(%rbp)
jmp    152d <_socket_udp+0x31d>
mov    -0x1c(%rbp),%edi
lea    -0x4c(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1512 <_socket_udp+0x302>
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1070 <memset@plt>
mov    0x2b4f(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x3c(%rbp),%edi
call   1040 <htons@plt>
mov    %rax,-0x30(%rbp)
mov    0x2b25(%rip),%rax
mov    (%rax),%edi
call   1060 <htonl@plt>
mov    %rax,-0x38(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x72(%rbp),%rsi
lea    -0x38(%rbp),%r8
mov    $0xe,%edx
xor    %ecx,%ecx
mov    $0x18,%r9d
call   1080 <sendto@plt>
cmp    $0x0,%rax
jge    14ec <_socket_udp+0x2dc>
movl   $0x8,-0x14(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x4c(%rbp),%rsi
call   1110 <FD_CLR@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x48(%rbp),%rsi
call   1120 <FD_SET@plt>
jmp    1519 <_socket_udp+0x309>
movl   $0x9,-0x14(%rbp)
jmp    151e <_socket_udp+0x30e>
jmp    1523 <_socket_udp+0x313>
jmp    1528 <_socket_udp+0x318>
jmp    1393 <_socket_udp+0x183>
mov    -0x1c(%rbp),%edi
call   1090 <close@plt>
cmp    $0x0,%rax
je     1546 <_socket_udp+0x336>
movl   $0xa,-0x14(%rbp)
mov    -0x18(%rbp),%edi
call   1090 <close@plt>
cmp    $0x0,%rax
je     155f <_socket_udp+0x34f>
movl   $0xb,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_socket_udp>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %rdi,%rsi
movabs $0x6362696c20534f,%rax
mov    %rax,0x26(%rsp)
movabs $0x534f61726f666544,%rax
61 4f 53
mov    %rax,0x20(%rsp)
lea    0xdc8(%rip),%rdi
lea    0xdd1(%rip),%rdx
call   1050 <printf@plt>
mov    0x2d8f(%rip),%r15
mov    (%r15),%rdi
mov    0x2d7d(%rip),%rbx
mov    (%rbx),%esi
xor    %edx,%edx
call   1130 <socket@plt>
mov    $0x2,%ebp
test   %eax,%eax
js     131e <_socket_udp+0x10e>
mov    %eax,%r12d
mov    (%r15),%rdi
mov    (%rbx),%esi
xor    %edx,%edx
call   1130 <socket@plt>
test   %eax,%eax
js     1316 <_socket_udp+0x106>
mov    %eax,%r13d
lea    0x8(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1070 <memset@plt>
mov    (%r15),%rax
mov    %rax,0x18(%rsp)
xor    %edi,%edi
call   1040 <htons@plt>
mov    %rax,0x10(%rsp)
mov    0x2d16(%rip),%rax
mov    (%rax),%edi
call   1060 <htonl@plt>
mov    %rax,0x8(%rsp)
movl   $0x18,(%rsp)
mov    %r12d,%edi
mov    %rbp,%rsi
mov    $0x18,%edx
call   10f0 <bind@plt>
test   %rax,%rax
jne    12ff <_socket_udp+0xef>
lea    0x8(%rsp),%rsi
mov    %rsp,%rdx
mov    %r12d,%edi
call   1100 <getsockname@plt>
test   %rax,%rax
je     132f <_socket_udp+0x11f>
mov    %r13d,%edi
call   1090 <close@plt>
mov    %r12d,%edi
call   1090 <close@plt>
mov    $0x3,%ebp
jmp    131e <_socket_udp+0x10e>
mov    %r12d,%edi
call   1090 <close@plt>
mov    %ebp,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x10(%rsp),%rdi
call   10e0 <ntohs@plt>
mov    %eax,0x4(%rsp)
lea    0x34(%rsp),%rbp
mov    %rbp,%rdi
call   10b0 <FD_ZERO@plt>
lea    0x30(%rsp),%rbx
mov    %rbx,%rdi
call   10b0 <FD_ZERO@plt>
mov    %r13d,%edi
mov    %rbx,%rsi
call   1120 <FD_SET@plt>
mov    %r13d,%edi
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%edi
movl   $0x1,0x38(%rsp)
movq   $0x0,0x40(%rsp)
mov    %rbp,%rsi
mov    %rbx,%rdx
xor    %ecx,%ecx
lea    0x38(%rsp),%r8
call   10c0 <select@plt>
test   %eax,%eax
js     145e <_socket_udp+0x24e>
je     1466 <_socket_udp+0x256>
mov    %r12d,%edi
mov    %rbp,%rsi
call   1030 <FD_ISSET@plt>
test   %rax,%rax
jne    146e <_socket_udp+0x25e>
mov    %r13d,%edi
mov    %rbx,%rsi
call   1030 <FD_ISSET@plt>
test   %rax,%rax
je     14bd <_socket_udp+0x2ad>
mov    %rbx,%r14
mov    %rbp,%rbx
lea    0x8(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1070 <memset@plt>
mov    (%r15),%rax
mov    %rax,0x18(%rsp)
mov    0x4(%rsp),%edi
call   1040 <htons@plt>
mov    %rax,0x10(%rsp)
mov    0x2bd5(%rip),%rax
mov    (%rax),%edi
call   1060 <htonl@plt>
mov    %rax,0x8(%rsp)
mov    %r13d,%edi
lea    0x20(%rsp),%rsi
mov    $0xe,%edx
xor    %ecx,%ecx
mov    %rbp,%r8
mov    %rbx,%rbp
mov    %r14,%rbx
mov    $0x18,%r9d
call   1080 <sendto@plt>
mov    %rax,%r14
shr    $0x3c,%r14
mov    %r13d,%edi
mov    %rbx,%rsi
call   1110 <FD_CLR@plt>
mov    %r12d,%edi
mov    %rbp,%rsi
call   1120 <FD_SET@plt>
mov    %r12d,%edi
and    $0x8,%r14d
je     1370 <_socket_udp+0x160>
jmp    14c3 <_socket_udp+0x2b3>
mov    $0x4,%r14d
jmp    14c3 <_socket_udp+0x2b3>
mov    $0x5,%r14d
jmp    14c3 <_socket_udp+0x2b3>
lea    0x4a(%rsp),%rbp
xor    %r14d,%r14d
lea    0x8(%rsp),%r8
mov    %rsp,%r9
mov    %r12d,%edi
mov    %rbp,%rsi
mov    $0xe,%edx
xor    %ecx,%ecx
call   10d0 <recvfrom@plt>
cmp    $0xe,%eax
mov    $0x6,%ebx
cmove  %r14d,%ebx
lea    0x20(%rsp),%rsi
mov    %rbp,%rdi
mov    $0xe,%edx
call   10a0 <memcmp@plt>
test   %rax,%rax
mov    $0x7,%r14d
cmove  %ebx,%r14d
jmp    14c3 <_socket_udp+0x2b3>
mov    $0x9,%r14d
mov    %r13d,%edi
call   1090 <close@plt>
test   %rax,%rax
mov    $0xa,%ebx
cmove  %r14d,%ebx
mov    %r12d,%edi
call   1090 <close@plt>
test   %rax,%rax
mov    $0xb,%ebp
cmove  %ebx,%ebp
jmp    131e <_socket_udp+0x10e>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i8*, i8* }
%struct.TYPE_2__ = type { i8* }
%struct.timeval = type { i32, i64 }
%struct.sockaddr = type { i32 }
@__const._socket_udp.bufc = [14 x i8] c"DeforaOS libc\00"
@.str = [16 x i8] c"%s: Testing %s\0A\00"
@.str.1 = [4 x i8] c"UDP\00"
@AF_INET = global i8* null
@SOCK_DGRAM = global i32 0
@INADDR_LOOPBACK = global i32 0
define i32 @_socket_udp(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.sockaddr_in
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca %struct.timeval
%14 = alloca i32
%15 = alloca [14 x i8]
%16 = alloca [14 x i8]
store i8* %0, i8** %3
store i32 -1, i32* %5
%17 = bitcast [14 x i8]* %15 to i8*
%18 = load i8*, i8** %3
%19 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%20 = load i8*, i8** @AF_INET
%21 = load i32, i32* @SOCK_DGRAM
%22 = call i32 @socket(i8* %20, i32 %21, i32 0)
store i32 %22, i32* %5
%23 = icmp slt i32 %22, 0
br i1 %23, label %29, label %24
24: ; preds = %1
%25 = load i8*, i8** @AF_INET
%26 = load i32, i32* @SOCK_DGRAM
%27 = call i32 @socket(i8* %25, i32 %26, i32 0)
store i32 %27, i32* %6
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %36
29: ; preds = %24, %1
%30 = load i32, i32* %5
%31 = icmp sge i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %29
%33 = load i32, i32* %5
%34 = call i64 @close(i32 %33)
br label %35
35: ; preds = %32, %29
store i32 2, i32* %2
br label %151
36: ; preds = %24
%37 = call i32 @memset(%struct.sockaddr_in* %7, i32 0, i32 24)
%38 = load i8*, i8** @AF_INET
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i8* %38, i8** %39
%40 = call i8* @htons(i32 0)
%41 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
store i8* %40, i8** %41
%42 = load i32, i32* @INADDR_LOOPBACK
%43 = call i8* @htonl(i32 %42)
%44 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
%45 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %44, i32 0, i32 0
store i8* %43, i8** %45
store i32 24, i32* %9
%46 = load i32, i32* %5
%47 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%48 = call i64 @bind(i32 %46, %struct.sockaddr* %47, i32 24)
%49 = icmp ne i64 %48, 0
br i1 %49, label %55, label %50
50: ; preds = %36
%51 = load i32, i32* %5
%52 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%53 = call i64 @getsockname(i32 %51, %struct.sockaddr* %52, i32* %9)
%54 = icmp ne i64 %53, 0
br i1 %54, label %55, label %60
55: ; preds = %50, %36
%56 = load i32, i32* %6
%57 = call i64 @close(i32 %56)
%58 = load i32, i32* %5
%59 = call i64 @close(i32 %58)
store i32 3, i32* %2
br label %151
60: ; preds = %50
%61 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
%62 = load i8*, i8** %61
%63 = call i32 @ntohs(i8* %62)
store i32 %63, i32* %8
%64 = load i32, i32* %6
%65 = add nsw i32 %64, 1
store i32 %65, i32* %10
%66 = call i32 @FD_ZERO(i32* %11)
%67 = call i32 @FD_ZERO(i32* %12)
%68 = load i32, i32* %6
%69 = call i32 @FD_SET(i32 %68, i32* %12)
store i32 0, i32* %4
br label %70
70: ; preds = %138, %60
%71 = load i32, i32* %4
%72 = icmp eq i32 %71, 0
br i1 %72, label %73, label %139
73: ; preds = %70
%74 = getelementptr inbounds %struct.timeval, %struct.timeval* %13, i32 0, i32 0
store i32 1, i32* %74
%75 = getelementptr inbounds %struct.timeval, %struct.timeval* %13, i32 0, i32 1
store i64 0, i64* %75
%76 = load i32, i32* %10
%77 = call i32 @select(i32 %76, i32* %11, i32* %12, i32* null, %struct.timeval* %13)
store i32 %77, i32* %14
%78 = icmp slt i32 %77, 0
br i1 %78, label %79, label %80
79: ; preds = %73
store i32 4, i32* %4
br label %138
80: ; preds = %73
%81 = load i32, i32* %14
%82 = icmp eq i32 %81, 0
br i1 %82, label %83, label %84
83: ; preds = %80
store i32 5, i32* %4
br label %137
84: ; preds = %80
%85 = load i32, i32* %5
%86 = call i64 @FD_ISSET(i32 %85, i32* %11)
%87 = icmp ne i64 %86, 0
br i1 %87, label %88, label %106
88: ; preds = %84
%89 = load i32, i32* %5
%90 = getelementptr inbounds [14 x i8], [14 x i8]* %16, i64 0, i64 0
%91 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%92 = call i32 @recvfrom(i32 %89, i8* %90, i32 14, i32 0, %struct.sockaddr* %91, i32* %9)
store i32 %92, i32* %14
%93 = icmp slt i32 %92, 0
br i1 %93, label %98, label %94
94: ; preds = %88
%95 = load i32, i32* %14
%96 = sext i32 %95 to i64
%97 = icmp ne i64 %96, 14
br i1 %97, label %98, label %99
98: ; preds = %94, %88
store i32 6, i32* %4
br label %99
99: ; preds = %98, %94
%100 = getelementptr inbounds [14 x i8], [14 x i8]* %16, i64 0, i64 0
%101 = getelementptr inbounds [14 x i8], [14 x i8]* %15, i64 0, i64 0
%102 = call i64 @memcmp(i8* %100, i8* %101, i32 14)
%103 = icmp ne i64 %102, 0
br i1 %103, label %104, label %105
104: ; preds = %99
store i32 7, i32* %4
br label %105
105: ; preds = %104, %99
br label %139
106: ; preds = %84
%107 = load i32, i32* %6
%108 = call i64 @FD_ISSET(i32 %107, i32* %12)
%109 = icmp ne i64 %108, 0
br i1 %109, label %110, label %134
110: ; preds = %106
%111 = call i32 @memset(%struct.sockaddr_in* %7, i32 0, i32 24)
%112 = load i8*, i8** @AF_INET
%113 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i8* %112, i8** %113
%114 = load i32, i32* %8
%115 = call i8* @htons(i32 %114)
%116 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
store i8* %115, i8** %116
%117 = load i32, i32* @INADDR_LOOPBACK
%118 = call i8* @htonl(i32 %117)
%119 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
%120 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %119, i32 0, i32 0
store i8* %118, i8** %120
%121 = load i32, i32* %6
%122 = getelementptr inbounds [14 x i8], [14 x i8]* %15, i64 0, i64 0
%123 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%124 = call i64 @sendto(i32 %121, i8* %122, i32 14, i32 0, %struct.sockaddr* %123, i32 24)
%125 = icmp slt i64 %124, 0
br i1 %125, label %126, label %127
126: ; preds = %110
store i32 8, i32* %4
br label %127
127: ; preds = %126, %110
%128 = load i32, i32* %6
%129 = call i32 @FD_CLR(i32 %128, i32* %12)
%130 = load i32, i32* %5
%131 = add nsw i32 %130, 1
store i32 %131, i32* %10
%132 = load i32, i32* %5
%133 = call i32 @FD_SET(i32 %132, i32* %11)
br label %135
134: ; preds = %106
store i32 9, i32* %4
br label %135
135: ; preds = %134, %127
br label %136
136: ; preds = %135
br label %137
137: ; preds = %136, %83
br label %138
138: ; preds = %137, %79
br label %70
139: ; preds = %105, %70
%140 = load i32, i32* %6
%141 = call i64 @close(i32 %140)
%142 = icmp ne i64 %141, 0
br i1 %142, label %143, label %144
143: ; preds = %139
store i32 10, i32* %4
br label %144
144: ; preds = %143, %139
%145 = load i32, i32* %5
%146 = call i64 @close(i32 %145)
%147 = icmp ne i64 %146, 0
br i1 %147, label %148, label %149
148: ; preds = %144
store i32 11, i32* %4
br label %149
149: ; preds = %148, %144
%150 = load i32, i32* %4
store i32 %150, i32* %2
br label %151
151: ; preds = %149, %55, %35
%152 = load i32, i32* %2
ret i32 %152
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i8*, i8* }
%struct.TYPE_2__ = type { i8* }
%struct.timeval = type { i32, i64 }
%struct.sockaddr = type { i32 }
@__const._socket_udp.bufc = [14 x i8] c"DeforaOS libc\00"
@.str = [16 x i8] c"%s: Testing %s\0A\00"
@.str.1 = [4 x i8] c"UDP\00"
@AF_INET = global i8* null
@SOCK_DGRAM = global i32 0
@INADDR_LOOPBACK = global i32 0
define i32 @_socket_udp(i8* %0) {
%2 = alloca %struct.sockaddr_in
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.timeval
%7 = alloca [14 x i8]
%8 = alloca [14 x i8]
%9 = bitcast %struct.sockaddr_in* %2 to i8*
%10 = bitcast i32* %3 to i8*
%11 = bitcast i32* %4 to i8*
%12 = bitcast i32* %5 to i8*
%13 = bitcast %struct.timeval* %6 to i8*
%14 = getelementptr inbounds [14 x i8], [14 x i8]* %7, i64 0, i64 0
%15 = getelementptr inbounds [14 x i8], [14 x i8]* %8, i64 0, i64 0
%16 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%17 = load i8*, i8** @AF_INET
%18 = load i32, i32* @SOCK_DGRAM
%19 = tail call i32 @socket(i8* %17, i32 %18, i32 0)
%20 = icmp slt i32 %19, 0
br i1 %20, label %95, label %21
21: ; preds = %1
%22 = load i8*, i8** @AF_INET
%23 = load i32, i32* @SOCK_DGRAM
%24 = tail call i32 @socket(i8* %22, i32 %23, i32 0)
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %21
%27 = tail call i64 @close(i32 %19)
br label %95
28: ; preds = %21
%29 = call i32 @memset(%struct.sockaddr_in* %2, i32 0, i32 24)
%30 = load i8*, i8** @AF_INET
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 2
store i8* %30, i8** %31
%32 = call i8* @htons(i32 0)
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1
store i8* %32, i8** %33
%34 = load i32, i32* @INADDR_LOOPBACK
%35 = call i8* @htonl(i32 %34)
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0, i32 0
store i8* %35, i8** %36
store i32 24, i32* %3
%37 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%38 = call i64 @bind(i32 %19, %struct.sockaddr* %37, i32 24)
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %28
%41 = call i64 @getsockname(i32 %19, %struct.sockaddr* %37, i32* %3)
%42 = icmp eq i64 %41, 0
br i1 %42, label %46, label %43
43: ; preds = %40, %28
%44 = call i64 @close(i32 %24)
%45 = call i64 @close(i32 %19)
br label %95
46: ; preds = %40
%47 = load i8*, i8** %33
%48 = call i32 @ntohs(i8* %47)
%49 = call i32 @FD_ZERO(i32* %4)
%50 = call i32 @FD_ZERO(i32* %5)
%51 = call i32 @FD_SET(i32 %24, i32* %5)
%52 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i64 0, i32 0
%53 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i64 0, i32 1
br label %54
54: ; preds = %46, %74
%55 = phi i32 [ %24, %46 ], [ %19, %74 ]
%56 = add nuw nsw i32 %55, 1
store i32 1, i32* %52
store i64 0, i64* %53
%57 = call i32 @select(i32 %56, i32* %4, i32* %5, i32* null, %struct.timeval* %6)
%58 = icmp slt i32 %57, 0
br i1 %58, label %87, label %59
59: ; preds = %54
%60 = icmp eq i32 %57, 0
br i1 %60, label %87, label %61
61: ; preds = %59
%62 = call i64 @FD_ISSET(i32 %19, i32* %4)
%63 = icmp eq i64 %62, 0
br i1 %63, label %71, label %64
64: ; preds = %61
%65 = call i32 @recvfrom(i32 %19, i8* %15, i32 14, i32 0, %struct.sockaddr* %37, i32* %3)
%66 = icmp eq i32 %65, 14
%67 = select i1 %66, i32 0, i32 6
%68 = call i64 @memcmp(i8* %15, i8* %14, i32 14)
%69 = icmp eq i64 %68, 0
%70 = select i1 %69, i32 %67, i32 7
br label %87
71: ; preds = %61
%72 = call i64 @FD_ISSET(i32 %24, i32* %5)
%73 = icmp eq i64 %72, 0
br i1 %73, label %87, label %74
74: ; preds = %71
%75 = call i32 @memset(%struct.sockaddr_in* %2, i32 0, i32 24)
%76 = load i8*, i8** @AF_INET
store i8* %76, i8** %31
%77 = call i8* @htons(i32 %48)
store i8* %77, i8** %33
%78 = load i32, i32* @INADDR_LOOPBACK
%79 = call i8* @htonl(i32 %78)
store i8* %79, i8** %36
%80 = call i64 @sendto(i32 %24, i8* %14, i32 14, i32 0, %struct.sockaddr* %37, i32 24)
%81 = lshr i64 %80, 60
%82 = trunc i64 %81 to i32
%83 = and i32 %82, 8
%84 = call i32 @FD_CLR(i32 %24, i32* %5)
%85 = call i32 @FD_SET(i32 %19, i32* %4)
%86 = icmp eq i32 %83, 0
br i1 %86, label %54, label %87
87: ; preds = %71, %59, %54, %74, %64
%88 = phi i32 [ %70, %64 ], [ 4, %54 ], [ 5, %59 ], [ 9, %71 ], [ %83, %74 ]
%89 = call i64 @close(i32 %24)
%90 = icmp eq i64 %89, 0
%91 = select i1 %90, i32 %88, i32 10
%92 = call i64 @close(i32 %19)
%93 = icmp eq i64 %92, 0
%94 = select i1 %93, i32 %91, i32 11
br label %95
95: ; preds = %1, %26, %87, %43
%96 = phi i32 [ 3, %43 ], [ %94, %87 ], [ 2, %26 ], [ 2, %1 ]
ret i32 %96
}