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

/* Variables and functions */
scalar_t__ sshbuf_check_sanity(struct sshbuf *);
int /*<<< orphan*/ sshbuf_free(struct sshbuf *);
struct sshbuf *sshbuf_from(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sshbuf_len(struct sshbuf *);
int /*<<< orphan*/ sshbuf_ptr(struct sshbuf *);
scalar_t__ sshbuf_set_parent(struct sshbuf *, struct sshbuf *);
struct sshbuf *sshbuf_fromb(struct sshbuf *buf) {
  struct sshbuf *ret;
  if (sshbuf_check_sanity(buf) != 0)
    return NULL;
  if ((ret = sshbuf_from(sshbuf_ptr(buf), sshbuf_len(buf))) == NULL)
    return NULL;
  if (sshbuf_set_parent(ret, buf) != 0) {
    sshbuf_free(ret);
    return NULL;
  }
  return ret;
}


x86 assembly (clang, -O0):
<sshbuf_fromb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <sshbuf_check_sanity@plt>
cmp    $0x0,%rax
je     118c <sshbuf_fromb+0x2c>
movq   $0x0,-0x8(%rbp)
jmp    11fb <sshbuf_fromb+0x9b>
mov    -0x10(%rbp),%rdi
call   1060 <sshbuf_ptr@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <sshbuf_len@plt>
mov    -0x1c(%rbp),%edi
mov    %eax,%esi
call   1040 <sshbuf_from@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11c6 <sshbuf_fromb+0x66>
movq   $0x0,-0x8(%rbp)
jmp    11fb <sshbuf_fromb+0x9b>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1080 <sshbuf_set_parent@plt>
cmp    $0x0,%rax
je     11f3 <sshbuf_fromb+0x93>
mov    -0x18(%rbp),%rdi
call   1050 <sshbuf_free@plt>
movq   $0x0,-0x8(%rbp)
jmp    11fb <sshbuf_fromb+0x9b>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sshbuf_fromb>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1070 <sshbuf_check_sanity@plt>
test   %rax,%rax
jne    11ac <sshbuf_fromb+0x4c>
mov    %r14,%rdi
call   1060 <sshbuf_ptr@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1030 <sshbuf_len@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1040 <sshbuf_from@plt>
test   %rax,%rax
je     11ac <sshbuf_fromb+0x4c>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1080 <sshbuf_set_parent@plt>
test   %rax,%rax
je     11ae <sshbuf_fromb+0x4e>
mov    %rbx,%rdi
call   1050 <sshbuf_free@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.sshbuf = type { i32 }
define %struct.sshbuf* @sshbuf_fromb(%struct.sshbuf* %0) {
%2 = alloca %struct.sshbuf*
%3 = alloca %struct.sshbuf*
%4 = alloca %struct.sshbuf*
store %struct.sshbuf* %0, %struct.sshbuf** %3
%5 = load %struct.sshbuf*, %struct.sshbuf** %3
%6 = call i64 @sshbuf_check_sanity(%struct.sshbuf* %5)
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %1
store %struct.sshbuf* null, %struct.sshbuf** %2
br label %27
9: ; preds = %1
%10 = load %struct.sshbuf*, %struct.sshbuf** %3
%11 = call i32 @sshbuf_ptr(%struct.sshbuf* %10)
%12 = load %struct.sshbuf*, %struct.sshbuf** %3
%13 = call i32 @sshbuf_len(%struct.sshbuf* %12)
%14 = call %struct.sshbuf* @sshbuf_from(i32 %11, i32 %13)
store %struct.sshbuf* %14, %struct.sshbuf** %4
%15 = icmp eq %struct.sshbuf* %14, null
br i1 %15, label %16, label %17
16: ; preds = %9
store %struct.sshbuf* null, %struct.sshbuf** %2
br label %27
17: ; preds = %9
%18 = load %struct.sshbuf*, %struct.sshbuf** %4
%19 = load %struct.sshbuf*, %struct.sshbuf** %3
%20 = call i64 @sshbuf_set_parent(%struct.sshbuf* %18, %struct.sshbuf* %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %17
%23 = load %struct.sshbuf*, %struct.sshbuf** %4
%24 = call i32 @sshbuf_free(%struct.sshbuf* %23)
store %struct.sshbuf* null, %struct.sshbuf** %2
br label %27
25: ; preds = %17
%26 = load %struct.sshbuf*, %struct.sshbuf** %4
store %struct.sshbuf* %26, %struct.sshbuf** %2
br label %27
27: ; preds = %25, %22, %16, %8
%28 = load %struct.sshbuf*, %struct.sshbuf** %2
ret %struct.sshbuf* %28
}

LLVM IR (-O2):
%struct.sshbuf = type { i32 }
define %struct.sshbuf* @sshbuf_fromb(%struct.sshbuf* %0) {
%2 = tail call i64 @sshbuf_check_sanity(%struct.sshbuf* %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %14
4: ; preds = %1
%5 = tail call i32 @sshbuf_ptr(%struct.sshbuf* %0)
%6 = tail call i32 @sshbuf_len(%struct.sshbuf* %0)
%7 = tail call %struct.sshbuf* @sshbuf_from(i32 %5, i32 %6)
%8 = icmp eq %struct.sshbuf* %7, null
br i1 %8, label %14, label %9
9: ; preds = %4
%10 = tail call i64 @sshbuf_set_parent(%struct.sshbuf* %7, %struct.sshbuf* %0)
%11 = icmp eq i64 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %9
%13 = tail call i32 @sshbuf_free(%struct.sshbuf* %7)
br label %14
14: ; preds = %9, %4, %1, %12
%15 = phi %struct.sshbuf* [ null, %12 ], [ null, %1 ], [ null, %4 ], [ %7, %9 ]
ret %struct.sshbuf* %15
}