#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 size_t u_char;
struct sshbuf {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ memcpy(size_t *, void const *, size_t);
int sshbuf_reserve(struct sshbuf *, size_t, size_t **);
int sshbuf_put_string8(struct sshbuf *buf, const void *v, size_t len) {
  u_char *d;
  int r;
  if (len > 0xFF - 1) {
    ;
    return -9;
  }
  if ((r = sshbuf_reserve(buf, len + 1, &d)) < 0)
    return r;
  d[0] = len;
  if (len != 0)
    memcpy(d + 1, v, len);
  return 0;
}


x86 assembly (clang, -O0):
<sshbuf_put_string8>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0xfe,-0x20(%rbp)
jbe    114e <sshbuf_put_string8+0x2e>
movl   $0xfffffff7,-0x4(%rbp)
jmp    11ac <sshbuf_put_string8+0x8c>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
add    $0x1,%rsi
lea    -0x28(%rbp),%rdx
call   1030 <sshbuf_reserve@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
jge    117a <sshbuf_put_string8+0x5a>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ac <sshbuf_put_string8+0x8c>
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
cmpq   $0x0,-0x20(%rbp)
je     11a5 <sshbuf_put_string8+0x85>
mov    -0x28(%rbp),%rdi
add    $0x8,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <memcpy@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sshbuf_put_string8>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    $0xfffffff7,%ebp
cmp    $0xfe,%rdx
ja     1170 <sshbuf_put_string8+0x50>
mov    %rdx,%rbx
mov    %rsi,%r14
lea    0x1(%rdx),%rsi
lea    0x8(%rsp),%rdx
call   1030 <sshbuf_reserve@plt>
test   %eax,%eax
js     116e <sshbuf_put_string8+0x4e>
mov    0x8(%rsp),%rdi
mov    %rbx,(%rdi)
xor    %ebp,%ebp
test   %rbx,%rbx
je     1170 <sshbuf_put_string8+0x50>
add    $0x8,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1040 <memcpy@plt>
jmp    1170 <sshbuf_put_string8+0x50>
mov    %eax,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.sshbuf = type { i32 }
define i32 @sshbuf_put_string8(%struct.sshbuf* %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca %struct.sshbuf*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64*
%9 = alloca i32
store %struct.sshbuf* %0, %struct.sshbuf** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
%10 = load i64, i64* %7
%11 = icmp ugt i64 %10, 254
br i1 %11, label %12, label %13
12: ; preds = %3
store i32 -9, i32* %4
br label %34
13: ; preds = %3
%14 = load %struct.sshbuf*, %struct.sshbuf** %5
%15 = load i64, i64* %7
%16 = add i64 %15, 1
%17 = call i32 @sshbuf_reserve(%struct.sshbuf* %14, i64 %16, i64** %8)
store i32 %17, i32* %9
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %13
%20 = load i32, i32* %9
store i32 %20, i32* %4
br label %34
21: ; preds = %13
%22 = load i64, i64* %7
%23 = load i64*, i64** %8
%24 = getelementptr inbounds i64, i64* %23, i64 0
store i64 %22, i64* %24
%25 = load i64, i64* %7
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %33
27: ; preds = %21
%28 = load i64*, i64** %8
%29 = getelementptr inbounds i64, i64* %28, i64 1
%30 = load i8*, i8** %6
%31 = load i64, i64* %7
%32 = call i32 @memcpy(i64* %29, i8* %30, i64 %31)
br label %33
33: ; preds = %27, %21
store i32 0, i32* %4
br label %34
34: ; preds = %33, %19, %12
%35 = load i32, i32* %4
ret i32 %35
}

LLVM IR (-O2):
%struct.sshbuf = type { i32 }
define i32 @sshbuf_put_string8(%struct.sshbuf* %0, i8* %1, i64 %2) {
%4 = alloca i64*
%5 = bitcast i64** %4 to i8*
%6 = icmp ugt i64 %2, 254
br i1 %6, label %17, label %7
7: ; preds = %3
%8 = add nuw nsw i64 %2, 1
%9 = call i32 @sshbuf_reserve(%struct.sshbuf* %0, i64 %8, i64** %4)
%10 = icmp slt i32 %9, 0
br i1 %10, label %17, label %11
11: ; preds = %7
%12 = load i64*, i64** %4
store i64 %2, i64* %12
%13 = icmp eq i64 %2, 0
br i1 %13, label %17, label %14
14: ; preds = %11
%15 = getelementptr inbounds i64, i64* %12, i64 1
%16 = call i32 @memcpy(i64* %15, i8* %1, i64 %2)
br label %17
17: ; preds = %11, %14, %7, %3
%18 = phi i32 [ -9, %3 ], [ %9, %7 ], [ 0, %14 ], [ 0, %11 ]
ret i32 %18
}