#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 dummy;
};

/* Variables and functions */
int /*<<< orphan*/ getBroadcastAddress();
int /*<<< orphan*/ getBroadcastSocket();
int sendto(int /*<<< orphan*/, char **, size_t, int /*<<< orphan*/,
           int /*<<< orphan*/, int);
int strlen(char const *);
int multiCastRequest(unsigned char type, const char *path, const char *data,
                     size_t length) {
  size_t path_len = strlen(path) + 1;
  if (data == NULL)
    length = 0;
  size_t buffer_len = 1 + path_len + length;
  if (path_len + length > 65536)
    return -1;
  char buffer[65536];
  buffer[0] = type;
  size_t i;
  for (i = 0; i < path_len; i++)
    buffer[i + 1] = path[i];
  for (i = 0; i < length; i++)
    buffer[path_len + i] = data[i];
  return sendto(getBroadcastSocket(), &buffer, buffer_len, 0,
                getBroadcastAddress(), sizeof(struct sockaddr_in));
}


x86 assembly (clang, -O0):
<multiCastRequest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10050,%rsp
mov    %dil,%al
mov    %al,-0x5(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
cltq
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1182 <multiCastRequest+0x42>
movq   $0x0,-0x20(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
add    -0x20(%rbp),%rax
cmp    $0x10000,%rax
jbe    11b2 <multiCastRequest+0x72>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b1 <multiCastRequest+0x171>
mov    -0x5(%rbp),%al
mov    %al,-0x10030(%rbp)
movq   $0x0,-0x10038(%rbp)
mov    -0x10038(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    120a <multiCastRequest+0xca>
mov    -0x10(%rbp),%rax
mov    -0x10038(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
mov    -0x10038(%rbp),%rax
mov    %cl,-0x1002f(%rbp,%rax,1)
mov    -0x10038(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10038(%rbp)
jmp    11c6 <multiCastRequest+0x86>
movq   $0x0,-0x10038(%rbp)
mov    -0x10038(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    125d <multiCastRequest+0x11d>
mov    -0x18(%rbp),%rax
mov    -0x10038(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
mov    -0x28(%rbp),%rax
add    -0x10038(%rbp),%rax
mov    %cl,-0x10030(%rbp,%rax,1)
mov    -0x10038(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10038(%rbp)
jmp    1215 <multiCastRequest+0xd5>
mov    $0x0,%al
call   1060 <getBroadcastSocket@plt>
mov    %eax,-0x1004c(%rbp)
lea    -0x10030(%rbp),%rax
mov    %rax,-0x10048(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x10040(%rbp)
mov    $0x0,%al
call   1030 <getBroadcastAddress@plt>
mov    -0x1004c(%rbp),%edi
mov    -0x10048(%rbp),%rsi
mov    -0x10040(%rbp),%rdx
mov    %eax,%r8d
xor    %ecx,%ecx
mov    $0x4,%r9d
call   1050 <sendto@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10050,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<multiCastRequest>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10008,%rsp
mov    %rcx,%rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %edi,%r12d
mov    %rsi,%rdi
call   1040 <strlen@plt>
test   %r14,%r14
cmove  %r14,%rbx
movslq %eax,%rbp
lea    (%rbx,%rbp,1),%rcx
add    $0x1,%rcx
mov    $0xffffffff,%eax
cmp    $0x10000,%rcx
ja     1200 <multiCastRequest+0xb0>
lea    0x1(%rbp),%r13
mov    %r12b,(%rsp)
test   %r13d,%r13d
je     11bc <multiCastRequest+0x6c>
lea    0x1(%rsp),%rdi
cmp    $0x2,%r13
mov    $0x1,%edx
cmovae %r13,%rdx
mov    %r15,%rsi
call   1060 <memcpy@plt>
lea    (%rbx,%rbp,1),%r15
add    $0x2,%r15
test   %rbx,%rbx
je     11d8 <multiCastRequest+0x88>
lea    (%rsp,%r13,1),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1060 <memcpy@plt>
xor    %eax,%eax
call   1070 <getBroadcastSocket@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1030 <getBroadcastAddress@plt>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    %r15,%rdx
xor    %ecx,%ecx
mov    %eax,%r8d
mov    $0x4,%r9d
call   1050 <sendto@plt>
add    $0x10008,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @multiCastRequest(i8 zeroext %0, i8* %1, i8* %2, i64 %3) {
%5 = alloca i32
%6 = alloca i8
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca [65536 x i8]
%13 = alloca i64
store i8 %0, i8* %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i64 %3, i64* %9
%14 = load i8*, i8** %7
%15 = call i32 @strlen(i8* %14)
%16 = add nsw i32 %15, 1
%17 = sext i32 %16 to i64
store i64 %17, i64* %10
%18 = load i8*, i8** %8
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %21
20: ; preds = %4
store i64 0, i64* %9
br label %21
21: ; preds = %20, %4
%22 = load i64, i64* %10
%23 = add i64 1, %22
%24 = load i64, i64* %9
%25 = add i64 %23, %24
store i64 %25, i64* %11
%26 = load i64, i64* %10
%27 = load i64, i64* %9
%28 = add i64 %26, %27
%29 = icmp ugt i64 %28, 65536
br i1 %29, label %30, label %31
30: ; preds = %21
store i32 -1, i32* %5
br label %72
31: ; preds = %21
%32 = load i8, i8* %6
%33 = getelementptr inbounds [65536 x i8], [65536 x i8]* %12, i64 0, i64 0
store i8 %32, i8* %33
store i64 0, i64* %13
br label %34
34: ; preds = %46, %31
%35 = load i64, i64* %13
%36 = load i64, i64* %10
%37 = icmp ult i64 %35, %36
br i1 %37, label %38, label %49
38: ; preds = %34
%39 = load i8*, i8** %7
%40 = load i64, i64* %13
%41 = getelementptr inbounds i8, i8* %39, i64 %40
%42 = load i8, i8* %41
%43 = load i64, i64* %13
%44 = add i64 %43, 1
%45 = getelementptr inbounds [65536 x i8], [65536 x i8]* %12, i64 0, i64 %44
store i8 %42, i8* %45
br label %46
46: ; preds = %38
%47 = load i64, i64* %13
%48 = add i64 %47, 1
store i64 %48, i64* %13
br label %34
49: ; preds = %34
store i64 0, i64* %13
br label %50
50: ; preds = %63, %49
%51 = load i64, i64* %13
%52 = load i64, i64* %9
%53 = icmp ult i64 %51, %52
br i1 %53, label %54, label %66
54: ; preds = %50
%55 = load i8*, i8** %8
%56 = load i64, i64* %13
%57 = getelementptr inbounds i8, i8* %55, i64 %56
%58 = load i8, i8* %57
%59 = load i64, i64* %10
%60 = load i64, i64* %13
%61 = add i64 %59, %60
%62 = getelementptr inbounds [65536 x i8], [65536 x i8]* %12, i64 0, i64 %61
store i8 %58, i8* %62
br label %63
63: ; preds = %54
%64 = load i64, i64* %13
%65 = add i64 %64, 1
store i64 %65, i64* %13
br label %50
66: ; preds = %50
%67 = call i32 (...) @getBroadcastSocket()
%68 = bitcast [65536 x i8]* %12 to i8**
%69 = load i64, i64* %11
%70 = call i32 (...) @getBroadcastAddress()
%71 = call i32 @sendto(i32 %67, i8** %68, i64 %69, i32 0, i32 %70, i32 4)
store i32 %71, i32* %5
br label %72
72: ; preds = %66, %30
%73 = load i32, i32* %5
ret i32 %73
}

LLVM IR (-O2):
define i32 @multiCastRequest(i8 zeroext %0, i8* %1, i8* %2, i64 %3) {
%5 = alloca [65536 x i8]
%6 = tail call i32 @strlen(i8* %1)
%7 = add nsw i32 %6, 1
%8 = sext i32 %7 to i64
%9 = icmp eq i8* %2, null
%10 = select i1 %9, i64 0, i64 %3
%11 = add i64 %10, %8
%12 = add i64 %11, 1
%13 = icmp ugt i64 %11, 65536
br i1 %13, label %29, label %14
14: ; preds = %4
%15 = getelementptr inbounds [65536 x i8], [65536 x i8]* %5, i64 0, i64 0
store i8 %0, i8* %15
%16 = icmp eq i32 %7, 0
br i1 %16, label %20, label %17
17: ; preds = %14
%18 = getelementptr inbounds [65536 x i8], [65536 x i8]* %5, i64 0, i64 1
%19 = call i64 @llvm.umax.i64(i64 %8, i64 1)
br label %20
20: ; preds = %17, %14
%21 = icmp eq i64 %10, 0
br i1 %21, label %24, label %22
22: ; preds = %20
%23 = getelementptr [65536 x i8], [65536 x i8]* %5, i64 0, i64 %8
br label %24
24: ; preds = %22, %20
%25 = tail call i32 (...) @getBroadcastSocket()
%26 = bitcast [65536 x i8]* %5 to i8**
%27 = tail call i32 (...) @getBroadcastAddress()
%28 = call i32 @sendto(i32 %25, i8** %26, i64 %12, i32 0, i32 %27, i32 4)
br label %29
29: ; preds = %4, %24
%30 = phi i32 [ %28, %24 ], [ -1, %4 ]
ret i32 %30
}