#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 /*<<< orphan*/ ASM(char *);
unsigned char get_nibble();
int /*<<< orphan*/ print_string(char *);
int get_byte() {
  unsigned char hi = get_nibble();
  unsigned char lo;
  if (hi != 0xFF) {
    lo = get_nibble();
    if (lo != 0xFF)
      return (hi << 4) | lo;
  }
  print_string("\r\nERROR: not hex\r\n");
  ASM(" HALT");
}


x86 assembly (clang, -O0):
<get_byte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1040 <get_nibble@plt>
mov    %al,-0x5(%rbp)
movzbl -0x5(%rbp),%eax
cmp    $0xff,%eax
je     1184 <get_byte+0x54>
mov    $0x0,%al
call   1040 <get_nibble@plt>
mov    %al,-0x6(%rbp)
movzbl -0x6(%rbp),%eax
cmp    $0xff,%eax
je     117f <get_byte+0x4f>
movzbl -0x5(%rbp),%eax
shl    $0x4,%eax
movzbl -0x6(%rbp),%ecx
or     %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    119c <get_byte+0x6c>
jmp    1184 <get_byte+0x54>
lea    0xe75(%rip),%rdi
call   1030 <print_string@plt>
lea    0xe7c(%rip),%rdi
call   1050 <ASM@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_byte>:
push   %rbx
xor    %eax,%eax
call   1040 <get_nibble@plt>
cmp    $0xff,%al
je     1158 <get_byte+0x28>
mov    %eax,%ebx
xor    %eax,%eax
call   1040 <get_nibble@plt>
cmp    $0xff,%al
je     1158 <get_byte+0x28>
mov    %eax,%ecx
movzbl %bl,%eax
movzbl %cl,%ecx
shl    $0x4,%eax
or     %ecx,%eax
pop    %rbx
ret
lea    0xea1(%rip),%rdi
call   1030 <print_string@plt>
lea    0xea8(%rip),%rdi
call   1050 <ASM@plt>
pop    %rbx
ret

LLVM IR (-O0):
@.str = [19 x i8] c"\0D\0AERROR: not hex\0D\0A\00"
@.str.1 = [6 x i8] c" HALT\00"
define i32 @get_byte() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca i8
%4 = call zeroext i8 (...) @get_nibble()
store i8 %4, i8* %2
%5 = load i8, i8* %2
%6 = zext i8 %5 to i32
%7 = icmp ne i32 %6, 255
br i1 %7, label %8, label %21
8: ; preds = %0
%9 = call zeroext i8 (...) @get_nibble()
store i8 %9, i8* %3
%10 = load i8, i8* %3
%11 = zext i8 %10 to i32
%12 = icmp ne i32 %11, 255
br i1 %12, label %13, label %20
13: ; preds = %8
%14 = load i8, i8* %2
%15 = zext i8 %14 to i32
%16 = shl i32 %15, 4
%17 = load i8, i8* %3
%18 = zext i8 %17 to i32
%19 = or i32 %16, %18
store i32 %19, i32* %1
br label %24
20: ; preds = %8
br label %21
21: ; preds = %20, %0
%22 = call i32 @print_string(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%23 = call i32 @ASM(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %24
24: ; preds = %21, %13
%25 = load i32, i32* %1
ret i32 %25
}

LLVM IR (-O2):
@.str = [19 x i8] c"\0D\0AERROR: not hex\0D\0A\00"
@.str.1 = [6 x i8] c" HALT\00"
define i32 @get_byte() {
%1 = tail call zeroext i8 (...) @get_nibble()
%2 = zext i8 %1 to i32
%3 = icmp eq i8 %1, -1
br i1 %3, label %11, label %4
4: ; preds = %0
%5 = tail call zeroext i8 (...) @get_nibble()
%6 = icmp eq i8 %5, -1
br i1 %6, label %11, label %7
7: ; preds = %4
%8 = zext i8 %5 to i32
%9 = shl nuw nsw i32 %2, 4
%10 = or i32 %9, %8
br label %14
11: ; preds = %4, %0
%12 = tail call i32 @print_string(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 @ASM(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %11, %7
%15 = phi i32 [ %10, %7 ], [ undef, %11 ]
ret i32 %15
}