#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 */
typedef scalar_t__ ssize_t;

/* Variables and functions */
unsigned int little2bigEndian(unsigned int);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, unsigned int);
scalar_t__ write(int, unsigned char *, int);
unsigned int write_to_server(int connfd, unsigned char *sendBuff,
                             unsigned int buf_len) {
  unsigned char buffer[4048];
  *((unsigned int *)buffer) = little2bigEndian(buf_len + sizeof(unsigned int));
  memcpy((buffer + 4), sendBuff, buf_len);
  ssize_t len = write(connfd, buffer, 4 + buf_len);
  return (int)len;
}


x86 assembly (clang, -O0):
<write_to_server>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1000,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x4,%rax
mov    %eax,%edi
call   1050 <little2bigEndian@plt>
mov    %eax,-0xff0(%rbp)
lea    -0xff0(%rbp),%rdi
add    $0x4,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x4(%rbp),%edi
lea    -0xff0(%rbp),%rsi
mov    -0x14(%rbp),%edx
add    $0x4,%edx
call   1030 <write@plt>
mov    %rax,-0xff8(%rbp)
mov    -0xff8(%rbp),%rax
add    $0x1000,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_to_server>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0xfd8,%rsp
mov    %edx,%ebx
mov    %rsi,%r14
mov    %edi,%r15d
lea    0x4(%rbx),%ebp
mov    %ebp,%edi
call   1050 <little2bigEndian@plt>
mov    %eax,(%rsp)
lea    0x4(%rsp),%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1040 <memcpy@plt>
mov    %rsp,%rsi
mov    %r15d,%edi
mov    %ebp,%edx
call   1030 <write@plt>
add    $0xfd8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @write_to_server(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [4048 x i8]
%8 = alloca i64
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = load i32, i32* %6
%10 = zext i32 %9 to i64
%11 = add i64 %10, 4
%12 = trunc i64 %11 to i32
%13 = call i32 @little2bigEndian(i32 %12)
%14 = getelementptr inbounds [4048 x i8], [4048 x i8]* %7, i64 0, i64 0
%15 = bitcast i8* %14 to i32*
store i32 %13, i32* %15
%16 = getelementptr inbounds [4048 x i8], [4048 x i8]* %7, i64 0, i64 0
%17 = getelementptr inbounds i8, i8* %16, i64 4
%18 = load i8*, i8** %5
%19 = load i32, i32* %6
%20 = call i32 @memcpy(i8* %17, i8* %18, i32 %19)
%21 = load i32, i32* %4
%22 = getelementptr inbounds [4048 x i8], [4048 x i8]* %7, i64 0, i64 0
%23 = load i32, i32* %6
%24 = add i32 4, %23
%25 = call i64 @write(i32 %21, i8* %22, i32 %24)
store i64 %25, i64* %8
%26 = load i64, i64* %8
%27 = trunc i64 %26 to i32
ret i32 %27
}

LLVM IR (-O2):
define i32 @write_to_server(i32 %0, i8* %1, i32 %2) {
%4 = alloca [4048 x i8]
%5 = getelementptr inbounds [4048 x i8], [4048 x i8]* %4, i64 0, i64 0
%6 = add i32 %2, 4
%7 = tail call i32 @little2bigEndian(i32 %6)
%8 = bitcast [4048 x i8]* %4 to i32*
store i32 %7, i32* %8
%9 = getelementptr inbounds [4048 x i8], [4048 x i8]* %4, i64 0, i64 4
%10 = call i32 @memcpy(i8* %9, i8* %1, i32 %2)
%11 = call i64 @write(i32 %0, i8* %5, i32 %6)
%12 = trunc i64 %11 to i32
ret i32 %12
}