#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_next;
  int /*<<< orphan*/ *ai_canonname;
  scalar_t__ ai_protocol;
  int /*<<< orphan*/ ai_flags;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
};
typedef int /*<<< orphan*/ len;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ AF_UNSPEC;
int /*<<< orphan*/ AI_PASSIVE;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
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 *, char *);
int read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int write(int, ...);
int main(int argc, char *argv[]) {
  int s, fd, len = 1;
  struct addrinfo hints;
  struct addrinfo *result;
  char buf[1024];
  char cmd;
  int bytes;
  if (argc < 2) {
    fprintf(stderr, "Enter name/ip of host to connect to\n");
    exit(1);
  }
  if (argc < 3 ||
      (strcmp(argv[2], "snapshot") != 0 && strcmp(argv[2], "summary") != 0)) {
    fprintf(stderr, "command must be 'snapshot' or 'summary'\n");
    exit(1);
  }
  if (strcmp(argv[2], "summary") == 0) {
    cmd = '1';
  } else {
    cmd = '2';
  }
  memset(&hints, 0, sizeof(struct addrinfo));
  hints.ai_family = AF_UNSPEC;
  hints.ai_socktype = SOCK_DGRAM;
  hints.ai_flags = AI_PASSIVE;
  hints.ai_protocol = 0;
  hints.ai_canonname = NULL;
  hints.ai_addr = NULL;
  hints.ai_next = NULL;
  s = getaddrinfo(argv[1], "5678", &hints, &result);
  if (s != 0) {
    fprintf(stderr, "getaddrinfo %s\n", gai_strerror(s));
    exit(1);
  }
  fd = socket(AF_INET, SOCK_STREAM, 0);
  if (fd < 0) {
    perror("socket");
    exit(1);
  }
  printf("connecting to server at %s\n", argv[1]);
  if (connect(fd, result->ai_addr, result->ai_addrlen) < 0) {
    perror("connect");
    exit(1);
  }
  bytes = write(fd, &len, sizeof(len));
  if (bytes != sizeof(len)) {
    fprintf(stderr, "expented %d got %d: ", sizeof(len), bytes);
    perror("write len");
    exit(1);
  }
  if (write(fd, &cmd, 1) != 1) {
    perror("write cmd");
    exit(1);
  }
  while ((bytes = read(fd, buf, 1024)) != 0) {
    write(1, buf, bytes);
  }
  write(1, "\n", 1);
  close(fd);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x470,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x1c(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    121b <main+0x4b>
mov    0x2dbf(%rip),%rax
mov    (%rax),%edi
lea    0xdf6(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
cmpl   $0x3,-0x8(%rbp)
jl     1261 <main+0x91>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xdf1(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
je     1282 <main+0xb2>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xddc(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
je     1282 <main+0xb2>
mov    0x2d58(%rip),%rax
mov    (%rax),%edi
lea    0xdc5(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xd9d(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    12ac <main+0xdc>
movb   $0x31,-0x461(%rbp)
jmp    12b3 <main+0xe3>
movb   $0x32,-0x461(%rbp)
lea    -0x58(%rbp),%rdi
xor    %esi,%esi
mov    $0x38,%edx
call   1060 <memset@plt>
mov    0x2d0e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2cfa(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2d06(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x50(%rbp)
movq   $0x0,-0x48(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd49(%rip),%rsi
lea    -0x58(%rbp),%rdx
lea    -0x60(%rbp),%rcx
call   10e0 <getaddrinfo@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1368 <main+0x198>
mov    0x2c89(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x46c(%rbp)
mov    -0x14(%rbp),%edi
call   1050 <gai_strerror@plt>
mov    -0x46c(%rbp),%edi
mov    %rax,%rdx
lea    0xd0d(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    0x2c71(%rip),%rax
mov    (%rax),%edi
mov    0x2c40(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    13a4 <main+0x1d4>
lea    0xcdf(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xcc8(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%edi
mov    -0x60(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x60(%rbp),%rax
mov    (%rax),%edx
call   10d0 <connect@plt>
cmp    $0x0,%rax
jge    13ee <main+0x21e>
lea    0xcb8(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x18(%rbp),%edi
lea    -0x1c(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1030 <write@plt>
mov    %eax,-0x468(%rbp)
movslq -0x468(%rbp),%rax
cmp    $0x4,%rax
je     1450 <main+0x280>
mov    0x2ba1(%rip),%rax
mov    (%rax),%edi
mov    -0x468(%rbp),%ecx
lea    0xc71(%rip),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   10a0 <fprintf@plt>
lea    0xc73(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x18(%rbp),%edi
lea    -0x461(%rbp),%rsi
mov    $0x1,%edx
mov    $0x0,%al
call   1030 <write@plt>
cmp    $0x1,%eax
je     1485 <main+0x2b5>
lea    0xc48(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
jmp    148a <main+0x2ba>
mov    -0x18(%rbp),%edi
lea    -0x460(%rbp),%rsi
mov    $0x400,%edx
call   1080 <read@plt>
mov    %eax,-0x468(%rbp)
cmp    $0x0,%eax
je     14cb <main+0x2fb>
lea    -0x460(%rbp),%rsi
mov    -0x468(%rbp),%edx
mov    $0x1,%edi
mov    $0x0,%al
call   1030 <write@plt>
jmp    148a <main+0x2ba>
mov    $0x1,%edx
lea    0xb86(%rip),%rsi
mov    %edx,%edi
mov    $0x0,%al
call   1030 <write@plt>
mov    -0x18(%rbp),%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x470,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x450,%rsp
movl   $0x1,0xc(%rsp)
cmp    $0x1,%edi
jle    13b3 <main+0x1e3>
cmp    $0x2,%edi
je     13a1 <main+0x1d1>
mov    %rsi,%r14
mov    0x10(%rsi),%rdi
lea    0xe22(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     1226 <main+0x56>
mov    0x10(%r14),%rdi
lea    0xe16(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
jne    13a1 <main+0x1d1>
mov    0x10(%r14),%rdi
lea    0xdfd(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x1,%rax
mov    $0x32,%al
sbb    $0x0,%al
mov    %al,0xb(%rsp)
lea    0x18(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x38,%edx
call   1060 <memset@plt>
mov    0x2d7b(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x48(%rsp)
mov    0x2d66(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x44(%rsp)
mov    0x2d71(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x40(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x20(%rsp)
movups %xmm0,0x30(%rsp)
mov    0x8(%r14),%rdi
lea    0xdca(%rip),%rsi
lea    0x10(%rsp),%rcx
mov    %rbx,%rdx
call   10e0 <getaddrinfo@plt>
test   %eax,%eax
jne    13d4 <main+0x204>
mov    0x2d2f(%rip),%rax
mov    (%rax),%edi
mov    0x2cfe(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
test   %eax,%eax
js     1401 <main+0x231>
mov    %eax,%ebp
mov    0x8(%r14),%rsi
lea    0xda3(%rip),%rdi
call   1040 <printf@plt>
mov    0x10(%rsp),%rax
mov    0x8(%rax),%rsi
mov    (%rax),%edx
mov    %ebp,%edi
call   10d0 <connect@plt>
test   %rax,%rax
js     140a <main+0x23a>
lea    0xc(%rsp),%rsi
mov    $0x4,%edx
mov    %ebp,%edi
xor    %eax,%eax
call   1030 <write@plt>
cmp    $0x4,%eax
jne    1413 <main+0x243>
lea    0xb(%rsp),%rsi
mov    %ebp,%edi
mov    $0x1,%edx
xor    %eax,%eax
call   1030 <write@plt>
cmp    $0x1,%eax
jne    143a <main+0x26a>
lea    0x50(%rsp),%rsi
mov    %ebp,%edi
mov    $0x400,%edx
call   1080 <read@plt>
test   %eax,%eax
je     1374 <main+0x1a4>
lea    0x50(%rsp),%rbx
nopw   0x0(%rax,%rax,1)
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <write@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1080 <read@plt>
test   %eax,%eax
jne    1350 <main+0x180>
lea    0xce2(%rip),%rsi
mov    $0x1,%edi
mov    $0x1,%edx
xor    %eax,%eax
call   1030 <write@plt>
mov    %ebp,%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x450,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2c18(%rip),%rax
mov    (%rax),%edi
lea    0xc85(%rip),%rsi
jmp    13c3 <main+0x1f3>
mov    0x2c06(%rip),%rax
mov    (%rax),%edi
lea    0xc3d(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    0x2be5(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1050 <gai_strerror@plt>
lea    0xc79(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
lea    0xc6c(%rip),%rdi
jmp    1441 <main+0x271>
lea    0xc86(%rip),%rdi
jmp    1441 <main+0x271>
mov    0x2ba6(%rip),%rcx
mov    (%rcx),%edi
lea    0xc7c(%rip),%rsi
mov    $0x4,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   10a0 <fprintf@plt>
lea    0xc7c(%rip),%rdi
jmp    1441 <main+0x271>
lea    0xc7d(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32*, i32*, i32*, i64, i32, i32, i32 }
@stderr = global i32 0
@.str = [37 x i8] c"Enter name/ip of host to connect to\0A\00"
@.str.1 = [9 x i8] c"snapshot\00"
@.str.2 = [8 x i8] c"summary\00"
@.str.3 = [41 x i8] c"command must be 'snapshot' or 'summary'\0A\00"
@AF_UNSPEC = global i32 0
@SOCK_DGRAM = global i32 0
@AI_PASSIVE = global i32 0
@.str.4 = [5 x i8] c"5678\00"
@.str.5 = [16 x i8] c"getaddrinfo %s\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.6 = [7 x i8] c"socket\00"
@.str.7 = [28 x i8] c"connecting to server at %s\0A\00"
@.str.8 = [8 x i8] c"connect\00"
@.str.9 = [21 x i8] c"expented %d got %d: \00"
@.str.10 = [10 x i8] c"write len\00"
@.str.11 = [10 x i8] c"write cmd\00"
@.str.12 = [2 x i8] c"\0A\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 %struct.addrinfo
%10 = alloca %struct.addrinfo*
%11 = alloca [1024 x i8]
%12 = alloca i8
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %8
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 2
br i1 %15, label %16, label %20
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %2
%21 = load i32, i32* %4
%22 = icmp slt i32 %21, 3
br i1 %22, label %35, label %23
23: ; preds = %20
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 2
%26 = load i8*, i8** %25
%27 = call i64 @strcmp(i8* %26, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %39
29: ; preds = %23
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 2
%32 = load i8*, i8** %31
%33 = call i64 @strcmp(i8* %32, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %39
35: ; preds = %29, %20
%36 = load i32, i32* @stderr
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0))
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %29, %23
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 2
%42 = load i8*, i8** %41
%43 = call i64 @strcmp(i8* %42, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %46
45: ; preds = %39
store i8 49, i8* %12
br label %47
46: ; preds = %39
store i8 50, i8* %12
br label %47
47: ; preds = %46, %45
%48 = call i32 @memset(%struct.addrinfo* %9, i32 0, i32 56)
%49 = load i32, i32* @AF_UNSPEC
%50 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %9, i32 0, i32 7
store i32 %49, i32* %50
%51 = load i32, i32* @SOCK_DGRAM
%52 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %9, i32 0, i32 6
store i32 %51, i32* %52
%53 = load i32, i32* @AI_PASSIVE
%54 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %9, i32 0, i32 5
store i32 %53, i32* %54
%55 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %9, i32 0, i32 4
store i64 0, i64* %55
%56 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %9, i32 0, i32 3
store i32* null, i32** %56
%57 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %9, i32 0, i32 1
store i32* null, i32** %57
%58 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %9, i32 0, i32 2
store i32* null, i32** %58
%59 = load i8**, i8*** %5
%60 = getelementptr inbounds i8*, i8** %59, i64 1
%61 = load i8*, i8** %60
%62 = call i32 @getaddrinfo(i8* %61, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), %struct.addrinfo* %9, %struct.addrinfo** %10)
store i32 %62, i32* %6
%63 = load i32, i32* %6
%64 = icmp ne i32 %63, 0
br i1 %64, label %65, label %71
65: ; preds = %47
%66 = load i32, i32* @stderr
%67 = load i32, i32* %6
%68 = call i8* @gai_strerror(i32 %67)
%69 = call i32 (i32, i8*, ...) @fprintf(i32 %66, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i8* %68)
%70 = call i32 @exit(i32 1)
unreachable
71: ; preds = %47
%72 = load i32, i32* @AF_INET
%73 = load i32, i32* @SOCK_STREAM
%74 = call i32 @socket(i32 %72, i32 %73, i32 0)
store i32 %74, i32* %7
%75 = load i32, i32* %7
%76 = icmp slt i32 %75, 0
br i1 %76, label %77, label %80
77: ; preds = %71
%78 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%79 = call i32 @exit(i32 1)
unreachable
80: ; preds = %71
%81 = load i8**, i8*** %5
%82 = getelementptr inbounds i8*, i8** %81, i64 1
%83 = load i8*, i8** %82
%84 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0), i8* %83)
%85 = load i32, i32* %7
%86 = load %struct.addrinfo*, %struct.addrinfo** %10
%87 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %86, i32 0, i32 1
%88 = load i32*, i32** %87
%89 = load %struct.addrinfo*, %struct.addrinfo** %10
%90 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %89, i32 0, i32 0
%91 = load i32, i32* %90
%92 = call i64 @connect(i32 %85, i32* %88, i32 %91)
%93 = icmp slt i64 %92, 0
br i1 %93, label %94, label %97
94: ; preds = %80
%95 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0))
%96 = call i32 @exit(i32 1)
unreachable
97: ; preds = %80
%98 = load i32, i32* %7
%99 = call i32 (i32, ...) @write(i32 %98, i32* %8, i64 4)
store i32 %99, i32* %13
%100 = load i32, i32* %13
%101 = sext i32 %100 to i64
%102 = icmp ne i64 %101, 4
br i1 %102, label %103, label %109
103: ; preds = %97
%104 = load i32, i32* @stderr
%105 = load i32, i32* %13
%106 = call i32 (i32, i8*, ...) @fprintf(i32 %104, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.9, i64 0, i64 0), i64 4, i32 %105)
%107 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i64 0, i64 0))
%108 = call i32 @exit(i32 1)
unreachable
109: ; preds = %97
%110 = load i32, i32* %7
%111 = call i32 (i32, ...) @write(i32 %110, i8* %12, i32 1)
%112 = icmp ne i32 %111, 1
br i1 %112, label %113, label %116
113: ; preds = %109
%114 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.11, i64 0, i64 0))
%115 = call i32 @exit(i32 1)
unreachable
116: ; preds = %109
br label %117
117: ; preds = %122, %116
%118 = load i32, i32* %7
%119 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%120 = call i32 @read(i32 %118, i8* %119, i32 1024)
store i32 %120, i32* %13
%121 = icmp ne i32 %120, 0
br i1 %121, label %122, label %126
122: ; preds = %117
%123 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%124 = load i32, i32* %13
%125 = call i32 (i32, ...) @write(i32 1, i8* %123, i32 %124)
br label %117
126: ; preds = %117
%127 = call i32 (i32, ...) @write(i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.12, i64 0, i64 0), i32 1)
%128 = load i32, i32* %7
%129 = call i32 @close(i32 %128)
ret i32 0
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32*, i32*, i32*, i64, i32, i32, i32 }
@stderr = global i32 0
@.str = [37 x i8] c"Enter name/ip of host to connect to\0A\00"
@.str.1 = [9 x i8] c"snapshot\00"
@.str.2 = [8 x i8] c"summary\00"
@.str.3 = [41 x i8] c"command must be 'snapshot' or 'summary'\0A\00"
@AF_UNSPEC = global i32 0
@SOCK_DGRAM = global i32 0
@AI_PASSIVE = global i32 0
@.str.4 = [5 x i8] c"5678\00"
@.str.5 = [16 x i8] c"getaddrinfo %s\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.6 = [7 x i8] c"socket\00"
@.str.7 = [28 x i8] c"connecting to server at %s\0A\00"
@.str.8 = [8 x i8] c"connect\00"
@.str.9 = [21 x i8] c"expented %d got %d: \00"
@.str.10 = [10 x i8] c"write len\00"
@.str.11 = [10 x i8] c"write cmd\00"
@.str.12 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca %struct.addrinfo
%5 = alloca %struct.addrinfo*
%6 = alloca [1024 x i8]
%7 = alloca i8
%8 = bitcast i32* %3 to i8*
store i32 1, i32* %3
%9 = bitcast %struct.addrinfo* %4 to i8*
%10 = bitcast %struct.addrinfo** %5 to i8*
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%12 = icmp slt i32 %0, 2
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = tail call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = icmp eq i32 %0, 2
br i1 %18, label %28, label %19
19: ; preds = %17
%20 = getelementptr inbounds i8*, i8** %1, i64 2
%21 = load i8*, i8** %20
%22 = tail call i64 @strcmp(i8* %21, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
br i1 %23, label %32, label %24
24: ; preds = %19
%25 = load i8*, i8** %20
%26 = tail call i64 @strcmp(i8* %25, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br i1 %27, label %32, label %28
28: ; preds = %24, %17
%29 = load i32, i32* @stderr
%30 = tail call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0))
%31 = tail call i32 @exit(i32 1)
unreachable
32: ; preds = %24, %19
%33 = load i8*, i8** %20
%34 = tail call i64 @strcmp(i8* %33, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%35 = icmp eq i64 %34, 0
%36 = select i1 %35, i8 49, i8 50
store i8 %36, i8* %7
%37 = call i32 @memset(%struct.addrinfo* %4, i32 0, i32 56)
%38 = load i32, i32* @AF_UNSPEC
%39 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i64 0, i32 7
store i32 %38, i32* %39
%40 = load i32, i32* @SOCK_DGRAM
%41 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i64 0, i32 6
store i32 %40, i32* %41
%42 = load i32, i32* @AI_PASSIVE
%43 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i64 0, i32 5
store i32 %42, i32* %43
%44 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i64 0, i32 1
%45 = getelementptr inbounds i8*, i8** %1, i64 1
%46 = bitcast i32** %44 to i8*
%47 = load i8*, i8** %45
%48 = call i32 @getaddrinfo(i8* %47, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), %struct.addrinfo* %4, %struct.addrinfo** %5)
%49 = icmp eq i32 %48, 0
br i1 %49, label %55, label %50
50: ; preds = %32
%51 = load i32, i32* @stderr
%52 = call i8* @gai_strerror(i32 %48)
%53 = call i32 (i32, i8*, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i8* %52)
%54 = call i32 @exit(i32 1)
unreachable
55: ; preds = %32
%56 = load i32, i32* @AF_INET
%57 = load i32, i32* @SOCK_STREAM
%58 = call i32 @socket(i32 %56, i32 %57, i32 0)
%59 = icmp slt i32 %58, 0
br i1 %59, label %60, label %63
60: ; preds = %55
%61 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%62 = call i32 @exit(i32 1)
unreachable
63: ; preds = %55
%64 = load i8*, i8** %45
%65 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0), i8* %64)
%66 = load %struct.addrinfo*, %struct.addrinfo** %5
%67 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %66, i64 0, i32 1
%68 = load i32*, i32** %67
%69 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %66, i64 0, i32 0
%70 = load i32, i32* %69
%71 = call i64 @connect(i32 %58, i32* %68, i32 %70)
%72 = icmp slt i64 %71, 0
br i1 %72, label %73, label %76
73: ; preds = %63
%74 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0))
%75 = call i32 @exit(i32 1)
unreachable
76: ; preds = %63
%77 = call i32 (i32, ...) @write(i32 %58, i32* %3, i64 4)
%78 = icmp eq i32 %77, 4
br i1 %78, label %84, label %79
79: ; preds = %76
%80 = load i32, i32* @stderr
%81 = call i32 (i32, i8*, ...) @fprintf(i32 %80, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.9, i64 0, i64 0), i64 4, i32 %77)
%82 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i64 0, i64 0))
%83 = call i32 @exit(i32 1)
unreachable
84: ; preds = %76
%85 = call i32 (i32, ...) @write(i32 %58, i8* %7, i32 1)
%86 = icmp eq i32 %85, 1
br i1 %86, label %87, label %90
87: ; preds = %84
%88 = call i32 @read(i32 %58, i8* %11, i32 1024)
%89 = icmp eq i32 %88, 0
br i1 %89, label %98, label %93
90: ; preds = %84
%91 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.11, i64 0, i64 0))
%92 = call i32 @exit(i32 1)
unreachable
93: ; preds = %87, %93
%94 = phi i32 [ %96, %93 ], [ %88, %87 ]
%95 = call i32 (i32, ...) @write(i32 1, i8* %11, i32 %94)
%96 = call i32 @read(i32 %58, i8* %11, i32 1024)
%97 = icmp eq i32 %96, 0
br i1 %97, label %98, label %93
98: ; preds = %93, %87
%99 = call i32 (i32, ...) @write(i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.12, i64 0, i64 0), i32 1)
%100 = call i32 @close(i32 %58)
ret i32 0
}