#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 */
int strlen(char *);
scalar_t__ strtoul(char *, int /*<<< orphan*/ *, int);
void mls_type_data_str_to_bytearray(char *instr, unsigned char *outb,
                                    int size) {
  int i, len = strlen(instr);
  char *str;
  char token[2 + 1];
  for (i = 0, str = instr; (i < len) && (0 < size); i += 2, str += 2, size--) {
    token[0] = str[0];
    token[1] = str[1];
    token[2] = '\0';
    *outb = (unsigned char)strtoul(token, NULL, 16);
    outb += 1;
  }
}


x86 assembly (clang, -O0):
<mls_type_data_str_to_bytearray>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%ecx
xor    %eax,%eax
cmp    -0x1c(%rbp),%ecx
mov    %al,-0x2c(%rbp)
jge    116a <mls_type_data_str_to_bytearray+0x4a>
xor    %eax,%eax
cmp    -0x14(%rbp),%eax
setl   %al
mov    %al,-0x2c(%rbp)
mov    -0x2c(%rbp),%al
test   $0x1,%al
jne    117a <mls_type_data_str_to_bytearray+0x5a>
jmp    11da <mls_type_data_str_to_bytearray+0xba>
mov    -0x28(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x2b(%rbp)
mov    -0x28(%rbp),%rax
mov    0x1(%rax),%al
mov    %al,-0x2a(%rbp)
movb   $0x0,-0x29(%rbp)
lea    -0x2b(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1040 <strtoul@plt>
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x18(%rbp)
mov    -0x28(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    114e <mls_type_data_str_to_bytearray+0x2e>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mls_type_data_str_to_bytearray>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <strlen@plt>
test   %eax,%eax
jle    1193 <mls_type_data_str_to_bytearray+0x73>
test   %ebx,%ebx
jle    1193 <mls_type_data_str_to_bytearray+0x73>
mov    %eax,%r13d
mov    $0x2,%ebp
xor    %r12d,%r12d
nopl   0x0(%rax,%rax,1)
movzbl (%r15,%r12,2),%eax
mov    %al,0x5(%rsp)
movzbl 0x1(%r15,%r12,2),%eax
mov    %al,0x6(%rsp)
movb   $0x0,0x7(%rsp)
lea    0x5(%rsp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <strtoul@plt>
mov    %al,(%r14,%r12,1)
cmp    %r13d,%ebp
jge    1193 <mls_type_data_str_to_bytearray+0x73>
lea    -0x1(%rbx),%eax
add    $0x1,%r12
add    $0x2,%ebp
cmp    $0x1,%ebx
mov    %eax,%ebx
ja     1150 <mls_type_data_str_to_bytearray+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @mls_type_data_str_to_bytearray(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca [3 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%11 = load i8*, i8** %4
%12 = call i32 @strlen(i8* %11)
store i32 %12, i32* %8
store i32 0, i32* %7
%13 = load i8*, i8** %4
store i8* %13, i8** %9
br label %14
14: ; preds = %39, %3
%15 = load i32, i32* %7
%16 = load i32, i32* %8
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = load i32, i32* %6
%20 = icmp slt i32 0, %19
br label %21
21: ; preds = %18, %14
%22 = phi i1 [ false, %14 ], [ %20, %18 ]
br i1 %22, label %23, label %46
23: ; preds = %21
%24 = load i8*, i8** %9
%25 = getelementptr inbounds i8, i8* %24, i64 0
%26 = load i8, i8* %25
%27 = getelementptr inbounds [3 x i8], [3 x i8]* %10, i64 0, i64 0
store i8 %26, i8* %27
%28 = load i8*, i8** %9
%29 = getelementptr inbounds i8, i8* %28, i64 1
%30 = load i8, i8* %29
%31 = getelementptr inbounds [3 x i8], [3 x i8]* %10, i64 0, i64 1
store i8 %30, i8* %31
%32 = getelementptr inbounds [3 x i8], [3 x i8]* %10, i64 0, i64 2
store i8 0, i8* %32
%33 = getelementptr inbounds [3 x i8], [3 x i8]* %10, i64 0, i64 0
%34 = call i64 @strtoul(i8* %33, i32* null, i32 16)
%35 = trunc i64 %34 to i8
%36 = load i8*, i8** %5
store i8 %35, i8* %36
%37 = load i8*, i8** %5
%38 = getelementptr inbounds i8, i8* %37, i64 1
store i8* %38, i8** %5
br label %39
39: ; preds = %23
%40 = load i32, i32* %7
%41 = add nsw i32 %40, 2
store i32 %41, i32* %7
%42 = load i8*, i8** %9
%43 = getelementptr inbounds i8, i8* %42, i64 2
store i8* %43, i8** %9
%44 = load i32, i32* %6
%45 = add nsw i32 %44, -1
store i32 %45, i32* %6
br label %14
46: ; preds = %21
ret void
}

LLVM IR (-O2):
define void @mls_type_data_str_to_bytearray(i8* %0, i8* nocapture writeonly %1, i32 %2) {
%4 = alloca [3 x i8]
%5 = tail call i32 @strlen(i8* %0)
%6 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%7 = icmp sgt i32 %5, 0
%8 = icmp sgt i32 %2, 0
%9 = and i1 %7, %8
br i1 %9, label %10, label %30
10: ; preds = %3
%11 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 1
%12 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 2
br label %13
13: ; preds = %10, %13
%14 = phi i8* [ %0, %10 ], [ %25, %13 ]
%15 = phi i8* [ %1, %10 ], [ %23, %13 ]
%16 = phi i32 [ 0, %10 ], [ %24, %13 ]
%17 = phi i32 [ %2, %10 ], [ %26, %13 ]
%18 = load i8, i8* %14
store i8 %18, i8* %6
%19 = getelementptr inbounds i8, i8* %14, i64 1
%20 = load i8, i8* %19
store i8 %20, i8* %11
store i8 0, i8* %12
%21 = call i64 @strtoul(i8* nocapture %6, i32* null, i32 16)
%22 = trunc i64 %21 to i8
store i8 %22, i8* %15
%23 = getelementptr inbounds i8, i8* %15, i64 1
%24 = add nuw nsw i32 %16, 2
%25 = getelementptr inbounds i8, i8* %14, i64 2
%26 = add nsw i32 %17, -1
%27 = icmp slt i32 %24, %5
%28 = icmp ugt i32 %17, 1
%29 = select i1 %27, i1 %28, i1 false
br i1 %29, label %13, label %30
30: ; preds = %13, %3
ret void
}