#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 */

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ memcpy(char *, ...);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *);
int send(int, char *, int, int /*<<< orphan*/);
int sendMessage(int socketfd, char *strSourceIP, char *strDestIP,
                int dwCommTYPE, int dwTransLength, char *rgbBuffer) {
  int dwSendbytes, dwData_type, dwData_length;
  char str_send_buf[65536];
  dwData_length = dwTransLength + 40;
  memset(str_send_buf, 0, 65536);
  memcpy(str_send_buf, strSourceIP, 16);
  memcpy(str_send_buf + 16, strDestIP, 16);
  memcpy(str_send_buf + 32, &dwCommTYPE, 4);
  memcpy(str_send_buf + 36, &dwData_length, 4);
  if ((dwTransLength != 0) && (rgbBuffer != NULL)) {
    memcpy(str_send_buf + 40, rgbBuffer, dwTransLength);
  }
  if ((dwSendbytes = send(socketfd, str_send_buf, dwData_length, 0)) == -1) {
    printf("Send error!\n");
    exit(1);
  }
  if (dwSendbytes == dwData_length) {
    return 0;
  } else {
    return -1;
  }
}


x86 assembly (clang, -O0):
<sendMessage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10040,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
mov    -0x20(%rbp),%eax
add    $0x28,%eax
mov    %eax,-0x34(%rbp)
lea    -0x10040(%rbp),%rdi
xor    %esi,%esi
mov    $0x10000,%edx
call   1050 <memset@plt>
lea    -0x10040(%rbp),%rdi
mov    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    $0x10,%edx
call   1060 <memcpy@plt>
lea    -0x10040(%rbp),%rdi
add    $0x10,%rdi
mov    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    $0x10,%edx
call   1060 <memcpy@plt>
lea    -0x10040(%rbp),%rdi
add    $0x20,%rdi
xor    %eax,%eax
lea    -0x1c(%rbp),%rsi
mov    $0x4,%edx
call   1060 <memcpy@plt>
lea    -0x10040(%rbp),%rdi
add    $0x24,%rdi
xor    %eax,%eax
lea    -0x34(%rbp),%rsi
mov    $0x4,%edx
call   1060 <memcpy@plt>
cmpl   $0x0,-0x20(%rbp)
je     1223 <sendMessage+0xd3>
cmpq   $0x0,-0x28(%rbp)
je     1223 <sendMessage+0xd3>
lea    -0x10040(%rbp),%rdi
add    $0x28,%rdi
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%edx
xor    %eax,%eax
call   1060 <memcpy@plt>
mov    -0x8(%rbp),%edi
lea    -0x10040(%rbp),%rsi
mov    -0x34(%rbp),%edx
xor    %ecx,%ecx
call   1030 <send@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0xffffffff,%eax
jne    1259 <sendMessage+0x109>
lea    0xdb6(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x2c(%rbp),%eax
cmp    -0x34(%rbp),%eax
jne    1271 <sendMessage+0x121>
movl   $0x0,-0x4(%rbp)
jmp    1278 <sendMessage+0x128>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sendMessage>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10018,%rsp
mov    %r9,%r15
mov    %r8d,%r12d
mov    %rdx,%r13
mov    %rsi,%rbp
mov    %edi,%r14d
mov    %ecx,0xc(%rsp)
lea    0x28(%r12),%eax
mov    %eax,0x8(%rsp)
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x10000,%edx
call   1050 <memset@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    $0x10,%edx
xor    %eax,%eax
call   1060 <memcpy@plt>
lea    0x20(%rsp),%rdi
mov    %r13,%rsi
mov    $0x10,%edx
xor    %eax,%eax
call   1060 <memcpy@plt>
lea    0x30(%rsp),%rdi
lea    0xc(%rsp),%rsi
mov    $0x4,%edx
xor    %eax,%eax
call   1060 <memcpy@plt>
lea    0x34(%rsp),%rdi
lea    0x8(%rsp),%rsi
mov    $0x4,%edx
xor    %eax,%eax
call   1060 <memcpy@plt>
test   %r12d,%r12d
je     11ff <sendMessage+0xaf>
test   %r15,%r15
je     11ff <sendMessage+0xaf>
lea    0x38(%rsp),%rdi
mov    %r15,%rsi
mov    %r12d,%edx
xor    %eax,%eax
call   1060 <memcpy@plt>
mov    0x8(%rsp),%edx
lea    0x10(%rsp),%rsi
mov    %r14d,%edi
xor    %ecx,%ecx
call   1040 <send@plt>
cmp    $0xffffffff,%eax
je     1236 <sendMessage+0xe6>
xor    %ecx,%ecx
cmp    0x8(%rsp),%eax
setne  %cl
neg    %ecx
mov    %ecx,%eax
add    $0x10018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdc3(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"Send error!\0A\00"
define i32 @sendMessage(i32 %0, i8* %1, i8* %2, i32 %3, i32 %4, i8* %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca [65536 x i8]
store i32 %0, i32* %8
store i8* %1, i8** %9
store i8* %2, i8** %10
store i32 %3, i32* %11
store i32 %4, i32* %12
store i8* %5, i8** %13
%18 = load i32, i32* %12
%19 = add nsw i32 %18, 40
store i32 %19, i32* %16
%20 = getelementptr inbounds [65536 x i8], [65536 x i8]* %17, i64 0, i64 0
%21 = call i32 @memset(i8* %20, i32 0, i32 65536)
%22 = getelementptr inbounds [65536 x i8], [65536 x i8]* %17, i64 0, i64 0
%23 = load i8*, i8** %9
%24 = call i32 (i8*, ...) @memcpy(i8* %22, i8* %23, i32 16)
%25 = getelementptr inbounds [65536 x i8], [65536 x i8]* %17, i64 0, i64 0
%26 = getelementptr inbounds i8, i8* %25, i64 16
%27 = load i8*, i8** %10
%28 = call i32 (i8*, ...) @memcpy(i8* %26, i8* %27, i32 16)
%29 = getelementptr inbounds [65536 x i8], [65536 x i8]* %17, i64 0, i64 0
%30 = getelementptr inbounds i8, i8* %29, i64 32
%31 = call i32 (i8*, ...) @memcpy(i8* %30, i32* %11, i32 4)
%32 = getelementptr inbounds [65536 x i8], [65536 x i8]* %17, i64 0, i64 0
%33 = getelementptr inbounds i8, i8* %32, i64 36
%34 = call i32 (i8*, ...) @memcpy(i8* %33, i32* %16, i32 4)
%35 = load i32, i32* %12
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %46
37: ; preds = %6
%38 = load i8*, i8** %13
%39 = icmp ne i8* %38, null
br i1 %39, label %40, label %46
40: ; preds = %37
%41 = getelementptr inbounds [65536 x i8], [65536 x i8]* %17, i64 0, i64 0
%42 = getelementptr inbounds i8, i8* %41, i64 40
%43 = load i8*, i8** %13
%44 = load i32, i32* %12
%45 = call i32 (i8*, ...) @memcpy(i8* %42, i8* %43, i32 %44)
br label %46
46: ; preds = %40, %37, %6
%47 = load i32, i32* %8
%48 = getelementptr inbounds [65536 x i8], [65536 x i8]* %17, i64 0, i64 0
%49 = load i32, i32* %16
%50 = call i32 @send(i32 %47, i8* %48, i32 %49, i32 0)
store i32 %50, i32* %14
%51 = icmp eq i32 %50, -1
br i1 %51, label %52, label %55
52: ; preds = %46
%53 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%54 = call i32 @exit(i32 1)
unreachable
55: ; preds = %46
%56 = load i32, i32* %14
%57 = load i32, i32* %16
%58 = icmp eq i32 %56, %57
br i1 %58, label %59, label %60
59: ; preds = %55
store i32 0, i32* %7
br label %61
60: ; preds = %55
store i32 -1, i32* %7
br label %61
61: ; preds = %60, %59
%62 = load i32, i32* %7
ret i32 %62
}

LLVM IR (-O2):
@str = [12 x i8] c"Send error!\00"
define i32 @sendMessage(i32 %0, i8* %1, i8* %2, i32 %3, i32 %4, i8* %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca [65536 x i8]
store i32 %3, i32* %7
%10 = bitcast i32* %8 to i8*
%11 = getelementptr inbounds [65536 x i8], [65536 x i8]* %9, i64 0, i64 0
%12 = add nsw i32 %4, 40
store i32 %12, i32* %8
%13 = call i32 @memset(i8* %11, i32 0, i32 65536)
%14 = call i32 (i8*, ...) @memcpy(i8* %11, i8* %1, i32 16)
%15 = getelementptr inbounds [65536 x i8], [65536 x i8]* %9, i64 0, i64 16
%16 = call i32 (i8*, ...) @memcpy(i8* %15, i8* %2, i32 16)
%17 = getelementptr inbounds [65536 x i8], [65536 x i8]* %9, i64 0, i64 32
%18 = call i32 (i8*, ...) @memcpy(i8* %17, i32* %7, i32 4)
%19 = getelementptr inbounds [65536 x i8], [65536 x i8]* %9, i64 0, i64 36
%20 = call i32 (i8*, ...) @memcpy(i8* %19, i32* %8, i32 4)
%21 = icmp ne i32 %4, 0
%22 = icmp ne i8* %5, null
%23 = and i1 %21, %22
br i1 %23, label %24, label %27
24: ; preds = %6
%25 = getelementptr inbounds [65536 x i8], [65536 x i8]* %9, i64 0, i64 40
%26 = call i32 (i8*, ...) @memcpy(i8* %25, i8* %5, i32 %4)
br label %27
27: ; preds = %24, %6
%28 = load i32, i32* %8
%29 = call i32 @send(i32 %0, i8* %11, i32 %28, i32 0)
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %34
31: ; preds = %27
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %27
%35 = load i32, i32* %8
%36 = icmp ne i32 %29, %35
%37 = sext i1 %36 to i32
ret i32 %37
}