#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 scalar_t__ u_int8_t;
typedef scalar_t__ u_char;
struct sshbuf {
  int dummy;
};

/* Variables and functions */
int sshbuf_consume(struct sshbuf *, int);
scalar_t__ *sshbuf_ptr(struct sshbuf *);
int sshbuf_get_u8(struct sshbuf *buf, u_char *valp) {
  const u_char *p = sshbuf_ptr(buf);
  int r;
  if ((r = sshbuf_consume(buf, 1)) < 0)
    return r;
  if (valp != NULL)
    *valp = (u_int8_t)*p;
  return 0;
}


x86 assembly (clang, -O0):
<sshbuf_get_u8>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <sshbuf_ptr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   1030 <sshbuf_consume@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jge    1162 <sshbuf_get_u8+0x42>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1182 <sshbuf_get_u8+0x62>
cmpq   $0x0,-0x18(%rbp)
je     117b <sshbuf_get_u8+0x5b>
mov    -0x20(%rbp),%rax
mov    (%rax),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sshbuf_get_u8>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%rbx
call   1040 <sshbuf_ptr@plt>
mov    %rax,%r14
mov    %rbx,%rdi
mov    $0x1,%esi
call   1030 <sshbuf_consume@plt>
test   %eax,%eax
js     1151 <sshbuf_get_u8+0x31>
xor    %eax,%eax
test   %r15,%r15
je     1151 <sshbuf_get_u8+0x31>
mov    (%r14),%rcx
mov    %rcx,(%r15)
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
%struct.sshbuf = type { i32 }
define i32 @sshbuf_get_u8(%struct.sshbuf* %0, i64* writeonly %1) {
%3 = tail call i64* @sshbuf_ptr(%struct.sshbuf* %0)
%4 = tail call i32 @sshbuf_consume(%struct.sshbuf* %0, i32 1)
%5 = icmp slt i32 %4, 0
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = icmp eq i64* %1, null
br i1 %7, label %10, label %8
8: ; preds = %6
%9 = load i64, i64* %3
store i64 %9, i64* %1
br label %10
10: ; preds = %6, %8, %2
%11 = phi i32 [ %4, %2 ], [ 0, %8 ], [ 0, %6 ]
ret i32 %11
}