#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 /*<<< orphan*/ uint32_t;
struct in_addr {
  int dummy;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_zero;
  struct in_addr sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  scalar_t__ h_addr;
};
typedef int /*<<< orphan*/ packet;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_BROADCAST;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ memset(int /*<<< orphan*/, char, int);
int /*<<< orphan*/ perror(char *);
int sendto(int, int /*<<< orphan*/ **, int, int /*<<< orphan*/,
           struct sockaddr *, int);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
void broadcaster() {
  int sockfd;
  struct sockaddr_in their_addr;
  struct hostent *he;
  int numbytes;
  int broadcast = 1;
  if ((he = gethostbyname("255.255.255.255")) == NULL) {
    perror("gethostbyname");
    exit(1);
  }
  if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
    perror("socket");
    exit(1);
  }
  if (setsockopt(sockfd, SOL_SOCKET, SO_BROADCAST, &broadcast,
                 sizeof broadcast) == -1) {
    perror("setsockopt (SO_BROADCAST)");
    exit(1);
  }
  their_addr.sin_family = AF_INET;
  their_addr.sin_port = htons(4950);
  their_addr.sin_addr = *((struct in_addr *)he->h_addr);
  memset(their_addr.sin_zero, '\0', sizeof their_addr.sin_zero);
  uint32_t packet[2];
  packet[0] = htonl((uint32_t)3141593);
  packet[1] = htonl((uint32_t)10789);
  if ((numbytes = sendto(sockfd, &packet, sizeof(packet), 0,
                         (struct sockaddr *)&their_addr, sizeof their_addr)) ==
      -1) {
    perror("sendto");
    exit(1);
  }
  close(sockfd);
}


