#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_4__ TYPE_2__;
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct TYPE_4__ {
  int /*<<< orphan*/ s_addr;
};
struct TYPE_3__ {
  int /*<<< orphan*/ s_addr;
};
struct ip_mreq {
  TYPE_2__ imr_interface;
  TYPE_1__ imr_multiaddr;
};
typedef int /*<<< orphan*/ srcaddr;
typedef int socklen_t;
typedef int /*<<< orphan*/ recvaddr;
typedef int /*<<< orphan*/ mreq;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ IPPROTO_IP;
int /*<<< orphan*/ IP_ADD_MEMBERSHIP;
int /*<<< orphan*/ SOCK_DGRAM;
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_pton(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ recvfrom(int, char *, int, int /*<<< orphan*/,
                            struct sockaddr *, int *);
int /*<<< orphan*/ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              struct ip_mreq *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  char *listen_addr = "224.0.2.1";
  int listen_port = 19283;
  int sockfd;
  struct sockaddr_in recvaddr;
  struct sockaddr_in srcaddr;
  socklen_t srcaddrlen = sizeof(srcaddr);
  char recvdata[2048];
  struct ip_mreq mreq;
  bzero(&recvaddr, sizeof(recvaddr));
  recvaddr.sin_family = AF_INET;
  recvaddr.sin_port = htons(listen_port);
  inet_pton(AF_INET, listen_addr, &recvaddr.sin_addr);
  if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
    perror("socket failed to allocate");
  inet_pton(AF_INET, listen_addr, &mreq.imr_multiaddr.s_addr);
  mreq.imr_interface.s_addr = htonl(INADDR_ANY);
  setsockopt(sockfd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq));
  if (bind(sockfd, (struct sockaddr *)&recvaddr, sizeof(recvaddr)) < 0)
    perror("bind failed");
  recvfrom(sockfd, recvdata, 2048, 0, (struct sockaddr *)&srcaddr, &srcaddrlen);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x860,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe50(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x4b53,-0x1c(%rbp)
movl   $0xc,-0x44(%rbp)
lea    -0x30(%rbp),%rdi
mov    $0xc,%esi
call   10a0 <bzero@plt>
mov    0x2e09(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
call   1040 <htons@plt>
mov    %eax,-0x2c(%rbp)
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   1060 <inet_pton@plt>
mov    0x2ddc(%rip),%rax
mov    (%rax),%edi
mov    0x2dbb(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
jge    122e <main+0x9e>
lea    0xde1(%rip),%rdi
call   1090 <perror@plt>
mov    0x2dab(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rsi
lea    -0x858(%rbp),%rdx
add    $0x4,%rdx
call   1060 <inet_pton@plt>
mov    0x2d7e(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,-0x858(%rbp)
mov    -0x20(%rbp),%edi
mov    0x2d6f(%rip),%rax
mov    (%rax),%esi
mov    0x2d76(%rip),%rax
mov    (%rax),%edx
lea    -0x858(%rbp),%rcx
mov    $0x8,%r8d
call   1030 <setsockopt@plt>
mov    -0x20(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0xc,%edx
call   1080 <bind@plt>
cmp    $0x0,%rax
jge    12ad <main+0x11d>
lea    0xd7c(%rip),%rdi
call   1090 <perror@plt>
mov    -0x20(%rbp),%edi
lea    -0x850(%rbp),%rsi
lea    -0x40(%rbp),%r8
mov    $0x800,%edx
xor    %ecx,%ecx
lea    -0x44(%rbp),%r9
call   1070 <recvfrom@plt>
mov    -0x4(%rbp),%eax
add    $0x860,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x838,%rsp
movl   $0xc,0x4(%rsp)
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0xc,%esi
call   10a0 <bzero@plt>
mov    0x2e25(%rip),%r14
mov    (%r14),%eax
mov    %eax,0x18(%rsp)
mov    $0x4b53,%edi
call   1040 <htons@plt>
mov    %eax,0x14(%rsp)
mov    (%r14),%edi
lea    0xe26(%rip),%rsi
mov    %rbx,%rdx
call   1060 <inet_pton@plt>
mov    (%r14),%edi
mov    0x2ddc(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,%ebx
test   %eax,%eax
js     1289 <main+0xf9>
mov    (%r14),%edi
lea    0xc(%rsp),%rdx
lea    0xdf2(%rip),%rsi
call   1060 <inet_pton@plt>
mov    0x2db6(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,0x8(%rsp)
mov    0x2dac(%rip),%rax
mov    (%rax),%esi
mov    0x2db3(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%rcx
mov    %ebx,%edi
mov    $0x8,%r8d
call   1030 <setsockopt@plt>
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   1080 <bind@plt>
test   %rax,%rax
js     129a <main+0x10a>
lea    0x30(%rsp),%rsi
lea    0x20(%rsp),%r8
lea    0x4(%rsp),%r9
mov    %ebx,%edi
mov    $0x800,%edx
xor    %ecx,%ecx
call   1070 <recvfrom@plt>
xor    %eax,%eax
add    $0x838,%rsp
pop    %rbx
pop    %r14
ret
lea    0xd7a(%rip),%rdi
call   1090 <perror@plt>
jmp    11ff <main+0x6f>
lea    0xd83(%rip),%rdi
call   1090 <perror@plt>
jmp    125f <main+0xcf>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.ip_mreq = type { %struct.TYPE_4__, %struct.TYPE_3__ }
%struct.TYPE_4__ = type { i32 }
%struct.TYPE_3__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [10 x i8] c"224.0.2.1\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [26 x i8] c"socket failed to allocate\00"
@INADDR_ANY = global i32 0
@IPPROTO_IP = global i32 0
@IP_ADD_MEMBERSHIP = global i32 0
@.str.2 = [12 x i8] c"bind failed\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.sockaddr_in
%10 = alloca %struct.sockaddr_in
%11 = alloca i32
%12 = alloca [2048 x i8]
%13 = alloca %struct.ip_mreq
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %6
store i32 19283, i32* %7
store i32 12, i32* %11
%14 = call i32 @bzero(%struct.sockaddr_in* %9, i32 12)
%15 = load i32, i32* @AF_INET
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 2
store i32 %15, i32* %16
%17 = load i32, i32* %7
%18 = call i32 @htons(i32 %17)
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
store i32 %18, i32* %19
%20 = load i32, i32* @AF_INET
%21 = load i8*, i8** %6
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
%23 = call i32 @inet_pton(i32 %20, i8* %21, i32* %22)
%24 = load i32, i32* @AF_INET
%25 = load i32, i32* @SOCK_DGRAM
%26 = call i32 @socket(i32 %24, i32 %25, i32 0)
store i32 %26, i32* %8
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %2
%29 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %30
30: ; preds = %28, %2
%31 = load i32, i32* @AF_INET
%32 = load i8*, i8** %6
%33 = getelementptr inbounds %struct.ip_mreq, %struct.ip_mreq* %13, i32 0, i32 1
%34 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %33, i32 0, i32 0
%35 = call i32 @inet_pton(i32 %31, i8* %32, i32* %34)
%36 = load i32, i32* @INADDR_ANY
%37 = call i32 @htonl(i32 %36)
%38 = getelementptr inbounds %struct.ip_mreq, %struct.ip_mreq* %13, i32 0, i32 0
%39 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %38, i32 0, i32 0
store i32 %37, i32* %39
%40 = load i32, i32* %8
%41 = load i32, i32* @IPPROTO_IP
%42 = load i32, i32* @IP_ADD_MEMBERSHIP
%43 = call i32 @setsockopt(i32 %40, i32 %41, i32 %42, %struct.ip_mreq* %13, i32 8)
%44 = load i32, i32* %8
%45 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%46 = call i64 @bind(i32 %44, %struct.sockaddr* %45, i32 12)
%47 = icmp slt i64 %46, 0
br i1 %47, label %48, label %50
48: ; preds = %30
%49 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %50
50: ; preds = %48, %30
%51 = load i32, i32* %8
%52 = getelementptr inbounds [2048 x i8], [2048 x i8]* %12, i64 0, i64 0
%53 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%54 = call i32 @recvfrom(i32 %51, i8* %52, i32 2048, i32 0, %struct.sockaddr* %53, i32* %11)
%55 = load i32, i32* %3
ret i32 %55
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.ip_mreq = type { %struct.TYPE_4__, %struct.TYPE_3__ }
%struct.TYPE_4__ = type { i32 }
%struct.TYPE_3__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [10 x i8] c"224.0.2.1\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [26 x i8] c"socket failed to allocate\00"
@INADDR_ANY = global i32 0
@IPPROTO_IP = global i32 0
@IP_ADD_MEMBERSHIP = global i32 0
@.str.2 = [12 x i8] c"bind failed\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = alloca [2048 x i8]
%7 = alloca %struct.ip_mreq
%8 = bitcast %struct.sockaddr_in* %3 to i8*
%9 = bitcast %struct.sockaddr_in* %4 to i8*
%10 = bitcast i32* %5 to i8*
store i32 12, i32* %5
%11 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%12 = bitcast %struct.ip_mreq* %7 to i8*
%13 = call i32 @bzero(%struct.sockaddr_in* %3, i32 12)
%14 = load i32, i32* @AF_INET
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %14, i32* %15
%16 = tail call i32 @htons(i32 19283)
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %16, i32* %17
%18 = load i32, i32* @AF_INET
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%20 = call i32 @inet_pton(i32 %18, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32* %19)
%21 = load i32, i32* @AF_INET
%22 = load i32, i32* @SOCK_DGRAM
%23 = call i32 @socket(i32 %21, i32 %22, i32 0)
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %2
%26 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %27
27: ; preds = %25, %2
%28 = load i32, i32* @AF_INET
%29 = getelementptr inbounds %struct.ip_mreq, %struct.ip_mreq* %7, i64 0, i32 1, i32 0
%30 = call i32 @inet_pton(i32 %28, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32* %29)
%31 = load i32, i32* @INADDR_ANY
%32 = call i32 @htonl(i32 %31)
%33 = getelementptr inbounds %struct.ip_mreq, %struct.ip_mreq* %7, i64 0, i32 0, i32 0
store i32 %32, i32* %33
%34 = load i32, i32* @IPPROTO_IP
%35 = load i32, i32* @IP_ADD_MEMBERSHIP
%36 = call i32 @setsockopt(i32 %23, i32 %34, i32 %35, %struct.ip_mreq* %7, i32 8)
%37 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%38 = call i64 @bind(i32 %23, %struct.sockaddr* %37, i32 12)
%39 = icmp slt i64 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %27
%41 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %42
42: ; preds = %40, %27
%43 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%44 = call i32 @recvfrom(i32 %23, i8* %11, i32 2048, i32 0, %struct.sockaddr* %43, i32* %5)
ret i32 0
}