#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*/ uint8_t;
typedef int uint16_t;
struct tlv_iterator {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, char const *, int);
char *tlv_iter_get_data(struct tlv_iterator *);
int tlv_iter_get_len(struct tlv_iterator *);
int tlv_iter_decode_u8(struct tlv_iterator *tlv_iter, uint8_t *res) {
  const char *opt_data;
  uint16_t opt_len;
  opt_len = tlv_iter_get_len(tlv_iter);
  opt_data = tlv_iter_get_data(tlv_iter);
  if (opt_len != sizeof(*res)) {
    return (-1);
  }
  memcpy(res, opt_data, sizeof(*res));
  return (0);
}


x86 assembly (clang, -O0):
<tlv_iter_decode_u8>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <tlv_iter_get_len@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <tlv_iter_get_data@plt>
mov    %rax,-0x20(%rbp)
movslq -0x24(%rbp),%rax
cmp    $0x4,%rax
je     1173 <tlv_iter_decode_u8+0x43>
movl   $0xffffffff,-0x4(%rbp)
jmp    118c <tlv_iter_decode_u8+0x5c>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    $0x4,%edx
call   1050 <memcpy@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tlv_iter_decode_u8>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <tlv_iter_get_len@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <tlv_iter_get_data@plt>
mov    $0xffffffff,%ecx
cmp    $0x4,%ebp
jne    1165 <tlv_iter_decode_u8+0x35>
mov    %r14,%rdi
mov    %rax,%rsi
mov    $0x4,%edx
call   1050 <memcpy@plt>
xor    %ecx,%ecx
mov    %ecx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.tlv_iterator = type { i32 }
define i32 @tlv_iter_decode_u8(%struct.tlv_iterator* %0, i32* %1) {
%3 = alloca i32
%4 = alloca %struct.tlv_iterator*
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
store %struct.tlv_iterator* %0, %struct.tlv_iterator** %4
store i32* %1, i32** %5
%8 = load %struct.tlv_iterator*, %struct.tlv_iterator** %4
%9 = call i32 @tlv_iter_get_len(%struct.tlv_iterator* %8)
store i32 %9, i32* %7
%10 = load %struct.tlv_iterator*, %struct.tlv_iterator** %4
%11 = call i8* @tlv_iter_get_data(%struct.tlv_iterator* %10)
store i8* %11, i8** %6
%12 = load i32, i32* %7
%13 = sext i32 %12 to i64
%14 = icmp ne i64 %13, 4
br i1 %14, label %15, label %16
15: ; preds = %2
store i32 -1, i32* %3
br label %20
16: ; preds = %2
%17 = load i32*, i32** %5
%18 = load i8*, i8** %6
%19 = call i32 @memcpy(i32* %17, i8* %18, i32 4)
store i32 0, i32* %3
br label %20
20: ; preds = %16, %15
%21 = load i32, i32* %3
ret i32 %21
}

LLVM IR (-O2):
%struct.tlv_iterator = type { i32 }
define i32 @tlv_iter_decode_u8(%struct.tlv_iterator* %0, i32* %1) {
%3 = tail call i32 @tlv_iter_get_len(%struct.tlv_iterator* %0)
%4 = tail call i8* @tlv_iter_get_data(%struct.tlv_iterator* %0)
%5 = icmp eq i32 %3, 4
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @memcpy(i32* %1, i8* %4, i32 4)
br label %8
8: ; preds = %2, %6
%9 = phi i32 [ 0, %6 ], [ -1, %2 ]
ret i32 %9
}