#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 {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  int dummy;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ server_addr;
typedef int /*<<< orphan*/ buf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int atoi(char *);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
char *get_ip_addr();
struct hostent *gethostbyname(char *);
scalar_t__ getline(char **, int *, int /*<<< orphan*/ *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *,
                    int *);
scalar_t__ sendto(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, char *, int);
int /*<<< orphan*/ sscanf(char *, char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char *, char *);
int strlen(char *);
int /*<<< orphan*/ *strstr(char *, char *);
int main(int argc, char **argv) {
  int sockfd;
  struct sockaddr_in server_addr;
  struct hostent *server;
  char buf[1024];
  char ip_addr[1024];
  char *my_ip_addr;
  char *line;
  int port, examine_port;
  int line_length;
  int message_size;
  FILE *fp;
  my_ip_addr = get_ip_addr();
  printf("My ip addr is: %s\n", my_ip_addr);
  if (argc != 2) {
    fprintf(stderr, "Error, exiting. Usage: ./get_tshark <port_to_examine>\n");
    exit(1);
  }
  examine_port = atoi(argv[1]);
  fp = fopen("config_file", "r");
  if (fp == NULL) {
    fprintf(stderr,
            "Error opening config file with name 'config_file'. Exiting.\n");
    exit(1);
  }
  printf("Reading input file...\n");
  while (getline(&line, &line_length, fp) > 0) {
    if (strstr(line, "host_ip") != NULL) {
      sscanf(line, "host_ip: %s\n", ip_addr);
    } else if (strstr(line, "port") != NULL) {
      sscanf(line, "port: %d\n", &port);
    }
  }
  fclose(fp);
  printf("Connecting to: %s:%d\n", ip_addr, port);
  server = gethostbyname(ip_addr);
  socklen_t len = sizeof(server_addr);
  sockfd = socket(AF_INET, SOCK_DGRAM, 0);
  bzero((char *)&server_addr, sizeof(server_addr));
  server_addr.sin_family = AF_INET;
  server_addr.sin_addr.s_addr = inet_addr(ip_addr);
  server_addr.sin_port = htons(port);
  memset(buf, 0, sizeof(buf));
  sprintf(buf, "ip_addr: %s examine_port: %d", my_ip_addr, examine_port);
  printf("sending message '%s' to get_tshark server.\n", buf);
  if (sendto(sockfd, buf, strlen(buf), 0, (struct sockaddr *)&server_addr,
             len) < 0) {
    fprintf(stderr, "Failed to send.\n");
    exit(0);
  }
  printf("The server will send a response in approximately 1 minute.\n");
  memset(buf, 0, sizeof(buf));
  if (recvfrom(sockfd, buf, 1024, 0, (struct sockaddr *)&server_addr, &len) <
      0) {
    fprintf(stderr, "Failed to receive.\n");
    exit(0);
  }
  printf("Received from server: %s\n", buf);
  while (1) {
    memset(buf, 0, sizeof(buf));
    if (recvfrom(sockfd, buf, 1024, 0, (struct sockaddr *)&server_addr, &len) <
        0) {
      fprintf(stderr, "Failed to receive.\n");
      exit(0);
    }
    message_size = strlen(buf);
    printf("Received %i bytes from server: %s\n", message_size, buf);
    if (!strcmp(buf, "stop"))
      break;
  }
  close(sockfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x870,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   10a0 <get_ip_addr@plt>
mov    %rax,-0x838(%rbp)
mov    -0x838(%rbp),%rsi
lea    0xd6b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
cmpl   $0x2,-0x8(%rbp)
je     12c5 <main+0x65>
mov    0x2d23(%rip),%rax
mov    (%rax),%edi
lea    0xd5d(%rip),%rsi
call   10e0 <fprintf@plt>
mov    $0x1,%edi
call   1160 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1130 <atoi@plt>
mov    %eax,-0x848(%rbp)
lea    0xd6b(%rip),%rdi
lea    0xd70(%rip),%rsi
call   1110 <fopen@plt>
mov    %rax,-0x858(%rbp)
cmpq   $0x0,-0x858(%rbp)
jne    131f <main+0xbf>
mov    0x2cc9(%rip),%rax
mov    (%rax),%edi
lea    0xd48(%rip),%rsi
call   10e0 <fprintf@plt>
mov    $0x1,%edi
call   1160 <exit@plt>
lea    0xd6f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x858(%rbp),%rdx
lea    -0x840(%rbp),%rdi
lea    -0x84c(%rbp),%rsi
call   1140 <getline@plt>
cmp    $0x0,%rax
jle    13d2 <main+0x172>
mov    -0x840(%rbp),%rdi
lea    0xd4d(%rip),%rsi
call   1170 <strstr@plt>
cmp    $0x0,%rax
je     138f <main+0x12f>
mov    -0x840(%rbp),%rdi
lea    -0x830(%rbp),%rdx
lea    0xd31(%rip),%rsi
mov    $0x0,%al
call   1100 <sscanf@plt>
jmp    13cd <main+0x16d>
mov    -0x840(%rbp),%rdi
lea    0xd24(%rip),%rsi
call   1170 <strstr@plt>
cmp    $0x0,%rax
je     13c8 <main+0x168>
mov    -0x840(%rbp),%rdi
lea    0xd0c(%rip),%rsi
lea    -0x844(%rbp),%rdx
mov    $0x0,%al
call   1100 <sscanf@plt>
jmp    13cd <main+0x16d>
jmp    132d <main+0xcd>
mov    -0x858(%rbp),%rdi
call   1030 <fclose@plt>
lea    -0x830(%rbp),%rsi
mov    -0x844(%rbp),%edx
lea    0xcde(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x830(%rbp),%rdi
call   10d0 <gethostbyname@plt>
mov    %rax,-0x28(%rbp)
movl   $0xc,-0x85c(%rbp)
mov    0x2bce(%rip),%rax
mov    (%rax),%edi
mov    0x2bbd(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1180 <socket@plt>
mov    %eax,-0x14(%rbp)
lea    -0x20(%rbp),%rdi
mov    $0xc,%esi
call   1120 <bzero@plt>
mov    0x2ba4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
lea    -0x830(%rbp),%rdi
call   10b0 <inet_addr@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x844(%rbp),%edi
call   1050 <htons@plt>
mov    %eax,-0x20(%rbp)
lea    -0x430(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
lea    -0x430(%rbp),%rdi
mov    -0x838(%rbp),%rdx
mov    -0x848(%rbp),%ecx
lea    0xc52(%rip),%rsi
call   1150 <sprintf@plt>
lea    -0x430(%rbp),%rsi
lea    0xc5c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x86c(%rbp)
lea    -0x430(%rbp),%rax
mov    %rax,-0x868(%rbp)
lea    -0x430(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x86c(%rbp),%edi
mov    -0x868(%rbp),%rsi
mov    %eax,%edx
lea    -0x20(%rbp),%r8
mov    -0x85c(%rbp),%r9d
xor    %ecx,%ecx
call   1080 <sendto@plt>
cmp    $0x0,%rax
jge    1518 <main+0x2b8>
mov    0x2acd(%rip),%rax
mov    (%rax),%edi
lea    0xc23(%rip),%rsi
call   10e0 <fprintf@plt>
xor    %edi,%edi
call   1160 <exit@plt>
lea    0xc21(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x430(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
mov    -0x14(%rbp),%edi
lea    -0x430(%rbp),%rsi
lea    -0x20(%rbp),%r8
mov    $0x400,%edx
xor    %ecx,%ecx
lea    -0x85c(%rbp),%r9
call   10f0 <recvfrom@plt>
cmp    $0x0,%rax
jge    1580 <main+0x320>
mov    0x2a65(%rip),%rax
mov    (%rax),%edi
lea    0xc08(%rip),%rsi
call   10e0 <fprintf@plt>
xor    %edi,%edi
call   1160 <exit@plt>
lea    -0x430(%rbp),%rsi
lea    0xc02(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x430(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
mov    -0x14(%rbp),%edi
lea    -0x430(%rbp),%rsi
lea    -0x20(%rbp),%r8
mov    $0x400,%edx
xor    %ecx,%ecx
lea    -0x85c(%rbp),%r9
call   10f0 <recvfrom@plt>
cmp    $0x0,%rax
jge    15ef <main+0x38f>
mov    0x29f6(%rip),%rax
mov    (%rax),%edi
lea    0xb99(%rip),%rsi
call   10e0 <fprintf@plt>
xor    %edi,%edi
call   1160 <exit@plt>
lea    -0x430(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x850(%rbp)
mov    -0x850(%rbp),%esi
lea    -0x430(%rbp),%rdx
lea    0xb95(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x430(%rbp),%rdi
lea    0xba3(%rip),%rsi
call   10c0 <strcmp@plt>
cmp    $0x0,%eax
jne    163d <main+0x3dd>
jmp    1642 <main+0x3e2>
jmp    1595 <main+0x335>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
xor    %eax,%eax
add    $0x870,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x838,%rsp
mov    %rsi,%r14
mov    %edi,%ebp
xor    %eax,%eax
call   10b0 <get_ip_addr@plt>
mov    %rax,%rbx
lea    0xd79(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
cmp    $0x2,%ebp
jne    156a <main+0x30a>
mov    0x8(%r14),%rdi
call   1130 <atoi@plt>
mov    %eax,%r14d
lea    0xd9d(%rip),%rdi
lea    0xda2(%rip),%rsi
call   1110 <fopen@plt>
test   %rax,%rax
je     157c <main+0x31c>
mov    %rax,%rbp
mov    %r14d,0x18(%rsp)
mov    %rbx,0x28(%rsp)
lea    0xea9(%rip),%rdi
call   1030 <puts@plt>
lea    0x20(%rsp),%rdi
lea    0x1c(%rsp),%rsi
mov    %rbp,%rdx
call   1140 <getline@plt>
test   %rax,%rax
jle    1381 <main+0x121>
lea    0xd98(%rip),%rbx
lea    0x20(%rsp),%r15
lea    0x1c(%rsp),%r13
lea    0x430(%rsp),%r12
jmp    1347 <main+0xe7>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
lea    0xd73(%rip),%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1100 <sscanf@plt>
mov    %r15,%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
call   1140 <getline@plt>
test   %rax,%rax
jle    1381 <main+0x121>
mov    0x20(%rsp),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
call   1170 <strstr@plt>
test   %rax,%rax
jne    1320 <main+0xc0>
mov    %r14,%rdi
lea    0xd44(%rip),%rsi
call   1170 <strstr@plt>
test   %rax,%rax
je     1334 <main+0xd4>
mov    %r14,%rdi
lea    0xd35(%rip),%rsi
lea    0x4(%rsp),%rdx
jmp    132d <main+0xcd>
mov    %rbp,%rdi
call   1040 <fclose@plt>
mov    0x4(%rsp),%edx
lea    0xd25(%rip),%rdi
lea    0x430(%rsp),%rbp
mov    %rbp,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbp,%rdi
call   10d0 <gethostbyname@plt>
movl   $0xc,(%rsp)
mov    0x2c2c(%rip),%rbx
mov    (%rbx),%edi
mov    0x2c1b(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1180 <socket@plt>
mov    %eax,%r14d
lea    0x8(%rsp),%r15
mov    %r15,%rdi
mov    $0xc,%esi
call   1120 <bzero@plt>
mov    (%rbx),%eax
mov    %eax,0x10(%rsp)
mov    %rbp,%rdi
call   10c0 <inet_addr@plt>
mov    %eax,0xc(%rsp)
mov    0x4(%rsp),%edi
call   1060 <htons@plt>
mov    %eax,0x8(%rsp)
lea    0x30(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1080 <memset@plt>
lea    0xcb2(%rip),%rsi
mov    %rbp,%rdi
mov    0x28(%rsp),%rdx
mov    0x18(%rsp),%ecx
call   1150 <sprintf@plt>
lea    0xcb7(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    %r15,%r8
mov    $0xc,%r9d
call   1090 <sendto@plt>
test   %rax,%rax
js     159b <main+0x33b>
lea    0xd26(%rip),%rdi
call   1030 <puts@plt>
lea    0x30(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1080 <memset@plt>
lea    0x8(%rsp),%r8
mov    %rsp,%r9
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   10f0 <recvfrom@plt>
test   %rax,%rax
js     154e <main+0x2ee>
lea    0xc8b(%rip),%rdi
lea    0x30(%rsp),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0x8(%rsp),%r15
mov    %rsp,%r12
lea    0xc87(%rip),%r13
mov    $0x706f7473,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1080 <memset@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
mov    %r15,%r8
mov    %r12,%r9
call   10f0 <recvfrom@plt>
test   %rax,%rax
js     154e <main+0x2ee>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %r13,%rdi
mov    %eax,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x30(%rsp),%eax
xor    %ebp,%eax
movzbl 0x34(%rsp),%ecx
or     %eax,%ecx
jne    14e0 <main+0x280>
mov    %r14d,%edi
call   10a0 <close@plt>
xor    %eax,%eax
add    $0x838,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2a7b(%rip),%rax
mov    (%rax),%edi
lea    0xbcb(%rip),%rsi
call   10e0 <fprintf@plt>
xor    %edi,%edi
call   1160 <exit@plt>
mov    0x2a5f(%rip),%rax
mov    (%rax),%edi
lea    0xa99(%rip),%rsi
jmp    158c <main+0x32c>
mov    0x2a4d(%rip),%rax
mov    (%rax),%edi
lea    0xacc(%rip),%rsi
call   10e0 <fprintf@plt>
mov    $0x1,%edi
call   1160 <exit@plt>
mov    0x2a2e(%rip),%rax
mov    (%rax),%edi
lea    0xb6d(%rip),%rsi
jmp    155e <main+0x2fe>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [19 x i8] c"My ip addr is: %s\0A\00"
@stderr = global i32 0
@.str.1 = [55 x i8] c"Error, exiting. Usage: ./get_tshark <port_to_examine>\0A\00"
@.str.2 = [12 x i8] c"config_file\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [61 x i8] c"Error opening config file with name 'config_file'. Exiting.\0A\00"
@.str.5 = [23 x i8] c"Reading input file...\0A\00"
@.str.6 = [8 x i8] c"host_ip\00"
@.str.7 = [13 x i8] c"host_ip: %s\0A\00"
@.str.8 = [5 x i8] c"port\00"
@.str.9 = [10 x i8] c"port: %d\0A\00"
@.str.10 = [22 x i8] c"Connecting to: %s:%d\0A\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.11 = [29 x i8] c"ip_addr: %s examine_port: %d\00"
@.str.12 = [44 x i8] c"sending message '%s' to get_tshark server.\0A\00"
@.str.13 = [17 x i8] c"Failed to send.\0A\00"
@.str.14 = [60 x i8] c"The server will send a response in approximately 1 minute.\0A\00"
@.str.15 = [20 x i8] c"Failed to receive.\0A\00"
@.str.16 = [26 x i8] c"Received from server: %s\0A\00"
@.str.17 = [35 x i8] c"Received %i bytes from server: %s\0A\00"
@.str.18 = [5 x i8] c"stop\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.sockaddr_in
%8 = alloca %struct.hostent*
%9 = alloca [1024 x i8]
%10 = alloca [1024 x i8]
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32*
%18 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%19 = call i8* (...) @get_ip_addr()
store i8* %19, i8** %11
%20 = load i8*, i8** %11
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %20)
%22 = load i32, i32* %4
%23 = icmp ne i32 %22, 2
br i1 %23, label %24, label %28
24: ; preds = %2
%25 = load i32, i32* @stderr
%26 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0))
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %2
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = call i32 @atoi(i8* %31)
store i32 %32, i32* %14
%33 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %33, i32** %17
%34 = load i32*, i32** %17
%35 = icmp eq i32* %34, null
br i1 %35, label %36, label %40
36: ; preds = %28
%37 = load i32, i32* @stderr
%38 = call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.4, i64 0, i64 0))
%39 = call i32 @exit(i32 1)
unreachable
40: ; preds = %28
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
br label %42
42: ; preds = %62, %40
%43 = load i32*, i32** %17
%44 = call i64 @getline(i8** %12, i32* %15, i32* %43)
%45 = icmp sgt i64 %44, 0
br i1 %45, label %46, label %63
46: ; preds = %42
%47 = load i8*, i8** %12
%48 = call i32* @strstr(i8* %47, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
%49 = icmp ne i32* %48, null
br i1 %49, label %50, label %54
50: ; preds = %46
%51 = load i8*, i8** %12
%52 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%53 = call i32 (i8*, i8*, ...) @sscanf(i8* %51, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i8* %52)
br label %62
54: ; preds = %46
%55 = load i8*, i8** %12
%56 = call i32* @strstr(i8* %55, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%57 = icmp ne i32* %56, null
br i1 %57, label %58, label %61
58: ; preds = %54
%59 = load i8*, i8** %12
%60 = call i32 (i8*, i8*, ...) @sscanf(i8* %59, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.9, i64 0, i64 0), i32* %13)
br label %61
61: ; preds = %58, %54
br label %62
62: ; preds = %61, %50
br label %42
63: ; preds = %42
%64 = load i32*, i32** %17
%65 = call i32 @fclose(i32* %64)
%66 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%67 = load i32, i32* %13
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.10, i64 0, i64 0), i8* %66, i32 %67)
%69 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%70 = call %struct.hostent* @gethostbyname(i8* %69)
store %struct.hostent* %70, %struct.hostent** %8
store i32 12, i32* %18
%71 = load i32, i32* @AF_INET
%72 = load i32, i32* @SOCK_DGRAM
%73 = call i32 @socket(i32 %71, i32 %72, i32 0)
store i32 %73, i32* %6
%74 = bitcast %struct.sockaddr_in* %7 to i8*
%75 = call i32 @bzero(i8* %74, i32 12)
%76 = load i32, i32* @AF_INET
%77 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %76, i32* %77
%78 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%79 = call i32 @inet_addr(i8* %78)
%80 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
%81 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %80, i32 0, i32 0
store i32 %79, i32* %81
%82 = load i32, i32* %13
%83 = call i32 @htons(i32 %82)
%84 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
store i32 %83, i32* %84
%85 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%86 = call i32 @memset(i8* %85, i32 0, i32 1024)
%87 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%88 = load i8*, i8** %11
%89 = load i32, i32* %14
%90 = call i32 @sprintf(i8* %87, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.11, i64 0, i64 0), i8* %88, i32 %89)
%91 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%92 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.12, i64 0, i64 0), i8* %91)
%93 = load i32, i32* %6
%94 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%95 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%96 = call i32 @strlen(i8* %95)
%97 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%98 = load i32, i32* %18
%99 = call i64 @sendto(i32 %93, i8* %94, i32 %96, i32 0, %struct.sockaddr* %97, i32 %98)
%100 = icmp slt i64 %99, 0
br i1 %100, label %101, label %105
101: ; preds = %63
%102 = load i32, i32* @stderr
%103 = call i32 @fprintf(i32 %102, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.13, i64 0, i64 0))
%104 = call i32 @exit(i32 0)
unreachable
105: ; preds = %63
%106 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.14, i64 0, i64 0))
%107 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%108 = call i32 @memset(i8* %107, i32 0, i32 1024)
%109 = load i32, i32* %6
%110 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%111 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%112 = call i64 @recvfrom(i32 %109, i8* %110, i32 1024, i32 0, %struct.sockaddr* %111, i32* %18)
%113 = icmp slt i64 %112, 0
br i1 %113, label %114, label %118
114: ; preds = %105
%115 = load i32, i32* @stderr
%116 = call i32 @fprintf(i32 %115, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.15, i64 0, i64 0))
%117 = call i32 @exit(i32 0)
unreachable
118: ; preds = %105
%119 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%120 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.16, i64 0, i64 0), i8* %119)
br label %121
121: ; preds = %118, %143
%122 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%123 = call i32 @memset(i8* %122, i32 0, i32 1024)
%124 = load i32, i32* %6
%125 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%126 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%127 = call i64 @recvfrom(i32 %124, i8* %125, i32 1024, i32 0, %struct.sockaddr* %126, i32* %18)
%128 = icmp slt i64 %127, 0
br i1 %128, label %129, label %133
129: ; preds = %121
%130 = load i32, i32* @stderr
%131 = call i32 @fprintf(i32 %130, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.15, i64 0, i64 0))
%132 = call i32 @exit(i32 0)
unreachable
133: ; preds = %121
%134 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%135 = call i32 @strlen(i8* %134)
store i32 %135, i32* %16
%136 = load i32, i32* %16
%137 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%138 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.17, i64 0, i64 0), i32 %136, i8* %137)
%139 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%140 = call i32 @strcmp(i8* %139, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.18, i64 0, i64 0))
%141 = icmp ne i32 %140, 0
br i1 %141, label %143, label %142
142: ; preds = %133
br label %144
143: ; preds = %133
br label %121
144: ; preds = %142
%145 = load i32, i32* %6
%146 = call i32 @close(i32 %145)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [19 x i8] c"My ip addr is: %s\0A\00"
@stderr = global i32 0
@.str.1 = [55 x i8] c"Error, exiting. Usage: ./get_tshark <port_to_examine>\0A\00"
@.str.2 = [12 x i8] c"config_file\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [61 x i8] c"Error opening config file with name 'config_file'. Exiting.\0A\00"
@.str.6 = [8 x i8] c"host_ip\00"
@.str.7 = [13 x i8] c"host_ip: %s\0A\00"
@.str.8 = [5 x i8] c"port\00"
@.str.9 = [10 x i8] c"port: %d\0A\00"
@.str.10 = [22 x i8] c"Connecting to: %s:%d\0A\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.11 = [29 x i8] c"ip_addr: %s examine_port: %d\00"
@.str.12 = [44 x i8] c"sending message '%s' to get_tshark server.\0A\00"
@.str.13 = [17 x i8] c"Failed to send.\0A\00"
@.str.15 = [20 x i8] c"Failed to receive.\0A\00"
@.str.16 = [26 x i8] c"Received from server: %s\0A\00"
@.str.17 = [35 x i8] c"Received %i bytes from server: %s\0A\00"
@.str.18 = [5 x i8] c"stop\00"
@str = [22 x i8] c"Reading input file...\00"
@str.19 = [59 x i8] c"The server will send a response in approximately 1 minute.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [1024 x i8]
%5 = alloca [1024 x i8]
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = bitcast %struct.sockaddr_in* %3 to i8*
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%13 = bitcast i8** %6 to i8*
%14 = bitcast i32* %7 to i8*
%15 = bitcast i32* %8 to i8*
%16 = tail call i8* (...) @get_ip_addr()
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = icmp eq i32 %0, 2
br i1 %18, label %23, label %19
19: ; preds = %2
%20 = load i32, i32* @stderr
%21 = tail call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0))
%22 = tail call i32 @exit(i32 1)
unreachable
23: ; preds = %2
%24 = getelementptr inbounds i8*, i8** %1, i64 1
%25 = load i8*, i8** %24
%26 = tail call i32 @atoi(i8* %25)
%27 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %33
29: ; preds = %23
%30 = load i32, i32* @stderr
%31 = tail call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.4, i64 0, i64 0))
%32 = tail call i32 @exit(i32 1)
unreachable
33: ; preds = %23
%34 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%35 = call i64 @getline(i8** %6, i32* %8, i32* %27)
%36 = icmp sgt i64 %35, 0
br i1 %36, label %37, label %51
37: ; preds = %33, %48
%38 = load i8*, i8** %6
%39 = call i32* @strstr(i8* dereferenceable(1) %38, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
%40 = icmp eq i32* %39, null
br i1 %40, label %43, label %41
41: ; preds = %37
%42 = call i32 (i8*, i8*, ...) @sscanf(i8* %38, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i8* %12)
br label %48
43: ; preds = %37
%44 = call i32* @strstr(i8* dereferenceable(1) %38, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%45 = icmp eq i32* %44, null
br i1 %45, label %48, label %46
46: ; preds = %43
%47 = call i32 (i8*, i8*, ...) @sscanf(i8* %38, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.9, i64 0, i64 0), i32* %7)
br label %48
48: ; preds = %43, %46, %41
%49 = call i64 @getline(i8** %6, i32* %8, i32* %27)
%50 = icmp sgt i64 %49, 0
br i1 %50, label %37, label %51
51: ; preds = %48, %33
%52 = call i32 @fclose(i32* %27)
%53 = load i32, i32* %7
%54 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.10, i64 0, i64 0), i8* %12, i32 %53)
%55 = call %struct.hostent* @gethostbyname(i8* %12)
%56 = bitcast i32* %9 to i8*
store i32 12, i32* %9
%57 = load i32, i32* @AF_INET
%58 = load i32, i32* @SOCK_DGRAM
%59 = call i32 @socket(i32 %57, i32 %58, i32 0)
%60 = call i32 @bzero(i8* %10, i32 12)
%61 = load i32, i32* @AF_INET
%62 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %61, i32* %62
%63 = call i32 @inet_addr(i8* %12)
%64 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %63, i32* %64
%65 = load i32, i32* %7
%66 = call i32 @htons(i32 %65)
%67 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %66, i32* %67
%68 = call i32 @memset(i8* %11, i32 0, i32 1024)
%69 = call i32 @sprintf(i8* %11, i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.11, i64 0, i64 0), i8* %16, i32 %26)
%70 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.12, i64 0, i64 0), i8* %11)
%71 = call i32 @strlen(i8* %11)
%72 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%73 = call i64 @sendto(i32 %59, i8* %11, i32 %71, i32 0, %struct.sockaddr* %72, i32 12)
%74 = icmp slt i64 %73, 0
br i1 %74, label %75, label %79
75: ; preds = %51
%76 = load i32, i32* @stderr
%77 = call i32 @fprintf(i32 %76, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.13, i64 0, i64 0))
%78 = call i32 @exit(i32 0)
unreachable
79: ; preds = %51
%80 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @str.19, i64 0, i64 0))
%81 = call i32 @memset(i8* %11, i32 0, i32 1024)
%82 = call i64 @recvfrom(i32 %59, i8* %11, i32 1024, i32 0, %struct.sockaddr* %72, i32* %9)
%83 = icmp slt i64 %82, 0
br i1 %83, label %84, label %88
84: ; preds = %79
%85 = load i32, i32* @stderr
%86 = call i32 @fprintf(i32 %85, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.15, i64 0, i64 0))
%87 = call i32 @exit(i32 0)
unreachable
88: ; preds = %79
%89 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.16, i64 0, i64 0), i8* %11)
br label %90
90: ; preds = %98, %88
%91 = call i32 @memset(i8* %11, i32 0, i32 1024)
%92 = call i64 @recvfrom(i32 %59, i8* %11, i32 1024, i32 0, %struct.sockaddr* %72, i32* %9)
%93 = icmp slt i64 %92, 0
br i1 %93, label %94, label %98
94: ; preds = %90
%95 = load i32, i32* @stderr
%96 = call i32 @fprintf(i32 %95, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.15, i64 0, i64 0))
%97 = call i32 @exit(i32 0)
unreachable
98: ; preds = %90
%99 = call i32 @strlen(i8* %11)
%100 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.17, i64 0, i64 0), i32 %99, i8* %11)
%101 = call i32 @bcmp(i8* dereferenceable(5) %11, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.18, i64 0, i64 0), i64 5)
%102 = icmp eq i32 %101, 0
br i1 %102, label %103, label %90
103: ; preds = %98
%104 = call i32 @close(i32 %59)
ret i32 0
}