#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__ {
  void *s_addr;
};
struct sockaddr_in {
  TYPE_3__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct TYPE_5__ {
  void *s_addr;
};
struct TYPE_4__ {
  int /*<<< orphan*/ s_addr;
};
struct ip_mreq {
  TYPE_2__ imr_interface;
  TYPE_1__ imr_multiaddr;
};
typedef int /*<<< orphan*/ mreq;
typedef int /*<<< orphan*/ message;
typedef int /*<<< orphan*/ addr;

/* 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(char *, int);
int /*<<< orphan*/ exit(int);
void *htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
char *inet_ntoa(TYPE_3__);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *, short);
int recvfrom(int, short *, int, int /*<<< orphan*/, struct sockaddr *, int *);
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                      struct ip_mreq *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
short multicast() {
  struct sockaddr_in addr;
  int addrlen, sock, cnt;
  struct ip_mreq mreq;
  short message;
  bool flag = false;
  sock = socket(AF_INET, SOCK_DGRAM, 0);
  if (sock < 0) {
    perror("socket");
    exit(1);
  }
  bzero((char *)&addr, sizeof(addr));
  addr.sin_family = AF_INET;
  addr.sin_addr.s_addr = htonl(INADDR_ANY);
  addr.sin_port = htons(6000);
  addrlen = sizeof(addr);
  if (bind(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
    perror("bind");
    exit(1);
  }
  mreq.imr_multiaddr.s_addr = inet_addr("239.0.0.1");
  mreq.imr_interface.s_addr = htonl(INADDR_ANY);
  if (setsockopt(sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) <
      0) {
    perror("setsockopt mreq");
    exit(1);
  }
  cnt = recvfrom(sock, &message, sizeof(message), 0, (struct sockaddr *)&addr,
                 &addrlen);
  if (cnt < 0) {
    perror("recvfrom");
    exit(1);
  } else if (cnt == 0) {
  }
  printf("%s: message = \"%d\"\n", inet_ntoa(addr.sin_addr), message);
  return message;
}


x86 assembly (clang, -O0):
<multicast>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x38(%rbp)
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
mov    0x2de9(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    120b <multicast+0x4b>
lea    0xe04(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
lea    -0x10(%rbp),%rdi
mov    $0x10,%esi
call   10c0 <bzero@plt>
mov    0x2dc0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    0x2da4(%rip),%rax
mov    (%rax),%edi
call   1070 <htonl@plt>
mov    %rax,-0x10(%rbp)
mov    $0x1770,%edi
call   1050 <htons@plt>
mov    %eax,-0x8(%rbp)
movl   $0x10,-0x14(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0x10,%edx
call   10a0 <bind@plt>
cmp    $0x0,%rax
jge    127c <multicast+0xbc>
lea    0xd9a(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
lea    0xd89(%rip),%rdi
call   1080 <inet_addr@plt>
mov    %eax,-0x28(%rbp)
mov    0x2d3e(%rip),%rax
mov    (%rax),%edi
call   1070 <htonl@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%edi
mov    0x2d31(%rip),%rax
mov    (%rax),%esi
mov    0x2d38(%rip),%rax
mov    (%rax),%edx
lea    -0x30(%rbp),%rcx
mov    $0x10,%r8d
call   1030 <setsockopt@plt>
cmp    $0x0,%rax
jge    12e1 <multicast+0x121>
lea    0xd44(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x18(%rbp),%edi
lea    -0x10(%rbp),%r8
lea    -0x32(%rbp),%rsi
mov    $0x2,%edx
xor    %ecx,%ecx
lea    -0x14(%rbp),%r9
call   1090 <recvfrom@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    131f <multicast+0x15f>
lea    0xd16(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
cmpl   $0x0,-0x1c(%rbp)
jne    132e <multicast+0x16e>
jmp    132e <multicast+0x16e>
jmp    1333 <multicast+0x173>
mov    -0x10(%rbp),%rdi
call   1040 <inet_ntoa@plt>
mov    %rax,%rsi
lea    0xce9(%rip),%rdi
movswl -0x32(%rbp),%edx
call   1060 <printf@plt>
movswl -0x32(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<multicast>:
push   %r15
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    0x2e10(%rip),%r15
mov    (%r15),%edi
mov    0x2dee(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
test   %eax,%eax
js     12dc <multicast+0x11c>
mov    %eax,%ebx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0x10,%esi
call   10c0 <bzero@plt>
mov    (%r15),%eax
mov    %eax,0x1c(%rsp)
mov    0x2dc3(%rip),%r15
mov    (%r15),%edi
call   1070 <htonl@plt>
mov    %rax,0x10(%rsp)
mov    $0x1770,%edi
call   1050 <htons@plt>
mov    %eax,0x18(%rsp)
movl   $0x10,0xc(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x10,%edx
call   10a0 <bind@plt>
test   %rax,%rax
js     12e5 <multicast+0x125>
lea    0xdbd(%rip),%rdi
call   1080 <inet_addr@plt>
mov    %eax,0x28(%rsp)
mov    (%r15),%edi
call   1070 <htonl@plt>
mov    %rax,0x20(%rsp)
mov    0x2d6c(%rip),%rax
mov    (%rax),%esi
mov    0x2d73(%rip),%rax
mov    (%rax),%edx
lea    0x20(%rsp),%rcx
mov    %ebx,%edi
mov    $0x10,%r8d
call   1030 <setsockopt@plt>
test   %rax,%rax
js     12ee <multicast+0x12e>
lea    0xa(%rsp),%rsi
lea    0x10(%rsp),%r8
lea    0xc(%rsp),%r9
mov    %ebx,%edi
mov    $0x2,%edx
xor    %ecx,%ecx
call   1090 <recvfrom@plt>
test   %eax,%eax
js     12f7 <multicast+0x137>
mov    0x10(%rsp),%rdi
call   1040 <inet_ntoa@plt>
movswl 0xa(%rsp),%edx
lea    0xd6a(%rip),%rdi
mov    %rax,%rsi
call   1060 <printf@plt>
movzwl 0xa(%rsp),%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xd1d(%rip),%rdi
jmp    12fe <multicast+0x13e>
lea    0xd1b(%rip),%rdi
jmp    12fe <multicast+0x13e>
lea    0xd21(%rip),%rdi
jmp    12fe <multicast+0x13e>
lea    0xd28(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_6__, i32, i32 }
%struct.TYPE_6__ = type { i8* }
%struct.ip_mreq = type { %struct.TYPE_5__, %struct.TYPE_4__ }
%struct.TYPE_5__ = type { i8* }
%struct.TYPE_4__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [7 x i8] c"socket\00"
@INADDR_ANY = global i32 0
@.str.1 = [5 x i8] c"bind\00"
@.str.2 = [10 x i8] c"239.0.0.1\00"
@IPPROTO_IP = global i32 0
@IP_ADD_MEMBERSHIP = global i32 0
@.str.3 = [16 x i8] c"setsockopt mreq\00"
@.str.4 = [9 x i8] c"recvfrom\00"
@.str.5 = [20 x i8] c"%s: message = \22%d\22\0A\00"
define signext i16 @multicast() {
%1 = alloca %struct.sockaddr_in
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.ip_mreq
%6 = alloca i16
%7 = alloca i32
store i32 0, i32* %7
%8 = load i32, i32* @AF_INET
%9 = load i32, i32* @SOCK_DGRAM
%10 = call i32 @socket(i32 %8, i32 %9, i32 0)
store i32 %10, i32* %3
%11 = load i32, i32* %3
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %0
%14 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %0
%17 = bitcast %struct.sockaddr_in* %1 to i8*
%18 = call i32 @bzero(i8* %17, i32 16)
%19 = load i32, i32* @AF_INET
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i32 0, i32 2
store i32 %19, i32* %20
%21 = load i32, i32* @INADDR_ANY
%22 = call i8* @htonl(i32 %21)
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i32 0, i32 0
%24 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %23, i32 0, i32 0
store i8* %22, i8** %24
%25 = call i32 @htons(i32 6000)
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i32 0, i32 1
store i32 %25, i32* %26
store i32 16, i32* %2
%27 = load i32, i32* %3
%28 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%29 = call i64 @bind(i32 %27, %struct.sockaddr* %28, i32 16)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %16
%32 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %16
%35 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%36 = getelementptr inbounds %struct.ip_mreq, %struct.ip_mreq* %5, i32 0, i32 1
%37 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %36, i32 0, i32 0
store i32 %35, i32* %37
%38 = load i32, i32* @INADDR_ANY
%39 = call i8* @htonl(i32 %38)
%40 = getelementptr inbounds %struct.ip_mreq, %struct.ip_mreq* %5, i32 0, i32 0
%41 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %40, i32 0, i32 0
store i8* %39, i8** %41
%42 = load i32, i32* %3
%43 = load i32, i32* @IPPROTO_IP
%44 = load i32, i32* @IP_ADD_MEMBERSHIP
%45 = call i64 @setsockopt(i32 %42, i32 %43, i32 %44, %struct.ip_mreq* %5, i32 16)
%46 = icmp slt i64 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %34
%48 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%49 = call i32 @exit(i32 1)
unreachable
50: ; preds = %34
%51 = load i32, i32* %3
%52 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%53 = call i32 @recvfrom(i32 %51, i16* %6, i32 2, i32 0, %struct.sockaddr* %52, i32* %2)
store i32 %53, i32* %4
%54 = load i32, i32* %4
%55 = icmp slt i32 %54, 0
br i1 %55, label %56, label %59
56: ; preds = %50
%57 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%58 = call i32 @exit(i32 1)
unreachable
59: ; preds = %50
%60 = load i32, i32* %4
%61 = icmp eq i32 %60, 0
br i1 %61, label %62, label %63
62: ; preds = %59
br label %63
63: ; preds = %62, %59
br label %64
64: ; preds = %63
%65 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i32 0, i32 0
%66 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %65, i32 0, i32 0
%67 = load i8*, i8** %66
%68 = call i8* @inet_ntoa(i8* %67)
%69 = load i16, i16* %6
%70 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i8* %68, i16 signext %69)
%71 = load i16, i16* %6
ret i16 %71
}

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