#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 scalar_t__ ssize_t;
typedef int /*<<< orphan*/ server_address;
typedef int /*<<< orphan*/ message;
typedef int /*<<< orphan*/ broadcastPermission;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_BROADCAST;
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_pton(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, scalar_t__);
scalar_t__ sendto(int, char *, scalar_t__, int /*<<< orphan*/,
                  struct sockaddr *, int);
int /*<<< orphan*/ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              void *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int main() {
  int sockfd = socket(AF_INET, SOCK_DGRAM, 0);
  if (sockfd < 0) {
    fprintf(stderr, "socket error: %s\n", strerror(errno));
    return EXIT_FAILURE;
  }
  struct sockaddr_in server_address;
  bzero(&server_address, sizeof(server_address));
  server_address.sin_family = AF_INET;
  server_address.sin_port = htons(12345);
  inet_pton(AF_INET, "192.168.2.255", &server_address.sin_addr);
  int broadcastPermission = 1;
  setsockopt(sockfd, SOL_SOCKET, SO_BROADCAST, (void *)&broadcastPermission,
             sizeof(broadcastPermission));
  char a = 'a';
  char b = 'b';
  char message[9];
  message[0] = a;
  message[1] = b;
  message[2] = a;
  message[3] = b;
  message[4] = a;
  message[5] = b;
  message[6] = a;
  message[7] = b;
  message[8] = a;
  ssize_t message_len = sizeof(message);
  printf("%lu\n", message_len);
  if (sendto(sockfd, message, message_len, 0,
             (struct sockaddr *)&server_address,
             sizeof(server_address)) != message_len) {
    fprintf(stderr, "sendto error: %s\n", strerror(errno));
    return EXIT_FAILURE;
  }
  close(sockfd);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
mov    0x2e19(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1212 <main+0x72>
mov    0x2de4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x2dd0(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    %rax,%rdx
lea    0xe04(%rip),%rsi
call   1080 <fprintf@plt>
mov    0x2da8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    134a <main+0x1aa>
lea    -0x18(%rbp),%rdi
mov    $0xc,%esi
call   10a0 <bzero@plt>
mov    0x2db9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    $0x3039,%edi
call   1040 <htons@plt>
mov    %eax,-0x14(%rbp)
mov    0x2da0(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rdx
lea    0xdc5(%rip),%rsi
call   1090 <inet_pton@plt>
movl   $0x1,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2d85(%rip),%rax
mov    (%rax),%esi
mov    0x2d64(%rip),%rax
mov    (%rax),%edx
lea    -0x1c(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
movb   $0x61,-0x1d(%rbp)
movb   $0x62,-0x1e(%rbp)
mov    -0x1d(%rbp),%al
mov    %al,-0x27(%rbp)
mov    -0x1e(%rbp),%al
mov    %al,-0x26(%rbp)
mov    -0x1d(%rbp),%al
mov    %al,-0x25(%rbp)
mov    -0x1e(%rbp),%al
mov    %al,-0x24(%rbp)
mov    -0x1d(%rbp),%al
mov    %al,-0x23(%rbp)
mov    -0x1e(%rbp),%al
mov    %al,-0x22(%rbp)
mov    -0x1d(%rbp),%al
mov    %al,-0x21(%rbp)
mov    -0x1e(%rbp),%al
mov    %al,-0x20(%rbp)
mov    -0x1d(%rbp),%al
mov    %al,-0x1f(%rbp)
movq   $0x9,-0x30(%rbp)
mov    -0x30(%rbp),%rsi
lea    0xd52(%rip),%rdi
call   1050 <printf@plt>
mov    -0x8(%rbp),%edi
lea    -0x27(%rbp),%rsi
mov    -0x30(%rbp),%rdx
lea    -0x18(%rbp),%r8
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1060 <sendto@plt>
cmp    -0x30(%rbp),%rax
je     1336 <main+0x196>
mov    0x2cc0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    0x2cac(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x38(%rbp),%edi
mov    %rax,%rdx
lea    0xd05(%rip),%rsi
call   1080 <fprintf@plt>
mov    0x2c84(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    134a <main+0x1aa>
mov    -0x8(%rbp),%edi
call   1070 <close@plt>
mov    0x2c63(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    0x2e30(%rip),%r15
mov    (%r15),%edi
mov    0x2e1e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
test   %eax,%eax
js     1286 <main+0xe6>
mov    %eax,%ebx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0xc,%esi
call   10a0 <bzero@plt>
mov    (%r15),%eax
mov    %eax,0x18(%rsp)
mov    $0x3039,%edi
call   1040 <htons@plt>
mov    %eax,0x14(%rsp)
mov    (%r15),%edi
lea    0xe14(%rip),%rsi
mov    %r14,%rdx
call   1090 <inet_pton@plt>
movl   $0x1,(%rsp)
mov    0x2dd4(%rip),%rax
mov    (%rax),%esi
mov    0x2db3(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
movabs $0x6261626162616261,%rax
62 61 62
mov    %rax,0x7(%rsp)
movb   $0x61,0xf(%rsp)
lea    0xdd6(%rip),%rdi
mov    $0x9,%esi
call   1050 <printf@plt>
lea    0x7(%rsp),%rsi
mov    $0x9,%edx
mov    %ebx,%edi
xor    %ecx,%ecx
mov    %r14,%r8
mov    $0xc,%r9d
call   1060 <sendto@plt>
cmp    $0x9,%rax
jne    12a6 <main+0x106>
mov    %ebx,%edi
call   1070 <close@plt>
mov    0x2d24(%rip),%rax
jmp    12d5 <main+0x135>
mov    0x2d33(%rip),%rax
mov    (%rax),%ebx
mov    0x2d22(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xd5c(%rip),%rsi
jmp    12c4 <main+0x124>
mov    0x2d13(%rip),%rax
mov    (%rax),%ebx
mov    0x2d02(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xd61(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1080 <fprintf@plt>
mov    0x2cdb(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@stderr = global i32 0
@.str = [18 x i8] c"socket error: %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [14 x i8] c"192.168.2.255\00"
@SOL_SOCKET = global i32 0
@SO_BROADCAST = global i32 0
@.str.2 = [5 x i8] c"%lu\0A\00"
@.str.3 = [18 x i8] c"sendto error: %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = alloca i8
%6 = alloca i8
%7 = alloca [9 x i8]
%8 = alloca i64
store i32 0, i32* %1
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_DGRAM
%11 = call i32 @socket(i32 %9, i32 %10, i32 0)
store i32 %11, i32* %2
%12 = load i32, i32* %2
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %20
14: ; preds = %0
%15 = load i32, i32* @stderr
%16 = load i32, i32* @errno
%17 = call i8* @strerror(i32 %16)
%18 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = load i32, i32* @EXIT_FAILURE
store i32 %19, i32* %1
br label %71
20: ; preds = %0
%21 = call i32 @bzero(%struct.sockaddr_in* %3, i32 12)
%22 = load i32, i32* @AF_INET
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i32 %22, i32* %23
%24 = call i32 @htons(i32 12345)
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
store i32 %24, i32* %25
%26 = load i32, i32* @AF_INET
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
%28 = call i32 @inet_pton(i32 %26, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32* %27)
store i32 1, i32* %4
%29 = load i32, i32* %2
%30 = load i32, i32* @SOL_SOCKET
%31 = load i32, i32* @SO_BROADCAST
%32 = bitcast i32* %4 to i8*
%33 = call i32 @setsockopt(i32 %29, i32 %30, i32 %31, i8* %32, i32 4)
store i8 97, i8* %5
store i8 98, i8* %6
%34 = load i8, i8* %5
%35 = getelementptr inbounds [9 x i8], [9 x i8]* %7, i64 0, i64 0
store i8 %34, i8* %35
%36 = load i8, i8* %6
%37 = getelementptr inbounds [9 x i8], [9 x i8]* %7, i64 0, i64 1
store i8 %36, i8* %37
%38 = load i8, i8* %5
%39 = getelementptr inbounds [9 x i8], [9 x i8]* %7, i64 0, i64 2
store i8 %38, i8* %39
%40 = load i8, i8* %6
%41 = getelementptr inbounds [9 x i8], [9 x i8]* %7, i64 0, i64 3
store i8 %40, i8* %41
%42 = load i8, i8* %5
%43 = getelementptr inbounds [9 x i8], [9 x i8]* %7, i64 0, i64 4
store i8 %42, i8* %43
%44 = load i8, i8* %6
%45 = getelementptr inbounds [9 x i8], [9 x i8]* %7, i64 0, i64 5
store i8 %44, i8* %45
%46 = load i8, i8* %5
%47 = getelementptr inbounds [9 x i8], [9 x i8]* %7, i64 0, i64 6
store i8 %46, i8* %47
%48 = load i8, i8* %6
%49 = getelementptr inbounds [9 x i8], [9 x i8]* %7, i64 0, i64 7
store i8 %48, i8* %49
%50 = load i8, i8* %5
%51 = getelementptr inbounds [9 x i8], [9 x i8]* %7, i64 0, i64 8
store i8 %50, i8* %51
store i64 9, i64* %8
%52 = load i64, i64* %8
%53 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %52)
%54 = load i32, i32* %2
%55 = getelementptr inbounds [9 x i8], [9 x i8]* %7, i64 0, i64 0
%56 = load i64, i64* %8
%57 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%58 = call i64 @sendto(i32 %54, i8* %55, i64 %56, i32 0, %struct.sockaddr* %57, i32 12)
%59 = load i64, i64* %8
%60 = icmp ne i64 %58, %59
br i1 %60, label %61, label %67
61: ; preds = %20
%62 = load i32, i32* @stderr
%63 = load i32, i32* @errno
%64 = call i8* @strerror(i32 %63)
%65 = call i32 @fprintf(i32 %62, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %64)
%66 = load i32, i32* @EXIT_FAILURE
store i32 %66, i32* %1
br label %71
67: ; preds = %20
%68 = load i32, i32* %2
%69 = call i32 @close(i32 %68)
%70 = load i32, i32* @EXIT_SUCCESS
store i32 %70, i32* %1
br label %71
71: ; preds = %67, %61, %14
%72 = load i32, i32* %1
ret i32 %72
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@stderr = global i32 0
@.str = [18 x i8] c"socket error: %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [14 x i8] c"192.168.2.255\00"
@SOL_SOCKET = global i32 0
@SO_BROADCAST = global i32 0
@.str.2 = [5 x i8] c"%lu\0A\00"
@.str.3 = [18 x i8] c"sendto error: %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca i32
%3 = alloca [9 x i8]
%4 = load i32, i32* @AF_INET
%5 = load i32, i32* @SOCK_DGRAM
%6 = tail call i32 @socket(i32 %4, i32 %5, i32 0)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %14
8: ; preds = %0
%9 = load i32, i32* @stderr
%10 = load i32, i32* @errno
%11 = tail call i8* @strerror(i32 %10)
%12 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = load i32, i32* @EXIT_FAILURE
br label %51
14: ; preds = %0
%15 = bitcast %struct.sockaddr_in* %1 to i8*
%16 = call i32 @bzero(%struct.sockaddr_in* %1, i32 12)
%17 = load i32, i32* @AF_INET
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %17, i32* %18
%19 = tail call i32 @htons(i32 12345)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1
store i32 %19, i32* %20
%21 = load i32, i32* @AF_INET
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
%23 = call i32 @inet_pton(i32 %21, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32* %22)
%24 = bitcast i32* %2 to i8*
store i32 1, i32* %2
%25 = load i32, i32* @SOL_SOCKET
%26 = load i32, i32* @SO_BROADCAST
%27 = call i32 @setsockopt(i32 %6, i32 %25, i32 %26, i8* %24, i32 4)
%28 = getelementptr inbounds [9 x i8], [9 x i8]* %3, i64 0, i64 0
store i8 97, i8* %28
%29 = getelementptr inbounds [9 x i8], [9 x i8]* %3, i64 0, i64 1
store i8 98, i8* %29
%30 = getelementptr inbounds [9 x i8], [9 x i8]* %3, i64 0, i64 2
store i8 97, i8* %30
%31 = getelementptr inbounds [9 x i8], [9 x i8]* %3, i64 0, i64 3
store i8 98, i8* %31
%32 = getelementptr inbounds [9 x i8], [9 x i8]* %3, i64 0, i64 4
store i8 97, i8* %32
%33 = getelementptr inbounds [9 x i8], [9 x i8]* %3, i64 0, i64 5
store i8 98, i8* %33
%34 = getelementptr inbounds [9 x i8], [9 x i8]* %3, i64 0, i64 6
store i8 97, i8* %34
%35 = getelementptr inbounds [9 x i8], [9 x i8]* %3, i64 0, i64 7
store i8 98, i8* %35
%36 = getelementptr inbounds [9 x i8], [9 x i8]* %3, i64 0, i64 8
store i8 97, i8* %36
%37 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 9)
%38 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%39 = call i64 @sendto(i32 %6, i8* %28, i64 9, i32 0, %struct.sockaddr* %38, i32 12)
%40 = icmp eq i64 %39, 9
br i1 %40, label %46, label %41
41: ; preds = %14
%42 = load i32, i32* @stderr
%43 = load i32, i32* @errno
%44 = call i8* @strerror(i32 %43)
%45 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %44)
br label %48
46: ; preds = %14
%47 = call i32 @close(i32 %6)
br label %48
48: ; preds = %46, %41
%49 = phi i32* [ @EXIT_FAILURE, %41 ], [ @EXIT_SUCCESS, %46 ]
%50 = load i32, i32* %49
br label %51
51: ; preds = %48, %8
%52 = phi i32 [ %13, %8 ], [ %50, %48 ]
ret i32 %52
}