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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
void *htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ puts(char *);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int *);
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
main(int argc, char *argv[]) {
  struct sockaddr_in addr;
  int fd, nbytes, addrlen;
  struct ip_mreq mreq;
  char msgbuf[256];
  u_int yes = 1;
  if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
    perror("socket");
    exit(1);
  }
  if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) < 0) {
    perror("Reusing ADDR failed");
    exit(1);
  }
  memset(&addr, 0, sizeof(addr));
  addr.sin_family = AF_INET;
  addr.sin_addr.s_addr = htonl(INADDR_ANY);
  addr.sin_port = htons(2222);
  if (bind(fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
    perror("bind");
    exit(1);
  }
  mreq.imr_multiaddr.s_addr = inet_addr("239.192.101.131");
  mreq.imr_interface.s_addr = htonl(INADDR_ANY);
  while (1) {
    addrlen = sizeof(addr);
    if ((nbytes = recvfrom(fd, msgbuf, 256, 0, (struct sockaddr *)&addr,
                           &addrlen)) < 0) {
      perror("recvfrom");
      exit(1);
    }
    puts(msgbuf);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x160,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x154(%rbp)
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
mov    0x2ded(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
jge    120e <main+0x5e>
lea    0xe01(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x2c(%rbp),%edi
mov    0x2dd0(%rip),%rax
mov    (%rax),%esi
mov    0x2d9f(%rip),%rax
mov    (%rax),%edx
lea    -0x154(%rbp),%rcx
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
cmp    $0x0,%rax
jge    1255 <main+0xa5>
lea    0xdc1(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1070 <memset@plt>
mov    0x2d74(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2d60(%rip),%rax
mov    (%rax),%edi
call   1060 <htonl@plt>
mov    %rax,-0x20(%rbp)
mov    $0x8ae,%edi
call   1050 <htons@plt>
mov    %eax,-0x28(%rbp)
mov    -0x2c(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x18,%edx
call   10a0 <bind@plt>
cmp    $0x0,%rax
jge    12c1 <main+0x111>
lea    0xd69(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
lea    0xd58(%rip),%rdi
call   1080 <inet_addr@plt>
mov    %eax,-0x40(%rbp)
mov    0x2d01(%rip),%rax
mov    (%rax),%edi
call   1060 <htonl@plt>
mov    %rax,-0x48(%rbp)
movl   $0x18,-0x34(%rbp)
mov    -0x2c(%rbp),%edi
lea    -0x150(%rbp),%rsi
lea    -0x28(%rbp),%r8
mov    $0x100,%edx
xor    %ecx,%ecx
lea    -0x34(%rbp),%r9
call   1090 <recvfrom@plt>
mov    %eax,-0x30(%rbp)
cmp    $0x0,%eax
jge    1329 <main+0x179>
lea    0xd16(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
lea    -0x150(%rbp),%rdi
call   1030 <puts@plt>
jmp    12e2 <main+0x132>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x128,%rsp
movl   $0x1,0x4(%rsp)
mov    0x2e14(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2dfa(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
test   %eax,%eax
jns    11ef <main+0x3f>
lea    0xe16(%rip),%rdi
jmp    1302 <main+0x152>
mov    %eax,%r14d
mov    0x2def(%rip),%rax
mov    (%rax),%esi
mov    0x2dbe(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rcx
mov    %r14d,%edi
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
test   %rax,%rax
jns    1228 <main+0x78>
lea    0xde4(%rip),%rdi
jmp    1302 <main+0x152>
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1070 <memset@plt>
mov    0x0(%rbp),%eax
mov    %eax,0x18(%rsp)
mov    0x2d8e(%rip),%rbp
mov    0x0(%rbp),%edi
call   1060 <htonl@plt>
mov    %rax,0x10(%rsp)
mov    $0x8ae,%edi
call   1050 <htons@plt>
mov    %eax,0x8(%rsp)
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x18,%edx
call   10a0 <bind@plt>
test   %rax,%rax
jns    1286 <main+0xd6>
lea    0xd9a(%rip),%rdi
jmp    1302 <main+0x152>
lea    0xd93(%rip),%rdi
call   1080 <inet_addr@plt>
mov    0x0(%rbp),%edi
call   1060 <htonl@plt>
movl   $0x18,(%rsp)
lea    0x20(%rsp),%rsi
lea    0x8(%rsp),%r8
mov    %rsp,%r9
mov    %r14d,%edi
mov    $0x100,%edx
xor    %ecx,%ecx
call   1090 <recvfrom@plt>
test   %eax,%eax
js     12fb <main+0x14b>
lea    0x20(%rsp),%rbx
lea    0x8(%rsp),%r15
mov    %rsp,%rbp
xchg   %ax,%ax
mov    %rbx,%rdi
call   1030 <puts@plt>
movl   $0x18,(%rsp)
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x100,%edx
xor    %ecx,%ecx
mov    %r15,%r8
mov    %rbp,%r9
call   1090 <recvfrom@plt>
test   %eax,%eax
jns    12d0 <main+0x120>
lea    0xd2e(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_4__, i32 }
%struct.TYPE_4__ = type { i8* }
%struct.ip_mreq = type { %struct.TYPE_6__, %struct.TYPE_5__ }
%struct.TYPE_6__ = type { i8* }
%struct.TYPE_5__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [7 x i8] c"socket\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.1 = [20 x i8] c"Reusing ADDR failed\00"
@INADDR_ANY = global i32 0
@.str.2 = [5 x i8] c"bind\00"
@.str.3 = [16 x i8] c"239.192.101.131\00"
@.str.4 = [9 x i8] c"recvfrom\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.sockaddr_in
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.ip_mreq
%11 = alloca [256 x i8]
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %12
%13 = load i32, i32* @AF_INET
%14 = load i32, i32* @SOCK_DGRAM
%15 = call i32 @socket(i32 %13, i32 %14, i32 0)
store i32 %15, i32* %7
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %2
%18 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %2
%21 = load i32, i32* %7
%22 = load i32, i32* @SOL_SOCKET
%23 = load i32, i32* @SO_REUSEADDR
%24 = call i64 @setsockopt(i32 %21, i32 %22, i32 %23, i32* %12, i32 4)
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %20
%27 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %20
%30 = call i32 @memset(%struct.sockaddr_in* %6, i32 0, i32 24)
%31 = load i32, i32* @AF_INET
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i32 %31, i32* %32
%33 = load i32, i32* @INADDR_ANY
%34 = call i8* @htonl(i32 %33)
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
%36 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %35, i32 0, i32 0
store i8* %34, i8** %36
%37 = call i32 @htons(i32 2222)
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
store i32 %37, i32* %38
%39 = load i32, i32* %7
%40 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%41 = call i64 @bind(i32 %39, %struct.sockaddr* %40, i32 24)
%42 = icmp slt i64 %41, 0
br i1 %42, label %43, label %46
43: ; preds = %29
%44 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%45 = call i32 @exit(i32 1)
unreachable
46: ; preds = %29
%47 = call i32 @inet_addr(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%48 = getelementptr inbounds %struct.ip_mreq, %struct.ip_mreq* %10, i32 0, i32 1
%49 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %48, i32 0, i32 0
store i32 %47, i32* %49
%50 = load i32, i32* @INADDR_ANY
%51 = call i8* @htonl(i32 %50)
%52 = getelementptr inbounds %struct.ip_mreq, %struct.ip_mreq* %10, i32 0, i32 0
%53 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %52, i32 0, i32 0
store i8* %51, i8** %53
br label %54
54: ; preds = %46, %63
store i32 24, i32* %9
%55 = load i32, i32* %7
%56 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%57 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%58 = call i32 @recvfrom(i32 %55, i8* %56, i32 256, i32 0, %struct.sockaddr* %57, i32* %9)
store i32 %58, i32* %8
%59 = icmp slt i32 %58, 0
br i1 %59, label %60, label %63
60: ; preds = %54
%61 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%62 = call i32 @exit(i32 1)
unreachable
63: ; preds = %54
%64 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%65 = call i32 @puts(i8* %64)
br label %54
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_4__, i32 }
%struct.TYPE_4__ = type { i8* }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [7 x i8] c"socket\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.1 = [20 x i8] c"Reusing ADDR failed\00"
@INADDR_ANY = global i32 0
@.str.2 = [5 x i8] c"bind\00"
@.str.3 = [16 x i8] c"239.192.101.131\00"
@.str.4 = [9 x i8] c"recvfrom\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = alloca [256 x i8]
%6 = alloca i32
%7 = bitcast %struct.sockaddr_in* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%10 = bitcast i32* %6 to i8*
store i32 1, i32* %6
%11 = load i32, i32* @AF_INET
%12 = load i32, i32* @SOCK_DGRAM
%13 = tail call i32 @socket(i32 %11, i32 %12, i32 0)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %2
%19 = load i32, i32* @SOL_SOCKET
%20 = load i32, i32* @SO_REUSEADDR
%21 = call i64 @setsockopt(i32 %13, i32 %19, i32 %20, i32* %6, i32 4)
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %18
%24 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %18
%27 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 24)
%28 = load i32, i32* @AF_INET
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %28, i32* %29
%30 = load i32, i32* @INADDR_ANY
%31 = call i8* @htonl(i32 %30)
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i8* %31, i8** %32
%33 = call i32 @htons(i32 2222)
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %33, i32* %34
%35 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%36 = call i64 @bind(i32 %13, %struct.sockaddr* %35, i32 24)
%37 = icmp slt i64 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %26
%39 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%40 = call i32 @exit(i32 1)
unreachable
41: ; preds = %26
%42 = call i32 @inet_addr(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%43 = load i32, i32* @INADDR_ANY
%44 = call i8* @htonl(i32 %43)
store i32 24, i32* %4
%45 = call i32 @recvfrom(i32 %13, i8* %9, i32 256, i32 0, %struct.sockaddr* %35, i32* %4)
%46 = icmp slt i32 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %50, %41
%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 = %41, %50
%51 = call i32 @puts(i8* %9)
store i32 24, i32* %4
%52 = call i32 @recvfrom(i32 %13, i8* %9, i32 256, i32 0, %struct.sockaddr* %35, i32* %4)
%53 = icmp slt i32 %52, 0
br i1 %53, label %47, label %50
}