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

/* Variables and functions */
int /*<<< orphan*/ memset(char *, unsigned char, int const);
int strlen(unsigned char *);
int /*<<< orphan*/ strtoul(char *, int /*<<< orphan*/ *, int);
int finalize(unsigned char *src, unsigned char **dest, const int len) {
  int i = 0, j = 0, srclen = strlen(src);
  char *tmp = *dest, buf[len + 1];
  for (i = 0; i < srclen; i++) {
    memset(buf, '\0', len + 1);
    for (j = 0; j < len; j++) {
      memset(&buf[j], src[i++], 1);
    }
    uint32_t num = strtoul(buf, NULL, 16);
    *tmp++ = num;
    i--;
  }
  return 0;
}


x86 assembly (clang, -O0):
<finalize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    1245 <finalize+0x115>
mov    -0x48(%rbp),%rdi
mov    -0x14(%rbp),%edx
add    $0x1,%edx
xor    %esi,%esi
call   1040 <memset@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1203 <finalize+0xd3>
mov    -0x48(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x18(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
movzbl %al,%esi
mov    $0x1,%edx
call   1040 <memset@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11bc <finalize+0x8c>
mov    -0x48(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1050 <strtoul@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    %al,%cl
mov    -0x28(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x28(%rbp)
mov    %cl,(%rax)
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1198 <finalize+0x68>
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
xor    %eax,%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<finalize>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %edx,%ebx
mov    %rsi,%r14
mov    %rdi,-0x40(%rbp)
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    %rbx,%rax
mov    %rbx,-0x38(%rbp)
lea    0x1(%rbx),%eax
mov    %rsp,%rbx
mov    %rax,-0x48(%rbp)
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %ecx,-0x2c(%rbp)
test   %ecx,%ecx
jle    11f9 <finalize+0xc9>
mov    (%r14),%r14
mov    -0x38(%rbp),%r15d
xor    %r12d,%r12d
jmp    11ac <finalize+0x7c>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <strtoul@plt>
mov    %al,(%r14)
add    $0x1,%r14
cmp    -0x2c(%rbp),%r12d
jge    11f9 <finalize+0xc9>
mov    %rbx,%rdi
xor    %esi,%esi
mov    -0x48(%rbp),%rdx
call   1040 <memset@plt>
cmpl   $0x0,-0x38(%rbp)
jle    1190 <finalize+0x60>
mov    %r12,-0x50(%rbp)
movslq %r12d,%r13
add    -0x40(%rbp),%r13
xor    %r12d,%r12d
xchg   %ax,%ax
lea    (%rbx,%r12,1),%rdi
movzbl 0x0(%r13,%r12,1),%esi
mov    $0x1,%edx
call   1040 <memset@plt>
add    $0x1,%r12
cmp    %r12,%r15
jne    11d0 <finalize+0xa0>
mov    -0x50(%rbp),%rax
add    %r12d,%eax
mov    %rax,%r12
jmp    1190 <finalize+0x60>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @finalize(i8* %0, i8** %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i64
%13 = alloca i32
store i8* %0, i8** %4
store i8** %1, i8*** %5
store i32 %2, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
%14 = load i8*, i8** %4
%15 = call i32 @strlen(i8* %14)
store i32 %15, i32* %9
%16 = load i8**, i8*** %5
%17 = load i8*, i8** %16
store i8* %17, i8** %10
%18 = load i32, i32* %6
%19 = add nsw i32 %18, 1
%20 = zext i32 %19 to i64
%21 = call i8* @llvm.stacksave()
store i8* %21, i8** %11
%22 = alloca i8, i64 %20
store i64 %20, i64* %12
store i32 0, i32* %7
br label %23
23: ; preds = %57, %3
%24 = load i32, i32* %7
%25 = load i32, i32* %9
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %60
27: ; preds = %23
%28 = load i32, i32* %6
%29 = add nsw i32 %28, 1
%30 = call i32 @memset(i8* %22, i8 zeroext 0, i32 %29)
store i32 0, i32* %8
br label %31
31: ; preds = %46, %27
%32 = load i32, i32* %8
%33 = load i32, i32* %6
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %49
35: ; preds = %31
%36 = load i32, i32* %8
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %22, i64 %37
%39 = load i8*, i8** %4
%40 = load i32, i32* %7
%41 = add nsw i32 %40, 1
store i32 %41, i32* %7
%42 = sext i32 %40 to i64
%43 = getelementptr inbounds i8, i8* %39, i64 %42
%44 = load i8, i8* %43
%45 = call i32 @memset(i8* %38, i8 zeroext %44, i32 1)
br label %46
46: ; preds = %35
%47 = load i32, i32* %8
%48 = add nsw i32 %47, 1
store i32 %48, i32* %8
br label %31
49: ; preds = %31
%50 = call i32 @strtoul(i8* %22, i32* null, i32 16)
store i32 %50, i32* %13
%51 = load i32, i32* %13
%52 = trunc i32 %51 to i8
%53 = load i8*, i8** %10
%54 = getelementptr inbounds i8, i8* %53, i32 1
store i8* %54, i8** %10
store i8 %52, i8* %53
%55 = load i32, i32* %7
%56 = add nsw i32 %55, -1
store i32 %56, i32* %7
br label %57
57: ; preds = %49
%58 = load i32, i32* %7
%59 = add nsw i32 %58, 1
store i32 %59, i32* %7
br label %23
60: ; preds = %23
%61 = load i8*, i8** %11
ret i32 0
}

LLVM IR (-O2):
define i32 @finalize(i8* %0, i8** nocapture %1, i32 %2) {
%4 = tail call i32 @strlen(i8* %0)
%5 = add nsw i32 %2, 1
%6 = zext i32 %5 to i64
%7 = alloca i8, i64 %6
%8 = icmp sgt i32 %4, 0
br i1 %8, label %9, label %37
9: ; preds = %3
%10 = load i8*, i8** %1
%11 = icmp sgt i32 %2, 0
%12 = zext i32 %2 to i64
br label %13
13: ; preds = %9, %31
%14 = phi i32 [ 0, %9 ], [ %32, %31 ]
%15 = phi i8* [ %10, %9 ], [ %35, %31 ]
%16 = call i32 @memset(i8* %7, i8 zeroext 0, i32 %5)
br i1 %11, label %17, label %31
17: ; preds = %13
%18 = sext i32 %14 to i64
br label %19
19: ; preds = %17, %19
%20 = phi i64 [ 0, %17 ], [ %27, %19 ]
%21 = phi i64 [ %18, %17 ], [ %23, %19 ]
%22 = getelementptr inbounds i8, i8* %7, i64 %20
%23 = add nsw i64 %21, 1
%24 = getelementptr inbounds i8, i8* %0, i64 %21
%25 = load i8, i8* %24
%26 = call i32 @memset(i8* %22, i8 zeroext %25, i32 1)
%27 = add nuw nsw i64 %20, 1
%28 = icmp eq i64 %27, %12
br i1 %28, label %29, label %19
29: ; preds = %19
%30 = trunc i64 %23 to i32
br label %31
31: ; preds = %29, %13
%32 = phi i32 [ %14, %13 ], [ %30, %29 ]
%33 = call i32 @strtoul(i8* nocapture %7, i32* null, i32 16)
%34 = trunc i32 %33 to i8
%35 = getelementptr inbounds i8, i8* %15, i64 1
store i8 %34, i8* %15
%36 = icmp slt i32 %32, %4
br i1 %36, label %13, label %37
37: ; preds = %31, %3
ret i32 0
}