#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*/ memcpy(unsigned char *, unsigned char *, int);
int SshEncodeBuffer(unsigned char *pEncoding, int bufferLen,
                    unsigned char *pBuffer) {
  int adjustedLen = bufferLen, index;
  if (*pBuffer & 0x80) {
    adjustedLen++;
    pEncoding[4] = 0;
    index = 5;
  } else {
    index = 4;
  }
  pEncoding[0] = (unsigned char)(adjustedLen >> 24);
  pEncoding[1] = (unsigned char)(adjustedLen >> 16);
  pEncoding[2] = (unsigned char)(adjustedLen >> 8);
  pEncoding[3] = (unsigned char)(adjustedLen);
  memcpy(&pEncoding[index], pBuffer, bufferLen);
  return index + bufferLen;
}


x86 assembly (clang, -O0):
<SshEncodeBuffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
movzbl (%rax),%eax
and    $0x80,%eax
cmp    $0x0,%eax
je     115b <SshEncodeBuffer+0x4b>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
movb   $0x0,0x4(%rax)
movl   $0x5,-0x20(%rbp)
jmp    1162 <SshEncodeBuffer+0x52>
movl   $0x4,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
sar    $0x18,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
mov    -0x1c(%rbp),%eax
sar    $0x10,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x1c(%rbp),%eax
sar    $0x8,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x2(%rax)
mov    -0x1c(%rbp),%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x3(%rax)
mov    -0x8(%rbp),%rdi
movslq -0x20(%rbp),%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1030 <memcpy@plt>
mov    -0x20(%rbp),%eax
add    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SshEncodeBuffer>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebx
mov    $0x4,%ebp
cmpb   $0x0,(%rdx)
mov    %esi,%eax
jns    112d <SshEncodeBuffer+0x1d>
lea    0x1(%rbx),%eax
movb   $0x0,0x4(%rdi)
mov    $0x5,%ebp
bswap  %eax
mov    %eax,(%rdi)
mov    %ebp,%eax
add    %rdi,%rax
mov    %rax,%rdi
mov    %rdx,%rsi
mov    %ebx,%edx
call   1030 <memcpy@plt>
add    %ebx,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @SshEncodeBuffer(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%9 = load i32, i32* %5
store i32 %9, i32* %7
%10 = load i8*, i8** %6
%11 = load i8, i8* %10
%12 = zext i8 %11 to i32
%13 = and i32 %12, 128
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %3
%16 = load i32, i32* %7
%17 = add nsw i32 %16, 1
store i32 %17, i32* %7
%18 = load i8*, i8** %4
%19 = getelementptr inbounds i8, i8* %18, i64 4
store i8 0, i8* %19
store i32 5, i32* %8
br label %21
20: ; preds = %3
store i32 4, i32* %8
br label %21
21: ; preds = %20, %15
%22 = load i32, i32* %7
%23 = ashr i32 %22, 24
%24 = trunc i32 %23 to i8
%25 = load i8*, i8** %4
%26 = getelementptr inbounds i8, i8* %25, i64 0
store i8 %24, i8* %26
%27 = load i32, i32* %7
%28 = ashr i32 %27, 16
%29 = trunc i32 %28 to i8
%30 = load i8*, i8** %4
%31 = getelementptr inbounds i8, i8* %30, i64 1
store i8 %29, i8* %31
%32 = load i32, i32* %7
%33 = ashr i32 %32, 8
%34 = trunc i32 %33 to i8
%35 = load i8*, i8** %4
%36 = getelementptr inbounds i8, i8* %35, i64 2
store i8 %34, i8* %36
%37 = load i32, i32* %7
%38 = trunc i32 %37 to i8
%39 = load i8*, i8** %4
%40 = getelementptr inbounds i8, i8* %39, i64 3
store i8 %38, i8* %40
%41 = load i8*, i8** %4
%42 = load i32, i32* %8
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %41, i64 %43
%45 = load i8*, i8** %6
%46 = load i32, i32* %5
%47 = call i32 @memcpy(i8* %44, i8* %45, i32 %46)
%48 = load i32, i32* %8
%49 = load i32, i32* %5
%50 = add nsw i32 %48, %49
ret i32 %50
}

LLVM IR (-O2):
define i32 @SshEncodeBuffer(i8* %0, i32 %1, i8* %2) {
%4 = load i8, i8* %2
%5 = icmp sgt i8 %4, -1
br i1 %5, label %9, label %6
6: ; preds = %3
%7 = add nsw i32 %1, 1
%8 = getelementptr inbounds i8, i8* %0, i64 4
store i8 0, i8* %8
br label %9
9: ; preds = %3, %6
%10 = phi i32 [ %7, %6 ], [ %1, %3 ]
%11 = phi i32 [ 5, %6 ], [ 4, %3 ]
%12 = lshr i32 %10, 24
%13 = trunc i32 %12 to i8
store i8 %13, i8* %0
%14 = lshr i32 %10, 16
%15 = trunc i32 %14 to i8
%16 = getelementptr inbounds i8, i8* %0, i64 1
store i8 %15, i8* %16
%17 = lshr i32 %10, 8
%18 = trunc i32 %17 to i8
%19 = getelementptr inbounds i8, i8* %0, i64 2
store i8 %18, i8* %19
%20 = trunc i32 %10 to i8
%21 = getelementptr inbounds i8, i8* %0, i64 3
store i8 %20, i8* %21
%22 = zext i32 %11 to i64
%23 = getelementptr inbounds i8, i8* %0, i64 %22
%24 = tail call i32 @memcpy(i8* %23, i8* %2, i32 %1)
%25 = add nsw i32 %11, %1
ret i32 %25
}