#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 */
struct addrinfo {
  int /*<<< orphan*/ ai_addrlen;
  int /*<<< orphan*/ ai_addr;
  scalar_t__ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
  struct addrinfo *ai_next;
  scalar_t__ ai_flags;
};
typedef int ssize_t;

/* Variables and functions */
int /*<<< orphan*/ AF_UNSPEC;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
int connect(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
char *gai_strerror(int);
int getaddrinfo(char *, char *, struct addrinfo *, struct addrinfo **);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, long, char *);
int read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, scalar_t__);
int /*<<< orphan*/ stderr;
int strlen(char *);
size_t write(int, char *, size_t);
int main(int argc, char *argv[]) {
  struct addrinfo hints;
  struct addrinfo *result, *rp;
  int sfd, s, j;
  size_t len;
  ssize_t nread;
  char buf[500];
  if (argc < 3) {
    fprintf(stderr, "Usage: %s host port msg...\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  memset(&hints, 0, sizeof(struct addrinfo));
  hints.ai_family = AF_UNSPEC;
  hints.ai_socktype = SOCK_DGRAM;
  hints.ai_flags = 0;
  hints.ai_protocol = 0;
  s = getaddrinfo(argv[1], argv[2], &hints, &result);
  if (s != 0) {
    fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(s));
    exit(EXIT_FAILURE);
  }
  for (rp = result; rp != NULL; rp = rp->ai_next) {
    sfd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
    if (sfd == -1)
      continue;
    if (connect(sfd, rp->ai_addr, rp->ai_addrlen) != -1)
      break;
    close(sfd);
  }
  if (rp == NULL) {
    fprintf(stderr, "Could not connect to: (%s, %s)\n", argv[1], argv[2]);
    exit(EXIT_FAILURE);
  }
  freeaddrinfo(result);
  for (j = 3; j < argc; j++) {
    len = strlen(argv[j]) + 1;
    if (len + 1 > 500) {
      fprintf(stderr, "Ignoring long message in argument %d\n", j);
      continue;
    }
    if (write(sfd, argv[j], len) != len) {
      fprintf(stderr, "partial/failed write\n");
      exit(EXIT_FAILURE);
    } else
      printf("Message sent (%d bytes): %s\n", len, argv[j]);
    nread = read(sfd, buf, 500);
    if (nread == -1) {
      perror("read");
      exit(EXIT_FAILURE);
    }
    printf("Received from server (%ld bytes): %s\n", (long)nread, buf);
  }
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x270,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    122f <main+0x4f>
mov    0x2dc6(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xde6(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    0x2da0(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1070 <memset@plt>
mov    0x2da2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2d8e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    -0x38(%rbp),%rdx
lea    -0x40(%rbp),%rcx
call   10e0 <getaddrinfo@plt>
mov    %eax,-0x50(%rbp)
cmpl   $0x0,-0x50(%rbp)
je     12cd <main+0xed>
mov    0x2d38(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x264(%rbp)
mov    -0x50(%rbp),%edi
call   1060 <gai_strerror@plt>
mov    -0x264(%rbp),%edi
mov    %rax,%rdx
lea    0xd64(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    0x2d02(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    -0x40(%rbp),%rax
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
je     1349 <main+0x169>
mov    -0x48(%rbp),%rax
mov    0x14(%rax),%edi
mov    -0x48(%rbp),%rax
mov    0x10(%rax),%esi
mov    -0x48(%rbp),%rax
mov    0x8(%rax),%rdx
call   1100 <socket@plt>
mov    %eax,-0x4c(%rbp)
cmpl   $0xffffffff,-0x4c(%rbp)
jne    130d <main+0x12d>
jmp    1338 <main+0x158>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x48(%rbp),%rax
mov    (%rax),%edx
call   10d0 <connect@plt>
cmp    $0xffffffff,%eax
je     1330 <main+0x150>
jmp    1349 <main+0x169>
mov    -0x4c(%rbp),%edi
call   1080 <close@plt>
mov    -0x48(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x48(%rbp)
jmp    12d5 <main+0xf5>
cmpq   $0x0,-0x48(%rbp)
jne    1389 <main+0x1a9>
mov    0x2c75(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rcx
lea    0xcb9(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    0x2c46(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    -0x40(%rbp),%rdi
call   10f0 <freeaddrinfo@plt>
movl   $0x3,-0x54(%rbp)
mov    -0x54(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    14b5 <main+0x2d5>
mov    -0x10(%rbp),%rax
movslq -0x54(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
cltq
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rax
add    $0x1,%rax
cmp    $0x1f4,%rax
jbe    13f2 <main+0x212>
mov    0x2bf6(%rip),%rax
mov    (%rax),%edi
mov    -0x54(%rbp),%edx
lea    0xc67(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
jmp    14a7 <main+0x2c7>
mov    -0x4c(%rbp),%edi
mov    -0x10(%rbp),%rax
movslq -0x54(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
mov    -0x60(%rbp),%rdx
call   1030 <write@plt>
cmp    -0x60(%rbp),%rax
je     1439 <main+0x259>
mov    0x2bb5(%rip),%rax
mov    (%rax),%edi
lea    0xc4f(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    0x2b96(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    -0x60(%rbp),%rsi
mov    -0x10(%rbp),%rax
movslq -0x54(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xc39(%rip),%rdi
call   1050 <printf@plt>
mov    -0x4c(%rbp),%edi
lea    -0x260(%rbp),%rsi
mov    $0x1f4,%edx
call   1090 <read@plt>
mov    %eax,-0x64(%rbp)
cmpl   $0xffffffff,-0x64(%rbp)
jne    1490 <main+0x2b0>
lea    0xc29(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2b3f(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
movslq -0x64(%rbp),%rsi
lea    -0x260(%rbp),%rdx
lea    0xc09(%rip),%rdi
call   1050 <printf@plt>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    1399 <main+0x1b9>
mov    0x2b04(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x228,%rsp
mov    %rsi,%r15
cmp    $0x2,%edi
jg     1211 <main+0x31>
mov    0x2dd0(%rip),%rax
mov    (%rax),%edi
mov    (%r15),%rdx
lea    0xdf4(%rip),%rsi
jmp    139b <main+0x1bb>
mov    %edi,%r14d
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1070 <memset@plt>
mov    0x2db9(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x1c(%rsp)
mov    0x2da4(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
movq   $0x0,0x28(%rsp)
movq   $0x0,0x10(%rsp)
mov    0x8(%r15),%rdi
mov    0x10(%r15),%rsi
mov    %rsp,%rcx
mov    %rbx,%rdx
call   10e0 <getaddrinfo@plt>
test   %eax,%eax
jne    137f <main+0x19f>
mov    (%rsp),%rbx
jmp    128b <main+0xab>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebp,%edi
call   1080 <close@plt>
mov    0x18(%rbx),%rbx
test   %rbx,%rbx
je     13a4 <main+0x1c4>
mov    0x14(%rbx),%edi
mov    0x10(%rbx),%esi
mov    0x8(%rbx),%rdx
call   1100 <socket@plt>
cmp    $0xffffffff,%eax
je     1287 <main+0xa7>
mov    %eax,%ebp
mov    (%rbx),%edx
mov    0x4(%rbx),%esi
mov    %eax,%edi
call   10d0 <connect@plt>
cmp    $0xffffffff,%eax
je     1280 <main+0xa0>
mov    (%rsp),%rdi
call   10f0 <freeaddrinfo@plt>
cmp    $0x4,%r14d
jl     13d1 <main+0x1f1>
mov    %r14d,%r14d
mov    $0x3,%ebx
lea    0x30(%rsp),%r13
jmp    1306 <main+0x126>
nopl   (%rax)
mov    0x2ce9(%rip),%rax
mov    (%rax),%edi
lea    0xd5d(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   10a0 <fprintf@plt>
add    $0x1,%rbx
cmp    %rbx,%r14
je     13d1 <main+0x1f1>
mov    (%r15,%rbx,8),%rdi
call   1040 <strlen@plt>
movslq %eax,%r12
lea    -0x1f3(%r12),%rax
ff
cmp    $0xfffffffffffffe0a,%rax
jbe    12e0 <main+0x100>
add    $0x1,%r12
mov    (%r15,%rbx,8),%rsi
mov    %ebp,%edi
mov    %r12,%rdx
call   1030 <write@plt>
cmp    %r12,%rax
jne    13df <main+0x1ff>
mov    (%r15,%rbx,8),%rdx
lea    0xd41(%rip),%rdi
mov    %r12,%rsi
call   1050 <printf@plt>
mov    %ebp,%edi
mov    %r13,%rsi
mov    $0x1f4,%edx
call   1090 <read@plt>
cmp    $0xffffffff,%eax
je     13f8 <main+0x218>
movslq %eax,%rsi
lea    0xd39(%rip),%rdi
mov    %r13,%rdx
call   1050 <printf@plt>
jmp    12f9 <main+0x119>
mov    0x2c4a(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1060 <gai_strerror@plt>
lea    0xc86(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   10a0 <fprintf@plt>
jmp    13c3 <main+0x1e3>
mov    0x2c25(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r15),%rdx
mov    0x10(%r15),%rcx
lea    0xc71(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    0x2bfe(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    0x2be8(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    0x2bea(%rip),%rax
mov    (%rax),%edi
lea    0xc84(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
jmp    13c3 <main+0x1e3>
lea    0xca7(%rip),%rdi
call   10b0 <perror@plt>
jmp    13c3 <main+0x1e3>

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32, i64, i32, i32, %struct.addrinfo*, i64 }
@stderr = global i32 0
@.str = [28 x i8] c"Usage: %s host port msg...\0A\00"
@EXIT_FAILURE = global i32 0
@AF_UNSPEC = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [17 x i8] c"getaddrinfo: %s\0A\00"
@.str.2 = [32 x i8] c"Could not connect to: (%s, %s)\0A\00"
@.str.3 = [38 x i8] c"Ignoring long message in argument %d\0A\00"
@.str.4 = [22 x i8] c"partial/failed write\0A\00"
@.str.5 = [29 x i8] c"Message sent (%d bytes): %s\0A\00"
@.str.6 = [5 x i8] c"read\00"
@.str.7 = [38 x i8] c"Received from server (%ld bytes): %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.addrinfo
%7 = alloca %struct.addrinfo*
%8 = alloca %struct.addrinfo*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i64
%13 = alloca i32
%14 = alloca [500 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = load i32, i32* %4
%16 = icmp slt i32 %15, 3
br i1 %16, label %17, label %25
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 0
%21 = load i8*, i8** %20
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %21)
%23 = load i32, i32* @EXIT_FAILURE
%24 = call i32 @exit(i32 %23)
unreachable
25: ; preds = %2
%26 = call i32 @memset(%struct.addrinfo* %6, i32 0, i32 40)
%27 = load i32, i32* @AF_UNSPEC
%28 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 4
store i32 %27, i32* %28
%29 = load i32, i32* @SOCK_DGRAM
%30 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 3
store i32 %29, i32* %30
%31 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 6
store i64 0, i64* %31
%32 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 2
store i64 0, i64* %32
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 2
%38 = load i8*, i8** %37
%39 = call i32 @getaddrinfo(i8* %35, i8* %38, %struct.addrinfo* %6, %struct.addrinfo** %7)
store i32 %39, i32* %10
%40 = load i32, i32* %10
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %49
42: ; preds = %25
%43 = load i32, i32* @stderr
%44 = load i32, i32* %10
%45 = call i8* @gai_strerror(i32 %44)
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %45)
%47 = load i32, i32* @EXIT_FAILURE
%48 = call i32 @exit(i32 %47)
unreachable
49: ; preds = %25
%50 = load %struct.addrinfo*, %struct.addrinfo** %7
store %struct.addrinfo* %50, %struct.addrinfo** %8
br label %51
51: ; preds = %82, %49
%52 = load %struct.addrinfo*, %struct.addrinfo** %8
%53 = icmp ne %struct.addrinfo* %52, null
br i1 %53, label %54, label %86
54: ; preds = %51
%55 = load %struct.addrinfo*, %struct.addrinfo** %8
%56 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %55, i32 0, i32 4
%57 = load i32, i32* %56
%58 = load %struct.addrinfo*, %struct.addrinfo** %8
%59 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %58, i32 0, i32 3
%60 = load i32, i32* %59
%61 = load %struct.addrinfo*, %struct.addrinfo** %8
%62 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %61, i32 0, i32 2
%63 = load i64, i64* %62
%64 = call i32 @socket(i32 %57, i32 %60, i64 %63)
store i32 %64, i32* %9
%65 = load i32, i32* %9
%66 = icmp eq i32 %65, -1
br i1 %66, label %67, label %68
67: ; preds = %54
br label %82
68: ; preds = %54
%69 = load i32, i32* %9
%70 = load %struct.addrinfo*, %struct.addrinfo** %8
%71 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %70, i32 0, i32 1
%72 = load i32, i32* %71
%73 = load %struct.addrinfo*, %struct.addrinfo** %8
%74 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %73, i32 0, i32 0
%75 = load i32, i32* %74
%76 = call i32 @connect(i32 %69, i32 %72, i32 %75)
%77 = icmp ne i32 %76, -1
br i1 %77, label %78, label %79
78: ; preds = %68
br label %86
79: ; preds = %68
%80 = load i32, i32* %9
%81 = call i32 @close(i32 %80)
br label %82
82: ; preds = %79, %67
%83 = load %struct.addrinfo*, %struct.addrinfo** %8
%84 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %83, i32 0, i32 5
%85 = load %struct.addrinfo*, %struct.addrinfo** %84
store %struct.addrinfo* %85, %struct.addrinfo** %8
br label %51
86: ; preds = %78, %51
%87 = load %struct.addrinfo*, %struct.addrinfo** %8
%88 = icmp eq %struct.addrinfo* %87, null
br i1 %88, label %89, label %100
89: ; preds = %86
%90 = load i32, i32* @stderr
%91 = load i8**, i8*** %5
%92 = getelementptr inbounds i8*, i8** %91, i64 1
%93 = load i8*, i8** %92
%94 = load i8**, i8*** %5
%95 = getelementptr inbounds i8*, i8** %94, i64 2
%96 = load i8*, i8** %95
%97 = call i32 (i32, i8*, ...) @fprintf(i32 %90, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %93, i8* %96)
%98 = load i32, i32* @EXIT_FAILURE
%99 = call i32 @exit(i32 %98)
unreachable
100: ; preds = %86
%101 = load %struct.addrinfo*, %struct.addrinfo** %7
%102 = call i32 @freeaddrinfo(%struct.addrinfo* %101)
store i32 3, i32* %11
br label %103
103: ; preds = %162, %100
%104 = load i32, i32* %11
%105 = load i32, i32* %4
%106 = icmp slt i32 %104, %105
br i1 %106, label %107, label %165
107: ; preds = %103
%108 = load i8**, i8*** %5
%109 = load i32, i32* %11
%110 = sext i32 %109 to i64
%111 = getelementptr inbounds i8*, i8** %108, i64 %110
%112 = load i8*, i8** %111
%113 = call i32 @strlen(i8* %112)
%114 = add nsw i32 %113, 1
%115 = sext i32 %114 to i64
store i64 %115, i64* %12
%116 = load i64, i64* %12
%117 = add i64 %116, 1
%118 = icmp ugt i64 %117, 500
br i1 %118, label %119, label %123
119: ; preds = %107
%120 = load i32, i32* @stderr
%121 = load i32, i32* %11
%122 = call i32 (i32, i8*, ...) @fprintf(i32 %120, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i32 %121)
br label %162
123: ; preds = %107
%124 = load i32, i32* %9
%125 = load i8**, i8*** %5
%126 = load i32, i32* %11
%127 = sext i32 %126 to i64
%128 = getelementptr inbounds i8*, i8** %125, i64 %127
%129 = load i8*, i8** %128
%130 = load i64, i64* %12
%131 = call i64 @write(i32 %124, i8* %129, i64 %130)
%132 = load i64, i64* %12
%133 = icmp ne i64 %131, %132
br i1 %133, label %134, label %139
134: ; preds = %123
%135 = load i32, i32* @stderr
%136 = call i32 (i32, i8*, ...) @fprintf(i32 %135, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
%137 = load i32, i32* @EXIT_FAILURE
%138 = call i32 @exit(i32 %137)
unreachable
139: ; preds = %123
%140 = load i64, i64* %12
%141 = load i8**, i8*** %5
%142 = load i32, i32* %11
%143 = sext i32 %142 to i64
%144 = getelementptr inbounds i8*, i8** %141, i64 %143
%145 = load i8*, i8** %144
%146 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i64 %140, i8* %145)
br label %147
147: ; preds = %139
%148 = load i32, i32* %9
%149 = getelementptr inbounds [500 x i8], [500 x i8]* %14, i64 0, i64 0
%150 = call i32 @read(i32 %148, i8* %149, i32 500)
store i32 %150, i32* %13
%151 = load i32, i32* %13
%152 = icmp eq i32 %151, -1
br i1 %152, label %153, label %157
153: ; preds = %147
%154 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%155 = load i32, i32* @EXIT_FAILURE
%156 = call i32 @exit(i32 %155)
unreachable
157: ; preds = %147
%158 = load i32, i32* %13
%159 = sext i32 %158 to i64
%160 = getelementptr inbounds [500 x i8], [500 x i8]* %14, i64 0, i64 0
%161 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.7, i64 0, i64 0), i64 %159, i8* %160)
br label %162
162: ; preds = %157, %119
%163 = load i32, i32* %11
%164 = add nsw i32 %163, 1
store i32 %164, i32* %11
br label %103
165: ; preds = %103
%166 = load i32, i32* @EXIT_SUCCESS
%167 = call i32 @exit(i32 %166)
unreachable
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, i64, i32, i32, %struct.addrinfo*, i64 }
@stderr = global i32 0
@.str = [28 x i8] c"Usage: %s host port msg...\0A\00"
@EXIT_FAILURE = global i32 0
@AF_UNSPEC = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [17 x i8] c"getaddrinfo: %s\0A\00"
@.str.2 = [32 x i8] c"Could not connect to: (%s, %s)\0A\00"
@.str.3 = [38 x i8] c"Ignoring long message in argument %d\0A\00"
@.str.4 = [22 x i8] c"partial/failed write\0A\00"
@.str.5 = [29 x i8] c"Message sent (%d bytes): %s\0A\00"
@.str.6 = [5 x i8] c"read\00"
@.str.7 = [38 x i8] c"Received from server (%ld bytes): %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.addrinfo
%4 = alloca %struct.addrinfo*
%5 = alloca [500 x i8]
%6 = bitcast %struct.addrinfo* %3 to i8*
%7 = bitcast %struct.addrinfo** %4 to i8*
%8 = getelementptr inbounds [500 x i8], [500 x i8]* %5, i64 0, i64 0
%9 = icmp slt i32 %0, 3
br i1 %9, label %10, label %16
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i8*, i8** %1
%13 = tail call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = load i32, i32* @EXIT_FAILURE
%15 = tail call i32 @exit(i32 %14)
unreachable
16: ; preds = %2
%17 = call i32 @memset(%struct.addrinfo* %3, i32 0, i32 40)
%18 = load i32, i32* @AF_UNSPEC
%19 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 4
store i32 %18, i32* %19
%20 = load i32, i32* @SOCK_DGRAM
%21 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 3
store i32 %20, i32* %21
%22 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 6
store i64 0, i64* %22
%23 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 2
store i64 0, i64* %23
%24 = getelementptr inbounds i8*, i8** %1, i64 1
%25 = load i8*, i8** %24
%26 = getelementptr inbounds i8*, i8** %1, i64 2
%27 = load i8*, i8** %26
%28 = call i32 @getaddrinfo(i8* %25, i8* %27, %struct.addrinfo* %3, %struct.addrinfo** %4)
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %16
%31 = load %struct.addrinfo*, %struct.addrinfo** %4
%32 = icmp eq %struct.addrinfo* %31, null
br i1 %32, label %62, label %39
33: ; preds = %16
%34 = load i32, i32* @stderr
%35 = call i8* @gai_strerror(i32 %28)
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %35)
%37 = load i32, i32* @EXIT_FAILURE
%38 = call i32 @exit(i32 %37)
unreachable
39: ; preds = %30, %58
%40 = phi %struct.addrinfo* [ %60, %58 ], [ %31, %30 ]
%41 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %40, i64 0, i32 4
%42 = load i32, i32* %41
%43 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %40, i64 0, i32 3
%44 = load i32, i32* %43
%45 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %40, i64 0, i32 2
%46 = load i64, i64* %45
%47 = call i32 @socket(i32 %42, i32 %44, i64 %46)
%48 = icmp eq i32 %47, -1
br i1 %48, label %58, label %49
49: ; preds = %39
%50 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %40, i64 0, i32 1
%51 = load i32, i32* %50
%52 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %40, i64 0, i32 0
%53 = load i32, i32* %52
%54 = call i32 @connect(i32 %47, i32 %51, i32 %53)
%55 = icmp eq i32 %54, -1
br i1 %55, label %56, label %69
56: ; preds = %49
%57 = call i32 @close(i32 %47)
br label %58
58: ; preds = %39, %56
%59 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %40, i64 0, i32 5
%60 = load %struct.addrinfo*, %struct.addrinfo** %59
%61 = icmp eq %struct.addrinfo* %60, null
br i1 %61, label %62, label %39
62: ; preds = %58, %30
%63 = load i32, i32* @stderr
%64 = load i8*, i8** %24
%65 = load i8*, i8** %26
%66 = call i32 (i32, i8*, ...) @fprintf(i32 %63, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %64, i8* %65)
%67 = load i32, i32* @EXIT_FAILURE
%68 = call i32 @exit(i32 %67)
unreachable
69: ; preds = %49
%70 = load %struct.addrinfo*, %struct.addrinfo** %4
%71 = call i32 @freeaddrinfo(%struct.addrinfo* %70)
%72 = icmp sgt i32 %0, 3
br i1 %72, label %73, label %112
73: ; preds = %69
%74 = zext i32 %0 to i64
br label %75
75: ; preds = %73, %109
%76 = phi i64 [ 3, %73 ], [ %110, %109 ]
%77 = getelementptr inbounds i8*, i8** %1, i64 %76
%78 = load i8*, i8** %77
%79 = call i32 @strlen(i8* %78)
%80 = add nsw i32 %79, 1
%81 = sext i32 %80 to i64
%82 = add nsw i64 %81, -500
%83 = icmp ult i64 %82, -501
br i1 %83, label %84, label %88
84: ; preds = %75
%85 = load i32, i32* @stderr
%86 = trunc i64 %76 to i32
%87 = call i32 (i32, i8*, ...) @fprintf(i32 %85, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i32 %86)
br label %109
88: ; preds = %75
%89 = load i8*, i8** %77
%90 = call i64 @write(i32 %47, i8* %89, i64 %81)
%91 = icmp eq i64 %90, %81
br i1 %91, label %97, label %92
92: ; preds = %88
%93 = load i32, i32* @stderr
%94 = call i32 (i32, i8*, ...) @fprintf(i32 %93, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
%95 = load i32, i32* @EXIT_FAILURE
%96 = call i32 @exit(i32 %95)
unreachable
97: ; preds = %88
%98 = load i8*, i8** %77
%99 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i64 %81, i8* %98)
%100 = call i32 @read(i32 %47, i8* %8, i32 500)
%101 = icmp eq i32 %100, -1
br i1 %101, label %102, label %106
102: ; preds = %97
%103 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%104 = load i32, i32* @EXIT_FAILURE
%105 = call i32 @exit(i32 %104)
unreachable
106: ; preds = %97
%107 = sext i32 %100 to i64
%108 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.7, i64 0, i64 0), i64 %107, i8* %8)
br label %109
109: ; preds = %106, %84
%110 = add nuw nsw i64 %76, 1
%111 = icmp eq i64 %110, %74
br i1 %111, label %112, label %75
112: ; preds = %109, %69
%113 = load i32, i32* @EXIT_SUCCESS
%114 = call i32 @exit(i32 %113)
unreachable
}