#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 */
unsigned char *malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, unsigned char const,
                           unsigned char const);
unsigned char strtoul(unsigned char *, int /*<<< orphan*/ *, int);
unsigned char *avet_decoder(const unsigned char *buffer, unsigned char *payload,
                            int size) {
  0;
  int j = 0;
  payload = malloc((size / 2));
  0;
  int i = 0;
  do {
    unsigned char temp[3] = {0};
    sprintf((char *)temp, "%c%c", buffer[i], buffer[i + 1]);
    payload[j] = strtoul(temp, NULL, 16);
    0;
    i += 2;
    j++;
  } while (i < size);
  0;
  return payload;
}


x86 assembly (clang, -O0):
<avet_decoder>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    -0x1f(%rbp),%rdi
xor    %esi,%esi
mov    $0x3,%edx
call   1030 <memset@plt>
lea    -0x1f(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
lea    0xe56(%rip),%rsi
movzbl %dl,%edx
movzbl (%rax,%rcx,1),%ecx
call   1060 <sprintf@plt>
lea    -0x1f(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1050 <strtoul@plt>
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jl     1177 <avet_decoder+0x37>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<avet_decoder>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%r12d
mov    %rdi,%rbx
mov    %edx,%edi
shr    $0x1f,%edi
add    %edx,%edi
sar    %edi
call   1030 <malloc@plt>
mov    %rax,%r14
xor    %ebp,%ebp
lea    0xea2(%rip),%r15
lea    0xc(%rsp),%r13
mov    %rax,0x10(%rsp)
nopl   0x0(%rax,%rax,1)
movb   $0x0,0xe(%rsp)
movw   $0x0,0xc(%rsp)
movzbl (%rbx,%rbp,1),%edx
movzbl 0x1(%rbx,%rbp,1),%ecx
mov    %r13,%rdi
mov    %r15,%rsi
call   1050 <sprintf@plt>
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <strtoul@plt>
mov    %al,(%r14)
add    $0x2,%rbp
add    $0x1,%r14
cmp    %r12d,%ebp
jl     1170 <avet_decoder+0x40>
mov    0x10(%rsp),%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%c%c\00"
define i8* @avet_decoder(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [3 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 0, i32* %7
%10 = load i32, i32* %6
%11 = sdiv i32 %10, 2
%12 = call i8* @malloc(i32 %11)
store i8* %12, i8** %5
store i32 0, i32* %8
br label %13
13: ; preds = %38, %3
%14 = bitcast [3 x i8]* %9 to i8*
%15 = getelementptr inbounds [3 x i8], [3 x i8]* %9, i64 0, i64 0
%16 = load i8*, i8** %4
%17 = load i32, i32* %8
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = load i8, i8* %19
%21 = load i8*, i8** %4
%22 = load i32, i32* %8
%23 = add nsw i32 %22, 1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %21, i64 %24
%26 = load i8, i8* %25
%27 = call i32 @sprintf(i8* %15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %20, i8 zeroext %26)
%28 = getelementptr inbounds [3 x i8], [3 x i8]* %9, i64 0, i64 0
%29 = call zeroext i8 @strtoul(i8* %28, i32* null, i32 16)
%30 = load i8*, i8** %5
%31 = load i32, i32* %7
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
store i8 %29, i8* %33
%34 = load i32, i32* %8
%35 = add nsw i32 %34, 2
store i32 %35, i32* %8
%36 = load i32, i32* %7
%37 = add nsw i32 %36, 1
store i32 %37, i32* %7
br label %38
38: ; preds = %13
%39 = load i32, i32* %8
%40 = load i32, i32* %6
%41 = icmp slt i32 %39, %40
br i1 %41, label %13, label %42
42: ; preds = %38
%43 = load i8*, i8** %5
ret i8* %43
}

LLVM IR (-O2):
@.str = [5 x i8] c"%c%c\00"
define noalias i8* @avet_decoder(i8* nocapture %0, i8* nocapture readnone %1, i32 %2) {
%4 = alloca [3 x i8]
%5 = sdiv i32 %2, 2
%6 = tail call i8* @malloc(i32 %5)
%7 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
br label %8
8: ; preds = %8, %3
%9 = phi i64 [ %19, %8 ], [ 0, %3 ]
%10 = phi i64 [ %20, %8 ], [ 0, %3 ]
%11 = getelementptr inbounds i8, i8* %0, i64 %9
%12 = load i8, i8* %11
%13 = or i64 %9, 1
%14 = getelementptr inbounds i8, i8* %0, i64 %13
%15 = load i8, i8* %14
%16 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %12, i8 zeroext %15)
%17 = call zeroext i8 @strtoul(i8* nocapture %7, i32* null, i32 16)
%18 = getelementptr inbounds i8, i8* %6, i64 %10
store i8 %17, i8* %18
%19 = add nuw i64 %9, 2
%20 = add nuw i64 %10, 1
%21 = trunc i64 %19 to i32
%22 = icmp slt i32 %21, %2
br i1 %22, label %8, label %23
23: ; preds = %8
ret i8* %6
}