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

/* Variables and functions */
int /*<<< orphan*/ sscanf(char *, char *, int /*<<< orphan*/ *);
void convert_hex(char *str, uint8_t *bytes, int maxlen) {
  int bytelen = maxlen;
  int rpos, wpos = 0;
  for (rpos = 0; rpos < bytelen; rpos++) {
    sscanf(&str[rpos * 2], "%02hhx", &bytes[wpos++]);
  }
}


x86 assembly (clang, -O0):
<convert_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1184 <convert_hex+0x74>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%eax
shl    $0x1,%eax
cltq
add    %rax,%rdi
mov    -0x10(%rbp),%rdx
mov    -0x20(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x20(%rbp)
cltq
shl    $0x2,%rax
add    %rax,%rdx
lea    0xe8f(%rip),%rsi
call   1030 <sscanf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1137 <convert_hex+0x27>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convert_hex>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %edx,%edx
jle    114c <convert_hex+0x3c>
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %edx,%r12d
lea    0xed4(%rip),%r15
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1030 <sscanf@plt>
add    $0x2,%rbx
add    $0x4,%r14
add    $0xffffffffffffffff,%r12
jne    1130 <convert_hex+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%02hhx\00"
define void @convert_hex(i8* %0, i32* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
%10 = load i32, i32* %6
store i32 %10, i32* %7
store i32 0, i32* %9
store i32 0, i32* %8
br label %11
11: ; preds = %27, %3
%12 = load i32, i32* %8
%13 = load i32, i32* %7
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %30
15: ; preds = %11
%16 = load i8*, i8** %4
%17 = load i32, i32* %8
%18 = mul nsw i32 %17, 2
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %16, i64 %19
%21 = load i32*, i32** %5
%22 = load i32, i32* %9
%23 = add nsw i32 %22, 1
store i32 %23, i32* %9
%24 = sext i32 %22 to i64
%25 = getelementptr inbounds i32, i32* %21, i64 %24
%26 = call i32 @sscanf(i8* %20, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32* %25)
br label %27
27: ; preds = %15
%28 = load i32, i32* %8
%29 = add nsw i32 %28, 1
store i32 %29, i32* %8
br label %11
30: ; preds = %11
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"%02hhx\00"
define void @convert_hex(i8* nocapture %0, i32* %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %15
5: ; preds = %3
%6 = zext i32 %2 to i64
br label %7
7: ; preds = %5, %7
%8 = phi i64 [ 0, %5 ], [ %11, %7 ]
%9 = shl nuw nsw i64 %8, 1
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = add nuw nsw i64 %8, 1
%12 = getelementptr inbounds i32, i32* %1, i64 %8
%13 = tail call i32 @sscanf(i8* %10, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32* %12)
%14 = icmp eq i64 %11, %6
br i1 %14, label %15, label %7
15: ; preds = %7, %3
ret void
}