#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*/ ufa;
struct tm {
  int dummy;
};
struct timezone {
  int dummy;
};
struct timeval {
  int /*<<< orphan*/ tv_usec;
  int /*<<< orphan*/ tv_sec;
};
struct TYPE_2__ {
  int s_addr;
};
struct sockaddr_in {
  int sin_port;
  TYPE_1__ sin_addr;
  void *sin_family;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  int /*<<< orphan*/ h_length;
  int /*<<< orphan*/ h_addr;
};
typedef int /*<<< orphan*/ server;
typedef int /*<<< orphan*/ out;
typedef int /*<<< orphan*/ fmt;
typedef int /*<<< orphan*/ client;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
void *AF_INET;
int INADDR_ANY;
int INET_ADDRSTRLEN;
int /*<<< orphan*/ SOCK_DGRAM;
int atoi(char *);
int /*<<< orphan*/ bcopy(int /*<<< orphan*/, TYPE_1__ *, int /*<<< orphan*/);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
scalar_t__ getsockname(int, struct sockaddr *, int *);
scalar_t__ gettimeofday(struct timeval *, struct timezone *);
int htons(int);
int /*<<< orphan*/ inet_ntop(void *, int *, char *, int);
struct tm *localtime(int /*<<< orphan*/ *);
int ntohs(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int *);
int sendto(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, int /*<<< orphan*/);
int socket(void *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sscanf(char *, char *, int *, int *, int *);
int /*<<< orphan*/ strftime(char *, int, char *, struct tm *);
int main(int argc, char *argv[]) {
  if (argc < 3) {
    printf("usage: ./uha <UHA-PORT> <UFA-ADDR> <UFA-PORT>\n", argv[0]);
    return 0;
  }
  int sock, length;
  struct sockaddr_in server, client, ufa;
  struct hostent *hp, *gethostbyname();
  int msgsock;
  char buf[1024];
  char fmt[64], out[64];
  int rval, clilen;
  int i, seqno, reg, fa_port;
  char str[INET_ADDRSTRLEN];
  struct sockaddr_in *addr;
  struct timeval rcvtime;
  struct timezone zone;
  struct tm *tm;
  sock = socket(AF_INET, SOCK_DGRAM, 0);
  if (sock < 0) {
    perror("opening datagram socket");
    exit(1);
  }
  server.sin_family = AF_INET;
  server.sin_addr.s_addr = INADDR_ANY;
  server.sin_port = htons(atoi(argv[1]));
  if (bind(sock, (struct sockaddr *)&server, sizeof(server))) {
    perror("binding socket name");
    exit(1);
  }
  length = sizeof(server);
  if (getsockname(sock, (struct sockaddr *)&server, &length)) {
    perror("getting socket name");
    exit(1);
  }
  printf("Socket has port #%d\n", ntohs(server.sin_port));
  ufa.sin_port = htons(atoi(argv[3]));
  reg = 0;
  do {
    bzero(buf, sizeof(buf));
    clilen = sizeof(client);
    while ((rval = recvfrom(sock, buf, 1024, 0, (struct sockaddr *)&client,
                            &clilen)) < 0) {
      perror("receiver recvfrom");
    }
    sscanf(buf, "%d %d %d", &seqno, &reg, &fa_port);
    if (gettimeofday(&rcvtime, &zone) < 0) {
      perror("getting time");
      exit(1);
    }
    if ((tm = localtime(&rcvtime.tv_sec)) != NULL) {
      strftime(fmt, sizeof(fmt), "%H:%M:%S", tm);
      snprintf(out, sizeof(out), fmt, rcvtime.tv_usec);
    }
    ufa.sin_family = AF_INET;
    hp = gethostbyname(argv[2]);
    if (hp == 0) {
      printf("%s: unknown host\n", argv[2]);
      exit(2);
    }
    bcopy(hp->h_addr, &ufa.sin_addr, hp->h_length);
    addr = (struct sockaddr_in *)&ufa;
    int ipAddr = addr->sin_addr.s_addr;
    inet_ntop(AF_INET, &ipAddr, str, INET_ADDRSTRLEN);
    if (reg == 1) {
      printf("Registration Packet Received. Time = %s Changing care-of-address "
             "= %s/%d\n",
             out, str, fa_port);
      ufa.sin_port = htons(fa_port);
    } else {
      printf("Sequence Number = %2d Time = %s Forwarded to %s:%d\n", seqno, out,
             str, htons(ufa.sin_port));
    }
    if ((rval = sendto(sock, buf, sizeof(buf), 0, (struct sockaddr *)&ufa,
                       sizeof(ufa))) < 0) {
      perror("writing on datagram socket");
    }
  } while (rval != 0);
  close(sock);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x550,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    1294 <main+0x44>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xd7f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1683 <main+0x433>
mov    0x2d2d(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x500(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x538(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x508(%rbp)
mov    0x2d18(%rip),%rax
mov    (%rax),%rdi
mov    0x2cfe(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1170 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1306 <main+0xb6>
lea    0xd38(%rip),%rdi
call   1120 <perror@plt>
mov    $0x1,%edi
call   1160 <exit@plt>
mov    0x2cdb(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    0x2cc5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1150 <atoi@plt>
mov    %eax,%edi
call   1050 <htons@plt>
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x10,%edx
call   1100 <bind@plt>
cmp    $0x0,%rax
je     1368 <main+0x118>
lea    0xcee(%rip),%rdi
call   1120 <perror@plt>
mov    $0x1,%edi
call   1160 <exit@plt>
movl   $0x10,-0x18(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
lea    -0x18(%rbp),%rdx
call   1140 <getsockname@plt>
cmp    $0x0,%rax
je     139f <main+0x14f>
lea    0xccb(%rip),%rdi
call   1120 <perror@plt>
mov    $0x1,%edi
call   1160 <exit@plt>
mov    -0x28(%rbp),%edi
call   10f0 <ntohs@plt>
mov    %eax,%esi
lea    0xcbf(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1150 <atoi@plt>
mov    %eax,%edi
call   1050 <htons@plt>
mov    %eax,-0x48(%rbp)
movl   $0x0,-0x4f4(%rbp)
lea    -0x460(%rbp),%rdi
mov    $0x400,%esi
call   1130 <bzero@plt>
movl   $0x10,-0x4e8(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x460(%rbp),%rsi
lea    -0x38(%rbp),%r8
mov    $0x400,%edx
xor    %ecx,%ecx
lea    -0x4e8(%rbp),%r9
call   10c0 <recvfrom@plt>
mov    %eax,-0x4e4(%rbp)
cmp    $0x0,%eax
jge    1434 <main+0x1e4>
lea    0xc5a(%rip),%rdi
call   1120 <perror@plt>
jmp    13f3 <main+0x1a3>
lea    -0x460(%rbp),%rdi
lea    0xc54(%rip),%rsi
lea    -0x4f0(%rbp),%rdx
lea    -0x4f4(%rbp),%rcx
lea    -0x4f8(%rbp),%r8
call   10d0 <sscanf@plt>
lea    -0x518(%rbp),%rdi
lea    -0x520(%rbp),%rsi
call   1080 <gettimeofday@plt>
cmp    $0x0,%rax
jge    148f <main+0x23f>
lea    0xc1f(%rip),%rdi
call   1120 <perror@plt>
mov    $0x1,%edi
call   1160 <exit@plt>
lea    -0x518(%rbp),%rdi
add    $0x4,%rdi
call   1040 <localtime@plt>
mov    %rax,-0x528(%rbp)
cmp    $0x0,%rax
je     14ed <main+0x29d>
lea    -0x4a0(%rbp),%rdi
mov    -0x528(%rbp),%rcx
mov    $0x40,%esi
lea    0xbe2(%rip),%rdx
call   1110 <strftime@plt>
lea    -0x4e0(%rbp),%rdi
lea    -0x4a0(%rbp),%rdx
mov    -0x518(%rbp),%ecx
mov    $0x40,%esi
call   1070 <snprintf@plt>
mov    0x2af4(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    $0x0,%al
call   10b0 <gethostbyname@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
jne    1539 <main+0x2e9>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xb8d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x2,%edi
call   1160 <exit@plt>
mov    -0x50(%rbp),%rax
mov    0x4(%rax),%edi
lea    -0x48(%rbp),%rsi
add    $0x4,%rsi
mov    -0x50(%rbp),%rax
mov    (%rax),%edx
call   10e0 <bcopy@plt>
mov    -0x538(%rbp),%rdx
lea    -0x48(%rbp),%rax
mov    %rax,-0x510(%rbp)
mov    -0x510(%rbp),%rax
mov    0x4(%rax),%eax
mov    %eax,-0x52c(%rbp)
mov    0x2a6c(%rip),%rax
mov    (%rax),%rdi
mov    0x2a42(%rip),%rax
mov    (%rax),%ecx
lea    -0x52c(%rbp),%rsi
call   1030 <inet_ntop@plt>
cmpl   $0x1,-0x4f4(%rbp)
jne    15d6 <main+0x386>
mov    -0x538(%rbp),%rdx
lea    -0x4e0(%rbp),%rsi
mov    -0x4f8(%rbp),%ecx
lea    0xb0b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x4f8(%rbp),%edi
call   1050 <htons@plt>
mov    %eax,-0x48(%rbp)
jmp    161d <main+0x3cd>
mov    -0x4f0(%rbp),%eax
mov    %eax,-0x544(%rbp)
lea    -0x4e0(%rbp),%rax
mov    %rax,-0x540(%rbp)
mov    -0x48(%rbp),%edi
call   1050 <htons@plt>
mov    -0x544(%rbp),%esi
mov    -0x540(%rbp),%rdx
mov    -0x538(%rbp),%rcx
mov    %eax,%r8d
lea    0xafb(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x14(%rbp),%edi
lea    -0x460(%rbp),%rsi
lea    -0x48(%rbp),%r8
mov    $0x400,%edx
xor    %ecx,%ecx
mov    $0x10,%r9d
call   1090 <sendto@plt>
mov    %eax,-0x4e4(%rbp)
cmp    $0x0,%eax
jge    1658 <main+0x408>
lea    0xaf2(%rip),%rdi
call   1120 <perror@plt>
jmp    165d <main+0x40d>
cmpl   $0x0,-0x4e4(%rbp)
jne    13d8 <main+0x188>
mov    -0x14(%rbp),%edi
call   10a0 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x500(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x4f8,%rsp
mov    %rsi,-0x40(%rbp)
cmp    $0x2,%edi
jg     128e <main+0x2e>
lea    0xead(%rip),%rdi
call   1050 <puts@plt>
jmp    1546 <main+0x2e6>
mov    %rsp,%r12
mov    0x2d30(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r15
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
mov    0x2d36(%rip),%r13
mov    0x0(%r13),%rdi
mov    0x2d1b(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1180 <socket@plt>
test   %eax,%eax
js     158d <main+0x32d>
mov    %eax,%r14d
mov    0x0(%r13),%rax
mov    %rax,-0x70(%rbp)
mov    0x2d00(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x74(%rbp)
mov    -0x40(%rbp),%rax
mov    0x8(%rax),%rdi
call   1160 <atoi@plt>
mov    %eax,%edi
call   1060 <htons@plt>
mov    %eax,-0x78(%rbp)
lea    -0x78(%rbp),%rsi
mov    %r14d,%edi
mov    $0x10,%edx
call   1110 <bind@plt>
test   %rax,%rax
jne    1596 <main+0x336>
mov    %r12,-0x80(%rbp)
movl   $0x10,-0x4c(%rbp)
lea    -0x78(%rbp),%rsi
lea    -0x4c(%rbp),%rdx
mov    %r14d,%edi
call   1150 <getsockname@plt>
test   %rax,%rax
jne    159f <main+0x33f>
mov    -0x78(%rbp),%edi
call   1100 <ntohs@plt>
lea    0xcf7(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    -0x40(%rbp),%rax
mov    0x18(%rax),%rdi
call   1160 <atoi@plt>
mov    %eax,%edi
call   1060 <htons@plt>
mov    %eax,-0x60(%rbp)
movl   $0x0,-0x30(%rbp)
lea    -0x520(%rbp),%r12
lea    -0x98(%rbp),%rbx
jmp    13e6 <main+0x186>
mov    -0x48(%rbp),%ebx
mov    -0x60(%rbp),%edi
call   1060 <htons@plt>
lea    0xd50(%rip),%rdi
mov    %ebx,%esi
lea    -0xe0(%rbp),%rdx
mov    %r15,%rcx
mov    %eax,%r8d
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r14d,%edi
mov    %r12,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
lea    -0x60(%rbp),%r8
mov    $0x10,%r9d
call   10a0 <sendto@plt>
mov    %eax,%r13d
test   %eax,%eax
js     1529 <main+0x2c9>
test   %r13d,%r13d
mov    0x2c0f(%rip),%r13
lea    -0x98(%rbp),%rbx
je     153a <main+0x2da>
mov    %r12,%rdi
mov    $0x400,%esi
call   1140 <bzero@plt>
movl   $0x10,-0x34(%rbp)
mov    %r14d,%edi
mov    %r12,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
mov    %rbx,%r8
lea    -0x34(%rbp),%r9
call   10d0 <recvfrom@plt>
test   %eax,%eax
jns    1430 <main+0x1d0>
lea    0xc37(%rip),%rdi
call   1130 <perror@plt>
jmp    13fa <main+0x19a>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r12,%rdi
lea    0xc2d(%rip),%rsi
lea    -0x48(%rbp),%rdx
lea    -0x30(%rbp),%rcx
lea    -0x2c(%rbp),%r8
call   10e0 <sscanf@plt>
lea    -0x68(%rbp),%rdi
lea    -0x88(%rbp),%rsi
call   1090 <gettimeofday@plt>
test   %rax,%rax
js     1557 <main+0x2f7>
lea    -0x64(%rbp),%rdi
call   1040 <localtime@plt>
test   %rax,%rax
je     14a7 <main+0x247>
lea    -0x120(%rbp),%rbx
mov    %rbx,%rdi
mov    $0x40,%esi
lea    0xbf5(%rip),%rdx
mov    %rax,%rcx
call   1120 <strftime@plt>
mov    -0x68(%rbp),%ecx
lea    -0xe0(%rbp),%rdi
mov    $0x40,%esi
mov    %rbx,%rdx
call   1080 <snprintf@plt>
mov    0x0(%r13),%rax
mov    %rax,-0x58(%rbp)
mov    -0x40(%rbp),%rax
mov    0x10(%rax),%rdi
xor    %eax,%eax
call   10c0 <gethostbyname@plt>
test   %rax,%rax
je     156d <main+0x30d>
mov    (%rax),%edx
mov    0x4(%rax),%edi
lea    -0x5c(%rbp),%rsi
call   10f0 <bcopy@plt>
mov    -0x5c(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    0x0(%r13),%rdi
mov    0x2ae2(%rip),%rax
mov    (%rax),%ecx
lea    -0x44(%rbp),%rsi
mov    %r15,%rdx
call   1030 <inet_ntop@plt>
cmpl   $0x1,-0x30(%rbp)
jne    1380 <main+0x120>
mov    -0x2c(%rbp),%ecx
lea    0xb90(%rip),%rdi
lea    -0xe0(%rbp),%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1070 <printf@plt>
mov    -0x2c(%rbp),%edi
call   1060 <htons@plt>
mov    %eax,-0x60(%rbp)
jmp    13a8 <main+0x148>
lea    0xbe6(%rip),%rdi
call   1130 <perror@plt>
jmp    13cf <main+0x16f>
mov    %r14d,%edi
call   10b0 <close@plt>
mov    -0x80(%rbp),%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xb12(%rip),%rdi
call   1130 <perror@plt>
mov    $0x1,%edi
call   1170 <exit@plt>
mov    -0x40(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xb0a(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x2,%edi
call   1170 <exit@plt>
lea    0xa6c(%rip),%rdi
jmp    155e <main+0x2fe>
lea    0xa7b(%rip),%rdi
jmp    155e <main+0x2fe>
lea    0xa86(%rip),%rdi
jmp    155e <main+0x2fe>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i8* }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32, i32 }
%struct.timeval = type { i32, i32 }
%struct.timezone = type { i32 }
%struct.tm = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [47 x i8] c"usage: ./uha <UHA-PORT> <UFA-ADDR> <UFA-PORT>\0A\00"
@INET_ADDRSTRLEN = global i32 0
@AF_INET = global i8* null
@SOCK_DGRAM = global i32 0
@.str.1 = [24 x i8] c"opening datagram socket\00"
@INADDR_ANY = global i32 0
@.str.2 = [20 x i8] c"binding socket name\00"
@.str.3 = [20 x i8] c"getting socket name\00"
@.str.4 = [21 x i8] c"Socket has port #%d\0A\00"
@.str.5 = [18 x i8] c"receiver recvfrom\00"
@.str.6 = [9 x i8] c"%d %d %d\00"
@.str.7 = [13 x i8] c"getting time\00"
@.str.8 = [9 x i8] c"%H:%M:%S\00"
@.str.9 = [18 x i8] c"%s: unknown host\0A\00"
@.str.10 = [74 x i8] c"Registration Packet Received. Time = %s Changing care-of-address = %s/%d\0A\00"
@.str.11 = [52 x i8] c"Sequence Number = %2d Time = %s Forwarded to %s:%d\0A\00"
@.str.12 = [27 x i8] c"writing on datagram socket\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.sockaddr_in
%9 = alloca %struct.sockaddr_in
%10 = alloca %struct.sockaddr_in
%11 = alloca %struct.hostent*
%12 = alloca i32
%13 = alloca [1024 x i8]
%14 = alloca [64 x i8]
%15 = alloca [64 x i8]
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
%22 = alloca i8*
%23 = alloca i64
%24 = alloca %struct.sockaddr_in*
%25 = alloca %struct.timeval
%26 = alloca %struct.timezone
%27 = alloca %struct.tm*
%28 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%29 = load i32, i32* %4
%30 = icmp slt i32 %29, 3
br i1 %30, label %31, label %36
31: ; preds = %2
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 0
%34 = load i8*, i8** %33
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i8* %34)
store i32 0, i32* %3
br label %182
36: ; preds = %2
%37 = load i32, i32* @INET_ADDRSTRLEN
%38 = zext i32 %37 to i64
%39 = call i8* @llvm.stacksave()
store i8* %39, i8** %22
%40 = alloca i8, i64 %38
store i64 %38, i64* %23
%41 = load i8*, i8** @AF_INET
%42 = load i32, i32* @SOCK_DGRAM
%43 = call i32 @socket(i8* %41, i32 %42, i32 0)
store i32 %43, i32* %6
%44 = load i32, i32* %6
%45 = icmp slt i32 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %36
%47 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%48 = call i32 @exit(i32 1)
unreachable
49: ; preds = %36
%50 = load i8*, i8** @AF_INET
%51 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i8* %50, i8** %51
%52 = load i32, i32* @INADDR_ANY
%53 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
%54 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %53, i32 0, i32 0
store i32 %52, i32* %54
%55 = load i8**, i8*** %5
%56 = getelementptr inbounds i8*, i8** %55, i64 1
%57 = load i8*, i8** %56
%58 = call i32 @atoi(i8* %57)
%59 = call i32 @htons(i32 %58)
%60 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
store i32 %59, i32* %60
%61 = load i32, i32* %6
%62 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%63 = call i64 @bind(i32 %61, %struct.sockaddr* %62, i32 16)
%64 = icmp ne i64 %63, 0
br i1 %64, label %65, label %68
65: ; preds = %49
%66 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%67 = call i32 @exit(i32 1)
unreachable
68: ; preds = %49
store i32 16, i32* %7
%69 = load i32, i32* %6
%70 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%71 = call i64 @getsockname(i32 %69, %struct.sockaddr* %70, i32* %7)
%72 = icmp ne i64 %71, 0
br i1 %72, label %73, label %76
73: ; preds = %68
%74 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%75 = call i32 @exit(i32 1)
unreachable
76: ; preds = %68
%77 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
%78 = load i32, i32* %77
%79 = call i32 @ntohs(i32 %78)
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i32 %79)
%81 = load i8**, i8*** %5
%82 = getelementptr inbounds i8*, i8** %81, i64 3
%83 = load i8*, i8** %82
%84 = call i32 @atoi(i8* %83)
%85 = call i32 @htons(i32 %84)
%86 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
store i32 %85, i32* %86
store i32 0, i32* %20
br label %87
87: ; preds = %175, %76
%88 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 0
%89 = call i32 @bzero(i8* %88, i32 1024)
store i32 16, i32* %17
br label %90
90: ; preds = %96, %87
%91 = load i32, i32* %6
%92 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 0
%93 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%94 = call i32 @recvfrom(i32 %91, i8* %92, i32 1024, i32 0, %struct.sockaddr* %93, i32* %17)
store i32 %94, i32* %16
%95 = icmp slt i32 %94, 0
br i1 %95, label %96, label %98
96: ; preds = %90
%97 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
br label %90
98: ; preds = %90
%99 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 0
%100 = call i32 @sscanf(i8* %99, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i32* %19, i32* %20, i32* %21)
%101 = call i64 @gettimeofday(%struct.timeval* %25, %struct.timezone* %26)
%102 = icmp slt i64 %101, 0
br i1 %102, label %103, label %106
103: ; preds = %98
%104 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0))
%105 = call i32 @exit(i32 1)
unreachable
106: ; preds = %98
%107 = getelementptr inbounds %struct.timeval, %struct.timeval* %25, i32 0, i32 1
%108 = call %struct.tm* @localtime(i32* %107)
store %struct.tm* %108, %struct.tm** %27
%109 = icmp ne %struct.tm* %108, null
br i1 %109, label %110, label %119
110: ; preds = %106
%111 = getelementptr inbounds [64 x i8], [64 x i8]* %14, i64 0, i64 0
%112 = load %struct.tm*, %struct.tm** %27
%113 = call i32 @strftime(i8* %111, i32 64, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0), %struct.tm* %112)
%114 = getelementptr inbounds [64 x i8], [64 x i8]* %15, i64 0, i64 0
%115 = getelementptr inbounds [64 x i8], [64 x i8]* %14, i64 0, i64 0
%116 = getelementptr inbounds %struct.timeval, %struct.timeval* %25, i32 0, i32 0
%117 = load i32, i32* %116
%118 = call i32 @snprintf(i8* %114, i32 64, i8* %115, i32 %117)
br label %119
119: ; preds = %110, %106
%120 = load i8*, i8** @AF_INET
%121 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 2
store i8* %120, i8** %121
%122 = load i8**, i8*** %5
%123 = getelementptr inbounds i8*, i8** %122, i64 2
%124 = load i8*, i8** %123
%125 = call %struct.hostent* (i8*, ...) bitcast (%struct.hostent* (...)* @gethostbyname to %struct.hostent* (i8*, ...)*)(i8* %124)
store %struct.hostent* %125, %struct.hostent** %11
%126 = load %struct.hostent*, %struct.hostent** %11
%127 = icmp eq %struct.hostent* %126, null
br i1 %127, label %128, label %134
128: ; preds = %119
%129 = load i8**, i8*** %5
%130 = getelementptr inbounds i8*, i8** %129, i64 2
%131 = load i8*, i8** %130
%132 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.9, i64 0, i64 0), i8* %131)
%133 = call i32 @exit(i32 2)
unreachable
134: ; preds = %119
%135 = load %struct.hostent*, %struct.hostent** %11
%136 = getelementptr inbounds %struct.hostent, %struct.hostent* %135, i32 0, i32 1
%137 = load i32, i32* %136
%138 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 1
%139 = load %struct.hostent*, %struct.hostent** %11
%140 = getelementptr inbounds %struct.hostent, %struct.hostent* %139, i32 0, i32 0
%141 = load i32, i32* %140
%142 = call i32 @bcopy(i32 %137, %struct.TYPE_2__* %138, i32 %141)
store %struct.sockaddr_in* %10, %struct.sockaddr_in** %24
%143 = load %struct.sockaddr_in*, %struct.sockaddr_in** %24
%144 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %143, i32 0, i32 1
%145 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %144, i32 0, i32 0
%146 = load i32, i32* %145
store i32 %146, i32* %28
%147 = load i8*, i8** @AF_INET
%148 = load i32, i32* @INET_ADDRSTRLEN
%149 = call i32 @inet_ntop(i8* %147, i32* %28, i8* %40, i32 %148)
%150 = load i32, i32* %20
%151 = icmp eq i32 %150, 1
br i1 %151, label %152, label %159
152: ; preds = %134
%153 = getelementptr inbounds [64 x i8], [64 x i8]* %15, i64 0, i64 0
%154 = load i32, i32* %21
%155 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.10, i64 0, i64 0), i8* %153, i8* %40, i32 %154)
%156 = load i32, i32* %21
%157 = call i32 @htons(i32 %156)
%158 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
store i32 %157, i32* %158
br label %166
159: ; preds = %134
%160 = load i32, i32* %19
%161 = getelementptr inbounds [64 x i8], [64 x i8]* %15, i64 0, i64 0
%162 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
%163 = load i32, i32* %162
%164 = call i32 @htons(i32 %163)
%165 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.11, i64 0, i64 0), i32 %160, i8* %161, i8* %40, i32 %164)
br label %166
166: ; preds = %159, %152
%167 = load i32, i32* %6
%168 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 0
%169 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%170 = call i32 @sendto(i32 %167, i8* %168, i32 1024, i32 0, %struct.sockaddr* %169, i32 16)
store i32 %170, i32* %16
%171 = icmp slt i32 %170, 0
br i1 %171, label %172, label %174
172: ; preds = %166
%173 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.12, i64 0, i64 0))
br label %174
174: ; preds = %172, %166
br label %175
175: ; preds = %174
%176 = load i32, i32* %16
%177 = icmp ne i32 %176, 0
br i1 %177, label %87, label %178
178: ; preds = %175
%179 = load i32, i32* %6
%180 = call i32 @close(i32 %179)
store i32 0, i32* %3
%181 = load i8*, i8** %22
br label %182
182: ; preds = %178, %31
%183 = load i32, i32* %3
ret i32 %183
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i8* }
%struct.TYPE_2__ = type { i32 }
%struct.timeval = type { i32, i32 }
%struct.timezone = type { i32 }
%struct.sockaddr = type { i32 }
%struct.tm = type { i32 }
%struct.hostent = type { i32, i32 }
@INET_ADDRSTRLEN = global i32 0
@AF_INET = global i8* null
@SOCK_DGRAM = global i32 0
@.str.1 = [24 x i8] c"opening datagram socket\00"
@INADDR_ANY = global i32 0
@.str.2 = [20 x i8] c"binding socket name\00"
@.str.3 = [20 x i8] c"getting socket name\00"
@.str.4 = [21 x i8] c"Socket has port #%d\0A\00"
@.str.5 = [18 x i8] c"receiver recvfrom\00"
@.str.6 = [9 x i8] c"%d %d %d\00"
@.str.7 = [13 x i8] c"getting time\00"
@.str.8 = [9 x i8] c"%H:%M:%S\00"
@.str.9 = [18 x i8] c"%s: unknown host\0A\00"
@.str.10 = [74 x i8] c"Registration Packet Received. Time = %s Changing care-of-address = %s/%d\0A\00"
@.str.11 = [52 x i8] c"Sequence Number = %2d Time = %s Forwarded to %s:%d\0A\00"
@.str.12 = [27 x i8] c"writing on datagram socket\00"
@str = [46 x i8] c"usage: ./uha <UHA-PORT> <UFA-ADDR> <UFA-PORT>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = alloca %struct.sockaddr_in
%6 = alloca %struct.sockaddr_in
%7 = alloca [1024 x i8]
%8 = alloca [64 x i8]
%9 = alloca [64 x i8]
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca %struct.timeval
%15 = alloca %struct.timezone
%16 = alloca i32
%17 = icmp slt i32 %0, 3
br i1 %17, label %18, label %20
18: ; preds = %2
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str, i64 0, i64 0))
br label %147
20: ; preds = %2
%21 = bitcast i32* %3 to i8*
%22 = bitcast %struct.sockaddr_in* %4 to i8*
%23 = bitcast %struct.sockaddr_in* %5 to i8*
%24 = bitcast %struct.sockaddr_in* %6 to i8*
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%26 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%27 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%28 = bitcast i32* %10 to i8*
%29 = bitcast i32* %11 to i8*
%30 = bitcast i32* %12 to i8*
%31 = bitcast i32* %13 to i8*
%32 = load i32, i32* @INET_ADDRSTRLEN
%33 = zext i32 %32 to i64
%34 = tail call i8* @llvm.stacksave()
%35 = alloca i8, i64 %33
%36 = bitcast %struct.timeval* %14 to i8*
%37 = bitcast %struct.timezone* %15 to i8*
%38 = load i8*, i8** @AF_INET
%39 = load i32, i32* @SOCK_DGRAM
%40 = tail call i32 @socket(i8* %38, i32 %39, i32 0)
%41 = icmp slt i32 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %20
%43 = tail call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%44 = tail call i32 @exit(i32 1)
unreachable
45: ; preds = %20
%46 = load i8*, i8** @AF_INET
%47 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i8* %46, i8** %47
%48 = load i32, i32* @INADDR_ANY
%49 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1, i32 0
store i32 %48, i32* %49
%50 = getelementptr inbounds i8*, i8** %1, i64 1
%51 = load i8*, i8** %50
%52 = tail call i32 @atoi(i8* %51)
%53 = tail call i32 @htons(i32 %52)
%54 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
store i32 %53, i32* %54
%55 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%56 = call i64 @bind(i32 %40, %struct.sockaddr* %55, i32 16)
%57 = icmp eq i64 %56, 0
br i1 %57, label %61, label %58
58: ; preds = %45
%59 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%60 = call i32 @exit(i32 1)
unreachable
61: ; preds = %45
store i32 16, i32* %3
%62 = call i64 @getsockname(i32 %40, %struct.sockaddr* %55, i32* %3)
%63 = icmp eq i64 %62, 0
br i1 %63, label %67, label %64
64: ; preds = %61
%65 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%66 = call i32 @exit(i32 1)
unreachable
67: ; preds = %61
%68 = load i32, i32* %54
%69 = call i32 @ntohs(i32 %68)
%70 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i32 %69)
%71 = getelementptr inbounds i8*, i8** %1, i64 3
%72 = load i8*, i8** %71
%73 = call i32 @atoi(i8* %72)
%74 = call i32 @htons(i32 %73)
%75 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 0
store i32 %74, i32* %75
store i32 0, i32* %12
%76 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%77 = getelementptr inbounds %struct.timeval, %struct.timeval* %14, i64 0, i32 1
%78 = getelementptr inbounds %struct.timeval, %struct.timeval* %14, i64 0, i32 0
%79 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 2
%80 = getelementptr inbounds i8*, i8** %1, i64 2
%81 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 1
%82 = bitcast i32* %16 to i8*
%83 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %81, i64 0, i32 0
%84 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
br label %85
85: ; preds = %143, %67
%86 = call i32 @bzero(i8* %25, i32 1024)
store i32 16, i32* %10
%87 = call i32 @recvfrom(i32 %40, i8* %25, i32 1024, i32 0, %struct.sockaddr* %76, i32* %10)
%88 = icmp slt i32 %87, 0
br i1 %88, label %89, label %93
89: ; preds = %85, %89
%90 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
%91 = call i32 @recvfrom(i32 %40, i8* %25, i32 1024, i32 0, %struct.sockaddr* %76, i32* %10)
%92 = icmp slt i32 %91, 0
br i1 %92, label %89, label %93
93: ; preds = %89, %85
%94 = call i32 @sscanf(i8* %25, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i32* %11, i32* %12, i32* %13)
%95 = call i64 @gettimeofday(%struct.timeval* %14, %struct.timezone* %15)
%96 = icmp slt i64 %95, 0
br i1 %96, label %97, label %100
97: ; preds = %93
%98 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0))
%99 = call i32 @exit(i32 1)
unreachable
100: ; preds = %93
%101 = call %struct.tm* @localtime(i32* %77)
%102 = icmp eq %struct.tm* %101, null
br i1 %102, label %107, label %103
103: ; preds = %100
%104 = call i32 @strftime(i8* %26, i32 64, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0), %struct.tm* %101)
%105 = load i32, i32* %78
%106 = call i32 @snprintf(i8* %27, i32 64, i8* %26, i32 %105)
br label %107
107: ; preds = %103, %100
%108 = load i8*, i8** @AF_INET
store i8* %108, i8** %79
%109 = load i8*, i8** %80
%110 = call %struct.hostent* (i8*, ...) bitcast (%struct.hostent* (...)* @gethostbyname to %struct.hostent* (i8*, ...)*)(i8* %109)
%111 = icmp eq %struct.hostent* %110, null
br i1 %111, label %112, label %116
112: ; preds = %107
%113 = load i8*, i8** %80
%114 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.9, i64 0, i64 0), i8* %113)
%115 = call i32 @exit(i32 2)
unreachable
116: ; preds = %107
%117 = getelementptr inbounds %struct.hostent, %struct.hostent* %110, i64 0, i32 1
%118 = load i32, i32* %117
%119 = getelementptr inbounds %struct.hostent, %struct.hostent* %110, i64 0, i32 0
%120 = load i32, i32* %119
%121 = call i32 @bcopy(i32 %118, %struct.TYPE_2__* %81, i32 %120)
%122 = load i32, i32* %83
store i32 %122, i32* %16
%123 = load i8*, i8** @AF_INET
%124 = load i32, i32* @INET_ADDRSTRLEN
%125 = call i32 @inet_ntop(i8* %123, i32* %16, i8* %35, i32 %124)
%126 = load i32, i32* %12
%127 = icmp eq i32 %126, 1
br i1 %127, label %128, label %133
128: ; preds = %116
%129 = load i32, i32* %13
%130 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([74 x i8], [74 x i8]* @.str.10, i64 0, i64 0), i8* %27, i8* %35, i32 %129)
%131 = load i32, i32* %13
%132 = call i32 @htons(i32 %131)
store i32 %132, i32* %75
br label %138
133: ; preds = %116
%134 = load i32, i32* %11
%135 = load i32, i32* %75
%136 = call i32 @htons(i32 %135)
%137 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.11, i64 0, i64 0), i32 %134, i8* %27, i8* %35, i32 %136)
br label %138
138: ; preds = %133, %128
%139 = call i32 @sendto(i32 %40, i8* %25, i32 1024, i32 0, %struct.sockaddr* %84, i32 16)
%140 = icmp slt i32 %139, 0
br i1 %140, label %141, label %143
141: ; preds = %138
%142 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.12, i64 0, i64 0))
br label %143
143: ; preds = %141, %138
%144 = icmp eq i32 %139, 0
br i1 %144, label %145, label %85
145: ; preds = %143
%146 = call i32 @close(i32 %40)
br label %147
147: ; preds = %145, %18
ret i32 0
}