#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 */

/* Variables and functions */
char *bee_get_version();
int bee_tlv_creator(int, int, unsigned char **, void **);
int /*<<< orphan*/ bee_tlv_parser(void *, unsigned long *, unsigned char **,
                                  unsigned long *);
int /*<<< orphan*/ noly_hexdump(unsigned char *, unsigned long);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ service();
int main() {
  printf("BEE library version : %s\n", bee_get_version());
  unsigned char tmp[8];
  tmp[0] = 0x01;
  tmp[1] = 0xff;
  tmp[2] = 0x00;
  tmp[3] = 0x00;
  tmp[4] = 0x00;
  tmp[5] = 0x02;
  tmp[6] = 0x04;
  tmp[7] = 0x04;
  unsigned char *data;
  unsigned long data_len;
  unsigned long type;
  void *kk;
  int ret = bee_tlv_creator(12, 8, &tmp, &kk);
  if (ret > 0) {
    bee_tlv_parser(kk, &type, &data, &data_len);
  }
  printf("type: %ld length:%ld value\n", type, data_len);
  noly_hexdump(data, data_len);
  service();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1050 <bee_get_version@plt>
mov    %rax,%rsi
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movb   $0x1,-0xc(%rbp)
movb   $0xff,-0xb(%rbp)
movb   $0x0,-0xa(%rbp)
movb   $0x0,-0x9(%rbp)
movb   $0x0,-0x8(%rbp)
movb   $0x2,-0x7(%rbp)
movb   $0x4,-0x6(%rbp)
movb   $0x4,-0x5(%rbp)
lea    -0xc(%rbp),%rdx
mov    $0xc,%edi
mov    $0x8,%esi
lea    -0x30(%rbp),%rcx
call   1030 <bee_tlv_creator@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jle    11e0 <main+0x80>
mov    -0x30(%rbp),%rdi
lea    -0x28(%rbp),%rsi
lea    -0x18(%rbp),%rdx
lea    -0x20(%rbp),%rcx
call   1080 <bee_tlv_parser@plt>
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    0xe2b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1060 <noly_hexdump@plt>
mov    $0x0,%al
call   1070 <service@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x28,%rsp
xor    %eax,%eax
call   1050 <bee_get_version@plt>
lea    0xe8e(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
movabs $0x40402000000ff01,%rax
02 04 04
mov    %rax,0x20(%rsp)
lea    0x20(%rsp),%rdx
lea    0x8(%rsp),%rcx
mov    $0xc,%edi
mov    $0x8,%esi
call   1030 <bee_tlv_creator@plt>
mov    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
lea    0x18(%rsp),%rdx
mov    %rsp,%rcx
call   1080 <bee_tlv_parser@plt>
mov    0x10(%rsp),%rsi
mov    (%rsp),%rdx
lea    0xe4f(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x18(%rsp),%rdi
mov    (%rsp),%rsi
call   1060 <noly_hexdump@plt>
xor    %eax,%eax
call   1070 <service@plt>
xor    %eax,%eax
add    $0x28,%rsp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"BEE library version : %s\0A\00"
@.str.1 = [28 x i8] c"type: %ld length:%ld value\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [8 x i8]
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i32
store i32 0, i32* %1
%8 = call i8* (...) @bee_get_version()
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
store i8 1, i8* %10
%11 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 1
store i8 -1, i8* %11
%12 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 2
store i8 0, i8* %12
%13 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 3
store i8 0, i8* %13
%14 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 4
store i8 0, i8* %14
%15 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 5
store i8 2, i8* %15
%16 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 6
store i8 4, i8* %16
%17 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 7
store i8 4, i8* %17
%18 = bitcast [8 x i8]* %2 to i8**
%19 = call i32 @bee_tlv_creator(i32 12, i32 8, i8** %18, i8** %6)
store i32 %19, i32* %7
%20 = load i32, i32* %7
%21 = icmp sgt i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %0
%23 = load i8*, i8** %6
%24 = call i32 @bee_tlv_parser(i8* %23, i64* %5, i8** %3, i64* %4)
br label %25
25: ; preds = %22, %0
%26 = load i64, i64* %5
%27 = load i64, i64* %4
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i64 %26, i64 %27)
%29 = load i8*, i8** %3
%30 = load i64, i64* %4
%31 = call i32 @noly_hexdump(i8* %29, i64 %30)
%32 = call i32 (...) @service()
ret i32 0
}

LLVM IR (-O2):
@.str = [26 x i8] c"BEE library version : %s\0A\00"
@.str.1 = [28 x i8] c"type: %ld length:%ld value\0A\00"
define i32 @main() {
%1 = alloca i8*
%2 = bitcast i8** %1 to [8 x i8]*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i8*
%7 = tail call i8* (...) @bee_get_version()
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = bitcast i8** %1 to i8*
store i8 1, i8* %9
%10 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 1
store i8 -1, i8* %10
%11 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 2
store i8 0, i8* %11
%12 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 3
store i8 0, i8* %12
%13 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 4
store i8 0, i8* %13
%14 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 5
store i8 2, i8* %14
%15 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 6
store i8 4, i8* %15
%16 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 7
store i8 4, i8* %16
%17 = bitcast i8** %3 to i8*
%18 = bitcast i64* %4 to i8*
%19 = bitcast i64* %5 to i8*
%20 = bitcast i8** %6 to i8*
%21 = call i32 @bee_tlv_creator(i32 12, i32 8, i8** %1, i8** %6)
%22 = icmp sgt i32 %21, 0
%23 = load i8*, i8** %6
%24 = call i32 @bee_tlv_parser(i8* %23, i64* %5, i8** %3, i64* %4)
%25 = load i64, i64* %5
%26 = load i64, i64* %4
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i64 %25, i64 %26)
%28 = load i8*, i8** %3
%29 = load i64, i64* %4
%30 = call i32 @noly_hexdump(i8* %28, i64 %29)
%31 = call i32 (...) @service()
ret i32 0
}