#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 numeric(unsigned char);
void mkbin(unsigned char *to, unsigned char *s) {
  int byte1, byte2;
  for (; *s != '\0'; ++s) {
    byte1 = numeric(*s++);
    byte2 = numeric(*s);
    byte1 = byte1 << 4 | byte2;
    *to++ = byte1;
    if (*s == '\0')
      return;
  }
}


x86 assembly (clang, -O0):
<mkbin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x0,%eax
je     11a6 <mkbin+0x96>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movzbl (%rax),%edi
call   1030 <numeric@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movzbl (%rax),%edi
call   1030 <numeric@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
shl    $0x4,%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x0,%eax
jne    1190 <mkbin+0x80>
jmp    11a6 <mkbin+0x96>
jmp    1195 <mkbin+0x85>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1120 <mkbin+0x10>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mkbin>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    (%rsi),%al
test   %al,%al
je     1164 <mkbin+0x54>
mov    %rsi,%r15
mov    %rdi,%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
movzbl %al,%edi
call   1030 <numeric@plt>
mov    %eax,%ebp
movzbl 0x1(%r15,%rbx,2),%edi
call   1030 <numeric@plt>
shl    $0x4,%ebp
or     %eax,%ebp
mov    %bpl,(%r14,%rbx,1)
cmpb   $0x0,0x1(%r15,%rbx,2)
je     1164 <mkbin+0x54>
movzbl 0x2(%r15,%rbx,2),%eax
add    $0x1,%rbx
test   %al,%al
jne    1130 <mkbin+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @mkbin(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
br label %7
7: ; preds = %34, %2
%8 = load i8*, i8** %4
%9 = load i8, i8* %8
%10 = zext i8 %9 to i32
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %37
12: ; preds = %7
%13 = load i8*, i8** %4
%14 = getelementptr inbounds i8, i8* %13, i32 1
store i8* %14, i8** %4
%15 = load i8, i8* %13
%16 = call i32 @numeric(i8 zeroext %15)
store i32 %16, i32* %5
%17 = load i8*, i8** %4
%18 = load i8, i8* %17
%19 = call i32 @numeric(i8 zeroext %18)
store i32 %19, i32* %6
%20 = load i32, i32* %5
%21 = shl i32 %20, 4
%22 = load i32, i32* %6
%23 = or i32 %21, %22
store i32 %23, i32* %5
%24 = load i32, i32* %5
%25 = trunc i32 %24 to i8
%26 = load i8*, i8** %3
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %3
store i8 %25, i8* %26
%28 = load i8*, i8** %4
%29 = load i8, i8* %28
%30 = zext i8 %29 to i32
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %12
br label %37
33: ; preds = %12
br label %34
34: ; preds = %33
%35 = load i8*, i8** %4
%36 = getelementptr inbounds i8, i8* %35, i32 1
store i8* %36, i8** %4
br label %7
37: ; preds = %32, %7
ret void
}

LLVM IR (-O2):
define void @mkbin(i8* nocapture writeonly %0, i8* nocapture %1) {
%3 = load i8, i8* %1
%4 = icmp eq i8 %3, 0
br i1 %4, label %23, label %5
5: ; preds = %2, %18
%6 = phi i8 [ %21, %18 ], [ %3, %2 ]
%7 = phi i8* [ %19, %18 ], [ %0, %2 ]
%8 = phi i8* [ %20, %18 ], [ %1, %2 ]
%9 = getelementptr inbounds i8, i8* %8, i64 1
%10 = tail call i32 @numeric(i8 zeroext %6)
%11 = load i8, i8* %9
%12 = tail call i32 @numeric(i8 zeroext %11)
%13 = shl i32 %10, 4
%14 = or i32 %12, %13
%15 = trunc i32 %14 to i8
store i8 %15, i8* %7
%16 = load i8, i8* %9
%17 = icmp eq i8 %16, 0
br i1 %17, label %23, label %18
18: ; preds = %5
%19 = getelementptr inbounds i8, i8* %7, i64 1
%20 = getelementptr inbounds i8, i8* %8, i64 2
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 0
br i1 %22, label %23, label %5
23: ; preds = %5, %18, %2
ret void
}