#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*/ sa;
typedef int in_addr_t;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ close(int);
int htonl(int);
int /*<<< orphan*/ htons(int);
int ntohl(int);
int sendto(int, char const *, size_t const, int /*<<< orphan*/,
           struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ warn(char *);
void broadcast_msg(const char *msg, const size_t msgsize, in_addr_t ip_addr) {
  int s;
  struct sockaddr_in sa;
  long i;
  in_addr_t ip;
  if ((s = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
    warn("socket");
    return;
  }
  bzero(&sa, sizeof(sa));
  sa.sin_family = AF_INET;
  sa.sin_port = htons(1392);
  ;
  for (i = 1; i < 255; ++i) {
    ip = ntohl(ip_addr);
    ip = htonl((ip & 0xffffff00) | i);
    if (ip == ip_addr)
      continue;
    sa.sin_addr.s_addr = ip;
    if (sendto(s, msg, msgsize, 0, (struct sockaddr *)&sa, sizeof(sa)) == -1)
      warn("sendto");
  }
  close(s);
}


x86 assembly (clang, -O0):
<broadcast_msg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
mov    0x2e3d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    11c9 <broadcast_msg+0x49>
lea    0xe41(%rip),%rdi
call   1030 <warn@plt>
jmp    128f <broadcast_msg+0x10f>
lea    -0x28(%rbp),%rdi
mov    $0xc,%esi
call   1080 <bzero@plt>
mov    0x2e0a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    $0x570,%edi
call   1040 <htons@plt>
mov    %eax,-0x24(%rbp)
movq   $0x1,-0x30(%rbp)
cmpq   $0xff,-0x30(%rbp)
jge    1287 <broadcast_msg+0x107>
mov    -0x14(%rbp),%edi
call   1090 <ntohl@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
and    $0xffffff00,%eax
mov    %eax,%eax
or     -0x30(%rbp),%rax
mov    %eax,%edi
call   1050 <htonl@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    123a <broadcast_msg+0xba>
jmp    1276 <broadcast_msg+0xf6>
mov    -0x34(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    -0x28(%rbp),%r8
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1060 <sendto@plt>
cmp    $0xffffffff,%eax
jne    1271 <broadcast_msg+0xf1>
lea    0xd9b(%rip),%rdi
call   1030 <warn@plt>
jmp    1276 <broadcast_msg+0xf6>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    11f8 <broadcast_msg+0x78>
mov    -0x18(%rbp),%edi
call   1070 <close@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<broadcast_msg>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%ebx
mov    %rsi,%r14
mov    %rdi,%r15
mov    0x2e4b(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2e39(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
cmp    $0xffffffff,%eax
je     1261 <broadcast_msg+0xe1>
mov    %eax,%r13d
lea    0x8(%rsp),%rdi
mov    $0xc,%esi
call   1080 <bzero@plt>
mov    0x0(%rbp),%eax
mov    %eax,0x10(%rsp)
mov    $0x570,%edi
call   1040 <htons@plt>
mov    %eax,0xc(%rsp)
mov    %ebx,%edi
call   1090 <ntohl@plt>
mov    %eax,%ebp
and    $0xffffff00,%ebp
mov    $0xffffffffffffff02,%r12
jmp    1205 <broadcast_msg+0x85>
nopl   0x0(%rax,%rax,1)
inc    %r12
je     124a <broadcast_msg+0xca>
lea    0xff(%r12),%edi
or     %ebp,%edi
call   1050 <htonl@plt>
cmp    %ebx,%eax
je     1200 <broadcast_msg+0x80>
mov    %eax,0x8(%rsp)
mov    %r13d,%edi
mov    %r15,%rsi
mov    %r14,%rdx
xor    %ecx,%ecx
lea    0x8(%rsp),%r8
mov    $0xc,%r9d
call   1060 <sendto@plt>
cmp    $0xffffffff,%eax
jne    1200 <broadcast_msg+0x80>
lea    0xdc4(%rip),%rdi
call   1030 <warn@plt>
jmp    1200 <broadcast_msg+0x80>
mov    %r13d,%edi
call   1070 <close@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd98(%rip),%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <warn@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [7 x i8] c"socket\00"
@.str.1 = [7 x i8] c"sendto\00"
define void @broadcast_msg(i8* %0, i64 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.sockaddr_in
%9 = alloca i64
%10 = alloca i32
store i8* %0, i8** %4
store i64 %1, i64* %5
store i32 %2, i32* %6
%11 = load i32, i32* @AF_INET
%12 = load i32, i32* @SOCK_DGRAM
%13 = call i32 @socket(i32 %11, i32 %12, i32 0)
store i32 %13, i32* %7
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %17
15: ; preds = %3
%16 = call i32 @warn(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %59
17: ; preds = %3
%18 = call i32 @bzero(%struct.sockaddr_in* %8, i32 12)
%19 = load i32, i32* @AF_INET
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %19, i32* %20
%21 = call i32 @htons(i32 1392)
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
store i32 %21, i32* %22
store i64 1, i64* %9
br label %23
23: ; preds = %53, %17
%24 = load i64, i64* %9
%25 = icmp slt i64 %24, 255
br i1 %25, label %26, label %56
26: ; preds = %23
%27 = load i32, i32* %6
%28 = call i32 @ntohl(i32 %27)
store i32 %28, i32* %10
%29 = load i32, i32* %10
%30 = and i32 %29, -256
%31 = zext i32 %30 to i64
%32 = load i64, i64* %9
%33 = or i64 %31, %32
%34 = trunc i64 %33 to i32
%35 = call i32 @htonl(i32 %34)
store i32 %35, i32* %10
%36 = load i32, i32* %10
%37 = load i32, i32* %6
%38 = icmp eq i32 %36, %37
br i1 %38, label %39, label %40
39: ; preds = %26
br label %53
40: ; preds = %26
%41 = load i32, i32* %10
%42 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
%43 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %42, i32 0, i32 0
store i32 %41, i32* %43
%44 = load i32, i32* %7
%45 = load i8*, i8** %4
%46 = load i64, i64* %5
%47 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%48 = call i32 @sendto(i32 %44, i8* %45, i64 %46, i32 0, %struct.sockaddr* %47, i32 12)
%49 = icmp eq i32 %48, -1
br i1 %49, label %50, label %52
50: ; preds = %40
%51 = call i32 @warn(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %52
52: ; preds = %50, %40
br label %53
53: ; preds = %52, %39
%54 = load i64, i64* %9
%55 = add nsw i64 %54, 1
store i64 %55, i64* %9
br label %23
56: ; preds = %23
%57 = load i32, i32* %7
%58 = call i32 @close(i32 %57)
br label %59
59: ; preds = %56, %15
ret void
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [7 x i8] c"socket\00"
@.str.1 = [7 x i8] c"sendto\00"
define void @broadcast_msg(i8* %0, i64 %1, i32 %2) {
%4 = alloca %struct.sockaddr_in
%5 = bitcast %struct.sockaddr_in* %4 to i8*
%6 = load i32, i32* @AF_INET
%7 = load i32, i32* @SOCK_DGRAM
%8 = tail call i32 @socket(i32 %6, i32 %7, i32 0)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %12
10: ; preds = %3
%11 = tail call i32 @warn(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %38
12: ; preds = %3
%13 = call i32 @bzero(%struct.sockaddr_in* %4, i32 12)
%14 = load i32, i32* @AF_INET
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %14, i32* %15
%16 = tail call i32 @htons(i32 1392)
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
store i32 %16, i32* %17
%18 = call i32 @ntohl(i32 %2)
%19 = and i32 %18, -256
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0, i32 0
%21 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
br label %22
22: ; preds = %12, %33
%23 = phi i64 [ 1, %12 ], [ %34, %33 ]
%24 = trunc i64 %23 to i32
%25 = or i32 %19, %24
%26 = call i32 @htonl(i32 %25)
%27 = icmp eq i32 %26, %2
br i1 %27, label %33, label %28
28: ; preds = %22
store i32 %26, i32* %20
%29 = call i32 @sendto(i32 %8, i8* %0, i64 %1, i32 0, %struct.sockaddr* %21, i32 12)
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %33
31: ; preds = %28
%32 = call i32 @warn(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %33
33: ; preds = %28, %31, %22
%34 = add nuw nsw i64 %23, 1
%35 = icmp eq i64 %34, 255
br i1 %35, label %36, label %22
36: ; preds = %33
%37 = call i32 @close(i32 %8)
br label %38
38: ; preds = %36, %10
ret void
}