#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 /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ sendaddr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_pton(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sendto(int, char *, int /*<<< orphan*/, int /*<<< orphan*/,
                          struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strlen(char *);
int main(int argc, char *argv[]) {
  char *send_addr = "224.0.2.1";
  int send_port = 19283;
  int sockfd;
  struct sockaddr_in sendaddr;
  char senddata[2048];
  bzero(&sendaddr, sizeof(sendaddr));
  sendaddr.sin_family = AF_INET;
  sendaddr.sin_port = htons(send_port);
  inet_pton(AF_INET, send_addr, &sendaddr.sin_addr);
  if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
    perror("socket failed to allocate");
  strcpy(senddata, "A short message.");
  sendto(sockfd, senddata, strlen(senddata), 0, (struct sockaddr *)&sendaddr,
         sizeof(sendaddr));
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x840,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe60(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x4b53,-0x1c(%rbp)
lea    -0x30(%rbp),%rdi
mov    $0xc,%esi
call   1090 <bzero@plt>
mov    0x2e28(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
call   1050 <htons@plt>
mov    %eax,-0x2c(%rbp)
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   1070 <inet_pton@plt>
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
mov    0x2dea(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
jge    1217 <main+0x97>
lea    0xdf8(%rip),%rdi
call   1080 <perror@plt>
lea    -0x830(%rbp),%rdi
lea    0xdff(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x83c(%rbp)
lea    -0x830(%rbp),%rax
mov    %rax,-0x838(%rbp)
lea    -0x830(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x83c(%rbp),%edi
mov    -0x838(%rbp),%rsi
mov    %eax,%edx
lea    -0x30(%rbp),%r8
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1060 <sendto@plt>
mov    -0x4(%rbp),%eax
add    $0x840,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x818,%rsp
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0xc,%esi
call   1090 <bzero@plt>
mov    0x2e47(%rip),%rbx
mov    (%rbx),%eax
mov    %eax,0x8(%rsp)
mov    $0x4b53,%edi
call   1050 <htons@plt>
mov    %eax,0x4(%rsp)
mov    (%rbx),%edi
lea    0xe42(%rip),%rsi
mov    %r14,%rdx
call   1070 <inet_pton@plt>
mov    (%rbx),%edi
mov    0x2e11(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,%ebx
test   %eax,%eax
js     121e <main+0x9e>
lea    0xe3f(%rip),%rsi
lea    0x10(%rsp),%r14
mov    %r14,%rdi
call   1030 <strcpy@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %rsp,%r8
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1060 <sendto@plt>
xor    %eax,%eax
add    $0x818,%rsp
pop    %rbx
pop    %r14
ret
lea    0xde5(%rip),%rdi
call   1080 <perror@plt>
jmp    11de <main+0x5e>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [10 x i8] c"224.0.2.1\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [26 x i8] c"socket failed to allocate\00"
@.str.2 = [17 x i8] c"A short message.\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.sockaddr_in
%10 = alloca [2048 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %6
store i32 19283, i32* %7
%11 = call i32 @bzero(%struct.sockaddr_in* %9, i32 12)
%12 = load i32, i32* @AF_INET
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 2
store i32 %12, i32* %13
%14 = load i32, i32* %7
%15 = call i32 @htons(i32 %14)
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
store i32 %15, i32* %16
%17 = load i32, i32* @AF_INET
%18 = load i8*, i8** %6
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
%20 = call i32 @inet_pton(i32 %17, i8* %18, i32* %19)
%21 = load i32, i32* @AF_INET
%22 = load i32, i32* @SOCK_DGRAM
%23 = call i32 @socket(i32 %21, i32 %22, i32 0)
store i32 %23, i32* %8
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %2
%26 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %27
27: ; preds = %25, %2
%28 = getelementptr inbounds [2048 x i8], [2048 x i8]* %10, i64 0, i64 0
%29 = call i32 @strcpy(i8* %28, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%30 = load i32, i32* %8
%31 = getelementptr inbounds [2048 x i8], [2048 x i8]* %10, i64 0, i64 0
%32 = getelementptr inbounds [2048 x i8], [2048 x i8]* %10, i64 0, i64 0
%33 = call i32 @strlen(i8* %32)
%34 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%35 = call i32 @sendto(i32 %30, i8* %31, i32 %33, i32 0, %struct.sockaddr* %34, i32 12)
%36 = load i32, i32* %3
ret i32 %36
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [10 x i8] c"224.0.2.1\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [26 x i8] c"socket failed to allocate\00"
@.str.2 = [17 x i8] c"A short message.\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [2048 x i8]
%5 = bitcast %struct.sockaddr_in* %3 to i8*
%6 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 0
%7 = call i32 @bzero(%struct.sockaddr_in* %3, i32 12)
%8 = load i32, i32* @AF_INET
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %8, i32* %9
%10 = tail call i32 @htons(i32 19283)
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %10, i32* %11
%12 = load i32, i32* @AF_INET
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%14 = call i32 @inet_pton(i32 %12, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32* %13)
%15 = load i32, i32* @AF_INET
%16 = load i32, i32* @SOCK_DGRAM
%17 = call i32 @socket(i32 %15, i32 %16, i32 0)
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %2
%20 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %19, %2
%22 = call i32 @strcpy(i8* %6, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%23 = call i32 @strlen(i8* %6)
%24 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%25 = call i32 @sendto(i32 %17, i8* %6, i32 %23, i32 0, %struct.sockaddr* %24, i32 12)
ret i32 0
}