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

/* Variables and functions */
int CreateUdpSocket(char *, int, struct sockaddr_in *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ puts(char *);
scalar_t__ sendto(int, char *, scalar_t__, int /*<<< orphan*/,
                  struct sockaddr *, int);
scalar_t__ strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int main(void) {
  int fd;
  char text[12];
  struct sockaddr_in srvaddr;
  fd = CreateUdpSocket("224.0.1.1", 5001, &srvaddr);
  if (fd == -1)
    return -1;
  strncpy(text, "Hello world", 11);
  if (sendto(fd, text, strlen(text) + 1, 0, (struct sockaddr *)&srvaddr,
             sizeof(srvaddr)) < 0) {
    puts("Fail sending multicast data.");
    close(fd);
    return -1;
  }
  puts("Multicast data sended.");
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
mov    $0x1389,%esi
lea    -0x18(%rbp),%rdx
call   1080 <CreateUdpSocket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    119d <main+0x3d>
movl   $0xffffffff,-0x4(%rbp)
jmp    122d <main+0xcd>
lea    -0x14(%rbp),%rdi
lea    0xe62(%rip),%rsi
mov    $0xb,%edx
call   1030 <strncpy@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x24(%rbp)
lea    -0x14(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    -0x14(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
lea    -0x18(%rbp),%r8
xor    %ecx,%ecx
mov    $0x4,%r9d
call   1060 <sendto@plt>
cmp    $0x0,%rax
jge    1212 <main+0xb2>
lea    0xe1d(%rip),%rdi
call   1040 <puts@plt>
mov    -0x8(%rbp),%edi
call   1070 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    122d <main+0xcd>
lea    0xe1a(%rip),%rdi
call   1040 <puts@plt>
mov    -0x8(%rbp),%edi
call   1070 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
lea    0xe93(%rip),%rdi
lea    0x8(%rsp),%rdx
mov    $0x1389,%esi
call   1080 <CreateUdpSocket@plt>
cmp    $0xffffffff,%eax
je     11e9 <main+0x89>
mov    %eax,%ebp
lea    0xe80(%rip),%rsi
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
mov    $0xb,%edx
call   1030 <strncpy@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rdx
lea    0x8(%rsp),%r8
mov    %ebp,%edi
mov    %rbx,%rsi
xor    %ecx,%ecx
mov    $0x4,%r9d
call   1060 <sendto@plt>
mov    %rax,%rbx
test   %rax,%rax
lea    0xe4a(%rip),%rax
lea    0xe60(%rip),%rdi
cmovs  %rax,%rdi
sar    $0x3f,%rbx
call   1040 <puts@plt>
mov    %ebp,%edi
call   1070 <close@plt>
jmp    11ee <main+0x8e>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [10 x i8] c"224.0.1.1\00"
@.str.1 = [12 x i8] c"Hello world\00"
@.str.2 = [29 x i8] c"Fail sending multicast data.\00"
@.str.3 = [23 x i8] c"Multicast data sended.\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [12 x i8]
%4 = alloca %struct.sockaddr_in
store i32 0, i32* %1
%5 = call i32 @CreateUdpSocket(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 5001, %struct.sockaddr_in* %4)
store i32 %5, i32* %2
%6 = load i32, i32* %2
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %9
8: ; preds = %0
store i32 -1, i32* %1
br label %28
9: ; preds = %0
%10 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%11 = call i32 @strncpy(i8* %10, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 11)
%12 = load i32, i32* %2
%13 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%14 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%15 = call i64 @strlen(i8* %14)
%16 = add nsw i64 %15, 1
%17 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%18 = call i64 @sendto(i32 %12, i8* %13, i64 %16, i32 0, %struct.sockaddr* %17, i32 4)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %9
%21 = call i32 @puts(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%22 = load i32, i32* %2
%23 = call i32 @close(i32 %22)
store i32 -1, i32* %1
br label %28
24: ; preds = %9
%25 = call i32 @puts(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%26 = load i32, i32* %2
%27 = call i32 @close(i32 %26)
store i32 0, i32* %1
br label %28
28: ; preds = %24, %20, %8
%29 = load i32, i32* %1
ret i32 %29
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [10 x i8] c"224.0.1.1\00"
@.str.1 = [12 x i8] c"Hello world\00"
@.str.2 = [29 x i8] c"Fail sending multicast data.\00"
@.str.3 = [23 x i8] c"Multicast data sended.\00"
define i32 @main() {
%1 = alloca [12 x i8]
%2 = alloca %struct.sockaddr_in
%3 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 0
%4 = bitcast %struct.sockaddr_in* %2 to i8*
%5 = call i32 @CreateUdpSocket(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 5001, %struct.sockaddr_in* %2)
%6 = icmp eq i32 %5, -1
br i1 %6, label %19, label %7
7: ; preds = %0
%8 = call i32 @strncpy(i8* %3, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 11)
%9 = call i64 @strlen(i8* %3)
%10 = add nsw i64 %9, 1
%11 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%12 = call i64 @sendto(i32 %5, i8* %3, i64 %10, i32 0, %struct.sockaddr* %11, i32 4)
%13 = icmp slt i64 %12, 0
%14 = select i1 %13, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0)
%15 = ashr i64 %12, 63
%16 = trunc i64 %15 to i32
%17 = call i32 @puts(i8* dereferenceable(1) %14)
%18 = call i32 @close(i32 %5)
br label %19
19: ; preds = %7, %0
%20 = phi i32 [ -1, %0 ], [ %16, %7 ]
ret i32 %20
}