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

/* Variables and functions */
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, void const *, size_t);
int sshbuf_reserve(struct sshbuf *, size_t, int /*<<< orphan*/ **);
int sshbuf_put(struct sshbuf *buf, const void *v, size_t len) {
  u_char *p;
  int r;
  if ((r = sshbuf_reserve(buf, len, &p)) < 0)
    return r;
  if (len != 0)
    memcpy(p, v, len);
  return 0;
}


x86 assembly (clang, -O0):
<sshbuf_put>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
lea    -0x28(%rbp),%rdx
call   1030 <sshbuf_reserve@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
jge    115c <sshbuf_put+0x3c>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    117f <sshbuf_put+0x5f>
cmpq   $0x0,-0x20(%rbp)
je     1178 <sshbuf_put+0x58>
mov    -0x28(%rbp),%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>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
lea    0x8(%rsp),%rdx
mov    %r14,%rsi
call   1030 <sshbuf_reserve@plt>
test   %eax,%eax
js     1159 <sshbuf_put+0x39>
xor    %ebx,%ebx
test   %r14,%r14
je     115b <sshbuf_put+0x3b>
mov    0x8(%rsp),%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1040 <memcpy@plt>
jmp    115b <sshbuf_put+0x3b>
mov    %eax,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

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