#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 strlen(char *);
char strtol(char *, char **, int);
void char2buf(char *sBuf, char *dBuf) {
  int i;
  char buf[3] = {0x1, 0x2, 0x0};
  char *p, *pend;
  p = sBuf;
  int len = strlen(sBuf) / 2;
  for (i = 0; i < len; i++) {
    buf[0] = *p;
    p++;
    buf[1] = *p;
    p++;
    dBuf[i] = strtol(buf, &pend, 16);
  }
  dBuf[len] = 0x0;
}


x86 assembly (clang, -O0):
<char2buf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xec9(%rip),%ax
mov    %ax,-0x17(%rbp)
mov    0xec1(%rip),%al
mov    %al,-0x15(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x2c(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    11ca <char2buf+0xaa>
mov    -0x20(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x17(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x16(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
lea    -0x17(%rbp),%rdi
lea    -0x28(%rbp),%rsi
mov    $0x10,%edx
call   1040 <strtol@plt>
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1167 <char2buf+0x47>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<char2buf>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
movb   $0x0,0xa(%rsp)
movw   $0x201,0x8(%rsp)
call   1030 <strlen@plt>
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
mov    %ecx,0xc(%rsp)
cmp    $0x2,%eax
jl     11a0 <char2buf+0x80>
mov    0xc(%rsp),%ebp
xor    %r13d,%r13d
lea    0x8(%rsp),%r15
lea    0x10(%rsp),%r12
nopl   0x0(%rax,%rax,1)
movzbl (%rbx,%r13,2),%eax
mov    %al,0x8(%rsp)
movzbl 0x1(%rbx,%r13,2),%eax
mov    %al,0x9(%rsp)
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0x10,%edx
call   1040 <strtol@plt>
mov    %al,(%r14,%r13,1)
add    $0x1,%r13
cmp    %r13,%rbp
jne    1170 <char2buf+0x50>
movslq 0xc(%rsp),%rax
movb   $0x0,(%r14,%rax,1)
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@__const.char2buf.buf = [3 x i8] c"\01\02\00"
define void @char2buf(i8* %0, i8* nocapture writeonly %1) {
%3 = alloca [3 x i8]
%4 = alloca i8*
%5 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%6 = bitcast i8** %4 to i8*
%7 = tail call i32 @strlen(i8* %0)
%8 = sdiv i32 %7, 2
%9 = icmp sgt i32 %7, 1
br i1 %9, label %10, label %24
10: ; preds = %2
%11 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 1
%12 = zext i32 %8 to i64
br label %13
13: ; preds = %10, %13
%14 = phi i64 [ 0, %10 ], [ %22, %13 ]
%15 = phi i8* [ %0, %10 ], [ %19, %13 ]
%16 = load i8, i8* %15
store i8 %16, i8* %5
%17 = getelementptr inbounds i8, i8* %15, i64 1
%18 = load i8, i8* %17
store i8 %18, i8* %11
%19 = getelementptr inbounds i8, i8* %15, i64 2
%20 = call signext i8 @strtol(i8* %5, i8** %4, i32 16)
%21 = getelementptr inbounds i8, i8* %1, i64 %14
store i8 %20, i8* %21
%22 = add nuw nsw i64 %14, 1
%23 = icmp eq i64 %22, %12
br i1 %23, label %24, label %13
24: ; preds = %13, %2
%25 = sext i32 %8 to i64
%26 = getelementptr inbounds i8, i8* %1, i64 %25
store i8 0, i8* %26
ret void
}