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

/* Variables and functions */
unsigned char strtol(char *, int /*<<< orphan*/, int);
int64_t parse_binary(const char *src, char *dest, int64_t len) {
  int64_t i;
  int64_t index = 0;
  for (i = 0; i < len; i += 2) {
    char buf[3];
    buf[0] = src[i];
    buf[1] = src[i + 1];
    buf[2] = 0;
    unsigned char a = strtol(buf, 0, 16);
    dest[index++] = (char)a;
  }
  return index;
}


x86 assembly (clang, -O0):
<parse_binary>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    119b <parse_binary+0x8b>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x1f(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x1e(%rbp)
movb   $0x0,-0x1d(%rbp)
lea    -0x1f(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1030 <strtol@plt>
mov    %al,-0x20(%rbp)
mov    -0x20(%rbp),%dl
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x1c(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x18(%rbp)
jmp    1131 <parse_binary+0x21>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_binary>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edx,%edx
jle    117a <parse_binary+0x6a>
mov    %edx,%r15d
mov    %rsi,%r14
mov    %rdi,%r13
xor    %ebx,%ebx
lea    0x5(%rsp),%r12
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl 0x0(%r13,%rbp,2),%eax
mov    %al,0x5(%rsp)
movzbl 0x1(%r13,%rbp,2),%eax
mov    %al,0x6(%rsp)
movb   $0x0,0x7(%rsp)
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1030 <strtol@plt>
mov    %al,(%r14,%rbp,1)
add    $0x1,%rbp
add    $0x2,%ebx
cmp    %r15d,%ebx
jl     1140 <parse_binary+0x30>
jmp    117c <parse_binary+0x6c>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @parse_binary(i8* nocapture %0, i8* nocapture writeonly %1, i32 %2) {
%4 = alloca [3 x i8]
%5 = icmp sgt i32 %2, 0
br i1 %5, label %6, label %26
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
br label %10
10: ; preds = %6, %10
%11 = phi i64 [ 0, %6 ], [ %19, %10 ]
%12 = phi i64 [ 0, %6 ], [ %21, %10 ]
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = load i8, i8* %13
store i8 %14, i8* %7
%15 = or i64 %12, 1
%16 = getelementptr inbounds i8, i8* %0, i64 %15
%17 = load i8, i8* %16
store i8 %17, i8* %8
store i8 0, i8* %9
%18 = call zeroext i8 @strtol(i8* %7, i32 0, i32 16)
%19 = add nuw i64 %11, 1
%20 = getelementptr inbounds i8, i8* %1, i64 %11
store i8 %18, i8* %20
%21 = add nuw i64 %12, 2
%22 = trunc i64 %21 to i32
%23 = icmp slt i32 %22, %2
br i1 %23, label %10, label %24
24: ; preds = %10
%25 = trunc i64 %19 to i32
br label %26
26: ; preds = %24, %3
%27 = phi i32 [ 0, %3 ], [ %25, %24 ]
ret i32 %27
}