#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 hex(unsigned char);
int hex2(unsigned char *p) {
  int i;
  unsigned char c;
  i = hex(*p++);
  if (i < 0)
    return i;
  c = (i << 4);
  i = hex(*p);
  if (i < 0)
    return i;
  return c | i;
}


x86 assembly (clang, -O0):
<hex2>:
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)
movzbl (%rax),%edi
call   1030 <hex@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    114b <hex2+0x3b>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1182 <hex2+0x72>
mov    -0x14(%rbp),%eax
shl    $0x4,%eax
mov    %al,-0x15(%rbp)
mov    -0x10(%rbp),%rax
movzbl (%rax),%edi
call   1030 <hex@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1178 <hex2+0x68>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1182 <hex2+0x72>
movzbl -0x15(%rbp),%eax
or     -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex2>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
movzbl (%rdi),%edi
call   1030 <hex@plt>
mov    %eax,%ebx
test   %eax,%eax
js     113d <hex2+0x2d>
movzbl 0x1(%r14),%edi
call   1030 <hex@plt>
test   %eax,%eax
js     113b <hex2+0x2b>
shl    $0x4,%ebx
movzbl %bl,%ecx
or     %ecx,%eax
mov    %eax,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @hex2(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8
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 @hex(i8 zeroext %8)
store i32 %9, i32* %4
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %1
%13 = load i32, i32* %4
store i32 %13, i32* %2
br label %30
14: ; preds = %1
%15 = load i32, i32* %4
%16 = shl i32 %15, 4
%17 = trunc i32 %16 to i8
store i8 %17, i8* %5
%18 = load i8*, i8** %3
%19 = load i8, i8* %18
%20 = call i32 @hex(i8 zeroext %19)
store i32 %20, i32* %4
%21 = load i32, i32* %4
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %14
%24 = load i32, i32* %4
store i32 %24, i32* %2
br label %30
25: ; preds = %14
%26 = load i8, i8* %5
%27 = zext i8 %26 to i32
%28 = load i32, i32* %4
%29 = or i32 %27, %28
store i32 %29, i32* %2
br label %30
30: ; preds = %25, %23, %12
%31 = load i32, i32* %2
ret i32 %31
}

LLVM IR (-O2):
define i32 @hex2(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = tail call i32 @hex(i8 zeroext %2)
%4 = icmp slt i32 %3, 0
br i1 %4, label %14, label %5
5: ; preds = %1
%6 = getelementptr inbounds i8, i8* %0, i64 1
%7 = load i8, i8* %6
%8 = tail call i32 @hex(i8 zeroext %7)
%9 = icmp slt i32 %8, 0
br i1 %9, label %14, label %10
10: ; preds = %5
%11 = shl i32 %3, 4
%12 = and i32 %11, 240
%13 = or i32 %8, %12
br label %14
14: ; preds = %5, %1, %10
%15 = phi i32 [ %13, %10 ], [ %3, %1 ], [ %8, %5 ]
ret i32 %15
}