#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 scalar_t__ uint8_t;
typedef int /*<<< orphan*/ array;

/* Variables and functions */
int /*<<< orphan*/ memcpy(scalar_t__ *, scalar_t__ *, int);
char *strtok(char *, char *);
scalar_t__ strtol(char *, char **, int);
void parse(char *str, uint8_t *dest) {
  char *token;
  uint8_t array[256] = {0};
  uint8_t val;
  char *endptr;
  int index = 0;
  token = strtok(str, " ");
  val = (uint8_t)strtol(token, &endptr, 16);
  array[index++] = val;
  while (token != NULL) {
    token = strtok(NULL, " ");
    if (token == NULL) {
      continue;
    }
    val = (uint8_t)strtol(token, &endptr, 16);
    array[index++] = val;
  }
  memcpy(dest, array, sizeof(array));
}


x86 assembly (clang, -O0):
<parse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x840,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x820(%rbp),%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1030 <memset@plt>
movl   $0x0,-0x834(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe85(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x830(%rbp),%rsi
mov    $0x10,%edx
call   1040 <strtol@plt>
mov    %rax,-0x828(%rbp)
mov    -0x828(%rbp),%rcx
mov    -0x834(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x834(%rbp)
cltq
mov    %rcx,-0x820(%rbp,%rax,8)
ff
cmpq   $0x0,-0x18(%rbp)
je     1234 <parse+0xf4>
xor    %eax,%eax
mov    %eax,%edi
lea    0xe28(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11f1 <parse+0xb1>
jmp    11c2 <parse+0x82>
mov    -0x18(%rbp),%rdi
lea    -0x830(%rbp),%rsi
mov    $0x10,%edx
call   1040 <strtol@plt>
mov    %rax,-0x828(%rbp)
mov    -0x828(%rbp),%rcx
mov    -0x834(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x834(%rbp)
cltq
mov    %rcx,-0x820(%rbp,%rax,8)
ff
jmp    11c2 <parse+0x82>
mov    -0x10(%rbp),%rdi
lea    -0x820(%rbp),%rsi
mov    $0x800,%edx
call   1050 <memcpy@plt>
add    $0x840,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x818,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0x10(%rsp),%rdi
mov    $0x800,%edx
xor    %esi,%esi
call   1030 <memset@plt>
lea    0xe91(%rip),%r12
mov    %rbx,%rdi
mov    %r12,%rsi
call   1060 <strtok@plt>
mov    %rax,%r13
lea    0x8(%rsp),%r15
mov    %rax,%rdi
mov    %r15,%rsi
mov    $0x10,%edx
call   1040 <strtol@plt>
mov    %rax,0x10(%rsp)
mov    $0x1,%ebp
nopl   0x0(%rax)
test   %r13,%r13
je     11db <parse+0x9b>
xor    %edi,%edi
mov    %r12,%rsi
call   1060 <strtok@plt>
mov    $0x0,%r13d
test   %rax,%rax
je     11a0 <parse+0x60>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
mov    $0x10,%edx
call   1040 <strtol@plt>
mov    %rax,0x10(%rsp,%rbp,8)
add    $0x1,%rbp
mov    %rbx,%r13
jmp    11a0 <parse+0x60>
lea    0x10(%rsp),%rsi
mov    %r14,%rdi
mov    $0x800,%edx
call   1050 <memcpy@plt>
add    $0x818,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
define void @parse(i8* %0, i64* %1) {
%3 = alloca [256 x i64]
%4 = alloca i8*
%5 = bitcast [256 x i64]* %3 to i8*
%6 = bitcast i8** %4 to i8*
%7 = tail call i8* @strtok(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = call i64 @strtol(i8* %7, i8** %4, i32 16)
%9 = getelementptr inbounds [256 x i64], [256 x i64]* %3, i64 0, i64 0
store i64 %8, i64* %9
br label %10
10: ; preds = %19, %2
%11 = phi i64 [ %21, %19 ], [ 1, %2 ]
%12 = phi i8* [ %17, %19 ], [ %7, %2 ]
br label %13
13: ; preds = %10, %16
%14 = phi i8* [ null, %16 ], [ %12, %10 ]
%15 = icmp eq i8* %14, null
br i1 %15, label %23, label %16
16: ; preds = %13
%17 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%18 = icmp eq i8* %17, null
br i1 %18, label %13, label %19
19: ; preds = %16
%20 = call i64 @strtol(i8* %17, i8** %4, i32 16)
%21 = add nuw i64 %11, 1
%22 = getelementptr inbounds [256 x i64], [256 x i64]* %3, i64 0, i64 %11
store i64 %20, i64* %22
br label %10
23: ; preds = %13
%24 = call i32 @memcpy(i64* %1, i64* %9, i32 2048)
ret void
}