#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 */
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  void *sin_port;
  TYPE_1__ sin_addr;
  void *sin_family;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  int /*<<< orphan*/ h_length;
  scalar_t__ h_addr;
};
typedef int /*<<< orphan*/ serv_addr;

/* Variables and functions */
void *AF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ SOCK_STREAM;
int atoi(char *);
int /*<<< orphan*/ bcopy(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
struct hostent *gethostbyname(char *);
void *htons(int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ readMessage(char *, int);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *,
             unsigned int *);
scalar_t__ sendMessage(char *, int);
int sendto(int, char *, int /*<<< orphan*/, int /*<<< orphan*/,
           struct sockaddr const *, unsigned int);
int socket(void *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
char *strchr(char *, char);
int strcmp(char *, char *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  int isTcp = 1;
  int i = 0;
  if (argc < 3) {
    fprintf(stderr, "usage %s hostname port optional_flags\n", argv[0]);
    exit(0);
  }
  for (i = 3; i < argc; i++) {
    int comp = strcmp(argv[i], "-u");
    if (comp == 0)
      isTcp = 0;
  }
  if (isTcp == 1) {
    int sockfd, portno, n;
    struct sockaddr_in serv_addr;
    struct hostent *server;
    char buffer[256];
    portno = atoi(argv[2]);
    sockfd = socket(AF_INET, SOCK_STREAM, 0);
    if (sockfd < 0) {
      error("ERROR opening socket");
    }
    server = gethostbyname(argv[1]);
    if (server == NULL) {
      fprintf(stderr, "ERROR, no such host\n");
      exit(0);
    }
    bzero((char *)&serv_addr, sizeof(serv_addr));
    serv_addr.sin_family = AF_INET;
    bcopy((char *)server->h_addr, (char *)&serv_addr.sin_addr.s_addr,
          server->h_length);
    serv_addr.sin_port = htons(portno);
    if (connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) {
      error("ERROR connecting");
    }
    if (sendMessage(buffer, sockfd) < 0) {
      error("ERROR writing to socket");
    }
    if (readMessage(buffer, sockfd) < 0) {
      error("ERROR reading from socket");
    }
    printf("%s\n", buffer);
    close(sockfd);
  } else if (isTcp == 0) {
    int sockfd, n;
    unsigned int length;
    struct sockaddr_in server, from;
    struct hostent *hp;
    char buffer[256];
    sockfd = socket(AF_INET, SOCK_DGRAM, 0);
    if (sockfd < 0)
      error("ERROR opening UDP socket");
    server.sin_family = AF_INET;
    hp = gethostbyname(argv[1]);
    if (hp == 0)
      error("Unknown host");
    bcopy((char *)hp->h_addr, (char *)&server.sin_addr, hp->h_length);
    server.sin_port = htons(atoi(argv[2]));
    length = sizeof(struct sockaddr_in);
    printf("Please enter the message: ");
    bzero(buffer, 256);
    fgets(buffer, 255, stdin);
    char *pos;
    if ((pos = strchr(buffer, '\n')) != NULL)
      *pos = '\0';
    else
      error("ERROR removing the newline char from input");
    n = sendto(sockfd, buffer, strlen(buffer), 0,
               (const struct sockaddr *)&server, length);
    if (n < 0)
      error("Sendto");
    printf("\nHere is your message: %s\n", buffer);
    n = recvfrom(sockfd, buffer, 256, 0, (struct sockaddr *)&from, &length);
    if (n < 0)
      error("recvfrom");
    write(1, buffer, n);
    close(sockfd);
  } else {
    error("ERROR could not determine socket type");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2c0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    12a6 <main+0x56>
mov    0x2d40(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xd68(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
xor    %edi,%edi
call   1150 <exit@plt>
movl   $0x3,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12f8 <main+0xa8>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xd5b(%rip),%rsi
call   10b0 <strcmp@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    12e5 <main+0x95>
movl   $0x0,-0x14(%rbp)
jmp    12ea <main+0x9a>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    12ad <main+0x5d>
cmpl   $0x1,-0x14(%rbp)
jne    1455 <main+0x205>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1140 <atoi@plt>
mov    %eax,-0x24(%rbp)
mov    0x2ccf(%rip),%rax
mov    (%rax),%rdi
mov    0x2c9d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1170 <socket@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    1345 <main+0xf5>
lea    0xcea(%rip),%rdi
call   1120 <error@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10c0 <gethostbyname@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    137f <main+0x12f>
mov    0x2c60(%rip),%rax
mov    (%rax),%edi
lea    0xcce(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
xor    %edi,%edi
call   1150 <exit@plt>
lea    -0x40(%rbp),%rdi
mov    $0x18,%esi
call   1130 <bzero@plt>
mov    0x2c54(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x48(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x40(%rbp),%rsi
add    $0x8,%rsi
mov    -0x48(%rbp),%rax
mov    (%rax),%edx
call   1110 <bcopy@plt>
mov    -0x24(%rbp),%edi
call   1050 <htons@plt>
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x18,%edx
call   1160 <connect@plt>
cmp    $0x0,%rax
jge    13e9 <main+0x199>
lea    0xc70(%rip),%rdi
call   1120 <error@plt>
lea    -0x150(%rbp),%rdi
mov    -0x20(%rbp),%esi
call   10f0 <sendMessage@plt>
cmp    $0x0,%rax
jge    140e <main+0x1be>
lea    0xc5c(%rip),%rdi
call   1120 <error@plt>
lea    -0x150(%rbp),%rdi
mov    -0x20(%rbp),%esi
call   10d0 <readMessage@plt>
cmp    $0x0,%rax
jge    1433 <main+0x1e3>
lea    0xc4f(%rip),%rdi
call   1120 <error@plt>
lea    -0x150(%rbp),%rsi
lea    0xce0(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x20(%rbp),%edi
call   1090 <close@plt>
jmp    1692 <main+0x442>
cmpl   $0x0,-0x14(%rbp)
jne    1681 <main+0x431>
mov    0x2b82(%rip),%rax
mov    (%rax),%rdi
mov    0x2b68(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1170 <socket@plt>
mov    %eax,-0x154(%rbp)
cmpl   $0x0,-0x154(%rbp)
jge    1498 <main+0x248>
lea    0xc04(%rip),%rdi
call   1120 <error@plt>
mov    0x2b49(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x168(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10c0 <gethostbyname@plt>
mov    %rax,-0x198(%rbp)
cmpq   $0x0,-0x198(%rbp)
jne    14d7 <main+0x287>
lea    0xbde(%rip),%rdi
call   1120 <error@plt>
mov    -0x198(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x178(%rbp),%rsi
add    $0x8,%rsi
mov    -0x198(%rbp),%rax
mov    (%rax),%edx
call   1110 <bcopy@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1140 <atoi@plt>
mov    %eax,%edi
call   1050 <htons@plt>
mov    %rax,-0x178(%rbp)
movl   $0x18,-0x15c(%rbp)
lea    0xb96(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x2a0(%rbp),%rdi
mov    $0x100,%esi
call   1130 <bzero@plt>
lea    -0x2a0(%rbp),%rdi
mov    0x2a93(%rip),%rax
mov    (%rax),%edx
mov    $0xff,%esi
call   10a0 <fgets@plt>
lea    -0x2a0(%rbp),%rdi
mov    $0xa,%esi
call   1060 <strchr@plt>
mov    %rax,-0x2a8(%rbp)
cmp    $0x0,%rax
je     158a <main+0x33a>
mov    -0x2a8(%rbp),%rax
movb   $0x0,(%rax)
jmp    1596 <main+0x346>
lea    0xb47(%rip),%rdi
call   1120 <error@plt>
mov    -0x154(%rbp),%eax
mov    %eax,-0x2b4(%rbp)
lea    -0x2a0(%rbp),%rax
mov    %rax,-0x2b0(%rbp)
lea    -0x2a0(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x2b4(%rbp),%edi
mov    -0x2b0(%rbp),%rsi
mov    %eax,%edx
lea    -0x178(%rbp),%r8
mov    -0x15c(%rbp),%r9d
xor    %ecx,%ecx
call   1080 <sendto@plt>
mov    %eax,-0x158(%rbp)
cmpl   $0x0,-0x158(%rbp)
jge    15ff <main+0x3af>
lea    0xb09(%rip),%rdi
call   1120 <error@plt>
lea    -0x2a0(%rbp),%rsi
lea    0xafd(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x154(%rbp),%edi
lea    -0x2a0(%rbp),%rsi
lea    -0x190(%rbp),%r8
mov    $0x100,%edx
xor    %ecx,%ecx
lea    -0x15c(%rbp),%r9
call   1100 <recvfrom@plt>
mov    %eax,-0x158(%rbp)
cmpl   $0x0,-0x158(%rbp)
jge    165a <main+0x40a>
lea    0xad0(%rip),%rdi
call   1120 <error@plt>
lea    -0x2a0(%rbp),%rsi
mov    -0x158(%rbp),%edx
mov    $0x1,%edi
call   1030 <write@plt>
mov    -0x154(%rbp),%edi
call   1090 <close@plt>
jmp    168d <main+0x43d>
lea    0xaa6(%rip),%rdi
call   1120 <error@plt>
jmp    1692 <main+0x442>
xor    %eax,%eax
add    $0x2c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x140,%rsp
mov    %rsi,%r15
cmp    $0x3,%edi
jl     1539 <main+0x2d9>
je     12c3 <main+0x63>
mov    %edi,%r12d
mov    $0x1,%ebp
mov    $0x3,%ebx
lea    0xd96(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%r15,%rbx,8),%rdi
mov    %r14,%rsi
call   10c0 <strcmp@plt>
test   %eax,%eax
cmove  %eax,%ebp
add    $0x1,%rbx
cmp    %rbx,%r12
jne    12a0 <main+0x40>
cmp    $0x1,%ebp
jne    13b4 <main+0x154>
mov    0x10(%r15),%rdi
call   1150 <atoi@plt>
mov    %eax,%r14d
mov    0x2d12(%rip),%r12
mov    (%r12),%rdi
mov    0x2cdf(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1180 <socket@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    12fc <main+0x9c>
lea    0xd33(%rip),%rdi
call   1130 <error@plt>
mov    0x8(%r15),%rdi
call   10d0 <gethostbyname@plt>
test   %rax,%rax
je     155a <main+0x2fa>
mov    %rax,%rbx
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    $0x18,%esi
call   1140 <bzero@plt>
mov    (%r12),%rax
mov    %rax,0x20(%rsp)
mov    0x8(%rbx),%rsi
lea    0x18(%rsp),%rdi
mov    (%rbx),%edx
call   1120 <memmove@plt>
mov    %r14d,%edi
call   1060 <htons@plt>
mov    %rax,0x10(%rsp)
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x18,%edx
call   1170 <connect@plt>
test   %rax,%rax
jns    1369 <main+0x109>
lea    0xcf0(%rip),%rdi
call   1130 <error@plt>
lea    0x40(%rsp),%rdi
mov    %ebp,%esi
call   1100 <sendMessage@plt>
test   %rax,%rax
jns    1386 <main+0x126>
lea    0xce4(%rip),%rdi
call   1130 <error@plt>
lea    0x40(%rsp),%rdi
mov    %ebp,%esi
call   10e0 <readMessage@plt>
test   %rax,%rax
jns    13a3 <main+0x143>
lea    0xcdf(%rip),%rdi
call   1130 <error@plt>
lea    0x40(%rsp),%rdi
call   1030 <puts@plt>
mov    %ebp,%edi
jmp    1522 <main+0x2c2>
mov    0x2c2d(%rip),%rbx
mov    (%rbx),%rdi
mov    0x2c13(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1180 <socket@plt>
mov    %eax,%r14d
test   %eax,%eax
jns    13e1 <main+0x181>
lea    0xcbb(%rip),%rdi
call   1130 <error@plt>
mov    (%rbx),%rax
mov    %rax,0x20(%rsp)
mov    0x8(%r15),%rdi
call   10d0 <gethostbyname@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    1406 <main+0x1a6>
lea    0xcaf(%rip),%rdi
call   1130 <error@plt>
mov    0x8(%rbp),%rsi
lea    0x18(%rsp),%rdi
mov    0x0(%rbp),%edx
call   1120 <memmove@plt>
mov    0x10(%r15),%rdi
call   1150 <atoi@plt>
mov    %eax,%edi
call   1060 <htons@plt>
mov    %rax,0x10(%rsp)
movl   $0x18,0xc(%rsp)
lea    0xc82(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0x40(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
call   1140 <bzero@plt>
mov    0x2b85(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0xff,%esi
call   10b0 <fgets@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1070 <strchr@plt>
test   %rax,%rax
je     1485 <main+0x225>
movb   $0x0,(%rax)
mov    0xc(%rsp),%ebx
jmp    1496 <main+0x236>
lea    0xc4c(%rip),%rdi
call   1130 <error@plt>
mov    $0x18,%ebx
lea    0x40(%rsp),%rbp
mov    %rbp,%rdi
call   1050 <strlen@plt>
lea    0x10(%rsp),%r8
mov    %r14d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    %ebx,%r9d
call   1090 <sendto@plt>
test   %eax,%eax
jns    14ca <main+0x26a>
lea    0xc3e(%rip),%rdi
call   1130 <error@plt>
lea    0xc39(%rip),%rdi
lea    0x40(%rsp),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0x28(%rsp),%r8
lea    0xc(%rsp),%r9
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x100,%edx
xor    %ecx,%ecx
call   1110 <recvfrom@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    150e <main+0x2ae>
lea    0xc1c(%rip),%rdi
call   1130 <error@plt>
lea    0x40(%rsp),%rsi
mov    $0x1,%edi
mov    %ebx,%edx
call   1040 <write@plt>
mov    %r14d,%edi
call   10a0 <close@plt>
xor    %eax,%eax
add    $0x140,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2a88(%rip),%rax
mov    (%rax),%edi
mov    (%r15),%rdx
lea    0xab4(%rip),%rsi
xor    %eax,%eax
call   10f0 <fprintf@plt>
xor    %edi,%edi
call   1160 <exit@plt>
mov    0x2a67(%rip),%rax
mov    (%rax),%edi
lea    0xad5(%rip),%rsi
xor    %eax,%eax
call   10f0 <fprintf@plt>
xor    %edi,%edi
call   1160 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i8*, %struct.TYPE_2__, i8* }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32, i64 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [39 x i8] c"usage %s hostname port optional_flags\0A\00"
@.str.1 = [3 x i8] c"-u\00"
@AF_INET = global i8* null
@SOCK_STREAM = global i32 0
@.str.2 = [21 x i8] c"ERROR opening socket\00"
@.str.3 = [21 x i8] c"ERROR, no such host\0A\00"
@.str.4 = [17 x i8] c"ERROR connecting\00"
@.str.5 = [24 x i8] c"ERROR writing to socket\00"
@.str.6 = [26 x i8] c"ERROR reading from socket\00"
@.str.7 = [4 x i8] c"%s\0A\00"
@SOCK_DGRAM = global i32 0
@.str.8 = [25 x i8] c"ERROR opening UDP socket\00"
@.str.9 = [13 x i8] c"Unknown host\00"
@.str.10 = [27 x i8] c"Please enter the message: \00"
@stdin = global i32 0
@.str.11 = [43 x i8] c"ERROR removing the newline char from input\00"
@.str.12 = [7 x i8] c"Sendto\00"
@.str.13 = [27 x i8] c"\0AHere is your message: %s\0A\00"
@.str.14 = [9 x i8] c"recvfrom\00"
@.str.15 = [38 x i8] c"ERROR could not determine socket type\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 i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca %struct.sockaddr_in
%13 = alloca %struct.hostent*
%14 = alloca [256 x i8]
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca %struct.sockaddr_in
%19 = alloca %struct.sockaddr_in
%20 = alloca %struct.hostent*
%21 = alloca [256 x i8]
%22 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %6
store i32 0, i32* %7
%23 = load i32, i32* %4
%24 = icmp slt i32 %23, 3
br i1 %24, label %25, label %32
25: ; preds = %2
%26 = load i32, i32* @stderr
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 0
%29 = load i8*, i8** %28
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %29)
%31 = call i32 @exit(i32 0)
unreachable
32: ; preds = %2
store i32 3, i32* %7
br label %33
33: ; preds = %48, %32
%34 = load i32, i32* %7
%35 = load i32, i32* %4
%36 = icmp slt i32 %34, %35
br i1 %36, label %37, label %51
37: ; preds = %33
%38 = load i8**, i8*** %5
%39 = load i32, i32* %7
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8*, i8** %38, i64 %40
%42 = load i8*, i8** %41
%43 = call i32 @strcmp(i8* %42, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32 %43, i32* %8
%44 = load i32, i32* %8
%45 = icmp eq i32 %44, 0
br i1 %45, label %46, label %47
46: ; preds = %37
store i32 0, i32* %6
br label %47
47: ; preds = %46, %37
br label %48
48: ; preds = %47
%49 = load i32, i32* %7
%50 = add nsw i32 %49, 1
store i32 %50, i32* %7
br label %33
51: ; preds = %33
%52 = load i32, i32* %6
%53 = icmp eq i32 %52, 1
br i1 %53, label %54, label %121
54: ; preds = %51
%55 = load i8**, i8*** %5
%56 = getelementptr inbounds i8*, i8** %55, i64 2
%57 = load i8*, i8** %56
%58 = call i32 @atoi(i8* %57)
store i32 %58, i32* %10
%59 = load i8*, i8** @AF_INET
%60 = load i32, i32* @SOCK_STREAM
%61 = call i32 @socket(i8* %59, i32 %60, i32 0)
store i32 %61, i32* %9
%62 = load i32, i32* %9
%63 = icmp slt i32 %62, 0
br i1 %63, label %64, label %66
64: ; preds = %54
%65 = call i32 @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %66
66: ; preds = %64, %54
%67 = load i8**, i8*** %5
%68 = getelementptr inbounds i8*, i8** %67, i64 1
%69 = load i8*, i8** %68
%70 = call %struct.hostent* @gethostbyname(i8* %69)
store %struct.hostent* %70, %struct.hostent** %13
%71 = load %struct.hostent*, %struct.hostent** %13
%72 = icmp eq %struct.hostent* %71, null
br i1 %72, label %73, label %77
73: ; preds = %66
%74 = load i32, i32* @stderr
%75 = call i32 (i32, i8*, ...) @fprintf(i32 %74, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%76 = call i32 @exit(i32 0)
unreachable
77: ; preds = %66
%78 = bitcast %struct.sockaddr_in* %12 to i8*
%79 = call i32 @bzero(i8* %78, i32 24)
%80 = load i8*, i8** @AF_INET
%81 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 2
store i8* %80, i8** %81
%82 = load %struct.hostent*, %struct.hostent** %13
%83 = getelementptr inbounds %struct.hostent, %struct.hostent* %82, i32 0, i32 1
%84 = load i64, i64* %83
%85 = inttoptr i64 %84 to i8*
%86 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 1
%87 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %86, i32 0, i32 0
%88 = bitcast i32* %87 to i8*
%89 = load %struct.hostent*, %struct.hostent** %13
%90 = getelementptr inbounds %struct.hostent, %struct.hostent* %89, i32 0, i32 0
%91 = load i32, i32* %90
%92 = call i32 @bcopy(i8* %85, i8* %88, i32 %91)
%93 = load i32, i32* %10
%94 = call i8* @htons(i32 %93)
%95 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 0
store i8* %94, i8** %95
%96 = load i32, i32* %9
%97 = bitcast %struct.sockaddr_in* %12 to %struct.sockaddr*
%98 = call i64 @connect(i32 %96, %struct.sockaddr* %97, i32 24)
%99 = icmp slt i64 %98, 0
br i1 %99, label %100, label %102
100: ; preds = %77
%101 = call i32 @error(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
br label %102
102: ; preds = %100, %77
%103 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i64 0, i64 0
%104 = load i32, i32* %9
%105 = call i64 @sendMessage(i8* %103, i32 %104)
%106 = icmp slt i64 %105, 0
br i1 %106, label %107, label %109
107: ; preds = %102
%108 = call i32 @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
br label %109
109: ; preds = %107, %102
%110 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i64 0, i64 0
%111 = load i32, i32* %9
%112 = call i64 @readMessage(i8* %110, i32 %111)
%113 = icmp slt i64 %112, 0
br i1 %113, label %114, label %116
114: ; preds = %109
%115 = call i32 @error(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0))
br label %116
116: ; preds = %114, %109
%117 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i64 0, i64 0
%118 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i8* %117)
%119 = load i32, i32* %9
%120 = call i32 @close(i32 %119)
br label %205
121: ; preds = %51
%122 = load i32, i32* %6
%123 = icmp eq i32 %122, 0
br i1 %123, label %124, label %202
124: ; preds = %121
%125 = load i8*, i8** @AF_INET
%126 = load i32, i32* @SOCK_DGRAM
%127 = call i32 @socket(i8* %125, i32 %126, i32 0)
store i32 %127, i32* %15
%128 = load i32, i32* %15
%129 = icmp slt i32 %128, 0
br i1 %129, label %130, label %132
130: ; preds = %124
%131 = call i32 @error(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0))
br label %132
132: ; preds = %130, %124
%133 = load i8*, i8** @AF_INET
%134 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %18, i32 0, i32 2
store i8* %133, i8** %134
%135 = load i8**, i8*** %5
%136 = getelementptr inbounds i8*, i8** %135, i64 1
%137 = load i8*, i8** %136
%138 = call %struct.hostent* @gethostbyname(i8* %137)
store %struct.hostent* %138, %struct.hostent** %20
%139 = load %struct.hostent*, %struct.hostent** %20
%140 = icmp eq %struct.hostent* %139, null
br i1 %140, label %141, label %143
141: ; preds = %132
%142 = call i32 @error(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.9, i64 0, i64 0))
br label %143
143: ; preds = %141, %132
%144 = load %struct.hostent*, %struct.hostent** %20
%145 = getelementptr inbounds %struct.hostent, %struct.hostent* %144, i32 0, i32 1
%146 = load i64, i64* %145
%147 = inttoptr i64 %146 to i8*
%148 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %18, i32 0, i32 1
%149 = bitcast %struct.TYPE_2__* %148 to i8*
%150 = load %struct.hostent*, %struct.hostent** %20
%151 = getelementptr inbounds %struct.hostent, %struct.hostent* %150, i32 0, i32 0
%152 = load i32, i32* %151
%153 = call i32 @bcopy(i8* %147, i8* %149, i32 %152)
%154 = load i8**, i8*** %5
%155 = getelementptr inbounds i8*, i8** %154, i64 2
%156 = load i8*, i8** %155
%157 = call i32 @atoi(i8* %156)
%158 = call i8* @htons(i32 %157)
%159 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %18, i32 0, i32 0
store i8* %158, i8** %159
store i32 24, i32* %17
%160 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0))
%161 = getelementptr inbounds [256 x i8], [256 x i8]* %21, i64 0, i64 0
%162 = call i32 @bzero(i8* %161, i32 256)
%163 = getelementptr inbounds [256 x i8], [256 x i8]* %21, i64 0, i64 0
%164 = load i32, i32* @stdin
%165 = call i32 @fgets(i8* %163, i32 255, i32 %164)
%166 = getelementptr inbounds [256 x i8], [256 x i8]* %21, i64 0, i64 0
%167 = call i8* @strchr(i8* %166, i8 signext 10)
store i8* %167, i8** %22
%168 = icmp ne i8* %167, null
br i1 %168, label %169, label %171
169: ; preds = %143
%170 = load i8*, i8** %22
store i8 0, i8* %170
br label %173
171: ; preds = %143
%172 = call i32 @error(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.11, i64 0, i64 0))
br label %173
173: ; preds = %171, %169
%174 = load i32, i32* %15
%175 = getelementptr inbounds [256 x i8], [256 x i8]* %21, i64 0, i64 0
%176 = getelementptr inbounds [256 x i8], [256 x i8]* %21, i64 0, i64 0
%177 = call i32 @strlen(i8* %176)
%178 = bitcast %struct.sockaddr_in* %18 to %struct.sockaddr*
%179 = load i32, i32* %17
%180 = call i32 @sendto(i32 %174, i8* %175, i32 %177, i32 0, %struct.sockaddr* %178, i32 %179)
store i32 %180, i32* %16
%181 = load i32, i32* %16
%182 = icmp slt i32 %181, 0
br i1 %182, label %183, label %185
183: ; preds = %173
%184 = call i32 @error(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.12, i64 0, i64 0))
br label %185
185: ; preds = %183, %173
%186 = getelementptr inbounds [256 x i8], [256 x i8]* %21, i64 0, i64 0
%187 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.13, i64 0, i64 0), i8* %186)
%188 = load i32, i32* %15
%189 = getelementptr inbounds [256 x i8], [256 x i8]* %21, i64 0, i64 0
%190 = bitcast %struct.sockaddr_in* %19 to %struct.sockaddr*
%191 = call i32 @recvfrom(i32 %188, i8* %189, i32 256, i32 0, %struct.sockaddr* %190, i32* %17)
store i32 %191, i32* %16
%192 = load i32, i32* %16
%193 = icmp slt i32 %192, 0
br i1 %193, label %194, label %196
194: ; preds = %185
%195 = call i32 @error(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.14, i64 0, i64 0))
br label %196
196: ; preds = %194, %185
%197 = getelementptr inbounds [256 x i8], [256 x i8]* %21, i64 0, i64 0
%198 = load i32, i32* %16
%199 = call i32 @write(i32 1, i8* %197, i32 %198)
%200 = load i32, i32* %15
%201 = call i32 @close(i32 %200)
br label %204
202: ; preds = %121
%203 = call i32 @error(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.15, i64 0, i64 0))
br label %204
204: ; preds = %202, %196
br label %205
205: ; preds = %204, %116
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i8*, %struct.TYPE_2__, i8* }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32, i64 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [39 x i8] c"usage %s hostname port optional_flags\0A\00"
@.str.1 = [3 x i8] c"-u\00"
@AF_INET = global i8* null
@SOCK_STREAM = global i32 0
@.str.2 = [21 x i8] c"ERROR opening socket\00"
@.str.3 = [21 x i8] c"ERROR, no such host\0A\00"
@.str.4 = [17 x i8] c"ERROR connecting\00"
@.str.5 = [24 x i8] c"ERROR writing to socket\00"
@.str.6 = [26 x i8] c"ERROR reading from socket\00"
@SOCK_DGRAM = global i32 0
@.str.8 = [25 x i8] c"ERROR opening UDP socket\00"
@.str.9 = [13 x i8] c"Unknown host\00"
@.str.10 = [27 x i8] c"Please enter the message: \00"
@stdin = global i32 0
@.str.11 = [43 x i8] c"ERROR removing the newline char from input\00"
@.str.12 = [7 x i8] c"Sendto\00"
@.str.13 = [27 x i8] c"\0AHere is your message: %s\0A\00"
@.str.14 = [9 x i8] c"recvfrom\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [256 x i8]
%5 = alloca i32
%6 = alloca %struct.sockaddr_in
%7 = alloca %struct.sockaddr_in
%8 = alloca [256 x i8]
%9 = icmp slt i32 %0, 3
br i1 %9, label %14, label %10
10: ; preds = %2
%11 = icmp eq i32 %0, 3
br i1 %11, label %31, label %12
12: ; preds = %10
%13 = zext i32 %0 to i64
br label %19
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %1
%17 = tail call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = tail call i32 @exit(i32 0)
unreachable
19: ; preds = %12, %19
%20 = phi i64 [ 3, %12 ], [ %27, %19 ]
%21 = phi i32 [ 1, %12 ], [ %26, %19 ]
%22 = getelementptr inbounds i8*, i8** %1, i64 %20
%23 = load i8*, i8** %22
%24 = tail call i32 @strcmp(i8* dereferenceable(1) %23, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%25 = icmp eq i32 %24, 0
%26 = select i1 %25, i32 0, i32 %21
%27 = add nuw nsw i64 %20, 1
%28 = icmp eq i64 %27, %13
br i1 %28, label %29, label %19
29: ; preds = %19
%30 = icmp eq i32 %26, 1
br i1 %30, label %31, label %83
31: ; preds = %10, %29
%32 = bitcast %struct.sockaddr_in* %3 to i8*
%33 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%34 = getelementptr inbounds i8*, i8** %1, i64 2
%35 = load i8*, i8** %34
%36 = tail call i32 @atoi(i8* %35)
%37 = load i8*, i8** @AF_INET
%38 = load i32, i32* @SOCK_STREAM
%39 = tail call i32 @socket(i8* %37, i32 %38, i32 0)
%40 = icmp slt i32 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %31
%42 = tail call i32 @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %43
43: ; preds = %41, %31
%44 = getelementptr inbounds i8*, i8** %1, i64 1
%45 = load i8*, i8** %44
%46 = tail call %struct.hostent* @gethostbyname(i8* %45)
%47 = icmp eq %struct.hostent* %46, null
br i1 %47, label %48, label %52
48: ; preds = %43
%49 = load i32, i32* @stderr
%50 = tail call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%51 = tail call i32 @exit(i32 0)
unreachable
52: ; preds = %43
%53 = call i32 @bzero(i8* %32, i32 24)
%54 = load i8*, i8** @AF_INET
%55 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i8* %54, i8** %55
%56 = getelementptr inbounds %struct.hostent, %struct.hostent* %46, i64 0, i32 1
%57 = load i64, i64* %56
%58 = inttoptr i64 %57 to i8*
%59 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
%60 = bitcast i32* %59 to i8*
%61 = getelementptr inbounds %struct.hostent, %struct.hostent* %46, i64 0, i32 0
%62 = load i32, i32* %61
%63 = tail call i8* @htons(i32 %36)
%64 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i8* %63, i8** %64
%65 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%66 = call i64 @connect(i32 %39, %struct.sockaddr* %65, i32 24)
%67 = icmp slt i64 %66, 0
br i1 %67, label %68, label %70
68: ; preds = %52
%69 = call i32 @error(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
br label %70
70: ; preds = %68, %52
%71 = call i64 @sendMessage(i8* %33, i32 %39)
%72 = icmp slt i64 %71, 0
br i1 %72, label %73, label %75
73: ; preds = %70
%74 = call i32 @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
br label %75
75: ; preds = %73, %70
%76 = call i64 @readMessage(i8* %33, i32 %39)
%77 = icmp slt i64 %76, 0
br i1 %77, label %78, label %80
78: ; preds = %75
%79 = call i32 @error(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0))
br label %80
80: ; preds = %78, %75
%81 = call i32 @puts(i8* %33)
%82 = call i32 @close(i32 %39)
br label %144
83: ; preds = %29
%84 = bitcast i32* %5 to i8*
%85 = bitcast %struct.sockaddr_in* %6 to i8*
%86 = bitcast %struct.sockaddr_in* %7 to i8*
%87 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%88 = load i8*, i8** @AF_INET
%89 = load i32, i32* @SOCK_DGRAM
%90 = tail call i32 @socket(i8* %88, i32 %89, i32 0)
%91 = icmp slt i32 %90, 0
br i1 %91, label %92, label %94
92: ; preds = %83
%93 = tail call i32 @error(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0))
br label %94
94: ; preds = %92, %83
%95 = load i8*, i8** @AF_INET
%96 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 2
store i8* %95, i8** %96
%97 = getelementptr inbounds i8*, i8** %1, i64 1
%98 = load i8*, i8** %97
%99 = tail call %struct.hostent* @gethostbyname(i8* %98)
%100 = icmp eq %struct.hostent* %99, null
br i1 %100, label %101, label %103
101: ; preds = %94
%102 = tail call i32 @error(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.9, i64 0, i64 0))
br label %103
103: ; preds = %101, %94
%104 = getelementptr inbounds %struct.hostent, %struct.hostent* %99, i64 0, i32 1
%105 = load i64, i64* %104
%106 = inttoptr i64 %105 to i8*
%107 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 1
%108 = bitcast %struct.TYPE_2__* %107 to i8*
%109 = getelementptr inbounds %struct.hostent, %struct.hostent* %99, i64 0, i32 0
%110 = load i32, i32* %109
%111 = getelementptr inbounds i8*, i8** %1, i64 2
%112 = load i8*, i8** %111
%113 = tail call i32 @atoi(i8* %112)
%114 = tail call i8* @htons(i32 %113)
%115 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 0
store i8* %114, i8** %115
store i32 24, i32* %5
%116 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0))
%117 = call i32 @bzero(i8* %87, i32 256)
%118 = load i32, i32* @stdin
%119 = call i32 @fgets(i8* %87, i32 255, i32 %118)
%120 = call i8* @strchr(i8* %87, i8 signext 10)
%121 = icmp eq i8* %120, null
br i1 %121, label %124, label %122
122: ; preds = %103
store i8 0, i8* %120
%123 = load i32, i32* %5
br label %126
124: ; preds = %103
%125 = call i32 @error(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.11, i64 0, i64 0))
br label %126
126: ; preds = %124, %122
%127 = phi i32 [ 24, %124 ], [ %123, %122 ]
%128 = call i32 @strlen(i8* %87)
%129 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%130 = call i32 @sendto(i32 %90, i8* %87, i32 %128, i32 0, %struct.sockaddr* %129, i32 %127)
%131 = icmp slt i32 %130, 0
br i1 %131, label %132, label %134
132: ; preds = %126
%133 = call i32 @error(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.12, i64 0, i64 0))
br label %134
134: ; preds = %132, %126
%135 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.13, i64 0, i64 0), i8* %87)
%136 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%137 = call i32 @recvfrom(i32 %90, i8* %87, i32 256, i32 0, %struct.sockaddr* %136, i32* %5)
%138 = icmp slt i32 %137, 0
br i1 %138, label %139, label %141
139: ; preds = %134
%140 = call i32 @error(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.14, i64 0, i64 0))
br label %141
141: ; preds = %139, %134
%142 = call i32 @write(i32 1, i8* %87, i32 %137)
%143 = call i32 @close(i32 %90)
br label %144
144: ; preds = %141, %80
ret i32 0
}