#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__ {
  int s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ so_broadcast;
typedef int /*<<< orphan*/ addr;

/* 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*/ htons(int);
int /*<<< orphan*/ inet_pton(int /*<<< orphan*/, char *, int *);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int recvfrom(int, char *, int, int /*<<< orphan*/, int /*<<< orphan*/ *,
             int /*<<< orphan*/ *);
int sendto(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int);
int /*<<< orphan*/ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int strlen(char *);
int main() {
  int sockfd;
  int so_broadcast = 1;
  char buf[128] = "blablabla";
  struct sockaddr_in addr;
  int bin_addr;
  int n;
  sockfd = socket(AF_INET, SOCK_DGRAM, 0);
  if (sockfd < 0) {
    printf("create socket error\n");
    return -1;
  }
  setsockopt(sockfd, SOL_SOCKET, SO_BROADCAST, &so_broadcast,
             sizeof(so_broadcast));
  memset(&addr, 0, sizeof(addr));
  inet_pton(AF_INET, "255.255.255.255", &bin_addr);
  addr.sin_family = AF_INET;
  addr.sin_port = htons(30033);
  addr.sin_addr.s_addr = bin_addr;
  if ((n = sendto(sockfd, buf, strlen(buf), 0, (struct sockaddr *)&addr,
                  sizeof(struct sockaddr))) < 0)
    printf("send error \n");
  else
    printf("send: [%04d]%s\n", strlen(buf), buf);
  if ((n = recvfrom(sockfd, buf, 128, 0, NULL, NULL)) < 0)
    ;
  else
    printf("recv: [%04d]%s\n", strlen(buf), buf);
  close(sockfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0xc(%rbp)
lea    -0x90(%rbp),%rdi
lea    0xe29(%rip),%rsi
mov    $0x80,%edx
call   10a0 <memcpy@plt>
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
mov    0x2de7(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1221 <main+0x71>
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    138e <main+0x1de>
mov    -0x8(%rbp),%edi
mov    0x2dbd(%rip),%rax
mov    (%rax),%esi
mov    0x2d9c(%rip),%rax
mov    (%rax),%edx
lea    -0xc(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
lea    -0xa0(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
mov    0x2d81(%rip),%rax
mov    (%rax),%edi
lea    0xe2d(%rip),%rsi
lea    -0xa4(%rbp),%rdx
call   10b0 <inet_pton@plt>
mov    0x2d65(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x98(%rbp)
mov    $0x7551,%edi
call   1050 <htons@plt>
mov    %eax,-0x9c(%rbp)
mov    -0xa4(%rbp),%eax
mov    %eax,-0xa0(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xb4(%rbp)
lea    -0x90(%rbp),%rax
mov    %rax,-0xb0(%rbp)
lea    -0x90(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0xb4(%rbp),%edi
mov    -0xb0(%rbp),%rsi
mov    %eax,%edx
lea    -0xa0(%rbp),%r8
xor    %ecx,%ecx
mov    $0x4,%r9d
call   1080 <sendto@plt>
mov    %eax,-0xa8(%rbp)
cmp    $0x0,%eax
jge    1307 <main+0x157>
lea    0xdaa(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    132a <main+0x17a>
lea    -0x90(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%esi
lea    -0x90(%rbp),%rdx
lea    0xd8f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x8(%rbp),%edi
lea    -0x90(%rbp),%rsi
mov    $0x80,%edx
xor    %ecx,%ecx
xor    %eax,%eax
mov    %eax,%r9d
mov    %r9,%r8
call   10c0 <recvfrom@plt>
mov    %eax,-0xa8(%rbp)
cmp    $0x0,%eax
jge    135c <main+0x1ac>
jmp    137f <main+0x1cf>
lea    -0x90(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%esi
lea    -0x90(%rbp),%rdx
lea    0xd4a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x8(%rbp),%edi
call   1090 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0xa0,%rsp
movl   $0x1,0xc(%rsp)
movaps 0xea5(%rip),%xmm0
movaps %xmm0,0x90(%rsp)
movaps 0xe86(%rip),%xmm0
movaps %xmm0,0x80(%rsp)
movaps 0xe67(%rip),%xmm0
movaps %xmm0,0x70(%rsp)
movaps 0xe4b(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
movaps 0xe2f(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xe13(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xdf7(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xddb(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
mov    0x2daf(%rip),%r15
mov    (%r15),%edi
mov    0x2d9d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
test   %eax,%eax
js     1301 <main+0x151>
mov    %eax,%ebx
mov    0x2d93(%rip),%rax
mov    (%rax),%esi
mov    0x2d72(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
lea    0x10(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1080 <memset@plt>
mov    (%r15),%edi
lea    0xdf0(%rip),%rsi
lea    0x8(%rsp),%rdx
call   10b0 <inet_pton@plt>
mov    (%r15),%eax
mov    %eax,0x18(%rsp)
mov    $0x7551,%edi
call   1060 <htons@plt>
mov    %eax,0x14(%rsp)
mov    0x8(%rsp),%eax
mov    %eax,0x10(%rsp)
lea    0x20(%rsp),%r15
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    $0x4,%r9d
call   1090 <sendto@plt>
test   %eax,%eax
js     1315 <main+0x165>
lea    0x20(%rsp),%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0xd9d(%rip),%rdi
mov    %eax,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1070 <printf@plt>
jmp    1321 <main+0x171>
lea    0xdb4(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%r14d
jmp    1368 <main+0x1b8>
lea    0xd94(%rip),%rdi
call   1030 <puts@plt>
xor    %r14d,%r14d
lea    0x20(%rsp),%rsi
mov    %ebx,%edi
mov    $0x80,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   10c0 <recvfrom@plt>
test   %eax,%eax
js     1361 <main+0x1b1>
lea    0x20(%rsp),%r15
mov    %r15,%rdi
call   1050 <strlen@plt>
lea    0xd4b(%rip),%rdi
mov    %eax,%esi
mov    %r15,%rdx
xor    %eax,%eax
call   1070 <printf@plt>
mov    %ebx,%edi
call   10a0 <close@plt>
mov    %r14d,%eax
add    $0xa0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@__const.main.buf = [128 x i8] c"blablabla\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [21 x i8] c"create socket error\0A\00"
@SOL_SOCKET = global i32 0
@SO_BROADCAST = global i32 0
@.str.1 = [16 x i8] c"255.255.255.255\00"
@.str.2 = [13 x i8] c"send error \0A\00"
@.str.3 = [16 x i8] c"send: [%04d]%s\0A\00"
@.str.4 = [16 x i8] c"recv: [%04d]%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [128 x i8]
%5 = alloca %struct.sockaddr_in
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
store i32 1, i32* %3
%8 = bitcast [128 x i8]* %4 to i8*
%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 %16
14: ; preds = %0
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %1
br label %59
16: ; preds = %0
%17 = load i32, i32* %2
%18 = load i32, i32* @SOL_SOCKET
%19 = load i32, i32* @SO_BROADCAST
%20 = call i32 @setsockopt(i32 %17, i32 %18, i32 %19, i32* %3, i32 4)
%21 = call i32 @memset(%struct.sockaddr_in* %5, i32 0, i32 12)
%22 = load i32, i32* @AF_INET
%23 = call i32 @inet_pton(i32 %22, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32* %6)
%24 = load i32, i32* @AF_INET
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 2
store i32 %24, i32* %25
%26 = call i32 @htons(i32 30033)
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 1
store i32 %26, i32* %27
%28 = load i32, i32* %6
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 0
%30 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %29, i32 0, i32 0
store i32 %28, i32* %30
%31 = load i32, i32* %2
%32 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%33 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%34 = call i32 @strlen(i8* %33)
%35 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%36 = call i32 @sendto(i32 %31, i8* %32, i32 %34, i32 0, %struct.sockaddr* %35, i32 4)
store i32 %36, i32* %7
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %16
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %45
40: ; preds = %16
%41 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%42 = call i32 @strlen(i8* %41)
%43 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %42, i8* %43)
br label %45
45: ; preds = %40, %38
%46 = load i32, i32* %2
%47 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%48 = call i32 @recvfrom(i32 %46, i8* %47, i32 128, i32 0, i32* null, i32* null)
store i32 %48, i32* %7
%49 = icmp slt i32 %48, 0
br i1 %49, label %50, label %51
50: ; preds = %45
br label %56
51: ; preds = %45
%52 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%53 = call i32 @strlen(i8* %52)
%54 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %53, i8* %54)
br label %56
56: ; preds = %51, %50
%57 = load i32, i32* %2
%58 = call i32 @close(i32 %57)
store i32 0, i32* %1
br label %59
59: ; preds = %56, %14
%60 = load i32, i32* %1
ret i32 %60
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@__const.main.buf = [128 x i8] c"blablabla\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@SOL_SOCKET = global i32 0
@SO_BROADCAST = global i32 0
@.str.1 = [16 x i8] c"255.255.255.255\00"
@.str.3 = [16 x i8] c"send: [%04d]%s\0A\00"
@.str.4 = [16 x i8] c"recv: [%04d]%s\0A\00"
@str = [12 x i8] c"send error \00"
@str.5 = [20 x i8] c"create socket error\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [128 x i8]
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = bitcast i32* %1 to i8*
store i32 1, i32* %1
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%7 = bitcast %struct.sockaddr_in* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_DGRAM
%11 = tail call i32 @socket(i32 %9, i32 %10, i32 0)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %0
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.5, i64 0, i64 0))
br label %45
15: ; preds = %0
%16 = load i32, i32* @SOL_SOCKET
%17 = load i32, i32* @SO_BROADCAST
%18 = call i32 @setsockopt(i32 %11, i32 %16, i32 %17, i32* %1, i32 4)
%19 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%20 = load i32, i32* @AF_INET
%21 = call i32 @inet_pton(i32 %20, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%22 = load i32, i32* @AF_INET
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %22, i32* %23
%24 = call i32 @htons(i32 30033)
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %24, i32* %25
%26 = load i32, i32* %4
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
store i32 %26, i32* %27
%28 = call i32 @strlen(i8* %6)
%29 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%30 = call i32 @sendto(i32 %11, i8* %6, i32 %28, i32 0, %struct.sockaddr* %29, i32 4)
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %15
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
br label %37
34: ; preds = %15
%35 = call i32 @strlen(i8* %6)
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %35, i8* %6)
br label %37
37: ; preds = %34, %32
%38 = call i32 @recvfrom(i32 %11, i8* %6, i32 128, i32 0, i32* null, i32* null)
%39 = icmp slt i32 %38, 0
br i1 %39, label %43, label %40
40: ; preds = %37
%41 = call i32 @strlen(i8* %6)
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %41, i8* %6)
br label %43
43: ; preds = %37, %40
%44 = call i32 @close(i32 %11)
br label %45
45: ; preds = %43, %13
%46 = phi i32 [ -1, %13 ], [ 0, %43 ]
ret i32 %46
}