#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;
  int /*<<< orphan*/ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int atoi(char *);
int /*<<< orphan*/ close(int);
int connect(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
char *gai_strerror(int);
scalar_t__ getaddrinfo(char *, char *, struct addrinfo *, struct addrinfo **);
int getopt(int, char **, char *);
char *malloc(int);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
char *optarg;
char optopt;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int send(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int strlen(char *);
int main(int argc, char **argv) {
  char *server_port = "1234";
  char *server_ip = "127.0.0.1";
  char *message = malloc(1024);
  int sockfd, rc;
  int i;
  struct addrinfo hints, *server;
  int o;
  int num_packets = -1;
  while ((o = getopt(argc, argv, "p:h:m:n:")) != -1) {
    switch (o) {
    case 'p':
      server_port = optarg;
      break;
    case 'h':
      server_ip = optarg;
      break;
    case 'm':
      message = optarg;
      break;
    case 'n':
      num_packets = atoi(optarg);
      break;
    case '?':
      if (optopt == 'p' || optopt == 'h') {
        fprintf(stderr, "Option %c requires an argument.\n", optopt);
      } else {
        fprintf(stderr, "Unknown argument: %c.\n", optopt);
      }
      break;
    }
  }
  if (num_packets < 0) {
    printf("Sending packets forever\n");
  } else {
    printf("Sending %d packets", num_packets);
  }
  printf("server_ip: %s   port: %s\n", server_ip, server_port);
  for (i = strlen(message); i < 1024; i++) {
    message[i] = 'A';
  }
  message[1024 - 1] = '\0';
  memset(&hints, 0, sizeof hints);
  hints.ai_family = AF_INET;
  hints.ai_socktype = SOCK_STREAM;
  if (rc = getaddrinfo(server_ip, server_port, &hints, &server) != 0) {
    perror(gai_strerror(rc));
    exit(-1);
  }
  sockfd = socket(server->ai_family, server->ai_socktype, server->ai_protocol);
  if (sockfd == -1) {
    perror("ERROR opening socket");
    exit(-1);
  }
  rc = connect(sockfd, server->ai_addr, server->ai_addrlen);
  if (rc == -1) {
    perror("ERROR on connect");
    goto out;
  }
  i = 0;
  while (1) {
    rc = send(sockfd, message, 1024, 0);
    if (rc < 0) {
      perror("ERROR on send");
      exit(-1);
    }
    if (num_packets > 0 && i == num_packets) {
      break;
    }
    i++;
  }
out:
  freeaddrinfo(server);
  close(sockfd);
  free(message);
  printf("Done.\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe9b(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xe95(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    $0x400,%edi
call   10b0 <malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0xffffffff,-0x58(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe78(%rip),%rdx
call   10d0 <getopt@plt>
mov    %eax,-0x54(%rbp)
cmp    $0xffffffff,%eax
je     135c <main+0x14c>
mov    -0x54(%rbp),%eax
add    $0xffffffc1,%eax
mov    %eax,%ecx
mov    %rcx,-0x60(%rbp)
sub    $0x31,%eax
ja     1357 <main+0x147>
mov    -0x60(%rbp),%rax
lea    0xd70(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2d58(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    1357 <main+0x147>
mov    0x2d45(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    1357 <main+0x147>
mov    0x2d32(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
jmp    1357 <main+0x147>
mov    0x2d1f(%rip),%rax
mov    (%rax),%rdi
call   10e0 <atoi@plt>
mov    %eax,-0x58(%rbp)
jmp    1357 <main+0x147>
mov    0x2ce8(%rip),%rax
movsbl (%rax),%eax
cmp    $0x70,%eax
je     130f <main+0xff>
mov    0x2cd5(%rip),%rax
movsbl (%rax),%eax
cmp    $0x68,%eax
jne    1333 <main+0x123>
mov    0x2cb2(%rip),%rax
mov    (%rax),%edi
lea    0xdc1(%rip),%rsi
mov    0x2cb2(%rip),%rax
movsbl (%rax),%edx
call   10a0 <fprintf@plt>
jmp    1352 <main+0x142>
mov    0x2c8e(%rip),%rax
mov    (%rax),%edi
lea    0xdbe(%rip),%rsi
mov    0x2c8e(%rip),%rax
movsbl (%rax),%edx
call   10a0 <fprintf@plt>
jmp    1357 <main+0x147>
jmp    1251 <main+0x41>
cmpl   $0x0,-0x58(%rbp)
jge    1379 <main+0x169>
lea    0xdab(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    138a <main+0x17a>
mov    -0x58(%rbp),%esi
lea    0xdae(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xdab(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x400,-0x34(%rbp)
jge    13d3 <main+0x1c3>
mov    -0x28(%rbp),%rax
movslq -0x34(%rbp),%rcx
movb   $0x41,(%rax,%rcx,1)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    13ac <main+0x19c>
mov    -0x28(%rbp),%rax
movb   $0x0,0x3ff(%rax)
lea    -0x48(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1080 <memset@plt>
mov    0x2beb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    0x2bbf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x48(%rbp),%rdx
lea    -0x50(%rbp),%rcx
call   1110 <getaddrinfo@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,%cl
and    $0x1,%cl
movzbl %cl,%ecx
mov    %ecx,-0x30(%rbp)
test   $0x1,%al
jne    143a <main+0x22a>
jmp    1454 <main+0x244>
mov    -0x30(%rbp),%edi
call   1070 <gai_strerror@plt>
mov    %rax,%rdi
call   10c0 <perror@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>
mov    -0x50(%rbp),%rax
mov    0x10(%rax),%edi
mov    -0x50(%rbp),%rax
mov    0xc(%rax),%esi
mov    -0x50(%rbp),%rax
mov    0x8(%rax),%edx
call   1130 <socket@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    1491 <main+0x281>
lea    0xcdc(%rip),%rdi
call   10c0 <perror@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>
mov    -0x2c(%rbp),%edi
mov    -0x50(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x50(%rbp),%rax
mov    (%rax),%edx
call   1100 <connect@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0xffffffff,-0x30(%rbp)
jne    14c4 <main+0x2b4>
lea    0xcb9(%rip),%rdi
call   10c0 <perror@plt>
jmp    152f <main+0x31f>
movl   $0x0,-0x34(%rbp)
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jge    1501 <main+0x2f1>
lea    0xc92(%rip),%rdi
call   10c0 <perror@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>
cmpl   $0x0,-0x58(%rbp)
jle    151c <main+0x30c>
mov    -0x34(%rbp),%eax
cmp    -0x58(%rbp),%eax
jne    151c <main+0x30c>
jmp    152a <main+0x31a>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    14cb <main+0x2bb>
jmp    152f <main+0x31f>
mov    -0x50(%rbp),%rdi
call   1120 <freeaddrinfo@plt>
mov    -0x2c(%rbp),%edi
call   1090 <close@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
lea    0xc42(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
mov    $0x400,%edi
call   10c0 <malloc@plt>
mov    %rax,0x20(%rsp)
movl   $0xffffffff,0xc(%rsp)
ff
lea    0xe77(%rip),%rax
mov    %rax,0x18(%rsp)
lea    0xe70(%rip),%rax
mov    %rax,0x10(%rsp)
lea    0xe6e(%rip),%r14
lea    0xd90(%rip),%r12
mov    0x2d61(%rip),%r13
mov    0x2d4a(%rip),%r15
jmp    128f <main+0x6f>
mov    (%r15),%edi
lea    0xe56(%rip),%rsi
call   10b0 <fprintf@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   10e0 <getopt@plt>
lea    -0x3f(%rax),%ecx
cmp    $0x31,%ecx
ja     12d0 <main+0xb0>
movslq (%r12,%rcx,4),%rax
add    %r12,%rax
jmp    *%rax
movzbl 0x0(%r13),%eax
movsbl %al,%edx
cmp    $0x70,%al
je     1280 <main+0x60>
cmp    $0x68,%al
je     1280 <main+0x60>
mov    (%r15),%edi
lea    0xe3a(%rip),%rsi
call   10b0 <fprintf@plt>
jmp    128f <main+0x6f>
xchg   %ax,%ax
cmp    $0xffffffff,%eax
jne    128f <main+0x6f>
jmp    1322 <main+0x102>
mov    0x2d1a(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x10(%rsp)
jmp    128f <main+0x6f>
mov    0x2d09(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x20(%rsp)
jmp    128f <main+0x6f>
mov    0x2cf8(%rip),%rax
mov    (%rax),%rdi
call   10f0 <atoi@plt>
mov    %eax,0xc(%rsp)
jmp    128f <main+0x6f>
mov    0x2ce3(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x18(%rsp)
jmp    128f <main+0x6f>
mov    0xc(%rsp),%r15d
test   %r15d,%r15d
js     133f <main+0x11f>
lea    0xde5(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    134b <main+0x12b>
lea    0xe39(%rip),%rdi
call   1040 <puts@plt>
mov    0x20(%rsp),%r14
mov    0x18(%rsp),%rbp
mov    0x10(%rsp),%rbx
lea    0xdca(%rip),%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
cmp    $0x3ff,%eax
jg     1398 <main+0x178>
movslq %eax,%rdi
add    %r14,%rdi
mov    $0x3ff,%edx
sub    %eax,%edx
add    $0x1,%rdx
mov    $0x41,%esi
call   1090 <memset@plt>
movb   $0x0,0x3ff(%r14)
lea    0x30(%rsp),%r12
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1090 <memset@plt>
mov    0x2c25(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x40(%rsp)
mov    0x2bf8(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x3c(%rsp)
lea    0x28(%rsp),%rcx
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r12,%rdx
call   1120 <getaddrinfo@plt>
test   %rax,%rax
jne    14be <main+0x29e>
mov    0x28(%rsp),%rax
mov    0x10(%rax),%edi
mov    0x8(%rax),%edx
mov    0xc(%rax),%esi
call   1140 <socket@plt>
cmp    $0xffffffff,%eax
je     14cd <main+0x2ad>
mov    %eax,%ebx
mov    0x28(%rsp),%rax
mov    (%rax),%edx
mov    0x4(%rax),%esi
mov    %ebx,%edi
call   1110 <connect@plt>
cmp    $0xffffffff,%eax
je     149a <main+0x27a>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
test   %eax,%eax
js     14a8 <main+0x288>
mov    %r15d,%ebp
jmp    1455 <main+0x235>
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
test   %eax,%eax
js     14a8 <main+0x288>
sub    $0x1,%ebp
setb   %al
test   %r15d,%r15d
jle    1440 <main+0x220>
test   %al,%al
je     1440 <main+0x220>
mov    0x28(%rsp),%rdi
call   1130 <freeaddrinfo@plt>
mov    %ebx,%edi
call   10a0 <close@plt>
mov    %r14,%rdi
call   1030 <free@plt>
lea    0xcf5(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcb9(%rip),%rdi
call   10d0 <perror@plt>
jmp    1464 <main+0x244>
lea    0xcbc(%rip),%rdi
call   10d0 <perror@plt>
mov    $0xffffffff,%edi
call   1100 <exit@plt>
mov    $0x1,%edi
call   1080 <gai_strerror@plt>
mov    %rax,%rdi
jmp    14af <main+0x28f>
lea    0xc71(%rip),%rdi
jmp    14af <main+0x28f>

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32, i32, i32, i32 }
@.str = [5 x i8] c"1234\00"
@.str.1 = [10 x i8] c"127.0.0.1\00"
@.str.2 = [9 x i8] c"p:h:m:n:\00"
@optarg = global i8* null
@optopt = global i8 0
@stderr = global i32 0
@.str.3 = [33 x i8] c"Option %c requires an argument.\0A\00"
@.str.4 = [23 x i8] c"Unknown argument: %c.\0A\00"
@.str.5 = [25 x i8] c"Sending packets forever\0A\00"
@.str.6 = [19 x i8] c"Sending %d packets\00"
@.str.7 = [26 x i8] c"server_ip: %s port: %s\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.8 = [21 x i8] c"ERROR opening socket\00"
@.str.9 = [17 x i8] c"ERROR on connect\00"
@.str.10 = [14 x i8] c"ERROR on send\00"
@.str.11 = [7 x i8] c"Done.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca %struct.addrinfo
%13 = alloca %struct.addrinfo*
%14 = alloca i32
%15 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %6
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8** %7
%16 = call i8* @malloc(i32 1024)
store i8* %16, i8** %8
store i32 -1, i32* %15
br label %17
17: ; preds = %50, %2
%18 = load i32, i32* %4
%19 = load i8**, i8*** %5
%20 = call i32 @getopt(i32 %18, i8** %19, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
store i32 %20, i32* %14
%21 = icmp ne i32 %20, -1
br i1 %21, label %22, label %51
22: ; preds = %17
%23 = load i32, i32* %14
switch i32 %23, label %50 [
i32 112, label %24
i32 104, label %26
i32 109, label %28
i32 110, label %30
i32 63, label %33
]
24: ; preds = %22
%25 = load i8*, i8** @optarg
store i8* %25, i8** %6
br label %50
26: ; preds = %22
%27 = load i8*, i8** @optarg
store i8* %27, i8** %7
br label %50
28: ; preds = %22
%29 = load i8*, i8** @optarg
store i8* %29, i8** %8
br label %50
30: ; preds = %22
%31 = load i8*, i8** @optarg
%32 = call i32 @atoi(i8* %31)
store i32 %32, i32* %15
br label %50
33: ; preds = %22
%34 = load i8, i8* @optopt
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 112
br i1 %36, label %41, label %37
37: ; preds = %33
%38 = load i8, i8* @optopt
%39 = sext i8 %38 to i32
%40 = icmp eq i32 %39, 104
br i1 %40, label %41, label %45
41: ; preds = %37, %33
%42 = load i32, i32* @stderr
%43 = load i8, i8* @optopt
%44 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i8 signext %43)
br label %49
45: ; preds = %37
%46 = load i32, i32* @stderr
%47 = load i8, i8* @optopt
%48 = call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8 signext %47)
br label %49
49: ; preds = %45, %41
br label %50
50: ; preds = %22, %49, %30, %28, %26, %24
br label %17
51: ; preds = %17
%52 = load i32, i32* %15
%53 = icmp slt i32 %52, 0
br i1 %53, label %54, label %56
54: ; preds = %51
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0))
br label %59
56: ; preds = %51
%57 = load i32, i32* %15
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i32 %57)
br label %59
59: ; preds = %56, %54
%60 = load i8*, i8** %7
%61 = load i8*, i8** %6
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0), i8* %60, i8* %61)
%63 = load i8*, i8** %8
%64 = call i32 @strlen(i8* %63)
store i32 %64, i32* %11
br label %65
65: ; preds = %73, %59
%66 = load i32, i32* %11
%67 = icmp slt i32 %66, 1024
br i1 %67, label %68, label %76
68: ; preds = %65
%69 = load i8*, i8** %8
%70 = load i32, i32* %11
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds i8, i8* %69, i64 %71
store i8 65, i8* %72
br label %73
73: ; preds = %68
%74 = load i32, i32* %11
%75 = add nsw i32 %74, 1
store i32 %75, i32* %11
br label %65
76: ; preds = %65
%77 = load i8*, i8** %8
%78 = getelementptr inbounds i8, i8* %77, i64 1023
store i8 0, i8* %78
%79 = call i32 @memset(%struct.addrinfo* %12, i32 0, i32 20)
%80 = load i32, i32* @AF_INET
%81 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %12, i32 0, i32 4
store i32 %80, i32* %81
%82 = load i32, i32* @SOCK_STREAM
%83 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %12, i32 0, i32 3
store i32 %82, i32* %83
%84 = load i8*, i8** %7
%85 = load i8*, i8** %6
%86 = call i64 @getaddrinfo(i8* %84, i8* %85, %struct.addrinfo* %12, %struct.addrinfo** %13)
%87 = icmp ne i64 %86, 0
%88 = zext i1 %87 to i32
store i32 %88, i32* %10
br i1 %87, label %89, label %94
89: ; preds = %76
%90 = load i32, i32* %10
%91 = call i8* @gai_strerror(i32 %90)
%92 = call i32 @perror(i8* %91)
%93 = call i32 @exit(i32 -1)
unreachable
94: ; preds = %76
%95 = load %struct.addrinfo*, %struct.addrinfo** %13
%96 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %95, i32 0, i32 4
%97 = load i32, i32* %96
%98 = load %struct.addrinfo*, %struct.addrinfo** %13
%99 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %98, i32 0, i32 3
%100 = load i32, i32* %99
%101 = load %struct.addrinfo*, %struct.addrinfo** %13
%102 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %101, i32 0, i32 2
%103 = load i32, i32* %102
%104 = call i32 @socket(i32 %97, i32 %100, i32 %103)
store i32 %104, i32* %9
%105 = load i32, i32* %9
%106 = icmp eq i32 %105, -1
br i1 %106, label %107, label %110
107: ; preds = %94
%108 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0))
%109 = call i32 @exit(i32 -1)
unreachable
110: ; preds = %94
%111 = load i32, i32* %9
%112 = load %struct.addrinfo*, %struct.addrinfo** %13
%113 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %112, i32 0, i32 1
%114 = load i32, i32* %113
%115 = load %struct.addrinfo*, %struct.addrinfo** %13
%116 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %115, i32 0, i32 0
%117 = load i32, i32* %116
%118 = call i32 @connect(i32 %111, i32 %114, i32 %117)
store i32 %118, i32* %10
%119 = load i32, i32* %10
%120 = icmp eq i32 %119, -1
br i1 %120, label %121, label %123
121: ; preds = %110
%122 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.9, i64 0, i64 0))
br label %145
123: ; preds = %110
store i32 0, i32* %11
br label %124
124: ; preds = %123, %141
%125 = load i32, i32* %9
%126 = load i8*, i8** %8
%127 = call i32 @send(i32 %125, i8* %126, i32 1024, i32 0)
store i32 %127, i32* %10
%128 = load i32, i32* %10
%129 = icmp slt i32 %128, 0
br i1 %129, label %130, label %133
130: ; preds = %124
%131 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.10, i64 0, i64 0))
%132 = call i32 @exit(i32 -1)
unreachable
133: ; preds = %124
%134 = load i32, i32* %15
%135 = icmp sgt i32 %134, 0
br i1 %135, label %136, label %141
136: ; preds = %133
%137 = load i32, i32* %11
%138 = load i32, i32* %15
%139 = icmp eq i32 %137, %138
br i1 %139, label %140, label %141
140: ; preds = %136
br label %144
141: ; preds = %136, %133
%142 = load i32, i32* %11
%143 = add nsw i32 %142, 1
store i32 %143, i32* %11
br label %124
144: ; preds = %140
br label %145
145: ; preds = %144, %121
%146 = load %struct.addrinfo*, %struct.addrinfo** %13
%147 = call i32 @freeaddrinfo(%struct.addrinfo* %146)
%148 = load i32, i32* %9
%149 = call i32 @close(i32 %148)
%150 = load i8*, i8** %8
%151 = call i32 @free(i8* %150)
%152 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, i32, i32, i32 }
@.str = [5 x i8] c"1234\00"
@.str.1 = [10 x i8] c"127.0.0.1\00"
@.str.2 = [9 x i8] c"p:h:m:n:\00"
@optarg = global i8* null
@optopt = global i8 0
@stderr = global i32 0
@.str.3 = [33 x i8] c"Option %c requires an argument.\0A\00"
@.str.4 = [23 x i8] c"Unknown argument: %c.\0A\00"
@.str.6 = [19 x i8] c"Sending %d packets\00"
@.str.7 = [26 x i8] c"server_ip: %s port: %s\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.8 = [21 x i8] c"ERROR opening socket\00"
@.str.9 = [17 x i8] c"ERROR on connect\00"
@.str.10 = [14 x i8] c"ERROR on send\00"
@str = [6 x i8] c"Done.\00"
@str.12 = [24 x i8] c"Sending packets forever\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca %struct.addrinfo
%4 = alloca %struct.addrinfo*
%5 = tail call dereferenceable_or_null(1024) i8* @malloc(i32 1024)
%6 = bitcast %struct.addrinfo* %3 to i8*
%7 = bitcast %struct.addrinfo** %4 to i8*
br label %8
8: ; preds = %29, %2
%9 = phi i8* [ %30, %29 ], [ %5, %2 ]
%10 = phi i8* [ %14, %29 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), %2 ]
%11 = phi i8* [ %18, %29 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %2 ]
%12 = phi i32 [ %21, %29 ], [ -1, %2 ]
br label %13
13: ; preds = %8, %27
%14 = phi i8* [ %10, %8 ], [ %28, %27 ]
%15 = phi i8* [ %11, %8 ], [ %18, %27 ]
%16 = phi i32 [ %12, %8 ], [ %21, %27 ]
br label %17
17: ; preds = %13, %25
%18 = phi i8* [ %15, %13 ], [ %26, %25 ]
%19 = phi i32 [ %16, %13 ], [ %21, %25 ]
br label %20
20: ; preds = %17, %31
%21 = phi i32 [ %19, %17 ], [ %33, %31 ]
br label %22
22: ; preds = %24, %20
%23 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
switch i32 %23, label %24 [
i32 -1, label %42
i32 112, label %25
i32 104, label %27
i32 109, label %29
i32 110, label %31
i32 63, label %34
]
24: ; preds = %22, %36, %39
br label %22
25: ; preds = %22
%26 = load i8*, i8** @optarg
br label %17
27: ; preds = %22
%28 = load i8*, i8** @optarg
br label %13
29: ; preds = %22
%30 = load i8*, i8** @optarg
br label %8
31: ; preds = %22
%32 = load i8*, i8** @optarg
%33 = tail call i32 @atoi(i8* %32)
br label %20
34: ; preds = %22
%35 = load i8, i8* @optopt
switch i8 %35, label %39 [
i8 112, label %36
i8 104, label %36
]
36: ; preds = %34, %34
%37 = load i32, i32* @stderr
%38 = tail call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i8 signext %35)
br label %24
39: ; preds = %34
%40 = load i32, i32* @stderr
%41 = tail call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8 signext %35)
br label %24
42: ; preds = %22
%43 = icmp slt i32 %21, 0
br i1 %43, label %44, label %46
44: ; preds = %42
%45 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.12, i64 0, i64 0))
br label %48
46: ; preds = %42
%47 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i32 %21)
br label %48
48: ; preds = %46, %44
%49 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0), i8* %14, i8* %18)
%50 = tail call i32 @strlen(i8* %9)
%51 = icmp slt i32 %50, 1024
br i1 %51, label %52, label %58
52: ; preds = %48
%53 = sext i32 %50 to i64
%54 = getelementptr i8, i8* %9, i64 %53
%55 = sub i32 1023, %50
%56 = zext i32 %55 to i64
%57 = add nuw nsw i64 %56, 1
br label %58
58: ; preds = %52, %48
%59 = getelementptr inbounds i8, i8* %9, i64 1023
store i8 0, i8* %59
%60 = call i32 @memset(%struct.addrinfo* %3, i32 0, i32 20)
%61 = load i32, i32* @AF_INET
%62 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 4
store i32 %61, i32* %62
%63 = load i32, i32* @SOCK_STREAM
%64 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 3
store i32 %63, i32* %64
%65 = call i64 @getaddrinfo(i8* %14, i8* %18, %struct.addrinfo* %3, %struct.addrinfo** %4)
%66 = icmp eq i64 %65, 0
br i1 %66, label %71, label %67
67: ; preds = %58
%68 = call i8* @gai_strerror(i32 1)
%69 = call i32 @perror(i8* %68)
%70 = call i32 @exit(i32 -1)
unreachable
71: ; preds = %58
%72 = load %struct.addrinfo*, %struct.addrinfo** %4
%73 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %72, i64 0, i32 4
%74 = load i32, i32* %73
%75 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %72, i64 0, i32 3
%76 = load i32, i32* %75
%77 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %72, i64 0, i32 2
%78 = load i32, i32* %77
%79 = call i32 @socket(i32 %74, i32 %76, i32 %78)
%80 = icmp eq i32 %79, -1
br i1 %80, label %81, label %84
81: ; preds = %71
%82 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0))
%83 = call i32 @exit(i32 -1)
unreachable
84: ; preds = %71
%85 = load %struct.addrinfo*, %struct.addrinfo** %4
%86 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %85, i64 0, i32 1
%87 = load i32, i32* %86
%88 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %85, i64 0, i32 0
%89 = load i32, i32* %88
%90 = call i32 @connect(i32 %79, i32 %87, i32 %89)
%91 = icmp eq i32 %90, -1
br i1 %91, label %97, label %92
92: ; preds = %84
%93 = call i32 @send(i32 %79, i8* %9, i32 1024, i32 0)
%94 = icmp slt i32 %93, 0
br i1 %94, label %103, label %95
95: ; preds = %92
%96 = icmp sgt i32 %21, 0
br label %106
97: ; preds = %84
%98 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.9, i64 0, i64 0))
br label %110
99: ; preds = %106
%100 = add nuw nsw i32 %107, 1
%101 = call i32 @send(i32 %79, i8* %9, i32 1024, i32 0)
%102 = icmp slt i32 %101, 0
br i1 %102, label %103, label %106
103: ; preds = %99, %92
%104 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.10, i64 0, i64 0))
%105 = call i32 @exit(i32 -1)
unreachable
106: ; preds = %95, %99
%107 = phi i32 [ 0, %95 ], [ %100, %99 ]
%108 = icmp eq i32 %107, %21
%109 = select i1 %96, i1 %108, i1 false
br i1 %109, label %110, label %99
110: ; preds = %106, %97
%111 = load %struct.addrinfo*, %struct.addrinfo** %4
%112 = call i32 @freeaddrinfo(%struct.addrinfo* %111)
%113 = call i32 @close(i32 %79)
%114 = call i32 @free(i8* %9)
%115 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
ret i32 0
}