#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 */
scalar_t__ sshbuf_consume(struct sshbuf *, size_t);
int sshbuf_peek_string8_direct(struct sshbuf *, int /*<<< orphan*/ const **,
                               size_t *);
int sshbuf_get_string8_direct(struct sshbuf *buf, const u_char **valp,
                              size_t *lenp) {
  size_t len;
  const u_char *p;
  int r;
  if (valp != NULL)
    *valp = NULL;
  if (lenp != NULL)
    *lenp = 0;
  if ((r = sshbuf_peek_string8_direct(buf, &p, &len)) < 0)
    return r;
  if (valp != NULL)
    *valp = p;
  if (lenp != NULL)
    *lenp = len;
  if (sshbuf_consume(buf, len + 1) != 0) {
    ;
    ;
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<sshbuf_get_string8_direct>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     114a <sshbuf_get_string8_direct+0x2a>
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
cmpq   $0x0,-0x20(%rbp)
je     1160 <sshbuf_get_string8_direct+0x40>
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rsi
lea    -0x28(%rbp),%rdx
call   1040 <sshbuf_peek_string8_direct@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
jge    1188 <sshbuf_get_string8_direct+0x68>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11e2 <sshbuf_get_string8_direct+0xc2>
cmpq   $0x0,-0x18(%rbp)
je     119e <sshbuf_get_string8_direct+0x7e>
mov    -0x30(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
cmpq   $0x0,-0x20(%rbp)
je     11b4 <sshbuf_get_string8_direct+0x94>
mov    -0x28(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
add    $0x1,%rsi
call   1030 <sshbuf_consume@plt>
cmp    $0x0,%rax
je     11db <sshbuf_get_string8_direct+0xbb>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e2 <sshbuf_get_string8_direct+0xc2>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sshbuf_get_string8_direct>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r14
test   %rsi,%rsi
je     113e <sshbuf_get_string8_direct+0x1e>
movq   $0x0,(%rbx)
test   %r15,%r15
je     114a <sshbuf_get_string8_direct+0x2a>
movq   $0x0,(%r15)
mov    %rsp,%rsi
lea    0x8(%rsp),%rdx
mov    %r14,%rdi
call   1040 <sshbuf_peek_string8_direct@plt>
test   %eax,%eax
js     1188 <sshbuf_get_string8_direct+0x68>
test   %rbx,%rbx
je     116a <sshbuf_get_string8_direct+0x4a>
mov    (%rsp),%rax
mov    %rax,(%rbx)
mov    0x8(%rsp),%rsi
test   %r15,%r15
je     1177 <sshbuf_get_string8_direct+0x57>
mov    %rsi,(%r15)
add    $0x1,%rsi
mov    %r14,%rdi
call   1030 <sshbuf_consume@plt>
neg    %rax
sbb    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

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