#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 */
typedef int uint8_t;

/* Variables and functions */
int get_value(char const);
int strtobyte(const char *str, uint8_t *byte) {
  uint8_t total = 0;
  uint8_t part;
  part = get_value(str[0]);
  if (part > 15) {
    return 1;
  }
  total += 0x10 * part;
  part = get_value(str[1]);
  if (part > 15) {
    return 1;
  }
  total += part;
  *byte = total;
  return 0;
}


x86 assembly (clang, -O0):
<strtobyte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <get_value@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xf,-0x20(%rbp)
jle    114c <strtobyte+0x3c>
movl   $0x1,-0x4(%rbp)
jmp    1197 <strtobyte+0x87>
mov    -0x20(%rbp),%eax
shl    $0x4,%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1030 <get_value@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xf,-0x20(%rbp)
jle    117e <strtobyte+0x6e>
movl   $0x1,-0x4(%rbp)
jmp    1197 <strtobyte+0x87>
mov    -0x20(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strtobyte>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbp
movsbl (%rdi),%edi
call   1030 <get_value@plt>
mov    $0x1,%r15d
cmp    $0xf,%eax
jg     114b <strtobyte+0x3b>
mov    %eax,%ebx
movsbl 0x1(%rbp),%edi
call   1030 <get_value@plt>
cmp    $0xf,%eax
jg     114b <strtobyte+0x3b>
shl    $0x4,%ebx
add    %ebx,%eax
mov    %eax,(%r14)
xor    %r15d,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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