x86 assembly (clang, -O0):
<broadcaster>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x1,-0x28(%rbp)
lea    0xe4a(%rip),%rdi
call   1090 <gethostbyname@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11df <broadcaster+0x3f>
lea    0xe40(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
mov    0x2de9(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,-0x4(%rbp)
cmp    $0xffffffff,%eax
jne    121a <broadcaster+0x7a>
lea    0xe13(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x4(%rbp),%edi
mov    0x2dc4(%rip),%rax
mov    (%rax),%esi
mov    0x2da3(%rip),%rax
mov    (%rax),%edx
lea    -0x28(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    125d <broadcaster+0xbd>
lea    0xdd7(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    0x2d7c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    $0x1356,%edi
call   1040 <htons@plt>
mov    %eax,-0x10(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%edi
xor    %esi,%esi
mov    $0x4,%edx
call   1060 <memset@plt>
mov    $0x2fefd9,%edi
call   1050 <htonl@plt>
mov    %eax,-0x30(%rbp)
mov    $0x2a25,%edi
call   1050 <htonl@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x30(%rbp),%rsi
lea    -0x18(%rbp),%r8
mov    $0x8,%edx
xor    %ecx,%ecx
mov    $0x10,%r9d
call   1070 <sendto@plt>
mov    %eax,-0x24(%rbp)
cmp    $0xffffffff,%eax
jne    12ea <broadcaster+0x14a>
lea    0xd64(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x4(%rbp),%edi
call   1080 <close@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<broadcaster>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
movl   $0x1,0x4(%rsp)
lea    0xe48(%rip),%rdi
call   1090 <gethostbyname@plt>
test   %rax,%rax
je     1295 <broadcaster+0xf5>
mov    %rax,%r14
mov    0x2e10(%rip),%r15
mov    (%r15),%edi
mov    0x2dfe(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
cmp    $0xffffffff,%eax
je     129e <broadcaster+0xfe>
mov    %eax,%ebx
mov    0x2df3(%rip),%rax
mov    (%rax),%esi
mov    0x2dd2(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
je     12a7 <broadcaster+0x107>
mov    (%r15),%eax
mov    %eax,0x1c(%rsp)
mov    $0x1356,%edi
call   1040 <htons@plt>
mov    %eax,0x18(%rsp)
mov    (%r14),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
xor    %esi,%esi
mov    $0x4,%edx
call   1060 <memset@plt>
mov    $0x2fefd9,%edi
call   1050 <htonl@plt>
mov    %eax,0x8(%rsp)
mov    $0x2a25,%edi
call   1050 <htonl@plt>
mov    %eax,0xc(%rsp)
lea    0x8(%rsp),%rsi
lea    0x10(%rsp),%r8
mov    %ebx,%edi
mov    $0x8,%edx
xor    %ecx,%ecx
mov    $0x10,%r9d
call   1070 <sendto@plt>
cmp    $0xffffffff,%eax
je     12b0 <broadcaster+0x110>
mov    %ebx,%edi
call   1080 <close@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xd74(%rip),%rdi
jmp    12b7 <broadcaster+0x117>
lea    0xd79(%rip),%rdi
jmp    12b7 <broadcaster+0x117>
lea    0xd77(%rip),%rdi
jmp    12b7 <broadcaster+0x117>
lea    0xd88(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.in_addr, i32, i32 }
%struct.in_addr = type { i32 }
%struct.hostent = type { i64 }
%struct.sockaddr = type { i32 }
@.str = [16 x i8] c"255.255.255.255\00"
@.str.1 = [14 x i8] c"gethostbyname\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.2 = [7 x i8] c"socket\00"
@SOL_SOCKET = global i32 0
@SO_BROADCAST = global i32 0
@.str.3 = [26 x i8] c"setsockopt (SO_BROADCAST)\00"
@.str.4 = [7 x i8] c"sendto\00"
define void @broadcaster() {
%1 = alloca i32
%2 = alloca %struct.sockaddr_in
%3 = alloca %struct.hostent*
%4 = alloca i32
%5 = alloca i32
%6 = alloca [2 x i32]
store i32 1, i32* %5
%7 = call %struct.hostent* @gethostbyname(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
store %struct.hostent* %7, %struct.hostent** %3
%8 = icmp eq %struct.hostent* %7, null
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %0
%13 = load i32, i32* @AF_INET
%14 = load i32, i32* @SOCK_DGRAM
%15 = call i32 @socket(i32 %13, i32 %14, i32 0)
store i32 %15, i32* %1
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %20
17: ; preds = %12
%18 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %12
%21 = load i32, i32* %1
%22 = load i32, i32* @SOL_SOCKET
%23 = load i32, i32* @SO_BROADCAST
%24 = call i32 @setsockopt(i32 %21, i32 %22, i32 %23, i32* %5, i32 4)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %29
26: ; preds = %20
%27 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %20
%30 = load i32, i32* @AF_INET
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 3
store i32 %30, i32* %31
%32 = call i32 @htons(i32 4950)
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 2
store i32 %32, i32* %33
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 1
%35 = load %struct.hostent*, %struct.hostent** %3
%36 = getelementptr inbounds %struct.hostent, %struct.hostent* %35, i32 0, i32 0
%37 = load i64, i64* %36
%38 = inttoptr i64 %37 to %struct.in_addr*
%39 = bitcast %struct.in_addr* %34 to i8*
%40 = bitcast %struct.in_addr* %38 to i8*
%41 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 0
%42 = load i32, i32* %41
%43 = call i32 @memset(i32 %42, i8 signext 0, i32 4)
%44 = call i32 @htonl(i32 3141593)
%45 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
store i32 %44, i32* %45
%46 = call i32 @htonl(i32 10789)
%47 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
store i32 %46, i32* %47
%48 = load i32, i32* %1
%49 = bitcast [2 x i32]* %6 to i32**
%50 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%51 = call i32 @sendto(i32 %48, i32** %49, i32 8, i32 0, %struct.sockaddr* %50, i32 16)
store i32 %51, i32* %4
%52 = icmp eq i32 %51, -1
br i1 %52, label %53, label %56
53: ; preds = %29
%54 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%55 = call i32 @exit(i32 1)
unreachable
56: ; preds = %29
%57 = load i32, i32* %1
%58 = call i32 @close(i32 %57)
ret void
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.in_addr, i32, i32 }
%struct.in_addr = type { i32 }
%struct.hostent = type { i64 }
%struct.sockaddr = type { i32 }
@.str = [16 x i8] c"255.255.255.255\00"
@.str.1 = [14 x i8] c"gethostbyname\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.2 = [7 x i8] c"socket\00"
@SOL_SOCKET = global i32 0
@SO_BROADCAST = global i32 0
@.str.3 = [26 x i8] c"setsockopt (SO_BROADCAST)\00"
@.str.4 = [7 x i8] c"sendto\00"
define void @broadcaster() {
%1 = alloca %struct.sockaddr_in
%2 = alloca i32
%3 = alloca i32*
%4 = bitcast i32** %3 to [2 x i32]*
%5 = bitcast %struct.sockaddr_in* %1 to i8*
%6 = bitcast i32* %2 to i8*
store i32 1, i32* %2
%7 = tail call %struct.hostent* @gethostbyname(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq %struct.hostent* %7, null
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %0
%13 = load i32, i32* @AF_INET
%14 = load i32, i32* @SOCK_DGRAM
%15 = tail call i32 @socket(i32 %13, i32 %14, i32 0)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %20
17: ; preds = %12
%18 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %12
%21 = load i32, i32* @SOL_SOCKET
%22 = load i32, i32* @SO_BROADCAST
%23 = call i32 @setsockopt(i32 %15, i32 %21, i32 %22, i32* %2, i32 4)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %28
25: ; preds = %20
%26 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %20
%29 = load i32, i32* @AF_INET
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 3
store i32 %29, i32* %30
%31 = call i32 @htons(i32 4950)
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %31, i32* %32
%33 = getelementptr inbounds %struct.hostent, %struct.hostent* %7, i64 0, i32 0
%34 = load i64, i64* %33
%35 = inttoptr i64 %34 to i32*
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1, i32 0
%37 = load i32, i32* %35
store i32 %37, i32* %36
%38 = call i32 @memset(i32 undef, i8 signext 0, i32 4)
%39 = bitcast i32** %3 to i8*
%40 = call i32 @htonl(i32 3141593)
%41 = bitcast i32** %3 to i32*
store i32 %40, i32* %41
%42 = call i32 @htonl(i32 10789)
%43 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
store i32 %42, i32* %43
%44 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%45 = call i32 @sendto(i32 %15, i32** %3, i32 8, i32 0, %struct.sockaddr* %44, i32 16)
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %50
47: ; preds = %28
%48 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%49 = call i32 @exit(i32 1)
unreachable
50: ; preds = %28
%51 = call i32 @close(i32 %15)
ret void
}