#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 getLine(char *, int);
int isHexString(char *);
int /*<<< orphan*/ printf(char *, ...);
void getHexString(char hex[7]) {
  int length;
  while (length != 6) {
    printf("Enter hex string > ");
    length = getLine(hex, 7);
    if (length < 6)
      printf("*** Error - Hex string must be 6 chars long ***\n");
    if (isHexString(hex) == -1) {
      printf("*** Error - %s is not a valid hex string ***\n", hex);
      length = 0;
    }
  }
}


x86 assembly (clang, -O0):
<getHexString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
cmpl   $0x6,-0xc(%rbp)
je     11ad <getHexString+0x7d>
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    $0x7,%esi
call   1040 <getLine@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x6,-0xc(%rbp)
jge    117d <getHexString+0x4d>
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1050 <isHexString@plt>
cmp    $0xffffffff,%eax
jne    11a8 <getHexString+0x78>
mov    -0x8(%rbp),%rsi
lea    0xeab(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
jmp    113c <getHexString+0xc>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getHexString>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%rbx
lea    0xeae(%rip),%r14
lea    0xee9(%rip),%r15
lea    0xeb4(%rip),%r12
jmp    1182 <getHexString+0x42>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1060 <isHexString@plt>
cmp    $0xffffffff,%eax
je     11b0 <getHexString+0x70>
cmp    $0x6,%ebp
je     11c4 <getHexString+0x84>
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x7,%esi
call   1050 <getLine@plt>
mov    %eax,%ebp
cmp    $0x5,%eax
jg     1170 <getHexString+0x30>
mov    %r15,%rdi
call   1030 <puts@plt>
jmp    1170 <getHexString+0x30>
nopw   0x0(%rax,%rax,1)
xor    %ebp,%ebp
mov    %r12,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x6,%ebp
jne    1182 <getHexString+0x42>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"Enter hex string > \00"
@.str.1 = [49 x i8] c"*** Error - Hex string must be 6 chars long ***\0A\00"
@.str.2 = [46 x i8] c"*** Error - %s is not a valid hex string ***\0A\00"
define void @getHexString(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
br label %4
4: ; preds = %22, %1
%5 = load i32, i32* %3
%6 = icmp ne i32 %5, 6
br i1 %6, label %7, label %23
7: ; preds = %4
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%9 = load i8*, i8** %2
%10 = call i32 @getLine(i8* %9, i32 7)
store i32 %10, i32* %3
%11 = load i32, i32* %3
%12 = icmp slt i32 %11, 6
br i1 %12, label %13, label %15
13: ; preds = %7
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %13, %7
%16 = load i8*, i8** %2
%17 = call i32 @isHexString(i8* %16)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %22
19: ; preds = %15
%20 = load i8*, i8** %2
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0), i8* %20)
store i32 0, i32* %3
br label %22
22: ; preds = %19, %15
br label %4
23: ; preds = %4
ret void
}

LLVM IR (-O2):
@.str = [20 x i8] c"Enter hex string > \00"
@.str.2 = [46 x i8] c"*** Error - %s is not a valid hex string ***\0A\00"
@str = [48 x i8] c"*** Error - Hex string must be 6 chars long ***\00"
define void @getHexString(i8* %0) {
br label %2
2: ; preds = %1, %13
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 @getLine(i8* %0, i32 7)
%5 = icmp slt i32 %4, 6
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @str, i64 0, i64 0))
br label %8
8: ; preds = %6, %2
%9 = tail call i32 @isHexString(i8* %0)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %13
13: ; preds = %11, %8
%14 = phi i32 [ 0, %11 ], [ %4, %8 ]
%15 = icmp eq i32 %14, 6
br i1 %15, label %16, label %2
16: ; preds = %13
ret void
}