#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 */

/* Type definitions */
struct sockaddr_in {
  int dummy;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ claddr;

/* Variables and functions */
int BindMulticastSocket(char *, int, struct sockaddr_in *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ puts(char *);
scalar_t__ recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *,
                    unsigned int *);
int main(void) {
  unsigned sz;
  int fd;
  char buf[12];
  struct sockaddr_in claddr;
  fd = BindMulticastSocket("224.0.1.1", 5001, &claddr);
  sz = sizeof(claddr);
  for (;;) {
    if ((recvfrom(fd, buf, 11, 0, (struct sockaddr *)&claddr, &sz)) < 0) {
      puts("Fail receiving data.");
    }
    printf("Receiving: %s\n", buf);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
mov    $0x1389,%esi
lea    -0x20(%rbp),%rdx
call   1050 <BindMulticastSocket@plt>
mov    %eax,-0xc(%rbp)
movl   $0x4,-0x8(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x18(%rbp),%rsi
lea    -0x20(%rbp),%r8
mov    $0xb,%edx
xor    %ecx,%ecx
lea    -0x8(%rbp),%r9
call   1060 <recvfrom@plt>
cmp    $0x0,%rax
jge    119f <main+0x5f>
lea    0xe70(%rip),%rdi
call   1030 <puts@plt>
lea    -0x18(%rbp),%rsi
lea    0xe75(%rip),%rdi
call   1040 <printf@plt>
jmp    116e <main+0x2e>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xeab(%rip),%rdi
lea    0x8(%rsp),%r14
mov    $0x1389,%esi
mov    %r14,%rdx
call   1050 <BindMulticastSocket@plt>
mov    %eax,%ebp
movl   $0x4,0x4(%rsp)
lea    0xc(%rsp),%rbx
lea    0x4(%rsp),%r15
lea    0xe88(%rip),%r12
lea    0xe96(%rip),%r13
jmp    119b <main+0x5b>
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0xb,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    %r15,%r9
call   1060 <recvfrom@plt>
test   %rax,%rax
jns    1190 <main+0x50>
mov    %r12,%rdi
call   1030 <puts@plt>
jmp    1190 <main+0x50>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [10 x i8] c"224.0.1.1\00"
@.str.1 = [21 x i8] c"Fail receiving data.\00"
@.str.2 = [15 x i8] c"Receiving: %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [12 x i8]
%5 = alloca %struct.sockaddr_in
store i32 0, i32* %1
%6 = call i32 @BindMulticastSocket(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 5001, %struct.sockaddr_in* %5)
store i32 %6, i32* %3
store i32 4, i32* %2
br label %7
7: ; preds = %15, %0
%8 = load i32, i32* %3
%9 = getelementptr inbounds [12 x i8], [12 x i8]* %4, i64 0, i64 0
%10 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%11 = call i64 @recvfrom(i32 %8, i8* %9, i32 11, i32 0, %struct.sockaddr* %10, i32* %2)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %7
%14 = call i32 @puts(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %13, %7
%16 = getelementptr inbounds [12 x i8], [12 x i8]* %4, i64 0, i64 0
%17 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %16)
br label %7
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [10 x i8] c"224.0.1.1\00"
@.str.1 = [21 x i8] c"Fail receiving data.\00"
@.str.2 = [15 x i8] c"Receiving: %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [12 x i8]
%3 = alloca %struct.sockaddr_in
%4 = bitcast i32* %1 to i8*
%5 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 0
%6 = bitcast %struct.sockaddr_in* %3 to i8*
%7 = call i32 @BindMulticastSocket(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 5001, %struct.sockaddr_in* %3)
store i32 4, i32* %1
%8 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
br label %9
9: ; preds = %14, %0
%10 = call i64 @recvfrom(i32 %7, i8* %5, i32 11, i32 0, %struct.sockaddr* %8, i32* %1)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %12, %9
%15 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %5)
br label %9
}