#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_int8_t;

/* Variables and functions */
int /*<<< orphan*/ EINVAL;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ memcpy(void *, char const *, int);
int unmarshall_u_int8(u_int8_t *val, const char *buf, unsigned int buflen) {
  if (!val || !buf) {
    errno = EINVAL;
    return -1;
  }
  if (buflen >= sizeof(u_int8_t)) {
    memcpy((void *)val, buf, sizeof(u_int8_t));
    return sizeof(u_int8_t);
  }
  return 0;
}


x86 assembly (clang, -O0):
<unmarshall_u_int8>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1139 <unmarshall_u_int8+0x29>
cmpq   $0x0,-0x18(%rbp)
jne    1157 <unmarshall_u_int8+0x47>
mov    0x2e98(%rip),%rax
mov    (%rax),%ecx
mov    0x2e97(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    1189 <unmarshall_u_int8+0x79>
mov    -0x1c(%rbp),%eax
cmp    $0x4,%rax
jb     1182 <unmarshall_u_int8+0x72>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   1030 <memcpy@plt>
movl   $0x4,-0x4(%rbp)
jmp    1189 <unmarshall_u_int8+0x79>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unmarshall_u_int8>:
push   %rbx
test   %rdi,%rdi
je     1133 <unmarshall_u_int8+0x23>
test   %rsi,%rsi
je     1133 <unmarshall_u_int8+0x23>
xor    %ebx,%ebx
cmp    $0x4,%edx
jb     114a <unmarshall_u_int8+0x3a>
mov    $0x4,%ebx
mov    $0x4,%edx
call   1030 <memcpy@plt>
jmp    114a <unmarshall_u_int8+0x3a>
mov    0x2e9e(%rip),%rax
mov    (%rax),%eax
mov    0x2e9d(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@EINVAL = global i32 0
@errno = global i32 0
define i32 @unmarshall_u_int8(i32* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
store i32* %0, i32** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%8 = load i32*, i32** %5
%9 = icmp ne i32* %8, null
br i1 %9, label %10, label %13
10: ; preds = %3
%11 = load i8*, i8** %6
%12 = icmp ne i8* %11, null
br i1 %12, label %15, label %13
13: ; preds = %10, %3
%14 = load i32, i32* @EINVAL
store i32 %14, i32* @errno
store i32 -1, i32* %4
br label %25
15: ; preds = %10
%16 = load i32, i32* %7
%17 = zext i32 %16 to i64
%18 = icmp uge i64 %17, 4
br i1 %18, label %19, label %24
19: ; preds = %15
%20 = load i32*, i32** %5
%21 = bitcast i32* %20 to i8*
%22 = load i8*, i8** %6
%23 = call i32 @memcpy(i8* %21, i8* %22, i32 4)
store i32 4, i32* %4
br label %25
24: ; preds = %15
store i32 0, i32* %4
br label %25
25: ; preds = %24, %19, %13
%26 = load i32, i32* %4
ret i32 %26
}

LLVM IR (-O2):
@EINVAL = global i32 0
@errno = global i32 0
define i32 @unmarshall_u_int8(i32* %0, i8* %1, i32 %2) {
%4 = icmp ne i32* %0, null
%5 = icmp ne i8* %1, null
%6 = and i1 %4, %5
br i1 %6, label %9, label %7
7: ; preds = %3
%8 = load i32, i32* @EINVAL
store i32 %8, i32* @errno
br label %14
9: ; preds = %3
%10 = icmp ugt i32 %2, 3
br i1 %10, label %11, label %14
11: ; preds = %9
%12 = bitcast i32* %0 to i8*
%13 = tail call i32 @memcpy(i8* %12, i8* %1, i32 4)
br label %14
14: ; preds = %9, %11, %7
%15 = phi i32 [ 4, %11 ], [ -1, %7 ], [ 0, %9 ]
ret i32 %15
}