#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;

/* Variables and functions */
scalar_t__ strtol(char *, int /*<<< orphan*/ *, int);
int str_to_bin(uint8_t *data, char *hexstring, int len) {
  char *pos = hexstring;
  for (int count = 0; count < len; count++) {
    char buf[3] = {pos[0], pos[1], 0};
    data[count] = (uint8_t)strtol(buf, NULL, 16);
    pos += 2;
  }
  return 0;
}


x86 assembly (clang, -O0):
<str_to_bin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1190 <str_to_bin+0x80>
mov    -0x20(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x27(%rbp)
mov    -0x20(%rbp),%rax
mov    0x1(%rax),%al
mov    %al,-0x26(%rbp)
movb   $0x0,-0x25(%rbp)
lea    -0x27(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1030 <strtol@plt>
mov    %rax,%rdx
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1132 <str_to_bin+0x22>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_to_bin>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
test   %edx,%edx
jle    1175 <str_to_bin+0x65>
mov    %rsi,%r13
mov    %rdi,%r14
mov    %edx,%r12d
xor    %ebx,%ebx
lea    0xd(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl 0x0(%r13,%rbx,2),%eax
mov    %al,0xd(%rsp)
movzbl 0x1(%r13,%rbx,2),%eax
mov    %al,0xe(%rsp)
movb   $0x0,0xf(%rsp)
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1030 <strtol@plt>
mov    %rax,(%r14,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1140 <str_to_bin+0x30>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @str_to_bin(i64* %0, i8* %1, i32 %2) {
%4 = alloca i64*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca [3 x i8]
store i64* %0, i64** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%10 = load i8*, i8** %5
store i8* %10, i8** %7
store i32 0, i32* %8
br label %11
11: ; preds = %33, %3
%12 = load i32, i32* %8
%13 = load i32, i32* %6
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %36
15: ; preds = %11
%16 = getelementptr inbounds [3 x i8], [3 x i8]* %9, i64 0, i64 0
%17 = load i8*, i8** %7
%18 = getelementptr inbounds i8, i8* %17, i64 0
%19 = load i8, i8* %18
store i8 %19, i8* %16
%20 = getelementptr inbounds i8, i8* %16, i64 1
%21 = load i8*, i8** %7
%22 = getelementptr inbounds i8, i8* %21, i64 1
%23 = load i8, i8* %22
store i8 %23, i8* %20
%24 = getelementptr inbounds i8, i8* %20, i64 1
store i8 0, i8* %24
%25 = getelementptr inbounds [3 x i8], [3 x i8]* %9, i64 0, i64 0
%26 = call i64 @strtol(i8* %25, i32* null, i32 16)
%27 = load i64*, i64** %4
%28 = load i32, i32* %8
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i64, i64* %27, i64 %29
store i64 %26, i64* %30
%31 = load i8*, i8** %7
%32 = getelementptr inbounds i8, i8* %31, i64 2
store i8* %32, i8** %7
br label %33
33: ; preds = %15
%34 = load i32, i32* %8
%35 = add nsw i32 %34, 1
store i32 %35, i32* %8
br label %11
36: ; preds = %11
ret i32 0
}

LLVM IR (-O2):
define i32 @str_to_bin(i64* nocapture writeonly %0, i8* nocapture %1, i32 %2) {
%4 = alloca [3 x i8]
%5 = icmp sgt i32 %2, 0
br i1 %5, label %6, label %11
6: ; preds = %3
%7 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 1
%9 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 2
%10 = zext i32 %2 to i64
br label %12
11: ; preds = %12, %3
ret i32 0
12: ; preds = %6, %12
%13 = phi i64 [ 0, %6 ], [ %21, %12 ]
%14 = phi i8* [ %1, %6 ], [ %20, %12 ]
%15 = load i8, i8* %14
store i8 %15, i8* %7
%16 = getelementptr inbounds i8, i8* %14, i64 1
%17 = load i8, i8* %16
store i8 %17, i8* %8
store i8 0, i8* %9
%18 = call i64 @strtol(i8* nocapture %7, i32* null, i32 16)
%19 = getelementptr inbounds i64, i64* %0, i64 %13
store i64 %18, i64* %19
%20 = getelementptr inbounds i8, i8* %14, i64 2
%21 = add nuw nsw i64 %13, 1
%22 = icmp eq i64 %21, %10
br i1 %22, label %11, label %12
}