#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 */
unsigned short endianSwap(unsigned char, unsigned char);
int /*<<< orphan*/ sprintf(char *, char *, unsigned int);
char *size(char string[], unsigned char buffer[], int offset) {
  unsigned int size;
  unsigned short first = endianSwap(buffer[offset + 2], buffer[offset + 3]);
  unsigned short second = endianSwap(buffer[offset], buffer[offset + 1]);
  size = first << 16;
  size = size | second;
  sprintf(string, "%d Bytes.", size);
  return string;
}


x86 assembly (clang, -O0):
<size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x3,%ecx
movslq %ecx,%rcx
movzbl %dl,%edi
movzbl (%rax,%rcx,1),%esi
call   1030 <endianSwap@plt>
mov    %ax,-0x1a(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movzbl %dl,%edi
movzbl (%rax,%rcx,1),%esi
call   1030 <endianSwap@plt>
mov    %ax,-0x1c(%rbp)
movzwl -0x1a(%rbp),%eax
shl    $0x10,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
movzwl -0x1c(%rbp),%ecx
or     %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%edx
lea    0xe54(%rip),%rsi
call   1040 <sprintf@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<size>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
movslq %edx,%rbp
movzbl 0x2(%rsi,%rbp,1),%edi
movzbl 0x3(%rsi,%rbp,1),%esi
call   1030 <endianSwap@plt>
mov    %eax,%r15d
movzbl (%rbx,%rbp,1),%edi
movzbl 0x1(%rbx,%rbp,1),%esi
call   1030 <endianSwap@plt>
shl    $0x10,%r15d
movzwl %ax,%edx
or     %r15d,%edx
lea    0xe9f(%rip),%rsi
mov    %r14,%rdi
call   1040 <sprintf@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"%d Bytes.\00"
define i8* @size(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i16
%9 = alloca i16
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%10 = load i8*, i8** %5
%11 = load i32, i32* %6
%12 = add nsw i32 %11, 2
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %10, i64 %13
%15 = load i8, i8* %14
%16 = load i8*, i8** %5
%17 = load i32, i32* %6
%18 = add nsw i32 %17, 3
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %16, i64 %19
%21 = load i8, i8* %20
%22 = call zeroext i16 @endianSwap(i8 zeroext %15, i8 zeroext %21)
store i16 %22, i16* %8
%23 = load i8*, i8** %5
%24 = load i32, i32* %6
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = load i8, i8* %26
%28 = load i8*, i8** %5
%29 = load i32, i32* %6
%30 = add nsw i32 %29, 1
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %28, i64 %31
%33 = load i8, i8* %32
%34 = call zeroext i16 @endianSwap(i8 zeroext %27, i8 zeroext %33)
store i16 %34, i16* %9
%35 = load i16, i16* %8
%36 = zext i16 %35 to i32
%37 = shl i32 %36, 16
store i32 %37, i32* %7
%38 = load i32, i32* %7
%39 = load i16, i16* %9
%40 = zext i16 %39 to i32
%41 = or i32 %38, %40
store i32 %41, i32* %7
%42 = load i8*, i8** %4
%43 = load i32, i32* %7
%44 = call i32 @sprintf(i8* %42, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %43)
%45 = load i8*, i8** %4
ret i8* %45
}

LLVM IR (-O2):
@.str = [10 x i8] c"%d Bytes.\00"
define i8* @size(i8* returned writeonly %0, i8* nocapture %1, i32 %2) {
%4 = add nsw i32 %2, 2
%5 = sext i32 %4 to i64
%6 = getelementptr inbounds i8, i8* %1, i64 %5
%7 = load i8, i8* %6
%8 = add nsw i32 %2, 3
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %1, i64 %9
%11 = load i8, i8* %10
%12 = tail call zeroext i16 @endianSwap(i8 zeroext %7, i8 zeroext %11)
%13 = sext i32 %2 to i64
%14 = getelementptr inbounds i8, i8* %1, i64 %13
%15 = load i8, i8* %14
%16 = add nsw i32 %2, 1
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %1, i64 %17
%19 = load i8, i8* %18
%20 = tail call zeroext i16 @endianSwap(i8 zeroext %15, i8 zeroext %19)
%21 = zext i16 %12 to i32
%22 = shl nuw i32 %21, 16
%23 = zext i16 %20 to i32
%24 = or i32 %22, %23
%25 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %24)
ret i8* %0
}