#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 scalar_t__ uint32_t;
typedef int /*<<< orphan*/ thetime;
struct timeval {
  scalar_t__ tv_usec;
  scalar_t__ tv_sec;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct servent {
  int /*<<< orphan*/ s_port;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ from;
typedef int /*<<< orphan*/ fd_set;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
scalar_t__ EINTR;
scalar_t__ EIO;
scalar_t__ ETIMEDOUT;
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int SOCK_DGRAM;
int SOCK_STREAM;
int UINT32_C(int);
int _RPC_read(int, char *, int);
int /*<<< orphan*/ _rpc_dtablesize();
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ do_close(int);
scalar_t__ errno;
struct servent *getservbyname(char *, char *);
scalar_t__ ntohl(scalar_t__);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int *);
int select(int /*<<< orphan*/, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
int sendto(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int);
int socket(int /*<<< orphan*/, int, int /*<<< orphan*/);
int rtime(struct sockaddr_in *addrp, struct timeval *timep,
          struct timeval *timeout) {
  int s;
  fd_set readfds;
  int res;
  uint32_t thetime;
  struct sockaddr_in from;
  socklen_t fromlen;
  int type;
  struct servent *serv;
  if (timeout == NULL) {
    type = SOCK_STREAM;
  } else {
    type = SOCK_DGRAM;
  }
  s = socket(AF_INET, type, 0);
  if (s < 0) {
    return (-1);
  }
  addrp->sin_family = AF_INET;
  if ((serv = getservbyname("time", "tcp")) == NULL) {
    return (-1);
  }
  addrp->sin_port = serv->s_port;
  if (type == SOCK_DGRAM) {
    res = sendto(s, (char *)&thetime, sizeof(thetime), 0,
                 (struct sockaddr *)addrp, sizeof(*addrp));
    if (res < 0) {
      do_close(s);
      return (-1);
    }
    do {
      FD_ZERO(&readfds);
      FD_SET(s, &readfds);
      res = select(_rpc_dtablesize(), &readfds, (fd_set *)NULL, (fd_set *)NULL,
                   timeout);
    } while (res < 0 && errno == EINTR);
    if (res <= 0) {
      if (res == 0) {
        errno = ETIMEDOUT;
      }
      do_close(s);
      return (-1);
    }
    fromlen = sizeof(from);
    res = recvfrom(s, (char *)&thetime, sizeof(thetime), 0,
                   (struct sockaddr *)&from, &fromlen);
    do_close(s);
    if (res < 0) {
      return (-1);
    }
  } else {
    if (connect(s, (struct sockaddr *)addrp, sizeof(*addrp)) < 0) {
      do_close(s);
      return (-1);
    }
    res = _RPC_read(s, (char *)&thetime, sizeof(thetime));
    do_close(s);
    if (res < 0) {
      return (-1);
    }
  }
  if (res != sizeof(thetime)) {
    errno = EIO;
    return (-1);
  }
  thetime = ntohl(thetime);
  timep->tv_sec =
      thetime - (UINT32_C(60) * UINT32_C(60) * UINT32_C(24) *
                 (UINT32_C(365) * (UINT32_C(1970) - UINT32_C(1900)) +
                  ((UINT32_C(1970) - UINT32_C(1900)) / UINT32_C(4))));
  timep->tv_usec = 0;
  return (0);
}


x86 assembly (clang, -O0):
<rtime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1203 <rtime+0x33>
mov    0x2dcf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
jmp    120f <rtime+0x3f>
mov    0x2dd6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
mov    0x2dd2(%rip),%rax
mov    (%rax),%edi
mov    -0x48(%rbp),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    123b <rtime+0x6b>
movl   $0xffffffff,-0x4(%rbp)
jmp    153b <rtime+0x36b>
mov    0x2da6(%rip),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x4(%rax)
lea    0xdae(%rip),%rdi
lea    0xdac(%rip),%rsi
call   1040 <getservbyname@plt>
mov    %rax,-0x50(%rbp)
cmp    $0x0,%rax
jne    1278 <rtime+0xa8>
movl   $0xffffffff,-0x4(%rbp)
jmp    153b <rtime+0x36b>
mov    -0x50(%rbp),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x48(%rbp),%eax
mov    0x2d52(%rip),%rcx
cmp    (%rcx),%eax
jne    13c4 <rtime+0x1f4>
mov    -0x24(%rbp),%edi
lea    -0x38(%rbp),%rsi
mov    -0x10(%rbp),%r8
mov    $0x8,%r9d
xor    %ecx,%ecx
mov    %r9d,%edx
call   1060 <sendto@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    12d2 <rtime+0x102>
mov    -0x24(%rbp),%edi
call   10b0 <do_close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    153b <rtime+0x36b>
jmp    12d7 <rtime+0x107>
lea    -0x28(%rbp),%rdi
call   1070 <FD_ZERO@plt>
mov    -0x24(%rbp),%edi
lea    -0x28(%rbp),%rsi
call   10e0 <FD_SET@plt>
mov    $0x0,%al
call   1050 <_rpc_dtablesize@plt>
mov    %eax,%edi
mov    -0x20(%rbp),%r8
lea    -0x28(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rdx
call   1080 <select@plt>
mov    %eax,-0x2c(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x2c(%rbp)
mov    %al,-0x51(%rbp)
jge    1335 <rtime+0x165>
mov    0x2c9e(%rip),%rax
mov    (%rax),%rax
mov    0x2c84(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x51(%rbp)
mov    -0x51(%rbp),%al
test   $0x1,%al
jne    12d7 <rtime+0x107>
cmpl   $0x0,-0x2c(%rbp)
jg     137c <rtime+0x1ac>
cmpl   $0x0,-0x2c(%rbp)
jne    1368 <rtime+0x198>
mov    0x2c5d(%rip),%rax
mov    (%rax),%rcx
mov    0x2c5b(%rip),%rax
mov    %rcx,(%rax)
mov    -0x24(%rbp),%edi
call   10b0 <do_close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    153b <rtime+0x36b>
movl   $0x8,-0x44(%rbp)
mov    -0x24(%rbp),%edi
lea    -0x38(%rbp),%rsi
lea    -0x40(%rbp),%r8
mov    $0x8,%edx
xor    %ecx,%ecx
lea    -0x44(%rbp),%r9
call   1090 <recvfrom@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x24(%rbp),%edi
call   10b0 <do_close@plt>
cmpl   $0x0,-0x2c(%rbp)
jge    13bf <rtime+0x1ef>
movl   $0xffffffff,-0x4(%rbp)
jmp    153b <rtime+0x36b>
jmp    142a <rtime+0x25a>
mov    -0x24(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x8,%edx
call   10c0 <connect@plt>
cmp    $0x0,%rax
jge    13f3 <rtime+0x223>
mov    -0x24(%rbp),%edi
call   10b0 <do_close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    153b <rtime+0x36b>
mov    -0x24(%rbp),%edi
lea    -0x38(%rbp),%rsi
mov    $0x8,%edx
call   1030 <_RPC_read@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x24(%rbp),%edi
call   10b0 <do_close@plt>
cmpl   $0x0,-0x2c(%rbp)
jge    1425 <rtime+0x255>
movl   $0xffffffff,-0x4(%rbp)
jmp    153b <rtime+0x36b>
jmp    142a <rtime+0x25a>
movslq -0x2c(%rbp),%rax
cmp    $0x8,%rax
je     1458 <rtime+0x288>
mov    0x2b91(%rip),%rax
mov    (%rax),%rcx
mov    0x2b77(%rip),%rax
mov    %rcx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    153b <rtime+0x36b>
mov    -0x38(%rbp),%rdi
call   10d0 <ntohl@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    $0x3c,%edi
call   10a0 <UINT32_C@plt>
mov    %eax,-0x7c(%rbp)
mov    $0x3c,%edi
call   10a0 <UINT32_C@plt>
mov    %eax,%ecx
mov    -0x7c(%rbp),%eax
imul   %ecx,%eax
mov    %eax,-0x78(%rbp)
mov    $0x18,%edi
call   10a0 <UINT32_C@plt>
mov    %eax,%ecx
mov    -0x78(%rbp),%eax
imul   %ecx,%eax
mov    %eax,-0x58(%rbp)
mov    $0x16d,%edi
call   10a0 <UINT32_C@plt>
mov    %eax,-0x70(%rbp)
mov    $0x7b2,%edi
call   10a0 <UINT32_C@plt>
mov    %eax,-0x74(%rbp)
mov    $0x76c,%edi
call   10a0 <UINT32_C@plt>
mov    -0x74(%rbp),%ecx
mov    %eax,%edx
mov    -0x70(%rbp),%eax
sub    %edx,%ecx
imul   %ecx,%eax
mov    %eax,-0x5c(%rbp)
mov    $0x7b2,%edi
call   10a0 <UINT32_C@plt>
mov    %eax,-0x6c(%rbp)
mov    $0x76c,%edi
call   10a0 <UINT32_C@plt>
mov    %eax,%ecx
mov    -0x6c(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x60(%rbp)
mov    $0x4,%edi
call   10a0 <UINT32_C@plt>
mov    -0x68(%rbp),%rcx
mov    %eax,%esi
mov    -0x60(%rbp),%eax
cltd
idiv   %esi
mov    -0x5c(%rbp),%edx
mov    %eax,%esi
mov    -0x58(%rbp),%eax
add    %esi,%edx
imul   %edx,%eax
cltq
sub    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rtime>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdx,%rbp
mov    %rsi,0x10(%rsp)
mov    %rdi,%r12
test   %rdx,%rdx
jne    11f7 <rtime+0x27>
mov    0x2dd3(%rip),%rax
jmp    11fe <rtime+0x2e>
mov    0x2de2(%rip),%rax
mov    (%rax),%ebx
mov    0x2de1(%rip),%r14
mov    (%r14),%edi
mov    %ebx,%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    $0xffffffff,%r15d
test   %eax,%eax
js     1424 <rtime+0x254>
mov    %eax,%r13d
mov    (%r14),%eax
mov    %eax,0x4(%r12)
lea    0xdcd(%rip),%rdi
lea    0xdcb(%rip),%rsi
call   1040 <getservbyname@plt>
test   %rax,%rax
je     1424 <rtime+0x254>
mov    (%rax),%eax
mov    %eax,(%r12)
mov    0x2d8b(%rip),%rax
cmp    (%rax),%ebx
jne    1306 <rtime+0x136>
mov    %rsp,%rsi
mov    %r13d,%edi
mov    $0x8,%edx
xor    %ecx,%ecx
mov    %r12,%r8
mov    $0x8,%r9d
call   1060 <sendto@plt>
test   %eax,%eax
js     141c <rtime+0x24c>
lea    0x1c(%rsp),%rbx
mov    0x2d34(%rip),%r12
mov    0x2d1d(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
call   1070 <FD_ZERO@plt>
mov    %r13d,%edi
mov    %rbx,%rsi
call   10e0 <FD_SET@plt>
xor    %eax,%eax
call   1050 <_rpc_dtablesize@plt>
mov    %eax,%edi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %rbp,%r8
call   1080 <select@plt>
test   %eax,%eax
jns    12d8 <rtime+0x108>
mov    (%r14),%rcx
cmp    %rcx,(%r12)
je     12a0 <rtime+0xd0>
test   %eax,%eax
jle    140c <rtime+0x23c>
movl   $0x8,0xc(%rsp)
mov    %rsp,%rsi
lea    0x20(%rsp),%r8
lea    0xc(%rsp),%r9
mov    %r13d,%edi
mov    $0x8,%edx
xor    %ecx,%ecx
call   1090 <recvfrom@plt>
jmp    132f <rtime+0x15f>
mov    %r13d,%edi
mov    %r12,%rsi
mov    $0x8,%edx
call   10c0 <connect@plt>
test   %rax,%rax
js     141c <rtime+0x24c>
mov    %rsp,%rsi
mov    %r13d,%edi
mov    $0x8,%edx
call   1030 <_RPC_read@plt>
mov    %eax,%ebx
mov    %r13d,%edi
call   10b0 <do_close@plt>
test   %ebx,%ebx
js     1424 <rtime+0x254>
cmp    $0x8,%ebx
jne    13f6 <rtime+0x226>
mov    (%rsp),%rdi
call   10d0 <ntohl@plt>
mov    %rax,%r15
mov    %rax,(%rsp)
mov    $0x3c,%edi
call   10a0 <UINT32_C@plt>
mov    %eax,%ebx
mov    $0x3c,%edi
call   10a0 <UINT32_C@plt>
mov    %eax,%ebp
imul   %ebx,%ebp
mov    $0x18,%edi
call   10a0 <UINT32_C@plt>
mov    %eax,%r12d
imul   %ebp,%r12d
mov    $0x16d,%edi
call   10a0 <UINT32_C@plt>
mov    %eax,%ebp
mov    $0x7b2,%edi
call   10a0 <UINT32_C@plt>
mov    %eax,%ebx
mov    $0x76c,%edi
call   10a0 <UINT32_C@plt>
sub    %eax,%ebx
imul   %ebp,%ebx
mov    $0x7b2,%edi
call   10a0 <UINT32_C@plt>
mov    %eax,%ebp
mov    $0x76c,%edi
call   10a0 <UINT32_C@plt>
sub    %eax,%ebp
mov    $0x4,%edi
call   10a0 <UINT32_C@plt>
mov    %eax,%ecx
mov    %ebp,%eax
cltd
idiv   %ecx
add    %ebx,%eax
imul   %r12d,%eax
cltq
sub    %rax,%r15
mov    0x10(%rsp),%rax
mov    %r15,0x8(%rax)
movq   $0x0,(%rax)
xor    %r15d,%r15d
jmp    1424 <rtime+0x254>
mov    0x2bd3(%rip),%rax
mov    (%rax),%rax
mov    0x2bb9(%rip),%rcx
mov    %rax,(%rcx)
jmp    1424 <rtime+0x254>
jne    141c <rtime+0x24c>
mov    0x2ba3(%rip),%rax
mov    (%rax),%rax
mov    %rax,(%r12)
mov    %r13d,%edi
call   10b0 <do_close@plt>
mov    %r15d,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32 }
%struct.timeval = type { i64, i64 }
%struct.servent = type { i32 }
%struct.sockaddr = type { i32 }
@SOCK_STREAM = global i32 0
@SOCK_DGRAM = global i32 0
@AF_INET = global i32 0
@.str = [5 x i8] c"time\00"
@.str.1 = [4 x i8] c"tcp\00"
@errno = global i64 0
@EINTR = global i64 0
@ETIMEDOUT = global i64 0
@EIO = global i64 0
define i32 @rtime(%struct.sockaddr_in* %0, %struct.timeval* nocapture writeonly %1, %struct.timeval* %2) {
%4 = alloca i32
%5 = alloca i64
%6 = alloca %struct.sockaddr_in
%7 = alloca i32
%8 = bitcast i32* %4 to i8*
%9 = bitcast i64* %5 to i8*
%10 = bitcast %struct.sockaddr_in* %6 to i8*
%11 = bitcast i32* %7 to i8*
%12 = icmp eq %struct.timeval* %2, null
%13 = load i32, i32* @SOCK_STREAM
%14 = load i32, i32* @SOCK_DGRAM
%15 = select i1 %12, i32 %13, i32 %14
%16 = load i32, i32* @AF_INET
%17 = tail call i32 @socket(i32 %16, i32 %15, i32 0)
%18 = icmp slt i32 %17, 0
br i1 %18, label %97, label %19
19: ; preds = %3
%20 = load i32, i32* @AF_INET
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %0, i64 0, i32 1
store i32 %20, i32* %21
%22 = tail call %struct.servent* @getservbyname(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%23 = icmp eq %struct.servent* %22, null
br i1 %23, label %97, label %24
24: ; preds = %19
%25 = getelementptr inbounds %struct.servent, %struct.servent* %22, i64 0, i32 0
%26 = load i32, i32* %25
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %0, i64 0, i32 0
store i32 %26, i32* %27
%28 = load i32, i32* @SOCK_DGRAM
%29 = icmp eq i32 %15, %28
%30 = bitcast %struct.sockaddr_in* %0 to %struct.sockaddr*
br i1 %29, label %31, label %59
31: ; preds = %24
%32 = call i32 @sendto(i32 %17, i8* %9, i32 8, i32 0, %struct.sockaddr* %30, i32 8)
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %31
%35 = call i32 @do_close(i32 %17)
br label %97
36: ; preds = %31, %36
%37 = call i32 @FD_ZERO(i32* %4)
%38 = call i32 @FD_SET(i32 %17, i32* %4)
%39 = call i32 (...) @_rpc_dtablesize()
%40 = call i32 @select(i32 %39, i32* %4, i32* null, i32* null, %struct.timeval* %2)
%41 = icmp slt i32 %40, 0
%42 = load i64, i64* @errno
%43 = load i64, i64* @EINTR
%44 = icmp eq i64 %42, %43
%45 = select i1 %41, i1 %44, i1 false
br i1 %45, label %36, label %46
46: ; preds = %36
%47 = icmp slt i32 %40, 1
br i1 %47, label %48, label %54
48: ; preds = %46
%49 = icmp eq i32 %40, 0
br i1 %49, label %50, label %52
50: ; preds = %48
%51 = load i64, i64* @ETIMEDOUT
store i64 %51, i64* @errno
br label %52
52: ; preds = %50, %48
%53 = call i32 @do_close(i32 %17)
br label %97
54: ; preds = %46
store i32 8, i32* %7
%55 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%56 = call i32 @recvfrom(i32 %17, i8* %9, i32 8, i32 0, %struct.sockaddr* %55, i32* %7)
%57 = call i32 @do_close(i32 %17)
%58 = icmp slt i32 %56, 0
br i1 %58, label %97, label %68
59: ; preds = %24
%60 = tail call i64 @connect(i32 %17, %struct.sockaddr* %30, i32 8)
%61 = icmp slt i64 %60, 0
br i1 %61, label %62, label %64
62: ; preds = %59
%63 = tail call i32 @do_close(i32 %17)
br label %97
64: ; preds = %59
%65 = call i32 @_RPC_read(i32 %17, i8* %9, i32 8)
%66 = call i32 @do_close(i32 %17)
%67 = icmp slt i32 %65, 0
br i1 %67, label %97, label %68
68: ; preds = %64, %54
%69 = phi i32 [ %56, %54 ], [ %65, %64 ]
%70 = icmp eq i32 %69, 8
br i1 %70, label %73, label %71
71: ; preds = %68
%72 = load i64, i64* @EIO
store i64 %72, i64* @errno
br label %97
73: ; preds = %68
%74 = load i64, i64* %5
%75 = call i64 @ntohl(i64 %74)
store i64 %75, i64* %5
%76 = call i32 @UINT32_C(i32 60)
%77 = call i32 @UINT32_C(i32 60)
%78 = mul nsw i32 %77, %76
%79 = call i32 @UINT32_C(i32 24)
%80 = mul nsw i32 %78, %79
%81 = call i32 @UINT32_C(i32 365)
%82 = call i32 @UINT32_C(i32 1970)
%83 = call i32 @UINT32_C(i32 1900)
%84 = sub nsw i32 %82, %83
%85 = mul nsw i32 %84, %81
%86 = call i32 @UINT32_C(i32 1970)
%87 = call i32 @UINT32_C(i32 1900)
%88 = sub nsw i32 %86, %87
%89 = call i32 @UINT32_C(i32 4)
%90 = sdiv i32 %88, %89
%91 = add nsw i32 %90, %85
%92 = mul nsw i32 %80, %91
%93 = sext i32 %92 to i64
%94 = sub nsw i64 %75, %93
%95 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
store i64 %94, i64* %95
%96 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
store i64 0, i64* %96
br label %97
97: ; preds = %64, %54, %19, %3, %73, %71, %62, %52, %34
%98 = phi i32 [ -1, %34 ], [ -1, %52 ], [ -1, %71 ], [ 0, %73 ], [ -1, %62 ], [ -1, %3 ], [ -1, %19 ], [ -1, %54 ], [ -1, %64 ]
ret i32 %98
}