#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 sshbuf_consume(struct sshbuf *, size_t);
int /*<<< orphan*/ sshbuf_free(struct sshbuf *);
struct sshbuf *sshbuf_from(int /*<<< orphan*/ const *, size_t);
int sshbuf_peek_string_direct(struct sshbuf *, int /*<<< orphan*/ const **,
                              size_t *);
int sshbuf_set_parent(struct sshbuf *, struct sshbuf *);
int sshbuf_froms(struct sshbuf *buf, struct sshbuf **bufp) {
  const u_char *p;
  size_t len;
  struct sshbuf *ret;
  int r;
  if (buf == NULL || bufp == NULL)
    return -10;
  *bufp = NULL;
  if ((r = sshbuf_peek_string_direct(buf, &p, &len)) != 0)
    return r;
  if ((ret = sshbuf_from(p, len)) == NULL)
    return -2;
  if ((r = sshbuf_consume(buf, len + 4)) != 0 ||
      (r = sshbuf_set_parent(ret, buf)) != 0) {
    sshbuf_free(ret);
    return r;
  }
  *bufp = ret;
  return 0;
}


x86 assembly (clang, -O0):
<sshbuf_froms>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1176 <sshbuf_froms+0x26>
cmpq   $0x0,-0x18(%rbp)
jne    1182 <sshbuf_froms+0x32>
movl   $0xfffffff6,-0x4(%rbp)
jmp    1238 <sshbuf_froms+0xe8>
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
lea    -0x28(%rbp),%rdx
call   1040 <sshbuf_peek_string_direct@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
je     11b5 <sshbuf_froms+0x65>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1238 <sshbuf_froms+0xe8>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1050 <sshbuf_from@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    11dc <sshbuf_froms+0x8c>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1238 <sshbuf_froms+0xe8>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
add    $0x4,%rsi
call   1030 <sshbuf_consume@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
jne    1212 <sshbuf_froms+0xc2>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <sshbuf_set_parent@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
je     1226 <sshbuf_froms+0xd6>
mov    -0x30(%rbp),%rdi
call   1060 <sshbuf_free@plt>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1238 <sshbuf_froms+0xe8>
mov    -0x30(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sshbuf_froms>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    $0xfffffff6,%ebp
test   %rdi,%rdi
je     11e0 <sshbuf_froms+0x90>
mov    %rsi,%r14
test   %rsi,%rsi
je     11e0 <sshbuf_froms+0x90>
mov    %rdi,%rbx
movq   $0x0,(%r14)
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
call   1040 <sshbuf_peek_string_direct@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    11e0 <sshbuf_froms+0x90>
mov    0x10(%rsp),%rdi
mov    0x8(%rsp),%rsi
call   1050 <sshbuf_from@plt>
test   %rax,%rax
je     11d4 <sshbuf_froms+0x84>
mov    %rax,%r15
mov    0x8(%rsp),%rsi
add    $0x4,%rsi
mov    %rbx,%rdi
call   1030 <sshbuf_consume@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    11ca <sshbuf_froms+0x7a>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1070 <sshbuf_set_parent@plt>
mov    %eax,%ebp
test   %eax,%eax
je     11db <sshbuf_froms+0x8b>
mov    %r15,%rdi
call   1060 <sshbuf_free@plt>
jmp    11e0 <sshbuf_froms+0x90>
mov    $0xfffffffe,%ebp
jmp    11e0 <sshbuf_froms+0x90>
mov    %r15,(%r14)
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sshbuf = type { i32 }
define i32 @sshbuf_froms(%struct.sshbuf* %0, %struct.sshbuf** %1) {
%3 = alloca i32
%4 = alloca %struct.sshbuf*
%5 = alloca %struct.sshbuf**
%6 = alloca i32*
%7 = alloca i64
%8 = alloca %struct.sshbuf*
%9 = alloca i32
store %struct.sshbuf* %0, %struct.sshbuf** %4
store %struct.sshbuf** %1, %struct.sshbuf*** %5
%10 = load %struct.sshbuf*, %struct.sshbuf** %4
%11 = icmp eq %struct.sshbuf* %10, null
br i1 %11, label %15, label %12
12: ; preds = %2
%13 = load %struct.sshbuf**, %struct.sshbuf*** %5
%14 = icmp eq %struct.sshbuf** %13, null
br i1 %14, label %15, label %16
15: ; preds = %12, %2
store i32 -10, i32* %3
br label %47
16: ; preds = %12
%17 = load %struct.sshbuf**, %struct.sshbuf*** %5
store %struct.sshbuf* null, %struct.sshbuf** %17
%18 = load %struct.sshbuf*, %struct.sshbuf** %4
%19 = call i32 @sshbuf_peek_string_direct(%struct.sshbuf* %18, i32** %6, i64* %7)
store i32 %19, i32* %9
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = load i32, i32* %9
store i32 %22, i32* %3
br label %47
23: ; preds = %16
%24 = load i32*, i32** %6
%25 = load i64, i64* %7
%26 = call %struct.sshbuf* @sshbuf_from(i32* %24, i64 %25)
store %struct.sshbuf* %26, %struct.sshbuf** %8
%27 = icmp eq %struct.sshbuf* %26, null
br i1 %27, label %28, label %29
28: ; preds = %23
store i32 -2, i32* %3
br label %47
29: ; preds = %23
%30 = load %struct.sshbuf*, %struct.sshbuf** %4
%31 = load i64, i64* %7
%32 = add i64 %31, 4
%33 = call i32 @sshbuf_consume(%struct.sshbuf* %30, i64 %32)
store i32 %33, i32* %9
%34 = icmp ne i32 %33, 0
br i1 %34, label %40, label %35
35: ; preds = %29
%36 = load %struct.sshbuf*, %struct.sshbuf** %8
%37 = load %struct.sshbuf*, %struct.sshbuf** %4
%38 = call i32 @sshbuf_set_parent(%struct.sshbuf* %36, %struct.sshbuf* %37)
store i32 %38, i32* %9
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %44
40: ; preds = %35, %29
%41 = load %struct.sshbuf*, %struct.sshbuf** %8
%42 = call i32 @sshbuf_free(%struct.sshbuf* %41)
%43 = load i32, i32* %9
store i32 %43, i32* %3
br label %47
44: ; preds = %35
%45 = load %struct.sshbuf*, %struct.sshbuf** %8
%46 = load %struct.sshbuf**, %struct.sshbuf*** %5
store %struct.sshbuf* %45, %struct.sshbuf** %46
store i32 0, i32* %3
br label %47
47: ; preds = %44, %40, %28, %21, %15
%48 = load i32, i32* %3
ret i32 %48
}

LLVM IR (-O2):
%struct.sshbuf = type { i32 }
define i32 @sshbuf_froms(%struct.sshbuf* %0, %struct.sshbuf** writeonly %1) {
%3 = alloca i32*
%4 = alloca i64
%5 = bitcast i32** %3 to i8*
%6 = bitcast i64* %4 to i8*
%7 = icmp eq %struct.sshbuf* %0, null
%8 = icmp eq %struct.sshbuf** %1, null
%9 = or i1 %7, %8
br i1 %9, label %30, label %10
10: ; preds = %2
store %struct.sshbuf* null, %struct.sshbuf** %1
%11 = call i32 @sshbuf_peek_string_direct(%struct.sshbuf* %0, i32** %3, i64* %4)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %30
13: ; preds = %10
%14 = load i32*, i32** %3
%15 = load i64, i64* %4
%16 = call %struct.sshbuf* @sshbuf_from(i32* %14, i64 %15)
%17 = icmp eq %struct.sshbuf* %16, null
br i1 %17, label %30, label %18
18: ; preds = %13
%19 = load i64, i64* %4
%20 = add i64 %19, 4
%21 = call i32 @sshbuf_consume(%struct.sshbuf* %0, i64 %20)
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %18
%24 = call i32 @sshbuf_set_parent(%struct.sshbuf* %16, %struct.sshbuf* %0)
%25 = icmp eq i32 %24, 0
br i1 %25, label %29, label %26
26: ; preds = %23, %18
%27 = phi i32 [ %21, %18 ], [ %24, %23 ]
%28 = call i32 @sshbuf_free(%struct.sshbuf* %16)
br label %30
29: ; preds = %23
store %struct.sshbuf* %16, %struct.sshbuf** %1
br label %30
30: ; preds = %13, %10, %2, %29, %26
%31 = phi i32 [ %27, %26 ], [ 0, %29 ], [ -10, %2 ], [ %11, %10 ], [ -2, %13 ]
ret i32 %31
}