#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_6__ TYPE_3__;
typedef struct TYPE_5__ TYPE_2__;
typedef struct TYPE_4__ TYPE_1__;

/* Type definitions */
struct TYPE_6__ {
  int /*<<< orphan*/ s_addr;
};
struct TYPE_5__ {
  void *s_addr;
};
struct TYPE_4__ {
  void *s_addr;
};
struct sockaddr_in {
  TYPE_3__ sin_addr;
  TYPE_2__ imr_interface;
  TYPE_1__ imr_multiaddr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct ip_mreq {
  TYPE_3__ sin_addr;
  TYPE_2__ imr_interface;
  TYPE_1__ imr_multiaddr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ reuse;
typedef int /*<<< orphan*/ ack;
typedef int /*<<< orphan*/ UsbipGroup;
typedef int /*<<< orphan*/ LocalSock;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int EXIT_SUCCESS;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ IPPROTO_IP;
int /*<<< orphan*/ IP_ADD_MEMBERSHIP;
int /*<<< orphan*/ SHUT_RDWR;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
char *get_iface_addr();
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
void *inet_addr(char *);
char *inet_ntoa(TYPE_3__);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int recvfrom(int, int *, int, int /*<<< orphan*/, struct sockaddr *, int *);
int sendto(int, int /*<<< orphan*/ *, int /*<<< orphan*/, int /*<<< orphan*/,
           struct sockaddr *, int);
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ shutdown(int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(void) {
  struct sockaddr_in LocalSock;
  struct ip_mreq UsbipGroup;
  int status;
  int sockfd;
  int ack = 1;
  socklen_t socklen;
  memset(&LocalSock, 0, sizeof(LocalSock));
  memset(&UsbipGroup, 0, sizeof(UsbipGroup));
  sockfd = socket(AF_INET, SOCK_DGRAM, 0);
  if (sockfd < 0) {
    perror("can't create datagram socket");
    exit(1);
  }
  {
    int reuse = 1;
    if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, (char *)&reuse,
                   sizeof(reuse)) < 0) {
      perror("setting SO_REUSEADDR");
      close(sockfd);
      exit(1);
    }
  }
  LocalSock.sin_family = AF_INET;
  LocalSock.sin_port = htons(10296);
  LocalSock.sin_addr.s_addr = htonl(INADDR_ANY);
  status = bind(sockfd, (struct sockaddr *)&LocalSock, sizeof(LocalSock));
  if (status < 0) {
    perror("binding datagram socket");
    close(sockfd);
    exit(1);
  }
  UsbipGroup.imr_multiaddr.s_addr = inet_addr("239.255.0.1");
  UsbipGroup.imr_interface.s_addr = inet_addr(get_iface_addr());
  if (setsockopt(sockfd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *)&UsbipGroup,
                 sizeof(UsbipGroup)) < 0) {
    perror("setup multicast group");
    close(sockfd);
    exit(1);
  }
  while (1) {
    printf("Discovery Listener: listening on %s...\n", get_iface_addr());
    socklen = sizeof(LocalSock);
    status = recvfrom(sockfd, &ack, sizeof(ack), 0,
                      (struct sockaddr *)&LocalSock, &socklen);
    if (status < 0) {
      perror("recvfrom");
    } else {
      printf("received %d bytes from %s\n", status,
             inet_ntoa(LocalSock.sin_addr));
      printf("Discovery Listener: packet is %d bytes\n", status);
      printf("Discovery Listener: packet contains \"%d\"\n", ack);
      do {
        status =
            sendto(sockfd, NULL, 0, 0, (struct sockaddr *)&LocalSock, socklen);
      } while (status < 0);
    }
    printf("\n");
  }
  shutdown(sockfd, SHUT_RDWR);
  close(sockfd);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x54(%rbp)
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1080 <memset@plt>
lea    -0x48(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1080 <memset@plt>
mov    0x2dab(%rip),%rax
mov    (%rax),%edi
mov    0x2d8a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1110 <socket@plt>
mov    %eax,-0x50(%rbp)
cmpl   $0x0,-0x50(%rbp)
jge    1262 <main+0x72>
lea    0xdad(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
movl   $0x1,-0x5c(%rbp)
mov    -0x50(%rbp),%edi
mov    0x2d75(%rip),%rax
mov    (%rax),%esi
mov    0x2d34(%rip),%rax
mov    (%rax),%edx
lea    -0x5c(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0x0,%rax
jge    12b5 <main+0xc5>
lea    0xd7f(%rip),%rdi
call   10e0 <perror@plt>
mov    -0x50(%rbp),%edi
call   10a0 <close@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    0x2d1c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    $0x2838,%edi
call   1050 <htons@plt>
mov    %eax,-0x10(%rbp)
mov    0x2cf3(%rip),%rax
mov    (%rax),%edi
call   1070 <htonl@plt>
mov    %eax,-0x28(%rbp)
mov    -0x50(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x20,%edx
call   10d0 <bind@plt>
mov    %eax,-0x4c(%rbp)
cmpl   $0x0,-0x4c(%rbp)
jge    131b <main+0x12b>
lea    0xd2e(%rip),%rdi
call   10e0 <perror@plt>
mov    -0x50(%rbp),%edi
call   10a0 <close@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
lea    0xd28(%rip),%rdi
call   10b0 <inet_addr@plt>
mov    %rax,-0x38(%rbp)
mov    $0x0,%al
call   10f0 <get_iface_addr@plt>
mov    %rax,%rdi
call   10b0 <inet_addr@plt>
mov    %rax,-0x40(%rbp)
mov    -0x50(%rbp),%edi
mov    0x2c88(%rip),%rax
mov    (%rax),%esi
mov    0x2c8f(%rip),%rax
mov    (%rax),%edx
lea    -0x48(%rbp),%rcx
mov    $0x20,%r8d
call   1030 <setsockopt@plt>
cmp    $0x0,%rax
jge    138a <main+0x19a>
lea    0xce3(%rip),%rdi
call   10e0 <perror@plt>
mov    -0x50(%rbp),%edi
call   10a0 <close@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
jmp    138f <main+0x19f>
mov    $0x0,%al
call   10f0 <get_iface_addr@plt>
mov    %rax,%rsi
lea    0xccc(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x20,-0x58(%rbp)
mov    -0x50(%rbp),%edi
lea    -0x28(%rbp),%r8
lea    -0x54(%rbp),%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
lea    -0x58(%rbp),%r9
call   10c0 <recvfrom@plt>
mov    %eax,-0x4c(%rbp)
cmpl   $0x0,-0x4c(%rbp)
jge    13e7 <main+0x1f7>
lea    0xcb7(%rip),%rdi
call   10e0 <perror@plt>
jmp    1455 <main+0x265>
mov    -0x4c(%rbp),%eax
mov    %eax,-0x60(%rbp)
mov    -0x28(%rbp),%edi
call   1040 <inet_ntoa@plt>
mov    -0x60(%rbp),%esi
mov    %rax,%rdx
lea    0xc9b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x4c(%rbp),%esi
lea    0xca5(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x54(%rbp),%esi
lea    0xcbc(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x50(%rbp),%edi
lea    -0x28(%rbp),%r8
mov    -0x58(%rbp),%r9d
xor    %eax,%eax
mov    %eax,%esi
xor    %ecx,%ecx
mov    %ecx,%edx
call   1090 <sendto@plt>
mov    %eax,-0x4c(%rbp)
cmpl   $0x0,-0x4c(%rbp)
jl     142b <main+0x23b>
jmp    1455 <main+0x265>
lea    0xcac(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    138f <main+0x19f>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
movl   $0x1,0x4(%rsp)
lea    0x8(%rsp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1090 <memset@plt>
lea    0x28(%rsp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1090 <memset@plt>
mov    0x2d99(%rip),%rbx
mov    (%rbx),%edi
mov    0x2d78(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1120 <socket@plt>
test   %eax,%eax
js     13ed <main+0x1ed>
mov    %eax,%ebp
movl   $0x1,(%rsp)
mov    0x2d7f(%rip),%rax
mov    (%rax),%esi
mov    0x2d3e(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rcx
mov    %ebp,%edi
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
test   %rax,%rax
js     1403 <main+0x203>
mov    (%rbx),%eax
mov    %eax,0x24(%rsp)
mov    $0x2838,%edi
call   1060 <htons@plt>
mov    %eax,0x20(%rsp)
mov    0x2d20(%rip),%rax
mov    (%rax),%edi
call   1080 <htonl@plt>
mov    %eax,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %ebp,%edi
mov    $0x20,%edx
call   10e0 <bind@plt>
test   %eax,%eax
js     140c <main+0x20c>
lea    0xd77(%rip),%rdi
call   10c0 <inet_addr@plt>
mov    %rax,0x38(%rsp)
xor    %eax,%eax
call   1100 <get_iface_addr@plt>
mov    %rax,%rdi
call   10c0 <inet_addr@plt>
mov    %rax,0x30(%rsp)
mov    0x2cd8(%rip),%rax
mov    (%rax),%esi
mov    0x2cdf(%rip),%rax
mov    (%rax),%edx
lea    0x28(%rsp),%rcx
mov    %ebp,%edi
mov    $0x20,%r8d
call   1040 <setsockopt@plt>
test   %rax,%rax
js     1415 <main+0x215>
lea    0xd47(%rip),%r14
lea    0x4(%rsp),%r15
lea    0x8(%rsp),%rbx
mov    %rsp,%r12
jmp    1356 <main+0x156>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0xd4d(%rip),%rdi
call   10f0 <perror@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1100 <get_iface_addr@plt>
mov    %r14,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
movl   $0x20,(%rsp)
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
mov    %rbx,%r8
mov    %r12,%r9
call   10d0 <recvfrom@plt>
test   %eax,%eax
js     1340 <main+0x140>
mov    %eax,%r13d
mov    0x8(%rsp),%edi
call   1050 <inet_ntoa@plt>
lea    0xcfe(%rip),%rdi
mov    %r13d,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xd05(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x4(%rsp),%esi
lea    0xd18(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
nop
mov    (%rsp),%r9d
mov    %ebp,%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %rbx,%r8
call   10a0 <sendto@plt>
test   %eax,%eax
js     13d0 <main+0x1d0>
jmp    134c <main+0x14c>
lea    0xc0c(%rip),%rdi
call   10f0 <perror@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
lea    0xc13(%rip),%rdi
jmp    141c <main+0x21c>
lea    0xc1f(%rip),%rdi
jmp    141c <main+0x21c>
lea    0xc3a(%rip),%rdi
call   10f0 <perror@plt>
mov    %ebp,%edi
call   10b0 <close@plt>
mov    $0x1,%edi
call   1110 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_6__, %struct.TYPE_5__, %struct.TYPE_4__, i32, i32 }
%struct.TYPE_6__ = type { i32 }
%struct.TYPE_5__ = type { i8* }
%struct.TYPE_4__ = type { i8* }
%struct.ip_mreq = type { %struct.TYPE_6__, %struct.TYPE_5__, %struct.TYPE_4__, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [29 x i8] c"can't create datagram socket\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.1 = [21 x i8] c"setting SO_REUSEADDR\00"
@INADDR_ANY = global i32 0
@.str.2 = [24 x i8] c"binding datagram socket\00"
@.str.3 = [12 x i8] c"239.255.0.1\00"
@IPPROTO_IP = global i32 0
@IP_ADD_MEMBERSHIP = global i32 0
@.str.4 = [22 x i8] c"setup multicast group\00"
@.str.5 = [40 x i8] c"Discovery Listener: listening on %s...\0A\00"
@.str.6 = [9 x i8] c"recvfrom\00"
@.str.7 = [27 x i8] c"received %d bytes from %s\0A\00"
@.str.8 = [40 x i8] c"Discovery Listener: packet is %d bytes\0A\00"
@.str.9 = [42 x i8] c"Discovery Listener: packet contains \22%d\22\0A\00"
@.str.10 = [2 x i8] c"\0A\00"
@EXIT_SUCCESS = global i32 0
@SHUT_RDWR = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.sockaddr_in
%3 = alloca %struct.ip_mreq
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
store i32 1, i32* %6
%9 = call i32 @memset(%struct.sockaddr_in* %2, i32 0, i32 32)
%10 = bitcast %struct.ip_mreq* %3 to %struct.sockaddr_in*
%11 = call i32 @memset(%struct.sockaddr_in* %10, i32 0, i32 32)
%12 = load i32, i32* @AF_INET
%13 = load i32, i32* @SOCK_DGRAM
%14 = call i32 @socket(i32 %12, i32 %13, i32 0)
store i32 %14, i32* %5
%15 = load i32, i32* %5
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %0
%18 = call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %0
store i32 1, i32* %8
%21 = load i32, i32* %5
%22 = load i32, i32* @SOL_SOCKET
%23 = load i32, i32* @SO_REUSEADDR
%24 = bitcast i32* %8 to i8*
%25 = call i64 @setsockopt(i32 %21, i32 %22, i32 %23, i8* %24, i32 4)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %32
27: ; preds = %20
%28 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%29 = load i32, i32* %5
%30 = call i32 @close(i32 %29)
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %20
%33 = load i32, i32* @AF_INET
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 4
store i32 %33, i32* %34
%35 = call i32 @htons(i32 10296)
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 3
store i32 %35, i32* %36
%37 = load i32, i32* @INADDR_ANY
%38 = call i32 @htonl(i32 %37)
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 0
%40 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %39, i32 0, i32 0
store i32 %38, i32* %40
%41 = load i32, i32* %5
%42 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%43 = call i32 @bind(i32 %41, %struct.sockaddr* %42, i32 32)
store i32 %43, i32* %4
%44 = load i32, i32* %4
%45 = icmp slt i32 %44, 0
br i1 %45, label %46, label %51
46: ; preds = %32
%47 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%48 = load i32, i32* %5
%49 = call i32 @close(i32 %48)
%50 = call i32 @exit(i32 1)
unreachable
51: ; preds = %32
%52 = call i8* @inet_addr(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%53 = getelementptr inbounds %struct.ip_mreq, %struct.ip_mreq* %3, i32 0, i32 2
%54 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %53, i32 0, i32 0
store i8* %52, i8** %54
%55 = call i8* (...) @get_iface_addr()
%56 = call i8* @inet_addr(i8* %55)
%57 = getelementptr inbounds %struct.ip_mreq, %struct.ip_mreq* %3, i32 0, i32 1
%58 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %57, i32 0, i32 0
store i8* %56, i8** %58
%59 = load i32, i32* %5
%60 = load i32, i32* @IPPROTO_IP
%61 = load i32, i32* @IP_ADD_MEMBERSHIP
%62 = bitcast %struct.ip_mreq* %3 to i8*
%63 = call i64 @setsockopt(i32 %59, i32 %60, i32 %61, i8* %62, i32 32)
%64 = icmp slt i64 %63, 0
br i1 %64, label %65, label %70
65: ; preds = %51
%66 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
%67 = load i32, i32* %5
%68 = call i32 @close(i32 %67)
%69 = call i32 @exit(i32 1)
unreachable
70: ; preds = %51
br label %71
71: ; preds = %70, %101
%72 = call i8* (...) @get_iface_addr()
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0), i8* %72)
store i32 32, i32* %7
%74 = load i32, i32* %5
%75 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%76 = call i32 @recvfrom(i32 %74, i32* %6, i32 4, i32 0, %struct.sockaddr* %75, i32* %7)
store i32 %76, i32* %4
%77 = load i32, i32* %4
%78 = icmp slt i32 %77, 0
br i1 %78, label %79, label %81
79: ; preds = %71
%80 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
br label %101
81: ; preds = %71
%82 = load i32, i32* %4
%83 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 0
%84 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %83, i32 0, i32 0
%85 = load i32, i32* %84
%86 = call i8* @inet_ntoa(i32 %85)
%87 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0), i32 %82, i8* %86)
%88 = load i32, i32* %4
%89 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.8, i64 0, i64 0), i32 %88)
%90 = load i32, i32* %6
%91 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.9, i64 0, i64 0), i32 %90)
br label %92
92: ; preds = %97, %81
%93 = load i32, i32* %5
%94 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%95 = load i32, i32* %7
%96 = call i32 @sendto(i32 %93, i32* null, i32 0, i32 0, %struct.sockaddr* %94, i32 %95)
store i32 %96, i32* %4
br label %97
97: ; preds = %92
%98 = load i32, i32* %4
%99 = icmp slt i32 %98, 0
br i1 %99, label %92, label %100
100: ; preds = %97
br label %101
101: ; preds = %100, %79
%102 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
br label %71
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_6__, %struct.TYPE_5__, %struct.TYPE_4__, i32, i32 }
%struct.TYPE_6__ = type { i32 }
%struct.TYPE_5__ = type { i8* }
%struct.TYPE_4__ = type { i8* }
%struct.ip_mreq = type { %struct.TYPE_6__, %struct.TYPE_5__, %struct.TYPE_4__, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [29 x i8] c"can't create datagram socket\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.1 = [21 x i8] c"setting SO_REUSEADDR\00"
@INADDR_ANY = global i32 0
@.str.2 = [24 x i8] c"binding datagram socket\00"
@.str.3 = [12 x i8] c"239.255.0.1\00"
@IPPROTO_IP = global i32 0
@IP_ADD_MEMBERSHIP = global i32 0
@.str.4 = [22 x i8] c"setup multicast group\00"
@.str.5 = [40 x i8] c"Discovery Listener: listening on %s...\0A\00"
@.str.6 = [9 x i8] c"recvfrom\00"
@.str.7 = [27 x i8] c"received %d bytes from %s\0A\00"
@.str.8 = [40 x i8] c"Discovery Listener: packet is %d bytes\0A\00"
@.str.9 = [42 x i8] c"Discovery Listener: packet contains \22%d\22\0A\00"
@EXIT_SUCCESS = global i32 0
@SHUT_RDWR = global i32 0
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca %struct.ip_mreq
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = bitcast %struct.sockaddr_in* %1 to i8*
%7 = bitcast %struct.ip_mreq* %2 to i8*
%8 = bitcast i32* %3 to i8*
store i32 1, i32* %3
%9 = bitcast i32* %4 to i8*
%10 = call i32 @memset(%struct.sockaddr_in* %1, i32 0, i32 32)
%11 = bitcast %struct.ip_mreq* %2 to %struct.sockaddr_in*
%12 = call i32 @memset(%struct.sockaddr_in* %11, i32 0, i32 32)
%13 = load i32, i32* @AF_INET
%14 = load i32, i32* @SOCK_DGRAM
%15 = call i32 @socket(i32 %13, i32 %14, i32 0)
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %0
%18 = call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %0
%21 = bitcast i32* %5 to i8*
store i32 1, i32* %5
%22 = load i32, i32* @SOL_SOCKET
%23 = load i32, i32* @SO_REUSEADDR
%24 = call i64 @setsockopt(i32 %15, i32 %22, i32 %23, i8* %21, i32 4)
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %20
%27 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%28 = call i32 @close(i32 %15)
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %20
%31 = load i32, i32* @AF_INET
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 4
store i32 %31, i32* %32
%33 = call i32 @htons(i32 10296)
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 3
store i32 %33, i32* %34
%35 = load i32, i32* @INADDR_ANY
%36 = call i32 @htonl(i32 %35)
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0, i32 0
store i32 %36, i32* %37
%38 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%39 = call i32 @bind(i32 %15, %struct.sockaddr* %38, i32 32)
%40 = icmp slt i32 %39, 0
br i1 %40, label %41, label %45
41: ; preds = %30
%42 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%43 = call i32 @close(i32 %15)
%44 = call i32 @exit(i32 1)
unreachable
45: ; preds = %30
%46 = call i8* @inet_addr(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%47 = getelementptr inbounds %struct.ip_mreq, %struct.ip_mreq* %2, i64 0, i32 2, i32 0
store i8* %46, i8** %47
%48 = call i8* (...) @get_iface_addr()
%49 = call i8* @inet_addr(i8* %48)
%50 = getelementptr inbounds %struct.ip_mreq, %struct.ip_mreq* %2, i64 0, i32 1, i32 0
store i8* %49, i8** %50
%51 = load i32, i32* @IPPROTO_IP
%52 = load i32, i32* @IP_ADD_MEMBERSHIP
%53 = call i64 @setsockopt(i32 %15, i32 %51, i32 %52, i8* %7, i32 32)
%54 = icmp slt i64 %53, 0
br i1 %54, label %55, label %59
55: ; preds = %45
%56 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
%57 = call i32 @close(i32 %15)
%58 = call i32 @exit(i32 1)
unreachable
59: ; preds = %45, %77
%60 = call i8* (...) @get_iface_addr()
%61 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0), i8* %60)
store i32 32, i32* %4
%62 = call i32 @recvfrom(i32 %15, i32* %3, i32 4, i32 0, %struct.sockaddr* %38, i32* %4)
%63 = icmp slt i32 %62, 0
br i1 %63, label %64, label %66
64: ; preds = %59
%65 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
br label %77
66: ; preds = %59
%67 = load i32, i32* %37
%68 = call i8* @inet_ntoa(i32 %67)
%69 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0), i32 %62, i8* %68)
%70 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.8, i64 0, i64 0), i32 %62)
%71 = load i32, i32* %3
%72 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.9, i64 0, i64 0), i32 %71)
br label %73
73: ; preds = %73, %66
%74 = load i32, i32* %4
%75 = call i32 @sendto(i32 %15, i32* null, i32 0, i32 0, %struct.sockaddr* %38, i32 %74)
%76 = icmp slt i32 %75, 0
br i1 %76, label %73, label %77
77: ; preds = %73, %64
%78 = call i32 @putchar(i32 10)
br label %59
}