#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_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  void *s_addr;
};
struct sockaddr_in {
  void *sin_family;
  void *sin_port;
  TYPE_1__ sin_addr;
};
struct sockaddr {
  int dummy;
};

/* Variables and functions */
int INADDR_ANY;
int /*<<< orphan*/ IPPROTO_UDP;
void *PF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_BROADCAST;
int /*<<< orphan*/ atoi(char *);
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
void *htonl(int);
void *htons(int /*<<< orphan*/);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, int);
int sendto(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int /*<<< orphan*/ shutdown(int, int);
int socket(void *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *);
int strlen(char *);
int main(int argc, char *argv[]) {
  int sock, status, buflen, sinlen;
  char buffer[65536];
  struct sockaddr_in sock_in;
  int yes = 1;
  sinlen = sizeof(struct sockaddr_in);
  memset(&sock_in, 0, sinlen);
  buflen = 65536;
  sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
  sock_in.sin_addr.s_addr = htonl(INADDR_ANY);
  sock_in.sin_port = htons(0);
  sock_in.sin_family = PF_INET;
  status = bind(sock, (struct sockaddr *)&sock_in, sinlen);
  printf("Bind Status = %d\n", status);
  status = setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &yes, sizeof(int));
  printf("Setsockopt Status = %d\n", status);
  sock_in.sin_addr.s_addr = htonl(-1);
  sock_in.sin_port = htons(atoi(argv[1]));
  sock_in.sin_family = PF_INET;
  sprintf(buffer, "Ciao");
  buflen = strlen(buffer);
  status = sendto(sock, buffer, buflen, 0, (struct sockaddr *)&sock_in, sinlen);
  printf("sendto Status = %d\n", status);
  shutdown(sock, 2);
  close(sock);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10040,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x1003c(%rbp)
movl   $0x18,-0x20(%rbp)
mov    -0x20(%rbp),%edx
lea    -0x10038(%rbp),%rdi
xor    %esi,%esi
call   1090 <memset@plt>
movl   $0x10000,-0x1c(%rbp)
mov    0x2dae(%rip),%rax
mov    (%rax),%rdi
mov    0x2dbc(%rip),%rax
mov    (%rax),%esi
mov    0x2d8b(%rip),%rax
mov    (%rax),%edx
call   10f0 <socket@plt>
mov    %eax,-0x14(%rbp)
mov    0x2daa(%rip),%rax
mov    (%rax),%edi
call   1080 <htonl@plt>
mov    %rax,-0x10028(%rbp)
xor    %edi,%edi
call   1060 <htons@plt>
mov    %rax,-0x10030(%rbp)
mov    0x2d67(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x10038(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x10038(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   10c0 <bind@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xd7e(%rip),%rdi
call   1070 <printf@plt>
mov    -0x14(%rbp),%edi
mov    0x2d57(%rip),%rax
mov    (%rax),%esi
mov    0x2d36(%rip),%rax
mov    (%rax),%edx
lea    -0x1003c(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xd57(%rip),%rdi
call   1070 <printf@plt>
mov    $0xffffffff,%edi
call   1080 <htonl@plt>
mov    %rax,-0x10028(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10d0 <atoi@plt>
mov    %eax,%edi
call   1060 <htons@plt>
mov    %rax,-0x10030(%rbp)
mov    0x2ccd(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x10038(%rbp)
lea    -0x10020(%rbp),%rdi
lea    0xd1f(%rip),%rsi
call   10e0 <sprintf@plt>
lea    -0x10020(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x10020(%rbp),%rsi
mov    -0x1c(%rbp),%edx
lea    -0x10038(%rbp),%r8
mov    -0x20(%rbp),%r9d
xor    %ecx,%ecx
call   10a0 <sendto@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xce4(%rip),%rdi
call   1070 <printf@plt>
mov    -0x14(%rbp),%edi
mov    $0x2,%esi
call   1040 <shutdown@plt>
mov    -0x14(%rbp),%edi
call   10b0 <close@plt>
xor    %eax,%eax
add    $0x10040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x10028,%rsp
mov    %rsi,%rbx
movl   $0x1,0x4(%rsp)
lea    0x8(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1090 <memset@plt>
mov    0x2dcd(%rip),%r15
mov    (%r15),%rdi
mov    0x2ddb(%rip),%rax
mov    (%rax),%esi
mov    0x2daa(%rip),%rax
mov    (%rax),%edx
call   10e0 <socket@plt>
mov    %eax,%ebp
mov    0x2dca(%rip),%rax
mov    (%rax),%edi
call   1080 <htonl@plt>
mov    %rax,0x18(%rsp)
xor    %edi,%edi
call   1060 <htons@plt>
mov    %rax,0x10(%rsp)
mov    (%r15),%rax
mov    %rax,0x8(%rsp)
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x18,%edx
call   10c0 <bind@plt>
lea    0xdb4(%rip),%rdi
mov    %eax,%esi
call   1070 <printf@plt>
mov    0x2d8e(%rip),%rax
mov    (%rax),%esi
mov    0x2d6d(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rcx
mov    %ebp,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
lea    0xd94(%rip),%rdi
mov    %eax,%esi
call   1070 <printf@plt>
mov    $0xffffffff,%edi
call   1080 <htonl@plt>
mov    %rax,0x18(%rsp)
mov    0x8(%rbx),%rdi
call   10d0 <atoi@plt>
mov    %eax,%edi
call   1060 <htons@plt>
mov    %rax,0x10(%rsp)
mov    (%r15),%rax
mov    %rax,0x8(%rsp)
movl   $0x6f616943,0x20(%rsp)
6f
movb   $0x0,0x24(%rsp)
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    $0x18,%r9d
call   10a0 <sendto@plt>
lea    0xd46(%rip),%rdi
mov    %eax,%esi
call   1070 <printf@plt>
mov    %ebp,%edi
mov    $0x2,%esi
call   1040 <shutdown@plt>
mov    %ebp,%edi
call   10b0 <close@plt>
xor    %eax,%eax
add    $0x10028,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i8*, i8*, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i8* }
%struct.sockaddr = type { i32 }
@PF_INET = global i8* null
@SOCK_DGRAM = global i32 0
@IPPROTO_UDP = global i32 0
@INADDR_ANY = global i32 0
@.str = [18 x i8] c"Bind Status = %d\0A\00"
@SOL_SOCKET = global i32 0
@SO_BROADCAST = global i32 0
@.str.1 = [24 x i8] c"Setsockopt Status = %d\0A\00"
@.str.2 = [5 x i8] c"Ciao\00"
@.str.3 = [20 x i8] c"sendto Status = %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [65536 x i8]
%10 = alloca %struct.sockaddr_in
%11 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
store i32 1, i32* %11
store i32 24, i32* %8
%12 = load i32, i32* %8
%13 = call i32 @memset(%struct.sockaddr_in* %10, i32 0, i32 %12)
store i32 65536, i32* %7
%14 = load i8*, i8** @PF_INET
%15 = load i32, i32* @SOCK_DGRAM
%16 = load i32, i32* @IPPROTO_UDP
%17 = call i32 @socket(i8* %14, i32 %15, i32 %16)
store i32 %17, i32* %5
%18 = load i32, i32* @INADDR_ANY
%19 = call i8* @htonl(i32 %18)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 2
%21 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %20, i32 0, i32 0
store i8* %19, i8** %21
%22 = call i8* @htons(i32 0)
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 1
store i8* %22, i8** %23
%24 = load i8*, i8** @PF_INET
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
store i8* %24, i8** %25
%26 = load i32, i32* %5
%27 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%28 = load i32, i32* %8
%29 = call i32 @bind(i32 %26, %struct.sockaddr* %27, i32 %28)
store i32 %29, i32* %6
%30 = load i32, i32* %6
%31 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %30)
%32 = load i32, i32* %5
%33 = load i32, i32* @SOL_SOCKET
%34 = load i32, i32* @SO_BROADCAST
%35 = call i32 @setsockopt(i32 %32, i32 %33, i32 %34, i32* %11, i32 4)
store i32 %35, i32* %6
%36 = load i32, i32* %6
%37 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %36)
%38 = call i8* @htonl(i32 -1)
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 2
%40 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %39, i32 0, i32 0
store i8* %38, i8** %40
%41 = load i8**, i8*** %4
%42 = getelementptr inbounds i8*, i8** %41, i64 1
%43 = load i8*, i8** %42
%44 = call i32 @atoi(i8* %43)
%45 = call i8* @htons(i32 %44)
%46 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 1
store i8* %45, i8** %46
%47 = load i8*, i8** @PF_INET
%48 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
store i8* %47, i8** %48
%49 = getelementptr inbounds [65536 x i8], [65536 x i8]* %9, i64 0, i64 0
%50 = call i32 @sprintf(i8* %49, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%51 = getelementptr inbounds [65536 x i8], [65536 x i8]* %9, i64 0, i64 0
%52 = call i32 @strlen(i8* %51)
store i32 %52, i32* %7
%53 = load i32, i32* %5
%54 = getelementptr inbounds [65536 x i8], [65536 x i8]* %9, i64 0, i64 0
%55 = load i32, i32* %7
%56 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%57 = load i32, i32* %8
%58 = call i32 @sendto(i32 %53, i8* %54, i32 %55, i32 0, %struct.sockaddr* %56, i32 %57)
store i32 %58, i32* %6
%59 = load i32, i32* %6
%60 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %59)
%61 = load i32, i32* %5
%62 = call i32 @shutdown(i32 %61, i32 2)
%63 = load i32, i32* %5
%64 = call i32 @close(i32 %63)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i8*, i8*, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i8* }
%struct.sockaddr = type { i32 }
@PF_INET = global i8* null
@SOCK_DGRAM = global i32 0
@IPPROTO_UDP = global i32 0
@INADDR_ANY = global i32 0
@.str = [18 x i8] c"Bind Status = %d\0A\00"
@SOL_SOCKET = global i32 0
@SO_BROADCAST = global i32 0
@.str.1 = [24 x i8] c"Setsockopt Status = %d\0A\00"
@.str.2 = [5 x i8] c"Ciao\00"
@.str.3 = [20 x i8] c"sendto Status = %d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [65536 x i8]
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = getelementptr inbounds [65536 x i8], [65536 x i8]* %3, i64 0, i64 0
%7 = bitcast %struct.sockaddr_in* %4 to i8*
%8 = bitcast i32* %5 to i8*
store i32 1, i32* %5
%9 = call i32 @memset(%struct.sockaddr_in* %4, i32 0, i32 24)
%10 = load i8*, i8** @PF_INET
%11 = load i32, i32* @SOCK_DGRAM
%12 = load i32, i32* @IPPROTO_UDP
%13 = call i32 @socket(i8* %10, i32 %11, i32 %12)
%14 = load i32, i32* @INADDR_ANY
%15 = call i8* @htonl(i32 %14)
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2, i32 0
store i8* %15, i8** %16
%17 = call i8* @htons(i32 0)
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
store i8* %17, i8** %18
%19 = load i8*, i8** @PF_INET
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
store i8* %19, i8** %20
%21 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%22 = call i32 @bind(i32 %13, %struct.sockaddr* %21, i32 24)
%23 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %22)
%24 = load i32, i32* @SOL_SOCKET
%25 = load i32, i32* @SO_BROADCAST
%26 = call i32 @setsockopt(i32 %13, i32 %24, i32 %25, i32* %5, i32 4)
%27 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %26)
%28 = call i8* @htonl(i32 -1)
store i8* %28, i8** %16
%29 = getelementptr inbounds i8*, i8** %1, i64 1
%30 = load i8*, i8** %29
%31 = call i32 @atoi(i8* %30)
%32 = call i8* @htons(i32 %31)
store i8* %32, i8** %18
%33 = load i8*, i8** @PF_INET
store i8* %33, i8** %20
%34 = call i32 @strlen(i8* %6)
%35 = call i32 @sendto(i32 %13, i8* %6, i32 %34, i32 0, %struct.sockaddr* %21, i32 24)
%36 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %35)
%37 = call i32 @shutdown(i32 %13, i32 2)
%38 = call i32 @close(i32 %13)
ret i32 0
}