#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 */
typedef int u_char;
typedef int /*<<< orphan*/ ttl;
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int ssize_t;
typedef int /*<<< orphan*/ dst;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ IPPROTO_IP;
int /*<<< orphan*/ IP_MULTICAST_TTL;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ htons(int);
int inet_aton(char const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int sendto(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int);
int /*<<< orphan*/ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ usleep(int);
int main(int argc, char **argv) {
  int sock, status;
  struct sockaddr_in dst;
  char buf[] = "Hello, world!";
  const char *mcast_addr = "224.5.0.80";
  u_char ttl = 64;
  if (argc >= 2)
    mcast_addr = argv[1];
  sock = socket(PF_INET, SOCK_DGRAM, 0);
  assert(sock != -1);
  dst.sin_family = AF_INET;
  dst.sin_port = htons(2000);
  status = inet_aton(mcast_addr, &dst.sin_addr);
  assert(status);
  setsockopt(sock, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, sizeof(ttl));
  for (;;) {
    ssize_t s;
    s = sendto(sock, buf, sizeof(buf), 0, (struct sockaddr *)&dst, sizeof(dst));
    if (s == -1)
      perror("sendto: ");
    usleep(250000);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe63(%rip),%rax
mov    %rax,-0x36(%rbp)
mov    0xe61(%rip),%eax
mov    %eax,-0x2e(%rbp)
mov    0xe5b(%rip),%ax
mov    %ax,-0x2a(%rbp)
lea    0xe52(%rip),%rax
mov    %rax,-0x40(%rbp)
movl   $0x40,-0x44(%rbp)
cmpl   $0x2,-0x8(%rbp)
jl     11dd <main+0x5d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x40(%rbp)
mov    0x2ddc(%rip),%rax
mov    (%rax),%edi
mov    0x2deb(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    0x2dd7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    $0x7d0,%edi
call   1040 <htons@plt>
mov    %eax,-0x24(%rbp)
mov    -0x40(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1070 <inet_aton@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
call   1060 <assert@plt>
mov    -0x14(%rbp),%edi
mov    0x2d9b(%rip),%rax
mov    (%rax),%esi
mov    0x2d7a(%rip),%rax
mov    (%rax),%edx
lea    -0x44(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    -0x14(%rbp),%edi
lea    -0x36(%rbp),%rsi
lea    -0x28(%rbp),%r8
mov    $0xe,%edx
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1050 <sendto@plt>
mov    %eax,-0x48(%rbp)
cmpl   $0xffffffff,-0x48(%rbp)
jne    1295 <main+0x115>
lea    0xd89(%rip),%rdi
call   1080 <perror@plt>
mov    $0x3d090,%edi
call   1090 <usleep@plt>
jmp    125f <main+0xdf>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
movabs $0x21646c726f7720,%rax
mov    %rax,0x1e(%rsp)
movabs $0x77202c6f6c6c6548,%rax
2c 20 77
mov    %rax,0x18(%rsp)
movl   $0x40,0x4(%rsp)
cmp    $0x2,%edi
jl     11bc <main+0x3c>
mov    0x8(%rsi),%r15
jmp    11c3 <main+0x43>
lea    0xe4b(%rip),%r15
mov    0x2df6(%rip),%rax
mov    (%rax),%edi
mov    0x2e05(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,%ebx
xor    %edi,%edi
cmp    $0xffffffff,%eax
setne  %dil
call   1060 <assert@plt>
mov    0x2df5(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
mov    $0x7d0,%edi
call   1040 <htons@plt>
mov    %eax,0xc(%rsp)
lea    0x8(%rsp),%r14
mov    %r15,%rdi
mov    %r14,%rsi
call   1070 <inet_aton@plt>
mov    %eax,%edi
call   1060 <assert@plt>
mov    0x2dbb(%rip),%rax
mov    (%rax),%esi
mov    0x2d9a(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
lea    0x18(%rsp),%r15
lea    0xdcb(%rip),%r12
jmp    125a <main+0xda>
mov    $0x3d090,%edi
call   1090 <usleep@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0xe,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    $0xc,%r9d
call   1050 <sendto@plt>
cmp    $0xffffffff,%eax
jne    1250 <main+0xd0>
mov    %r12,%rdi
call   1080 <perror@plt>
jmp    1250 <main+0xd0>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@__const.main.buf = [14 x i8] c"Hello, world!\00"
@.str = [11 x i8] c"224.5.0.80\00"
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@AF_INET = global i32 0
@IPPROTO_IP = global i32 0
@IP_MULTICAST_TTL = global i32 0
@.str.1 = [9 x i8] c"sendto: \00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.sockaddr_in
%9 = alloca [14 x i8]
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = bitcast [14 x i8]* %9 to i8*
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8** %10
store i32 64, i32* %11
%14 = load i32, i32* %4
%15 = icmp sge i32 %14, 2
br i1 %15, label %16, label %20
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
store i8* %19, i8** %10
br label %20
20: ; preds = %16, %2
%21 = load i32, i32* @PF_INET
%22 = load i32, i32* @SOCK_DGRAM
%23 = call i32 @socket(i32 %21, i32 %22, i32 0)
store i32 %23, i32* %6
%24 = load i32, i32* %6
%25 = icmp ne i32 %24, -1
%26 = zext i1 %25 to i32
%27 = call i32 @assert(i32 %26)
%28 = load i32, i32* @AF_INET
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %28, i32* %29
%30 = call i32 @htons(i32 2000)
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
store i32 %30, i32* %31
%32 = load i8*, i8** %10
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
%34 = call i32 @inet_aton(i8* %32, i32* %33)
store i32 %34, i32* %7
%35 = load i32, i32* %7
%36 = call i32 @assert(i32 %35)
%37 = load i32, i32* %6
%38 = load i32, i32* @IPPROTO_IP
%39 = load i32, i32* @IP_MULTICAST_TTL
%40 = call i32 @setsockopt(i32 %37, i32 %38, i32 %39, i32* %11, i32 4)
br label %41
41: ; preds = %50, %20
%42 = load i32, i32* %6
%43 = getelementptr inbounds [14 x i8], [14 x i8]* %9, i64 0, i64 0
%44 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%45 = call i32 @sendto(i32 %42, i8* %43, i32 14, i32 0, %struct.sockaddr* %44, i32 12)
store i32 %45, i32* %12
%46 = load i32, i32* %12
%47 = icmp eq i32 %46, -1
br i1 %47, label %48, label %50
48: ; preds = %41
%49 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %50
50: ; preds = %48, %41
%51 = call i32 @usleep(i32 250000)
br label %41
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@__const.main.buf = [14 x i8] c"Hello, world!\00"
@.str = [11 x i8] c"224.5.0.80\00"
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@AF_INET = global i32 0
@IPPROTO_IP = global i32 0
@IP_MULTICAST_TTL = global i32 0
@.str.1 = [9 x i8] c"sendto: \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [14 x i8]
%5 = alloca i32
%6 = bitcast %struct.sockaddr_in* %3 to i8*
%7 = getelementptr inbounds [14 x i8], [14 x i8]* %4, i64 0, i64 0
%8 = bitcast i32* %5 to i8*
store i32 64, i32* %5
%9 = icmp sgt i32 %0, 1
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
br label %13
13: ; preds = %10, %2
%14 = phi i8* [ %12, %10 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), %2 ]
%15 = load i32, i32* @PF_INET
%16 = load i32, i32* @SOCK_DGRAM
%17 = tail call i32 @socket(i32 %15, i32 %16, i32 0)
%18 = icmp ne i32 %17, -1
%19 = zext i1 %18 to i32
%20 = tail call i32 @assert(i32 %19)
%21 = load i32, i32* @AF_INET
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %21, i32* %22
%23 = tail call i32 @htons(i32 2000)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %23, i32* %24
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%26 = call i32 @inet_aton(i8* %14, i32* %25)
%27 = call i32 @assert(i32 %26)
%28 = load i32, i32* @IPPROTO_IP
%29 = load i32, i32* @IP_MULTICAST_TTL
%30 = call i32 @setsockopt(i32 %17, i32 %28, i32 %29, i32* %5, i32 4)
%31 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
br label %32
32: ; preds = %37, %13
%33 = call i32 @sendto(i32 %17, i8* %7, i32 14, i32 0, %struct.sockaddr* %31, i32 12)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %37
35: ; preds = %32
%36 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %37
37: ; preds = %35, %32
%38 = call i32 @usleep(i32 250000)
br label %32
}