#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 /*<<< orphan*/ sscanf(char *, char *, unsigned int *);
void convert(unsigned char *dst, const unsigned char *src, int len) {
  int i;
  for (i = 0; i < len; i++, dst++, src += 2) {
    unsigned int n;
    sscanf((char *)src, "%2x", &n);
    *dst = (unsigned char)n;
  }
  *dst = 0;
}


x86 assembly (clang, -O0):
<convert>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    117b <convert+0x6b>
mov    -0x10(%rbp),%rdi
lea    0xebf(%rip),%rsi
lea    -0x1c(%rbp),%rdx
call   1030 <sscanf@plt>
mov    -0x1c(%rbp),%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x10(%rbp)
jmp    112a <convert+0x1a>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convert>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
test   %edx,%edx
jle    1163 <convert+0x53>
mov    %edx,%r14d
mov    %rsi,%rbp
lea    0xed0(%rip),%r15
lea    0xc(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1030 <sscanf@plt>
movzbl 0xc(%rsp),%eax
mov    %al,(%rbx)
add    $0x1,%rbx
add    $0x2,%rbp
add    $0xffffffff,%r14d
jne    1140 <convert+0x30>
movb   $0x0,(%rbx)
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [4 x i8] c"%2x\00"
define void @convert(i8* nocapture writeonly %0, i8* nocapture %1, i32 %2) {
%4 = alloca i32
%5 = icmp sgt i32 %2, 0
br i1 %5, label %6, label %19
6: ; preds = %3
%7 = bitcast i32* %4 to i8*
br label %8
8: ; preds = %6, %8
%9 = phi i32 [ 0, %6 ], [ %15, %8 ]
%10 = phi i8* [ %0, %6 ], [ %16, %8 ]
%11 = phi i8* [ %1, %6 ], [ %17, %8 ]
%12 = call i32 @sscanf(i8* %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %4)
%13 = load i32, i32* %4
%14 = trunc i32 %13 to i8
store i8 %14, i8* %10
%15 = add nuw nsw i32 %9, 1
%16 = getelementptr inbounds i8, i8* %10, i64 1
%17 = getelementptr inbounds i8, i8* %11, i64 2
%18 = icmp eq i32 %15, %2
br i1 %18, label %19, label %8
19: ; preds = %8, %3
%20 = phi i8* [ %0, %3 ], [ %16, %8 ]
store i8 0, i8* %20
ret void
}