#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 ascii2bin(char *a, char *b, int sa) {
  int sb = sa / 2;
  int i;
  unsigned int v;
  for (i = 0; i < sb; i++) {
    sscanf(a + i * 2, "%2x", &v);
    b[i] = v;
  }
}


x86 assembly (clang, -O0):
<ascii2bin>:
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    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1181 <ascii2bin+0x71>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%eax
shl    $0x1,%eax
cltq
add    %rax,%rdi
lea    0xea6(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1030 <sscanf@plt>
mov    -0x20(%rbp),%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1138 <ascii2bin+0x28>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ascii2bin>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%edx
jl     1164 <ascii2bin+0x54>
mov    %edx,%r15d
mov    %rsi,%r14
mov    %rdi,%rbx
shr    %r15d
xor    %ebp,%ebp
lea    0xecb(%rip),%r12
lea    0x4(%rsp),%r13
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
call   1030 <sscanf@plt>
movzbl 0x4(%rsp),%eax
mov    %al,(%r14,%rbp,1)
add    $0x1,%rbp
add    $0x2,%rbx
cmp    %rbp,%r15
jne    1140 <ascii2bin+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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