#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;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ navdata_receiver;
typedef int /*<<< orphan*/ navdata_addr;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ assert(int);
scalar_t__ bind(int, struct sockaddr *, int);
int errno;
int /*<<< orphan*/ exit(int);
int extractHeader(int /*<<< orphan*/ *, char *, int, int *);
int extractMetadata(char *, int *, int *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int *);
int /*<<< orphan*/ sendto(int, char *, int, int /*<<< orphan*/,
                          struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ usleep(int);
int main(int argc, char *argv[]) {
  char blackbox_file[128] =
      "/data/ftp/internal_000/Debug/current/blackbox/light_run_0";
  FILE *blackbox;
  char *header;
  int header_length = -1;
  int err;
  int datakey_number = -1;
  int datakey_length = -1;
  int packet_length = -1;
  int data_start_location;
  long current_data_size;
  int latest_navdata_packet_beginning;
  int navdata_socket;
  struct sockaddr_in navdata_addr;
  struct sockaddr_in navdata_receiver;
  socklen_t navdata_receiver_size = sizeof(navdata_receiver);
  char recv_buf[1024];
  int recv_len;
  char *navdata_buf;
  if (argc == 2) {
    assert(strlen(argv[1]) <= 128);
    strcpy(blackbox_file, argv[1]);
  }
  errno = 0;
  blackbox = fopen(blackbox_file, "rb");
  if (blackbox == NULL) {
    fprintf(stderr, "Error opening blackbox file: %s. Error number %i.\n",
            blackbox_file, errno);
    exit(1);
  }
  header = (char *)malloc(4096 * 4);
  err = extractHeader(blackbox, header, 4096 * 4, &header_length);
  if (err != 0) {
    if (err == 1) {
      fprintf(stderr, "Blackbox header too long! Must be shorter than %i.",
              4096 * 4);
    } else {
      fprintf(stderr, "Unknown error occurred extracting header!");
    }
    exit(1);
  }
  data_start_location = header_length + (int)strlen("-- Data\n");
  printf("Data starts at byte %i.\n", data_start_location);
  err = extractMetadata(header, &datakey_number, &datakey_length);
  if (err != 0) {
    fprintf(stderr, "Could not extract metadata from header!");
    exit(1);
  }
  packet_length = datakey_length * datakey_number;
  printf("Data composed of packets with %i %i-byte datakeys; packet length is "
         "%i.\n",
         datakey_number, datakey_length, packet_length);
  assert(datakey_length == sizeof(double));
  navdata_socket = socket(AF_INET, SOCK_DGRAM, 0);
  if (navdata_socket < 0) {
    fprintf(stderr, "Error creating UDP socket. Error number %i.\n", errno);
    fclose(blackbox);
    exit(1);
  }
  memset((char *)&navdata_addr, 0, sizeof(navdata_addr));
  navdata_addr.sin_family = AF_INET;
  navdata_addr.sin_addr.s_addr = htonl(INADDR_ANY);
  navdata_addr.sin_port = htons(56789);
  if (bind(navdata_socket, (struct sockaddr *)&navdata_addr,
           sizeof(navdata_addr)) < 0) {
    fprintf(stderr, "Error binding UDP socket on port %i. Error number %i.\n",
            56789, errno);
    fclose(blackbox);
    exit(1);
  }
  printf("Waiting for packet on port %i.\n", 56789);
  recv_len =
      recvfrom(navdata_socket, recv_buf, 1024, 0,
               (struct sockaddr *)&navdata_receiver, &navdata_receiver_size);
  printf("Got packet. Sending navdata!\n");
  navdata_buf = (char *)malloc(packet_length);
  while (1) {
    fseek(blackbox, 0L, SEEK_END);
    current_data_size = ftell(blackbox) - data_start_location;
    latest_navdata_packet_beginning =
        data_start_location +
        (current_data_size / packet_length) * packet_length - packet_length;
    fseek(blackbox, latest_navdata_packet_beginning, SEEK_SET);
    int read = fread(navdata_buf, packet_length, 1, blackbox);
    sendto(navdata_socket, navdata_buf, packet_length, 0,
           (struct sockaddr *)&navdata_receiver, sizeof(navdata_receiver));
    usleep(25 * 1000);
  }
  fclose(blackbox);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x530,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x90(%rbp),%rdi
lea    0xd69(%rip),%rsi
mov    $0x80,%edx
call   10f0 <memcpy@plt>
movl   $0xffffffff,-0xa4(%rbp)
ff ff ff
movl   $0xffffffff,-0xac(%rbp)
ff ff ff
movl   $0xffffffff,-0xb0(%rbp)
ff ff ff
movl   $0xffffffff,-0xb4(%rbp)
ff ff ff
movl   $0xc,-0xec(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    1310 <main+0xa0>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <strlen@plt>
cmp    $0x80,%eax
setle  %al
and    $0x1,%al
movzbl %al,%edi
call   10c0 <assert@plt>
lea    -0x90(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1030 <strcpy@plt>
mov    0x2ca1(%rip),%rax
movl   $0x0,(%rax)
lea    -0x90(%rbp),%rdi
lea    0xd55(%rip),%rsi
call   1160 <fopen@plt>
mov    %rax,-0x98(%rbp)
cmpq   $0x0,-0x98(%rbp)
jne    1376 <main+0x106>
mov    0x2c74(%rip),%rax
mov    (%rax),%edi
lea    -0x90(%rbp),%rdx
mov    0x2c5c(%rip),%rax
mov    (%rax),%ecx
lea    0xd1e(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
mov    $0x1,%edi
call   1170 <exit@plt>
mov    $0x4000,%edi
call   1100 <malloc@plt>
mov    %rax,-0xa0(%rbp)
mov    -0x98(%rbp),%rdi
mov    -0xa0(%rbp),%rsi
mov    $0x4000,%edx
lea    -0xa4(%rbp),%rcx
call   1150 <extractHeader@plt>
mov    %eax,-0xa8(%rbp)
cmpl   $0x0,-0xa8(%rbp)
je     1408 <main+0x198>
cmpl   $0x1,-0xa8(%rbp)
jne    13e7 <main+0x177>
mov    0x2bf3(%rip),%rax
mov    (%rax),%edi
lea    0xce0(%rip),%rsi
mov    $0x4000,%edx
mov    $0x0,%al
call   10d0 <fprintf@plt>
jmp    13fe <main+0x18e>
mov    0x2bd2(%rip),%rax
mov    (%rax),%edi
lea    0xcf2(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
mov    $0x1,%edi
call   1170 <exit@plt>
mov    -0xa4(%rbp),%eax
mov    %eax,-0x508(%rbp)
lea    0xcf8(%rip),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x508(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0xb8(%rbp)
mov    -0xb8(%rbp),%esi
lea    0xcdf(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0xa0(%rbp),%rdi
lea    -0xac(%rbp),%rsi
lea    -0xb0(%rbp),%rdx
call   1140 <extractMetadata@plt>
mov    %eax,-0xa8(%rbp)
cmpl   $0x0,-0xa8(%rbp)
je     1492 <main+0x222>
mov    0x2b48(%rip),%rax
mov    (%rax),%edi
lea    0xcb4(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
mov    $0x1,%edi
call   1170 <exit@plt>
mov    -0xb0(%rbp),%eax
imul   -0xac(%rbp),%eax
mov    %eax,-0xb4(%rbp)
mov    -0xac(%rbp),%esi
mov    -0xb0(%rbp),%edx
mov    -0xb4(%rbp),%ecx
lea    0xc9f(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movslq -0xb0(%rbp),%rax
cmp    $0x8,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10c0 <assert@plt>
mov    0x2afc(%rip),%rax
mov    (%rax),%edi
mov    0x2ae3(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1190 <socket@plt>
mov    %eax,-0xc8(%rbp)
cmpl   $0x0,-0xc8(%rbp)
jge    153f <main+0x2cf>
mov    0x2ab0(%rip),%rax
mov    (%rax),%edi
mov    0x2a9f(%rip),%rax
mov    (%rax),%edx
lea    0xc84(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
mov    -0x98(%rbp),%rdi
call   1050 <fclose@plt>
mov    $0x1,%edi
call   1170 <exit@plt>
lea    -0xd8(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   10a0 <memset@plt>
mov    0x2a87(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xd0(%rbp)
mov    0x2a70(%rip),%rax
mov    (%rax),%edi
call   1090 <htonl@plt>
mov    %eax,-0xd4(%rbp)
mov    $0xddd5,%edi
call   1070 <htons@plt>
mov    %eax,-0xd8(%rbp)
mov    -0xc8(%rbp),%edi
lea    -0xd8(%rbp),%rsi
mov    $0xc,%edx
call   1130 <bind@plt>
cmp    $0x0,%rax
jge    15e1 <main+0x371>
mov    0x2a13(%rip),%rax
mov    (%rax),%edi
mov    0x2a02(%rip),%rax
mov    (%rax),%ecx
lea    0xc14(%rip),%rsi
mov    $0xddd5,%edx
mov    $0x0,%al
call   10d0 <fprintf@plt>
mov    -0x98(%rbp),%rdi
call   1050 <fclose@plt>
mov    $0x1,%edi
call   1170 <exit@plt>
lea    0xc22(%rip),%rdi
mov    $0xddd5,%esi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0xc8(%rbp),%edi
lea    -0x4f0(%rbp),%rsi
lea    -0xe8(%rbp),%r8
mov    $0x400,%edx
xor    %ecx,%ecx
lea    -0xec(%rbp),%r9
call   1110 <recvfrom@plt>
mov    %eax,-0x4f4(%rbp)
lea    0xc02(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0xb4(%rbp),%edi
call   1100 <malloc@plt>
mov    %rax,-0x500(%rbp)
mov    -0x98(%rbp),%rdi
mov    0x2999(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1120 <fseek@plt>
mov    -0x98(%rbp),%rdi
call   10e0 <ftell@plt>
sub    -0xb8(%rbp),%eax
mov    %eax,-0x52c(%rbp)
cltq
mov    %rax,-0xc0(%rbp)
movslq -0xb8(%rbp),%rax
mov    %rax,-0x528(%rbp)
mov    -0xc0(%rbp),%rax
movslq -0xb4(%rbp),%rcx
cqto
idiv   %rcx
mov    %rax,%rcx
mov    -0x528(%rbp),%rax
movslq -0xb4(%rbp),%rdx
imul   %rdx,%rcx
mov    %rcx,-0x520(%rbp)
add    %rcx,%rax
mov    %rax,-0x518(%rbp)
movslq -0xb4(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x510(%rbp)
mov    %eax,-0xc4(%rbp)
mov    -0x98(%rbp),%rdi
mov    -0xc4(%rbp),%esi
mov    0x28c5(%rip),%rax
mov    (%rax),%edx
call   1120 <fseek@plt>
mov    -0x500(%rbp),%rdi
mov    -0xb4(%rbp),%esi
mov    -0x98(%rbp),%rcx
mov    $0x1,%edx
call   1040 <fread@plt>
mov    %eax,-0x504(%rbp)
mov    -0xc8(%rbp),%edi
mov    -0x500(%rbp),%rsi
mov    -0xb4(%rbp),%edx
lea    -0xe8(%rbp),%r8
xor    %ecx,%ecx
mov    $0xc,%r9d
call   10b0 <sendto@plt>
mov    $0x61a8,%edi
call   1180 <usleep@plt>
jmp    1641 <main+0x3d1>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x4b8,%rsp
movaps 0xde8(%rip),%xmm0
movaps %xmm0,0xa0(%rsp)
movaps 0xdc9(%rip),%xmm0
movaps %xmm0,0x90(%rsp)
movaps 0xdaa(%rip),%xmm0
movaps %xmm0,0x80(%rsp)
movaps 0xd8b(%rip),%xmm0
movaps %xmm0,0x70(%rsp)
movaps 0xd6f(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
movaps 0xd53(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xd37(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xd1b(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movl   $0xffffffff,0x8(%rsp)
ff
movl   $0xffffffff,0x4(%rsp)
ff
movl   $0xffffffff,(%rsp)
movl   $0xc,0xc(%rsp)
cmp    $0x2,%edi
jne    1338 <main+0xc8>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   1070 <strlen@plt>
xor    %edi,%edi
cmp    $0x81,%eax
setl   %dil
call   10d0 <assert@plt>
mov    0x8(%rbx),%rsi
lea    0x30(%rsp),%rdi
call   1030 <strcpy@plt>
mov    0x2c79(%rip),%rbx
movl   $0x0,(%rbx)
lea    0xd34(%rip),%rsi
lea    0x30(%rsp),%rdi
call   1160 <fopen@plt>
test   %rax,%rax
je     1582 <main+0x312>
mov    %rax,%r13
mov    $0x4000,%edi
call   1100 <malloc@plt>
mov    %rax,%rbx
lea    0x8(%rsp),%rcx
mov    %r13,%rdi
mov    %rax,%rsi
mov    $0x4000,%edx
call   1150 <extractHeader@plt>
test   %eax,%eax
jne    1553 <main+0x2e3>
mov    0x8(%rsp),%ebp
lea    0xd7c(%rip),%rdi
call   1070 <strlen@plt>
mov    %eax,%r14d
add    %ebp,%r14d
lea    0xd73(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1090 <printf@plt>
lea    0x4(%rsp),%rsi
mov    %rsp,%rdx
mov    %rbx,%rdi
call   1140 <extractMetadata@plt>
test   %eax,%eax
jne    15aa <main+0x33a>
mov    (%rsp),%edx
mov    0x4(%rsp),%esi
mov    %esi,%ebp
imul   %edx,%ebp
lea    0xd7f(%rip),%rdi
mov    %ebp,%ecx
xor    %eax,%eax
call   1090 <printf@plt>
xor    %edi,%edi
cmpl   $0x8,(%rsp)
sete   %dil
call   10d0 <assert@plt>
mov    0x2be3(%rip),%r12
mov    (%r12),%edi
mov    0x2bc8(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1190 <socket@plt>
test   %eax,%eax
js     15bc <main+0x34c>
mov    %eax,%r15d
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   10b0 <memset@plt>
mov    (%r12),%eax
mov    %eax,0x18(%rsp)
mov    0x2b99(%rip),%rax
mov    (%rax),%edi
call   10a0 <htonl@plt>
mov    %eax,0x14(%rsp)
mov    $0xddd5,%edi
call   1080 <htons@plt>
mov    %eax,0x10(%rsp)
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0xc,%edx
call   1130 <bind@plt>
test   %rax,%rax
js     15de <main+0x36e>
lea    0xd92(%rip),%rdi
mov    $0xddd5,%esi
xor    %eax,%eax
call   1090 <printf@plt>
lea    0xb0(%rsp),%rsi
lea    0x20(%rsp),%r8
lea    0xc(%rsp),%r9
mov    %r15d,%edi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1110 <recvfrom@plt>
lea    0xd7e(%rip),%rdi
call   1040 <puts@plt>
mov    %ebp,%edi
call   1100 <malloc@plt>
mov    %rax,%rbx
movslq %ebp,%r12
jmp    1515 <main+0x2a5>
cqto
idiv   %r12
add    %ebp,%edx
mov    %r14d,%esi
sub    %edx,%esi
add    %ecx,%esi
mov    0x2adb(%rip),%rax
mov    (%rax),%edx
mov    %r13,%rdi
call   1120 <fseek@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   1050 <fread@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
xor    %ecx,%ecx
lea    0x20(%rsp),%r8
mov    $0xc,%r9d
call   10c0 <sendto@plt>
mov    $0x61a8,%edi
call   1180 <usleep@plt>
mov    0x2acc(%rip),%rax
mov    (%rax),%edx
mov    %r13,%rdi
xor    %esi,%esi
call   1120 <fseek@plt>
mov    %r13,%rdi
call   10f0 <ftell@plt>
mov    %eax,%ecx
sub    %r14d,%ecx
movslq %ecx,%rax
mov    %rax,%rdx
or     %r12,%rdx
shr    $0x20,%rdx
jne    14c0 <main+0x250>
mov    %ecx,%eax
xor    %edx,%edx
div    %ebp
jmp    14c5 <main+0x255>
cmp    $0x1,%eax
jne    1615 <main+0x3a5>
mov    0x2a5d(%rip),%rax
mov    (%rax),%edi
lea    0xb4a(%rip),%rsi
mov    $0x4000,%edx
xor    %eax,%eax
call   10e0 <fprintf@plt>
mov    $0x1,%edi
call   1170 <exit@plt>
mov    0x2a37(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%ecx
lea    0xaef(%rip),%rsi
lea    0x30(%rsp),%rdx
xor    %eax,%eax
call   10e0 <fprintf@plt>
mov    $0x1,%edi
call   1170 <exit@plt>
mov    0x2a0f(%rip),%rax
mov    (%rax),%edi
lea    0xb7b(%rip),%rsi
jmp    1625 <main+0x3b5>
mov    0x29fd(%rip),%rax
mov    (%rax),%edi
mov    0x29ec(%rip),%rax
mov    (%rax),%edx
lea    0xbd1(%rip),%rsi
xor    %eax,%eax
call   10e0 <fprintf@plt>
jmp    1603 <main+0x393>
mov    0x29db(%rip),%rax
mov    (%rax),%edi
mov    0x29ca(%rip),%rax
mov    (%rax),%ecx
lea    0xbdc(%rip),%rsi
mov    $0xddd5,%edx
xor    %eax,%eax
call   10e0 <fprintf@plt>
mov    %r13,%rdi
call   1060 <fclose@plt>
mov    $0x1,%edi
call   1170 <exit@plt>
mov    0x29a4(%rip),%rax
mov    (%rax),%edi
lea    0xac4(%rip),%rsi
xor    %eax,%eax
call   10e0 <fprintf@plt>
mov    $0x1,%edi
call   1170 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@__const.main.blackbox_file = [128 x i8] c"/data/ftp/internal_000/Debug/current/blackbox/light_run_0\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@errno = global i32 0
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [51 x i8] c"Error opening blackbox file: %s. Error number %i.\0A\00"
@.str.2 = [51 x i8] c"Blackbox header too long! Must be shorter than %i.\00"
@.str.3 = [42 x i8] c"Unknown error occurred extracting header!\00"
@.str.4 = [9 x i8] c"-- Data\0A\00"
@.str.5 = [25 x i8] c"Data starts at byte %i.\0A\00"
@.str.6 = [40 x i8] c"Could not extract metadata from header!\00"
@.str.7 = [73 x i8] c"Data composed of packets with %i %i-byte datakeys; packet length is %i.\0A\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.8 = [45 x i8] c"Error creating UDP socket. Error number %i.\0A\00"
@INADDR_ANY = global i32 0
@.str.9 = [55 x i8] c"Error binding UDP socket on port %i. Error number %i.\0A\00"
@.str.10 = [32 x i8] c"Waiting for packet on port %i.\0A\00"
@.str.11 = [30 x i8] c"Got packet. Sending navdata!\0A\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [128 x i8]
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i64
%16 = alloca i32
%17 = alloca i32
%18 = alloca %struct.sockaddr_in
%19 = alloca %struct.sockaddr_in
%20 = alloca i32
%21 = alloca [1024 x i8]
%22 = alloca i32
%23 = alloca i8*
%24 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%25 = bitcast [128 x i8]* %6 to i8*
store i32 -1, i32* %9
store i32 -1, i32* %11
store i32 -1, i32* %12
store i32 -1, i32* %13
store i32 12, i32* %20
%26 = load i32, i32* %4
%27 = icmp eq i32 %26, 2
br i1 %27, label %28, label %41
28: ; preds = %2
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = call i32 @strlen(i8* %31)
%33 = icmp sle i32 %32, 128
%34 = zext i1 %33 to i32
%35 = call i32 @assert(i32 %34)
%36 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 1
%39 = load i8*, i8** %38
%40 = call i32 @strcpy(i8* %36, i8* %39)
br label %41
41: ; preds = %28, %2
store i32 0, i32* @errno
%42 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%43 = call i32* @fopen(i8* %42, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %43, i32** %7
%44 = load i32*, i32** %7
%45 = icmp eq i32* %44, null
br i1 %45, label %46, label %52
46: ; preds = %41
%47 = load i32, i32* @stderr
%48 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%49 = load i32, i32* @errno
%50 = call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i8* %48, i32 %49)
%51 = call i32 @exit(i32 1)
unreachable
52: ; preds = %41
%53 = call i64 @malloc(i32 16384)
%54 = inttoptr i64 %53 to i8*
store i8* %54, i8** %8
%55 = load i32*, i32** %7
%56 = load i8*, i8** %8
%57 = call i32 @extractHeader(i32* %55, i8* %56, i32 16384, i32* %9)
store i32 %57, i32* %10
%58 = load i32, i32* %10
%59 = icmp ne i32 %58, 0
br i1 %59, label %60, label %71
60: ; preds = %52
%61 = load i32, i32* %10
%62 = icmp eq i32 %61, 1
br i1 %62, label %63, label %66
63: ; preds = %60
%64 = load i32, i32* @stderr
%65 = call i32 (i32, i8*, ...) @fprintf(i32 %64, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0), i32 16384)
br label %69
66: ; preds = %60
%67 = load i32, i32* @stderr
%68 = call i32 (i32, i8*, ...) @fprintf(i32 %67, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0))
br label %69
69: ; preds = %66, %63
%70 = call i32 @exit(i32 1)
unreachable
71: ; preds = %52
%72 = load i32, i32* %9
%73 = call i32 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%74 = add nsw i32 %72, %73
store i32 %74, i32* %14
%75 = load i32, i32* %14
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i32 %75)
%77 = load i8*, i8** %8
%78 = call i32 @extractMetadata(i8* %77, i32* %11, i32* %12)
store i32 %78, i32* %10
%79 = load i32, i32* %10
%80 = icmp ne i32 %79, 0
br i1 %80, label %81, label %85
81: ; preds = %71
%82 = load i32, i32* @stderr
%83 = call i32 (i32, i8*, ...) @fprintf(i32 %82, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.6, i64 0, i64 0))
%84 = call i32 @exit(i32 1)
unreachable
85: ; preds = %71
%86 = load i32, i32* %12
%87 = load i32, i32* %11
%88 = mul nsw i32 %86, %87
store i32 %88, i32* %13
%89 = load i32, i32* %11
%90 = load i32, i32* %12
%91 = load i32, i32* %13
%92 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str.7, i64 0, i64 0), i32 %89, i32 %90, i32 %91)
%93 = load i32, i32* %12
%94 = sext i32 %93 to i64
%95 = icmp eq i64 %94, 8
%96 = zext i1 %95 to i32
%97 = call i32 @assert(i32 %96)
%98 = load i32, i32* @AF_INET
%99 = load i32, i32* @SOCK_DGRAM
%100 = call i32 @socket(i32 %98, i32 %99, i32 0)
store i32 %100, i32* %17
%101 = load i32, i32* %17
%102 = icmp slt i32 %101, 0
br i1 %102, label %103, label %110
103: ; preds = %85
%104 = load i32, i32* @stderr
%105 = load i32, i32* @errno
%106 = call i32 (i32, i8*, ...) @fprintf(i32 %104, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.8, i64 0, i64 0), i32 %105)
%107 = load i32*, i32** %7
%108 = call i32 @fclose(i32* %107)
%109 = call i32 @exit(i32 1)
unreachable
110: ; preds = %85
%111 = bitcast %struct.sockaddr_in* %18 to i8*
%112 = call i32 @memset(i8* %111, i32 0, i32 12)
%113 = load i32, i32* @AF_INET
%114 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %18, i32 0, i32 2
store i32 %113, i32* %114
%115 = load i32, i32* @INADDR_ANY
%116 = call i32 @htonl(i32 %115)
%117 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %18, i32 0, i32 1
%118 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %117, i32 0, i32 0
store i32 %116, i32* %118
%119 = call i32 @htons(i32 56789)
%120 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %18, i32 0, i32 0
store i32 %119, i32* %120
%121 = load i32, i32* %17
%122 = bitcast %struct.sockaddr_in* %18 to %struct.sockaddr*
%123 = call i64 @bind(i32 %121, %struct.sockaddr* %122, i32 12)
%124 = icmp slt i64 %123, 0
br i1 %124, label %125, label %132
125: ; preds = %110
%126 = load i32, i32* @stderr
%127 = load i32, i32* @errno
%128 = call i32 (i32, i8*, ...) @fprintf(i32 %126, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.9, i64 0, i64 0), i32 56789, i32 %127)
%129 = load i32*, i32** %7
%130 = call i32 @fclose(i32* %129)
%131 = call i32 @exit(i32 1)
unreachable
132: ; preds = %110
%133 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.10, i64 0, i64 0), i32 56789)
%134 = load i32, i32* %17
%135 = getelementptr inbounds [1024 x i8], [1024 x i8]* %21, i64 0, i64 0
%136 = bitcast %struct.sockaddr_in* %19 to %struct.sockaddr*
%137 = call i32 @recvfrom(i32 %134, i8* %135, i32 1024, i32 0, %struct.sockaddr* %136, i32* %20)
store i32 %137, i32* %22
%138 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.11, i64 0, i64 0))
%139 = load i32, i32* %13
%140 = call i64 @malloc(i32 %139)
%141 = inttoptr i64 %140 to i8*
store i8* %141, i8** %23
br label %142
142: ; preds = %132, %142
%143 = load i32*, i32** %7
%144 = load i32, i32* @SEEK_END
%145 = call i32 @fseek(i32* %143, i32 0, i32 %144)
%146 = load i32*, i32** %7
%147 = call i32 @ftell(i32* %146)
%148 = load i32, i32* %14
%149 = sub nsw i32 %147, %148
%150 = sext i32 %149 to i64
store i64 %150, i64* %15
%151 = load i32, i32* %14
%152 = sext i32 %151 to i64
%153 = load i64, i64* %15
%154 = load i32, i32* %13
%155 = sext i32 %154 to i64
%156 = sdiv i64 %153, %155
%157 = load i32, i32* %13
%158 = sext i32 %157 to i64
%159 = mul nsw i64 %156, %158
%160 = add nsw i64 %152, %159
%161 = load i32, i32* %13
%162 = sext i32 %161 to i64
%163 = sub nsw i64 %160, %162
%164 = trunc i64 %163 to i32
store i32 %164, i32* %16
%165 = load i32*, i32** %7
%166 = load i32, i32* %16
%167 = load i32, i32* @SEEK_SET
%168 = call i32 @fseek(i32* %165, i32 %166, i32 %167)
%169 = load i8*, i8** %23
%170 = load i32, i32* %13
%171 = load i32*, i32** %7
%172 = call i32 @fread(i8* %169, i32 %170, i32 1, i32* %171)
store i32 %172, i32* %24
%173 = load i32, i32* %17
%174 = load i8*, i8** %23
%175 = load i32, i32* %13
%176 = bitcast %struct.sockaddr_in* %19 to %struct.sockaddr*
%177 = call i32 @sendto(i32 %173, i8* %174, i32 %175, i32 0, %struct.sockaddr* %176, i32 12)
%178 = call i32 @usleep(i32 25000)
br label %142
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@__const.main.blackbox_file = [128 x i8] c"/data/ftp/internal_000/Debug/current/blackbox/light_run_0\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@errno = global i32 0
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [51 x i8] c"Error opening blackbox file: %s. Error number %i.\0A\00"
@.str.2 = [51 x i8] c"Blackbox header too long! Must be shorter than %i.\00"
@.str.3 = [42 x i8] c"Unknown error occurred extracting header!\00"
@.str.4 = [9 x i8] c"-- Data\0A\00"
@.str.5 = [25 x i8] c"Data starts at byte %i.\0A\00"
@.str.6 = [40 x i8] c"Could not extract metadata from header!\00"
@.str.7 = [73 x i8] c"Data composed of packets with %i %i-byte datakeys; packet length is %i.\0A\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.8 = [45 x i8] c"Error creating UDP socket. Error number %i.\0A\00"
@INADDR_ANY = global i32 0
@.str.9 = [55 x i8] c"Error binding UDP socket on port %i. Error number %i.\0A\00"
@.str.10 = [32 x i8] c"Waiting for packet on port %i.\0A\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@str = [29 x i8] c"Got packet. Sending navdata!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [128 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.sockaddr_in
%8 = alloca %struct.sockaddr_in
%9 = alloca i32
%10 = alloca [1024 x i8]
%11 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%12 = bitcast i32* %4 to i8*
store i32 -1, i32* %4
%13 = bitcast i32* %5 to i8*
store i32 -1, i32* %5
%14 = bitcast i32* %6 to i8*
store i32 -1, i32* %6
%15 = bitcast %struct.sockaddr_in* %7 to i8*
%16 = bitcast %struct.sockaddr_in* %8 to i8*
%17 = bitcast i32* %9 to i8*
store i32 12, i32* %9
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%19 = icmp eq i32 %0, 2
br i1 %19, label %20, label %29
20: ; preds = %2
%21 = getelementptr inbounds i8*, i8** %1, i64 1
%22 = load i8*, i8** %21
%23 = tail call i32 @strlen(i8* %22)
%24 = icmp slt i32 %23, 129
%25 = zext i1 %24 to i32
%26 = tail call i32 @assert(i32 %25)
%27 = load i8*, i8** %21
%28 = call i32 @strcpy(i8* %11, i8* %27)
br label %29
29: ; preds = %20, %2
store i32 0, i32* @errno
%30 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%31 = icmp eq i32* %30, null
br i1 %31, label %32, label %37
32: ; preds = %29
%33 = load i32, i32* @stderr
%34 = load i32, i32* @errno
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i8* %11, i32 %34)
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %29
%38 = call i64 @malloc(i32 16384)
%39 = inttoptr i64 %38 to i8*
%40 = call i32 @extractHeader(i32* %30, i8* %39, i32 16384, i32* %4)
switch i32 %40, label %44 [
i32 0, label %49
i32 1, label %41
]
41: ; preds = %37
%42 = load i32, i32* @stderr
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0), i32 16384)
br label %47
44: ; preds = %37
%45 = load i32, i32* @stderr
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0))
br label %47
47: ; preds = %44, %41
%48 = call i32 @exit(i32 1)
unreachable
49: ; preds = %37
%50 = load i32, i32* %4
%51 = call i32 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%52 = add nsw i32 %51, %50
%53 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i32 %52)
%54 = call i32 @extractMetadata(i8* %39, i32* %5, i32* %6)
%55 = icmp eq i32 %54, 0
br i1 %55, label %60, label %56
56: ; preds = %49
%57 = load i32, i32* @stderr
%58 = call i32 (i32, i8*, ...) @fprintf(i32 %57, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.6, i64 0, i64 0))
%59 = call i32 @exit(i32 1)
unreachable
60: ; preds = %49
%61 = load i32, i32* %6
%62 = load i32, i32* %5
%63 = mul nsw i32 %62, %61
%64 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([73 x i8], [73 x i8]* @.str.7, i64 0, i64 0), i32 %62, i32 %61, i32 %63)
%65 = load i32, i32* %6
%66 = icmp eq i32 %65, 8
%67 = zext i1 %66 to i32
%68 = call i32 @assert(i32 %67)
%69 = load i32, i32* @AF_INET
%70 = load i32, i32* @SOCK_DGRAM
%71 = call i32 @socket(i32 %69, i32 %70, i32 0)
%72 = icmp slt i32 %71, 0
br i1 %72, label %73, label %79
73: ; preds = %60
%74 = load i32, i32* @stderr
%75 = load i32, i32* @errno
%76 = call i32 (i32, i8*, ...) @fprintf(i32 %74, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.8, i64 0, i64 0), i32 %75)
%77 = call i32 @fclose(i32* %30)
%78 = call i32 @exit(i32 1)
unreachable
79: ; preds = %60
%80 = call i32 @memset(i8* %15, i32 0, i32 12)
%81 = load i32, i32* @AF_INET
%82 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i64 0, i32 2
store i32 %81, i32* %82
%83 = load i32, i32* @INADDR_ANY
%84 = call i32 @htonl(i32 %83)
%85 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i64 0, i32 1, i32 0
store i32 %84, i32* %85
%86 = call i32 @htons(i32 56789)
%87 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i64 0, i32 0
store i32 %86, i32* %87
%88 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%89 = call i64 @bind(i32 %71, %struct.sockaddr* %88, i32 12)
%90 = icmp slt i64 %89, 0
br i1 %90, label %91, label %97
91: ; preds = %79
%92 = load i32, i32* @stderr
%93 = load i32, i32* @errno
%94 = call i32 (i32, i8*, ...) @fprintf(i32 %92, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.9, i64 0, i64 0), i32 56789, i32 %93)
%95 = call i32 @fclose(i32* %30)
%96 = call i32 @exit(i32 1)
unreachable
97: ; preds = %79
%98 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.10, i64 0, i64 0), i32 56789)
%99 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%100 = call i32 @recvfrom(i32 %71, i8* %18, i32 1024, i32 0, %struct.sockaddr* %99, i32* %9)
%101 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
%102 = call i64 @malloc(i32 %63)
%103 = inttoptr i64 %102 to i8*
%104 = sext i32 %63 to i64
br label %105
105: ; preds = %105, %97
%106 = load i32, i32* @SEEK_END
%107 = call i32 @fseek(i32* %30, i32 0, i32 %106)
%108 = call i32 @ftell(i32* %30)
%109 = sub nsw i32 %108, %52
%110 = sext i32 %109 to i64
%111 = srem i64 %110, %104
%112 = trunc i64 %111 to i32
%113 = add i32 %63, %112
%114 = sub i32 %52, %113
%115 = add i32 %114, %109
%116 = load i32, i32* @SEEK_SET
%117 = call i32 @fseek(i32* %30, i32 %115, i32 %116)
%118 = call i32 @fread(i8* %103, i32 %63, i32 1, i32* %30)
%119 = call i32 @sendto(i32 %71, i8* %103, i32 %63, i32 0, %struct.sockaddr* %99, i32 12)
%120 = call i32 @usleep(i32 25000)
br label %105
}