#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*/ 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*/ *);
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*/);
scalar_t__ strlen(char *);
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.0.255", &server_address.sin_addr);
  int broadcastPermission = 1;
  setsockopt(sockfd, SOL_SOCKET, SO_BROADCAST, (void *)&broadcastPermission,
             sizeof(broadcastPermission));
  char *message = "Cześć Basia (255)";
  ssize_t message_len = strlen(message);
  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    130c <main+0x16c>
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   1050 <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>
lea    0xd9c(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x28(%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     12f8 <main+0x158>
mov    0x2cfe(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    0x2cea(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x38(%rbp),%edi
mov    %rax,%rdx
lea    0xd52(%rip),%rsi
call   1080 <fprintf@plt>
mov    0x2cc2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    130c <main+0x16c>
mov    -0x8(%rbp),%edi
call   1070 <close@plt>
mov    0x2ca1(%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    0x2e40(%rip),%r15
mov    (%r15),%edi
mov    0x2e2e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
test   %eax,%eax
js     1256 <main+0xc6>
mov    %eax,%ebx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0xc,%esi
call   1090 <bzero@plt>
mov    (%r15),%eax
mov    %eax,0x18(%rsp)
mov    $0x3039,%edi
call   1040 <htons@plt>
mov    %eax,0x14(%rsp)
mov    (%r15),%edi
lea    0xe24(%rip),%rsi
mov    %r14,%rdx
call   1080 <inet_pton@plt>
movl   $0x1,0xc(%rsp)
mov    0x2de3(%rip),%rax
mov    (%rax),%esi
mov    0x2dc2(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
lea    0xdf7(%rip),%rsi
mov    $0x13,%edx
mov    %ebx,%edi
xor    %ecx,%ecx
mov    %r14,%r8
mov    $0xc,%r9d
call   1050 <sendto@plt>
cmp    $0x13,%rax
jne    1276 <main+0xe6>
mov    %ebx,%edi
call   1060 <close@plt>
mov    0x2d54(%rip),%rax
jmp    12a5 <main+0x115>
mov    0x2d63(%rip),%rax
mov    (%rax),%ebx
mov    0x2d52(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xd8c(%rip),%rsi
jmp    1294 <main+0x104>
mov    0x2d43(%rip),%rax
mov    (%rax),%ebx
mov    0x2d32(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xda0(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1070 <fprintf@plt>
mov    0x2d0b(%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.0.255\00"
@SOL_SOCKET = global i32 0
@SO_BROADCAST = global i32 0
@.str.2 = [20 x i8] c"Cze\C5\9B\C4\87 Basia (255)\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 i64
store i32 0, i32* %1
%7 = load i32, i32* @AF_INET
%8 = load i32, i32* @SOCK_DGRAM
%9 = call i32 @socket(i32 %7, i32 %8, i32 0)
store i32 %9, i32* %2
%10 = load i32, i32* %2
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %18
12: ; preds = %0
%13 = load i32, i32* @stderr
%14 = load i32, i32* @errno
%15 = call i8* @strerror(i32 %14)
%16 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = load i32, i32* @EXIT_FAILURE
store i32 %17, i32* %1
br label %51
18: ; preds = %0
%19 = call i32 @bzero(%struct.sockaddr_in* %3, i32 12)
%20 = load i32, i32* @AF_INET
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i32 %20, i32* %21
%22 = call i32 @htons(i32 12345)
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
store i32 %22, i32* %23
%24 = load i32, i32* @AF_INET
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
%26 = call i32 @inet_pton(i32 %24, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32* %25)
store i32 1, i32* %4
%27 = load i32, i32* %2
%28 = load i32, i32* @SOL_SOCKET
%29 = load i32, i32* @SO_BROADCAST
%30 = bitcast i32* %4 to i8*
%31 = call i32 @setsockopt(i32 %27, i32 %28, i32 %29, i8* %30, i32 4)
store i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8** %5
%32 = load i8*, i8** %5
%33 = call i64 @strlen(i8* %32)
store i64 %33, i64* %6
%34 = load i32, i32* %2
%35 = load i8*, i8** %5
%36 = load i64, i64* %6
%37 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%38 = call i64 @sendto(i32 %34, i8* %35, i64 %36, i32 0, %struct.sockaddr* %37, i32 12)
%39 = load i64, i64* %6
%40 = icmp ne i64 %38, %39
br i1 %40, label %41, label %47
41: ; preds = %18
%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)
%46 = load i32, i32* @EXIT_FAILURE
store i32 %46, i32* %1
br label %51
47: ; preds = %18
%48 = load i32, i32* %2
%49 = call i32 @close(i32 %48)
%50 = load i32, i32* @EXIT_SUCCESS
store i32 %50, i32* %1
br label %51
51: ; preds = %47, %41, %12
%52 = load i32, i32* %1
ret i32 %52
}

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.0.255\00"
@SOL_SOCKET = global i32 0
@SO_BROADCAST = global i32 0
@.str.2 = [20 x i8] c"Cze\C5\9B\C4\87 Basia (255)\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 = load i32, i32* @AF_INET
%4 = load i32, i32* @SOCK_DGRAM
%5 = tail call i32 @socket(i32 %3, i32 %4, i32 0)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %13
7: ; preds = %0
%8 = load i32, i32* @stderr
%9 = load i32, i32* @errno
%10 = tail call i8* @strerror(i32 %9)
%11 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = load i32, i32* @EXIT_FAILURE
br label %40
13: ; preds = %0
%14 = bitcast %struct.sockaddr_in* %1 to i8*
%15 = call i32 @bzero(%struct.sockaddr_in* %1, i32 12)
%16 = load i32, i32* @AF_INET
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %16, i32* %17
%18 = tail call i32 @htons(i32 12345)
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1
store i32 %18, i32* %19
%20 = load i32, i32* @AF_INET
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
%22 = call i32 @inet_pton(i32 %20, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32* %21)
%23 = bitcast i32* %2 to i8*
store i32 1, i32* %2
%24 = load i32, i32* @SOL_SOCKET
%25 = load i32, i32* @SO_BROADCAST
%26 = call i32 @setsockopt(i32 %5, i32 %24, i32 %25, i8* %23, i32 4)
%27 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%28 = call i64 @sendto(i32 %5, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i64 19, i32 0, %struct.sockaddr* %27, i32 12)
%29 = icmp eq i64 %28, 19
br i1 %29, label %35, label %30
30: ; preds = %13
%31 = load i32, i32* @stderr
%32 = load i32, i32* @errno
%33 = call i8* @strerror(i32 %32)
%34 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %33)
br label %37
35: ; preds = %13
%36 = call i32 @close(i32 %5)
br label %37
37: ; preds = %35, %30
%38 = phi i32* [ @EXIT_FAILURE, %30 ], [ @EXIT_SUCCESS, %35 ]
%39 = load i32, i32* %38
br label %40
40: ; preds = %37, %7
%41 = phi i32 [ %12, %7 ], [ %39, %37 ]
ret i32 %41
}