#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(void *, int /*<<< orphan*/ const *, size_t);
int sshbuf_consume(struct sshbuf *, size_t);
int /*<<< orphan*/ *sshbuf_ptr(struct sshbuf *);
int sshbuf_get(struct sshbuf *buf, void *v, size_t len) {
  const u_char *p = sshbuf_ptr(buf);
  int r;
  if ((r = sshbuf_consume(buf, len)) < 0)
    return r;
  if (v != NULL && len != 0)
    memcpy(v, p, len);
  return 0;
}


x86 assembly (clang, -O0):
<sshbuf_get>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <sshbuf_ptr@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <sshbuf_consume@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
jge    1175 <sshbuf_get+0x45>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11a3 <sshbuf_get+0x73>
cmpq   $0x0,-0x18(%rbp)
je     119c <sshbuf_get+0x6c>
cmpq   $0x0,-0x20(%rbp)
je     119c <sshbuf_get+0x6c>
mov    -0x18(%rbp),%rdi
mov    -0x28(%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_get>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
call   1050 <sshbuf_ptr@plt>
mov    %rax,%r12
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <sshbuf_consume@plt>
test   %eax,%eax
js     1174 <sshbuf_get+0x44>
xor    %ebx,%ebx
test   %r15,%r15
je     1176 <sshbuf_get+0x46>
test   %r14,%r14
je     1176 <sshbuf_get+0x46>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
call   1040 <memcpy@plt>
jmp    1176 <sshbuf_get+0x46>
mov    %eax,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.sshbuf = type { i32 }
define i32 @sshbuf_get(%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 = call i32* @sshbuf_ptr(%struct.sshbuf* %10)
store i32* %11, i32** %8
%12 = load %struct.sshbuf*, %struct.sshbuf** %5
%13 = load i64, i64* %7
%14 = call i32 @sshbuf_consume(%struct.sshbuf* %12, i64 %13)
store i32 %14, i32* %9
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %3
%17 = load i32, i32* %9
store i32 %17, i32* %4
br label %30
18: ; preds = %3
%19 = load i8*, i8** %6
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %29
21: ; preds = %18
%22 = load i64, i64* %7
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %29
24: ; preds = %21
%25 = load i8*, i8** %6
%26 = load i32*, i32** %8
%27 = load i64, i64* %7
%28 = call i32 @memcpy(i8* %25, i32* %26, i64 %27)
br label %29
29: ; preds = %24, %21, %18
store i32 0, i32* %4
br label %30
30: ; preds = %29, %16
%31 = load i32, i32* %4
ret i32 %31
}

LLVM IR (-O2):
%struct.sshbuf = type { i32 }
define i32 @sshbuf_get(%struct.sshbuf* %0, i8* %1, i64 %2) {
%4 = tail call i32* @sshbuf_ptr(%struct.sshbuf* %0)
%5 = tail call i32 @sshbuf_consume(%struct.sshbuf* %0, i64 %2)
%6 = icmp slt i32 %5, 0
br i1 %6, label %13, label %7
7: ; preds = %3
%8 = icmp ne i8* %1, null
%9 = icmp ne i64 %2, 0
%10 = and i1 %8, %9
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = tail call i32 @memcpy(i8* %1, i32* %4, i64 %2)
br label %13
13: ; preds = %7, %11, %3
%14 = phi i32 [ %5, %3 ], [ 0, %11 ], [ 0, %7 ]
ret i32 %14
}