#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 char_value(char const);
int pair_value(const char *src, size_t id) {
  int i1 = char_value(src[id]);
  int i2 = char_value(src[id + 1]);
  if (i1 < 0 || i2 < 0)
    return -1;
  else
    return i1 * 16 + i2;
}


x86 assembly (clang, -O0):
<pair_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <char_value@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl 0x1(%rax,%rcx,1),%edi
call   1030 <char_value@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     115d <pair_value+0x4d>
cmpl   $0x0,-0x20(%rbp)
jge    1169 <pair_value+0x59>
movl   $0xffffffff,-0x4(%rbp)
jmp    1175 <pair_value+0x65>
mov    -0x1c(%rbp),%eax
shl    $0x4,%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pair_value>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
movsbl (%rdi,%rsi,1),%edi
call   1030 <char_value@plt>
mov    %eax,%ebp
movsbl 0x1(%rbx,%r14,1),%edi
call   1030 <char_value@plt>
mov    %ebp,%ecx
shl    $0x4,%ecx
add    %eax,%ecx
or     %eax,%ebp
mov    $0xffffffff,%eax
cmovns %ecx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @pair_value(i8* nocapture %0, i64 %1) {
%3 = getelementptr inbounds i8, i8* %0, i64 %1
%4 = load i8, i8* %3
%5 = tail call i32 @char_value(i8 signext %4)
%6 = add i64 %1, 1
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = load i8, i8* %7
%9 = tail call i32 @char_value(i8 signext %8)
%10 = icmp slt i32 %5, 0
%11 = icmp slt i32 %9, 0
%12 = select i1 %10, i1 true, i1 %11
%13 = shl nsw i32 %5, 4
%14 = add nsw i32 %9, %13
%15 = select i1 %12, i32 -1, i32 %14
ret i32 %15
}