#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 HexDecode(char);
int BSXEncodePair(char *buf) {
  int result;
  int v;
  v = HexDecode(*buf++);
  if (v == -1)
    return (-1);
  result = v * 16;
  v = HexDecode(*buf);
  if (v == -1)
    return (-1);
  result = result + v;
  return (result);
}


x86 assembly (clang, -O0):
<BSXEncodePair>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl (%rax),%edi
call   1030 <HexDecode@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    114c <BSXEncodePair+0x3c>
movl   $0xffffffff,-0x4(%rbp)
jmp    1189 <BSXEncodePair+0x79>
mov    -0x18(%rbp),%eax
shl    $0x4,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <HexDecode@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    117a <BSXEncodePair+0x6a>
movl   $0xffffffff,-0x4(%rbp)
jmp    1189 <BSXEncodePair+0x79>
mov    -0x14(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BSXEncodePair>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
movsbl (%rdi),%edi
call   1030 <HexDecode@plt>
mov    $0xffffffff,%r14d
cmp    $0xffffffff,%eax
je     1142 <BSXEncodePair+0x32>
mov    %eax,%ebp
movsbl 0x1(%rbx),%edi
call   1030 <HexDecode@plt>
cmp    $0xffffffff,%eax
je     1142 <BSXEncodePair+0x32>
shl    $0x4,%ebp
add    %ebp,%eax
mov    %eax,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @BSXEncodePair(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = getelementptr inbounds i8, i8* %6, i32 1
store i8* %7, i8** %3
%8 = load i8, i8* %6
%9 = call i32 @HexDecode(i8 signext %8)
store i32 %9, i32* %5
%10 = load i32, i32* %5
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %13
12: ; preds = %1
store i32 -1, i32* %2
br label %27
13: ; preds = %1
%14 = load i32, i32* %5
%15 = mul nsw i32 %14, 16
store i32 %15, i32* %4
%16 = load i8*, i8** %3
%17 = load i8, i8* %16
%18 = call i32 @HexDecode(i8 signext %17)
store i32 %18, i32* %5
%19 = load i32, i32* %5
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %22
21: ; preds = %13
store i32 -1, i32* %2
br label %27
22: ; preds = %13
%23 = load i32, i32* %4
%24 = load i32, i32* %5
%25 = add nsw i32 %23, %24
store i32 %25, i32* %4
%26 = load i32, i32* %4
store i32 %26, i32* %2
br label %27
27: ; preds = %22, %21, %12
%28 = load i32, i32* %2
ret i32 %28
}

LLVM IR (-O2):
define i32 @BSXEncodePair(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = tail call i32 @HexDecode(i8 signext %2)
%4 = icmp eq i32 %3, -1
br i1 %4, label %13, label %5
5: ; preds = %1
%6 = getelementptr inbounds i8, i8* %0, i64 1
%7 = load i8, i8* %6
%8 = tail call i32 @HexDecode(i8 signext %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %13, label %10
10: ; preds = %5
%11 = shl nsw i32 %3, 4
%12 = add nsw i32 %8, %11
br label %13
13: ; preds = %5, %1, %10
%14 = phi i32 [ %12, %10 ], [ -1, %1 ], [ -1, %5 ]
ret i32 %14
}