#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 */
typedef int /*<<< orphan*/ timeout;
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct timeval {
  int member_1;
  TYPE_1__ imr_multiaddr;
  int /*<<< orphan*/ imr_interface;
  int /*<<< orphan*/ member_0;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ member_0;
};
struct sockaddr {
  int dummy;
};
struct ip_mreq {
  int member_1;
  TYPE_1__ imr_multiaddr;
  int /*<<< orphan*/ imr_interface;
  int /*<<< orphan*/ member_0;
};
typedef int /*<<< orphan*/ ssdp_socket_address;
typedef int socklen_t;
typedef int /*<<< orphan*/ remote_address;
typedef int /*<<< orphan*/ mreq;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ IPPROTO_IP;
int /*<<< orphan*/ IP_ADD_MEMBERSHIP;
int LOG_CONS;
int /*<<< orphan*/ LOG_DAEMON;
int /*<<< orphan*/ LOG_DEBUG;
int LOG_PID;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_RCVTIMEO;
int create_bounded_socket(struct sockaddr_in);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fill_socketaddr_in(struct sockaddr_in *, int, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ inet_ntoa(int /*<<< orphan*/);
int /*<<< orphan*/ inet_pton(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
char *malloc(int);
int /*<<< orphan*/ openlog(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int recv(int, char *, int, int /*<<< orphan*/);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int *);
int /*<<< orphan*/ sendto(int, char *, int, int /*<<< orphan*/,
                          struct sockaddr *, int);
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                      struct timeval *, int);
char *sonos_location_string(char *);
int /*<<< orphan*/ stderr;
char *str_replace(char *, char *, char *, int /*<<< orphan*/);
int strlen(char *);
int /*<<< orphan*/ *strstr(char *, char *);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  openlog("sonos-f", LOG_PID | LOG_CONS, LOG_DAEMON);
  int ssdp_socket, forward_reply_socket;
  struct sockaddr_in ssdp_socket_address = {0},
                     forward_reply_socket_address = {0};
  struct sockaddr_in remote_address;
  socklen_t remote_address_length = sizeof(remote_address);
  char *receive_buffer = malloc(1E3 * sizeof(char));
  struct ip_mreq mreq;
  struct timeval timeout = {0, 5E5};
  if (argc != 4) {
    fprintf(stderr,
            "Call with 3 arguments:\n%s external-interface-ip-address "
            "internal-interface-ip-address sonos-box-ip-address",
            argv[0]);
  }
  char *outside_nat_ip_address = argv[1];
  char *inside_nat_ip_address = argv[2];
  char *sonos_box_ip_address = argv[3];
  char *to_replace = sonos_location_string(sonos_box_ip_address);
  char *replace_with = sonos_location_string(outside_nat_ip_address);
  fill_socketaddr_in(&ssdp_socket_address, 1900, "239.255.255.250");
  fill_socketaddr_in(&forward_reply_socket_address, 1900,
                     outside_nat_ip_address);
  ssdp_socket = create_bounded_socket(ssdp_socket_address);
  forward_reply_socket = create_bounded_socket(forward_reply_socket_address);
  inet_pton(AF_INET, argv[1], &mreq.imr_interface);
  mreq.imr_multiaddr.s_addr = inet_addr("239.255.255.250");
  if (setsockopt(ssdp_socket, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq,
                 sizeof(mreq)) < 0) {
    perror("setsockopt mreq");
    exit(1);
  }
  while (1) {
    int nr_bytes_received;
    nr_bytes_received =
        recvfrom(ssdp_socket, receive_buffer, 1E3, 0,
                 (struct sockaddr *)&remote_address, &remote_address_length);
    if (strstr(receive_buffer, "ZonePlayer") != NULL) {
      struct sockaddr_in passthrough_socket_address = {0};
      fill_socketaddr_in(&passthrough_socket_address, 0, inside_nat_ip_address);
      int passthrough_socket =
          create_bounded_socket(passthrough_socket_address);
      sendto(passthrough_socket, receive_buffer, nr_bytes_received, 0,
             (struct sockaddr *)&ssdp_socket_address,
             sizeof(ssdp_socket_address));
      if (setsockopt(passthrough_socket, SOL_SOCKET, SO_RCVTIMEO, &timeout,
                     sizeof(timeout)) < 0) {
        perror("Error");
        exit(1);
      }
      nr_bytes_received = recv(passthrough_socket, receive_buffer, 1E3, 0);
      if (nr_bytes_received <= 0) {
        syslog(LOG_DEBUG, "Message %s --> internal",
               inet_ntoa(remote_address.sin_addr));
      } else {
        int send_buffer_size =
            nr_bytes_received - strlen(to_replace) + strlen(replace_with) + 1;
        char *send_buffer =
            str_replace(receive_buffer, to_replace, replace_with, 0);
        sendto(forward_reply_socket, send_buffer, send_buffer_size, 0,
               (struct sockaddr *)&remote_address, remote_address_length);
        free(send_buffer);
        syslog(LOG_DEBUG, "Message %s <-> internal",
               inet_ntoa(remote_address.sin_addr));
      }
    } else {
      syslog(LOG_DEBUG, "Message %s not routed",
             inet_ntoa(remote_address.sin_addr));
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2d40(%rip),%rax
mov    (%rax),%esi
mov    0x2d27(%rip),%rax
or     (%rax),%esi
mov    0x2d56(%rip),%rax
mov    (%rax),%edx
lea    0xd75(%rip),%rdi
call   1140 <openlog@plt>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1090 <memset@plt>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1090 <memset@plt>
movl   $0x8,-0x34(%rbp)
mov    $0x3e8,%edi
call   1100 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    0xe20(%rip),%rax
mov    %rax,-0x60(%rbp)
mov    0xe1d(%rip),%rax
mov    %rax,-0x58(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     1301 <main+0xb1>
mov    0x2cbc(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xd0c(%rip),%rsi
call   10d0 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x68(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x70(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x78(%rbp)
mov    -0x78(%rbp),%rdi
call   1060 <sonos_location_string@plt>
mov    %rax,-0x80(%rbp)
mov    -0x68(%rbp),%rdi
call   1060 <sonos_location_string@plt>
mov    %rax,-0x88(%rbp)
lea    -0x20(%rbp),%rdi
mov    $0x76c,%esi
lea    0xd21(%rip),%rdx
call   1150 <fill_socketaddr_in@plt>
mov    -0x68(%rbp),%rdx
lea    -0x28(%rbp),%rdi
mov    $0x76c,%esi
call   1150 <fill_socketaddr_in@plt>
mov    -0x20(%rbp),%rdi
call   10a0 <create_bounded_socket@plt>
mov    %eax,-0x14(%rbp)
mov    -0x28(%rbp),%rdi
call   10a0 <create_bounded_socket@plt>
mov    %eax,-0x18(%rbp)
mov    0x2c48(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    -0x50(%rbp),%rdx
add    $0x8,%rdx
call   10f0 <inet_pton@plt>
lea    0xccd(%rip),%rdi
call   10c0 <inet_addr@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2c10(%rip),%rax
mov    (%rax),%esi
mov    0x2c1f(%rip),%rax
mov    (%rax),%edx
lea    -0x50(%rbp),%rcx
mov    $0x10,%r8d
call   1050 <setsockopt@plt>
cmp    $0x0,%rax
jge    13f2 <main+0x1a2>
lea    0xca0(%rip),%rdi
call   1130 <perror@plt>
mov    $0x1,%edi
call   1160 <exit@plt>
jmp    13f7 <main+0x1a7>
mov    -0x14(%rbp),%edi
mov    -0x40(%rbp),%rsi
lea    -0x30(%rbp),%r8
mov    $0x3e8,%edx
xor    %ecx,%ecx
lea    -0x34(%rbp),%r9
call   1120 <recvfrom@plt>
mov    %eax,-0x8c(%rbp)
mov    -0x40(%rbp),%rdi
lea    0xc70(%rip),%rsi
call   1170 <strstr@plt>
cmp    $0x0,%rax
je     15e6 <main+0x396>
lea    -0x98(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1090 <memset@plt>
mov    -0x70(%rbp),%rdx
lea    -0x98(%rbp),%rdi
xor    %esi,%esi
call   1150 <fill_socketaddr_in@plt>
mov    -0x98(%rbp),%rdi
call   10a0 <create_bounded_socket@plt>
mov    %eax,-0x9c(%rbp)
mov    -0x9c(%rbp),%edi
mov    -0x40(%rbp),%rsi
mov    -0x8c(%rbp),%edx
lea    -0x20(%rbp),%r8
xor    %ecx,%ecx
mov    $0x8,%r9d
call   10b0 <sendto@plt>
mov    -0x9c(%rbp),%edi
mov    0x2b51(%rip),%rax
mov    (%rax),%esi
mov    0x2b18(%rip),%rax
mov    (%rax),%edx
lea    -0x60(%rbp),%rcx
mov    $0x10,%r8d
call   1050 <setsockopt@plt>
cmp    $0x0,%rax
jge    14d1 <main+0x281>
lea    0xbdc(%rip),%rdi
call   1130 <perror@plt>
mov    $0x1,%edi
call   1160 <exit@plt>
mov    -0x9c(%rbp),%edi
mov    -0x40(%rbp),%rsi
mov    $0x3e8,%edx
xor    %ecx,%ecx
call   1040 <recv@plt>
mov    %eax,-0x8c(%rbp)
cmpl   $0x0,-0x8c(%rbp)
jg     152a <main+0x2da>
mov    0x2a97(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xac(%rbp)
mov    -0x30(%rbp),%edi
call   1070 <inet_ntoa@plt>
mov    -0xac(%rbp),%edi
mov    %eax,%edx
lea    0xb84(%rip),%rsi
call   1110 <syslog@plt>
jmp    15e1 <main+0x391>
mov    -0x8c(%rbp),%eax
mov    %eax,-0xb8(%rbp)
mov    -0x80(%rbp),%rdi
call   1080 <strlen@plt>
mov    %eax,%ecx
mov    -0xb8(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0xb4(%rbp)
mov    -0x88(%rbp),%rdi
call   1080 <strlen@plt>
mov    %eax,%ecx
mov    -0xb4(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
mov    %eax,-0xa0(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x80(%rbp),%rsi
mov    -0x88(%rbp),%rdx
xor    %ecx,%ecx
call   10e0 <str_replace@plt>
mov    %rax,-0xa8(%rbp)
mov    -0x18(%rbp),%edi
mov    -0xa8(%rbp),%rsi
mov    -0xa0(%rbp),%edx
lea    -0x30(%rbp),%r8
mov    -0x34(%rbp),%r9d
xor    %ecx,%ecx
call   10b0 <sendto@plt>
mov    -0xa8(%rbp),%rdi
call   1030 <free@plt>
mov    0x29db(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xb0(%rbp)
mov    -0x30(%rbp),%edi
call   1070 <inet_ntoa@plt>
mov    -0xb0(%rbp),%edi
mov    %eax,%edx
lea    0xae0(%rip),%rsi
call   1110 <syslog@plt>
jmp    1611 <main+0x3c1>
mov    0x29ab(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xbc(%rbp)
mov    -0x30(%rbp),%edi
call   1070 <inet_ntoa@plt>
mov    -0xbc(%rbp),%edi
mov    %eax,%edx
lea    0xac8(%rip),%rsi
call   1110 <syslog@plt>
jmp    13f7 <main+0x1a7>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    %rsi,%r14
mov    %edi,%ebp
mov    0x2d56(%rip),%rax
mov    0x2d3f(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2d6c(%rip),%rax
mov    (%rax),%edx
lea    0xd8b(%rip),%rdi
call   1130 <openlog@plt>
movq   $0x0,0x18(%rsp)
movq   $0x0,0x30(%rsp)
movl   $0x8,0xc(%rsp)
mov    $0x3e8,%edi
call   10f0 <malloc@plt>
mov    %rax,%r13
movups 0xe44(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
cmp    $0x4,%ebp
je     12ca <main+0x8a>
mov    0x2cef(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xd43(%rip),%rsi
call   10c0 <fprintf@plt>
mov    0x8(%r14),%rbp
mov    0x10(%r14),%rax
mov    %rax,0x48(%rsp)
mov    0x18(%r14),%rdi
call   1060 <sonos_location_string@plt>
mov    %rax,0x40(%rsp)
mov    %rbp,%rdi
call   1060 <sonos_location_string@plt>
mov    %rax,0x38(%rsp)
lea    0xd7a(%rip),%rbx
lea    0x18(%rsp),%rdi
mov    $0x76c,%esi
mov    %rbx,%rdx
call   1140 <fill_socketaddr_in@plt>
lea    0x30(%rsp),%rdi
mov    $0x76c,%esi
mov    %rbp,%rdx
call   1140 <fill_socketaddr_in@plt>
mov    0x18(%rsp),%rdi
call   1090 <create_bounded_socket@plt>
mov    %eax,%ebp
mov    0x30(%rsp),%rdi
call   1090 <create_bounded_socket@plt>
mov    %eax,0x20(%rsp)
mov    0x2c92(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r14),%rsi
lea    0x58(%rsp),%rdx
call   10e0 <inet_pton@plt>
mov    %rbx,%rdi
call   10b0 <inet_addr@plt>
mov    %eax,0x54(%rsp)
mov    0x2c67(%rip),%rax
mov    (%rax),%esi
mov    0x2c76(%rip),%rax
mov    (%rax),%edx
lea    0x50(%rsp),%rcx
mov    %ebp,0x24(%rsp)
mov    %ebp,%edi
mov    $0x10,%r8d
call   1050 <setsockopt@plt>
test   %rax,%rax
jns    1393 <main+0x153>
lea    0xcf5(%rip),%rdi
jmp    1527 <main+0x2e7>
lea    0x10(%rsp),%r12
mov    0x38(%rsp),%rbx
jmp    13c2 <main+0x182>
nop
mov    0x2bf1(%rip),%rax
mov    (%rax),%ebp
mov    0x10(%rsp),%edi
call   1070 <inet_ntoa@plt>
mov    %ebp,%edi
lea    0xd19(%rip),%rsi
mov    %eax,%edx
call   1100 <syslog@plt>
mov    0x24(%rsp),%edi
mov    %r13,%rsi
mov    $0x3e8,%edx
xor    %ecx,%ecx
mov    %r12,%r8
lea    0xc(%rsp),%r9
call   1110 <recvfrom@plt>
mov    %eax,%r14d
mov    %r13,%rdi
lea    0xca9(%rip),%rsi
call   1160 <strstr@plt>
test   %rax,%rax
je     13a0 <main+0x160>
movq   $0x0,0x28(%rsp)
lea    0x28(%rsp),%rdi
xor    %esi,%esi
mov    0x48(%rsp),%rdx
call   1140 <fill_socketaddr_in@plt>
mov    0x28(%rsp),%rdi
call   1090 <create_bounded_socket@plt>
mov    %eax,%r15d
mov    %eax,%edi
mov    %r13,%rsi
mov    %r14d,%edx
xor    %ecx,%ecx
lea    0x18(%rsp),%r8
mov    $0x8,%r9d
call   10a0 <sendto@plt>
mov    0x2bac(%rip),%rax
mov    (%rax),%esi
mov    0x2b73(%rip),%rax
mov    (%rax),%edx
mov    %r15d,%edi
lea    0x60(%rsp),%rcx
mov    $0x10,%r8d
call   1050 <setsockopt@plt>
test   %rax,%rax
js     1520 <main+0x2e0>
mov    %r15d,%edi
mov    %r13,%rsi
mov    $0x3e8,%edx
xor    %ecx,%ecx
call   1040 <recv@plt>
test   %eax,%eax
jle    1500 <main+0x2c0>
mov    %eax,%ebp
mov    0x40(%rsp),%r15
mov    %r15,%rdi
call   1080 <strlen@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
call   1080 <strlen@plt>
sub    %r14d,%ebp
lea    (%rax,%rbp,1),%r14d
add    $0x1,%r14d
mov    %r13,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
xor    %ecx,%ecx
call   10d0 <str_replace@plt>
mov    %rax,%rbp
mov    0xc(%rsp),%r9d
mov    0x20(%rsp),%edi
mov    %rax,%rsi
mov    %r14d,%edx
xor    %ecx,%ecx
mov    %r12,%r8
call   10a0 <sendto@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    0x2abb(%rip),%rax
mov    (%rax),%ebp
mov    0x10(%rsp),%edi
call   1070 <inet_ntoa@plt>
mov    %ebp,%edi
lea    0xbcb(%rip),%rsi
jmp    13bb <main+0x17b>
cs nopw 0x0(%rax,%rax,1)
mov    0x2a91(%rip),%rax
mov    (%rax),%ebp
mov    0x10(%rsp),%edi
call   1070 <inet_ntoa@plt>
mov    %ebp,%edi
lea    0xb89(%rip),%rsi
jmp    13bb <main+0x17b>
lea    0xb77(%rip),%rdi
call   1120 <perror@plt>
mov    $0x1,%edi
call   1150 <exit@plt>

LLVM IR (-O0):
%struct.timeval = type { i32, %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr_in = type { i32, i32 }
%struct.ip_mreq = type { i32, %struct.TYPE_2__, i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [8 x i8] c"sonos-f\00"
@LOG_PID = global i32 0
@LOG_CONS = global i32 0
@LOG_DAEMON = global i32 0
@__const.main.timeout = %struct.timeval { i32 0, %struct.TYPE_2__ { i32 500000 }, i32 0, i32 0 }
@stderr = global i32 0
@.str.1 = [107 x i8] c"Call with 3 arguments:\0A%s external-interface-ip-address internal-interface-ip-address sonos-box-ip-address\00"
@.str.2 = [16 x i8] c"239.255.255.250\00"
@AF_INET = global i32 0
@IPPROTO_IP = global i32 0
@IP_ADD_MEMBERSHIP = global i32 0
@.str.3 = [16 x i8] c"setsockopt mreq\00"
@.str.4 = [11 x i8] c"ZonePlayer\00"
@SOL_SOCKET = global i32 0
@SO_RCVTIMEO = global i32 0
@.str.5 = [6 x i8] c"Error\00"
@LOG_DEBUG = global i32 0
@.str.6 = [24 x i8] c"Message %s --> internal\00"
@.str.7 = [24 x i8] c"Message %s <-> internal\00"
@.str.8 = [22 x i8] c"Message %s not routed\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 %struct.sockaddr_in
%9 = alloca %struct.sockaddr_in
%10 = alloca %struct.sockaddr_in
%11 = alloca i32
%12 = alloca i8*
%13 = alloca %struct.ip_mreq
%14 = alloca %struct.timeval
%15 = alloca i8*
%16 = alloca i8*
%17 = alloca i8*
%18 = alloca i8*
%19 = alloca i8*
%20 = alloca i32
%21 = alloca %struct.sockaddr_in
%22 = alloca i32
%23 = alloca i32
%24 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%25 = load i32, i32* @LOG_PID
%26 = load i32, i32* @LOG_CONS
%27 = or i32 %25, %26
%28 = load i32, i32* @LOG_DAEMON
%29 = call i32 @openlog(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %27, i32 %28)
%30 = bitcast %struct.sockaddr_in* %8 to i8*
%31 = bitcast %struct.sockaddr_in* %9 to i8*
store i32 8, i32* %11
%32 = call i8* @malloc(i32 1000)
store i8* %32, i8** %12
%33 = bitcast %struct.timeval* %14 to i8*
%34 = load i32, i32* %4
%35 = icmp ne i32 %34, 4
br i1 %35, label %36, label %42
36: ; preds = %2
%37 = load i32, i32* @stderr
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 0
%40 = load i8*, i8** %39
%41 = call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([107 x i8], [107 x i8]* @.str.1, i64 0, i64 0), i8* %40)
br label %42
42: ; preds = %36, %2
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 1
%45 = load i8*, i8** %44
store i8* %45, i8** %15
%46 = load i8**, i8*** %5
%47 = getelementptr inbounds i8*, i8** %46, i64 2
%48 = load i8*, i8** %47
store i8* %48, i8** %16
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i64 3
%51 = load i8*, i8** %50
store i8* %51, i8** %17
%52 = load i8*, i8** %17
%53 = call i8* @sonos_location_string(i8* %52)
store i8* %53, i8** %18
%54 = load i8*, i8** %15
%55 = call i8* @sonos_location_string(i8* %54)
store i8* %55, i8** %19
%56 = call i32 @fill_socketaddr_in(%struct.sockaddr_in* %8, i32 1900, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%57 = load i8*, i8** %15
%58 = call i32 @fill_socketaddr_in(%struct.sockaddr_in* %9, i32 1900, i8* %57)
%59 = bitcast %struct.sockaddr_in* %8 to i64*
%60 = load i64, i64* %59
%61 = call i32 @create_bounded_socket(i64 %60)
store i32 %61, i32* %6
%62 = bitcast %struct.sockaddr_in* %9 to i64*
%63 = load i64, i64* %62
%64 = call i32 @create_bounded_socket(i64 %63)
store i32 %64, i32* %7
%65 = load i32, i32* @AF_INET
%66 = load i8**, i8*** %5
%67 = getelementptr inbounds i8*, i8** %66, i64 1
%68 = load i8*, i8** %67
%69 = getelementptr inbounds %struct.ip_mreq, %struct.ip_mreq* %13, i32 0, i32 2
%70 = call i32 @inet_pton(i32 %65, i8* %68, i32* %69)
%71 = call i32 @inet_addr(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%72 = getelementptr inbounds %struct.ip_mreq, %struct.ip_mreq* %13, i32 0, i32 1
%73 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %72, i32 0, i32 0
store i32 %71, i32* %73
%74 = load i32, i32* %6
%75 = load i32, i32* @IPPROTO_IP
%76 = load i32, i32* @IP_ADD_MEMBERSHIP
%77 = bitcast %struct.ip_mreq* %13 to %struct.timeval*
%78 = call i64 @setsockopt(i32 %74, i32 %75, i32 %76, %struct.timeval* %77, i32 16)
%79 = icmp slt i64 %78, 0
br i1 %79, label %80, label %83
80: ; preds = %42
%81 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%82 = call i32 @exit(i32 1)
unreachable
83: ; preds = %42
br label %84
84: ; preds = %83, %157
%85 = load i32, i32* %6
%86 = load i8*, i8** %12
%87 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%88 = call i32 @recvfrom(i32 %85, i8* %86, i32 1000, i32 0, %struct.sockaddr* %87, i32* %11)
store i32 %88, i32* %20
%89 = load i8*, i8** %12
%90 = call i32* @strstr(i8* %89, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%91 = icmp ne i32* %90, null
br i1 %91, label %92, label %151
92: ; preds = %84
%93 = bitcast %struct.sockaddr_in* %21 to i8*
%94 = load i8*, i8** %16
%95 = call i32 @fill_socketaddr_in(%struct.sockaddr_in* %21, i32 0, i8* %94)
%96 = bitcast %struct.sockaddr_in* %21 to i64*
%97 = load i64, i64* %96
%98 = call i32 @create_bounded_socket(i64 %97)
store i32 %98, i32* %22
%99 = load i32, i32* %22
%100 = load i8*, i8** %12
%101 = load i32, i32* %20
%102 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%103 = call i32 @sendto(i32 %99, i8* %100, i32 %101, i32 0, %struct.sockaddr* %102, i32 8)
%104 = load i32, i32* %22
%105 = load i32, i32* @SOL_SOCKET
%106 = load i32, i32* @SO_RCVTIMEO
%107 = call i64 @setsockopt(i32 %104, i32 %105, i32 %106, %struct.timeval* %14, i32 16)
%108 = icmp slt i64 %107, 0
br i1 %108, label %109, label %112
109: ; preds = %92
%110 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%111 = call i32 @exit(i32 1)
unreachable
112: ; preds = %92
%113 = load i32, i32* %22
%114 = load i8*, i8** %12
%115 = call i32 @recv(i32 %113, i8* %114, i32 1000, i32 0)
store i32 %115, i32* %20
%116 = load i32, i32* %20
%117 = icmp sle i32 %116, 0
br i1 %117, label %118, label %124
118: ; preds = %112
%119 = load i32, i32* @LOG_DEBUG
%120 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
%121 = load i32, i32* %120
%122 = call i32 @inet_ntoa(i32 %121)
%123 = call i32 @syslog(i32 %119, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i32 %122)
br label %150
124: ; preds = %112
%125 = load i32, i32* %20
%126 = load i8*, i8** %18
%127 = call i32 @strlen(i8* %126)
%128 = sub nsw i32 %125, %127
%129 = load i8*, i8** %19
%130 = call i32 @strlen(i8* %129)
%131 = add nsw i32 %128, %130
%132 = add nsw i32 %131, 1
store i32 %132, i32* %23
%133 = load i8*, i8** %12
%134 = load i8*, i8** %18
%135 = load i8*, i8** %19
%136 = call i8* @str_replace(i8* %133, i8* %134, i8* %135, i32 0)
store i8* %136, i8** %24
%137 = load i32, i32* %7
%138 = load i8*, i8** %24
%139 = load i32, i32* %23
%140 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%141 = load i32, i32* %11
%142 = call i32 @sendto(i32 %137, i8* %138, i32 %139, i32 0, %struct.sockaddr* %140, i32 %141)
%143 = load i8*, i8** %24
%144 = call i32 @free(i8* %143)
%145 = load i32, i32* @LOG_DEBUG
%146 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
%147 = load i32, i32* %146
%148 = call i32 @inet_ntoa(i32 %147)
%149 = call i32 @syslog(i32 %145, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), i32 %148)
br label %150
150: ; preds = %124, %118
br label %157
151: ; preds = %84
%152 = load i32, i32* @LOG_DEBUG
%153 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
%154 = load i32, i32* %153
%155 = call i32 @inet_ntoa(i32 %154)
%156 = call i32 @syslog(i32 %152, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0), i32 %155)
br label %157
157: ; preds = %151, %150
br label %84
}

LLVM IR (-O2):
%struct.timeval = type { i32, %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr_in = type { i32, i32 }
%struct.ip_mreq = type { i32, %struct.TYPE_2__, i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [8 x i8] c"sonos-f\00"
@LOG_PID = global i32 0
@LOG_CONS = global i32 0
@LOG_DAEMON = global i32 0
@__const.main.timeout = %struct.timeval { i32 0, %struct.TYPE_2__ { i32 500000 }, i32 0, i32 0 }
@stderr = global i32 0
@.str.1 = [107 x i8] c"Call with 3 arguments:\0A%s external-interface-ip-address internal-interface-ip-address sonos-box-ip-address\00"
@.str.2 = [16 x i8] c"239.255.255.250\00"
@AF_INET = global i32 0
@IPPROTO_IP = global i32 0
@IP_ADD_MEMBERSHIP = global i32 0
@.str.3 = [16 x i8] c"setsockopt mreq\00"
@.str.4 = [11 x i8] c"ZonePlayer\00"
@SOL_SOCKET = global i32 0
@SO_RCVTIMEO = global i32 0
@.str.5 = [6 x i8] c"Error\00"
@LOG_DEBUG = global i32 0
@.str.6 = [24 x i8] c"Message %s --> internal\00"
@.str.7 = [24 x i8] c"Message %s <-> internal\00"
@.str.8 = [22 x i8] c"Message %s not routed\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i64
%4 = bitcast i64* %3 to %struct.sockaddr_in*
%5 = alloca i64
%6 = bitcast i64* %5 to %struct.sockaddr_in*
%7 = alloca %struct.sockaddr_in
%8 = alloca i32
%9 = alloca %struct.ip_mreq
%10 = alloca %struct.timeval
%11 = alloca i64
%12 = bitcast i64* %11 to %struct.sockaddr_in*
%13 = load i32, i32* @LOG_PID
%14 = load i32, i32* @LOG_CONS
%15 = or i32 %14, %13
%16 = load i32, i32* @LOG_DAEMON
%17 = tail call i32 @openlog(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %15, i32 %16)
%18 = bitcast i64* %3 to i8*
store i64 0, i64* %3
%19 = bitcast i64* %5 to i8*
store i64 0, i64* %5
%20 = bitcast %struct.sockaddr_in* %7 to i8*
%21 = bitcast i32* %8 to i8*
store i32 8, i32* %8
%22 = tail call dereferenceable_or_null(1000) i8* @malloc(i32 1000)
%23 = bitcast %struct.ip_mreq* %9 to i8*
%24 = bitcast %struct.timeval* %10 to i8*
%25 = icmp eq i32 %0, 4
br i1 %25, label %30, label %26
26: ; preds = %2
%27 = load i32, i32* @stderr
%28 = load i8*, i8** %1
%29 = tail call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([107 x i8], [107 x i8]* @.str.1, i64 0, i64 0), i8* %28)
br label %30
30: ; preds = %26, %2
%31 = getelementptr inbounds i8*, i8** %1, i64 1
%32 = load i8*, i8** %31
%33 = getelementptr inbounds i8*, i8** %1, i64 2
%34 = load i8*, i8** %33
%35 = getelementptr inbounds i8*, i8** %1, i64 3
%36 = load i8*, i8** %35
%37 = tail call i8* @sonos_location_string(i8* %36)
%38 = tail call i8* @sonos_location_string(i8* %32)
%39 = call i32 @fill_socketaddr_in(%struct.sockaddr_in* %4, i32 1900, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%40 = call i32 @fill_socketaddr_in(%struct.sockaddr_in* %6, i32 1900, i8* %32)
%41 = load i64, i64* %3
%42 = call i32 @create_bounded_socket(i64 %41)
%43 = load i64, i64* %5
%44 = call i32 @create_bounded_socket(i64 %43)
%45 = load i32, i32* @AF_INET
%46 = load i8*, i8** %31
%47 = getelementptr inbounds %struct.ip_mreq, %struct.ip_mreq* %9, i64 0, i32 2
%48 = call i32 @inet_pton(i32 %45, i8* %46, i32* %47)
%49 = call i32 @inet_addr(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%50 = getelementptr inbounds %struct.ip_mreq, %struct.ip_mreq* %9, i64 0, i32 1, i32 0
store i32 %49, i32* %50
%51 = load i32, i32* @IPPROTO_IP
%52 = load i32, i32* @IP_ADD_MEMBERSHIP
%53 = bitcast %struct.ip_mreq* %9 to %struct.timeval*
%54 = call i64 @setsockopt(i32 %42, i32 %51, i32 %52, %struct.timeval* %53, i32 16)
%55 = icmp slt i64 %54, 0
br i1 %55, label %61, label %56
56: ; preds = %30
%57 = bitcast i64* %11 to i8*
%58 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%59 = bitcast i64* %3 to %struct.sockaddr*
%60 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i64 0, i32 0
br label %64
61: ; preds = %30
%62 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%63 = call i32 @exit(i32 1)
unreachable
64: ; preds = %108, %56
%65 = call i32 @recvfrom(i32 %42, i8* %22, i32 1000, i32 0, %struct.sockaddr* %58, i32* %8)
%66 = call i32* @strstr(i8* dereferenceable(1) %22, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%67 = icmp eq i32* %66, null
br i1 %67, label %103, label %68
68: ; preds = %64
store i64 0, i64* %11
%69 = call i32 @fill_socketaddr_in(%struct.sockaddr_in* %12, i32 0, i8* %34)
%70 = load i64, i64* %11
%71 = call i32 @create_bounded_socket(i64 %70)
%72 = call i32 @sendto(i32 %71, i8* %22, i32 %65, i32 0, %struct.sockaddr* %59, i32 8)
%73 = load i32, i32* @SOL_SOCKET
%74 = load i32, i32* @SO_RCVTIMEO
%75 = call i64 @setsockopt(i32 %71, i32 %73, i32 %74, %struct.timeval* %10, i32 16)
%76 = icmp slt i64 %75, 0
br i1 %76, label %77, label %80
77: ; preds = %68
%78 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%79 = call i32 @exit(i32 1)
unreachable
80: ; preds = %68
%81 = call i32 @recv(i32 %71, i8* %22, i32 1000, i32 0)
%82 = icmp slt i32 %81, 1
br i1 %82, label %83, label %88
83: ; preds = %80
%84 = load i32, i32* @LOG_DEBUG
%85 = load i32, i32* %60
%86 = call i32 @inet_ntoa(i32 %85)
%87 = call i32 @syslog(i32 %84, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i32 %86)
br label %102
88: ; preds = %80
%89 = call i32 @strlen(i8* %37)
%90 = call i32 @strlen(i8* %38)
%91 = add nuw i32 %81, 1
%92 = sub i32 %91, %89
%93 = add i32 %92, %90
%94 = call i8* @str_replace(i8* %22, i8* %37, i8* %38, i32 0)
%95 = load i32, i32* %8
%96 = call i32 @sendto(i32 %44, i8* %94, i32 %93, i32 0, %struct.sockaddr* %58, i32 %95)
%97 = call i32 @free(i8* %94)
%98 = load i32, i32* @LOG_DEBUG
%99 = load i32, i32* %60
%100 = call i32 @inet_ntoa(i32 %99)
%101 = call i32 @syslog(i32 %98, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), i32 %100)
br label %102
102: ; preds = %88, %83
br label %108
103: ; preds = %64
%104 = load i32, i32* @LOG_DEBUG
%105 = load i32, i32* %60
%106 = call i32 @inet_ntoa(i32 %105)
%107 = call i32 @syslog(i32 %104, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0), i32 %106)
br label %108
108: ; preds = %103, %102
br label %64
}