#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 EOF;
int getchar();
int /*<<< orphan*/ printf(char *);
int getlinee(char s[], int lim) {
  int i, c;
  i = 0;
  while (i < lim - 1 && (c = getchar()) != EOF && c != '\n') {
    if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') ||
        (c >= 'A' && c <= 'F')) {
      s[i] = c;
      ++i;
    } else
      printf("This is not a hexadecimal number. Please enter a valid "
             "hexadecimal number\n");
  }
  return i - 1;
}


x86 assembly (clang, -O0):
<getlinee>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%ecx
mov    -0xc(%rbp),%edx
sub    $0x1,%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x15(%rbp)
jge    1176 <getlinee+0x56>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,%ecx
mov    %ecx,-0x14(%rbp)
xor    %eax,%eax
mov    0x2e87(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x15(%rbp)
je     1176 <getlinee+0x56>
cmpl   $0xa,-0x14(%rbp)
setne  %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    1186 <getlinee+0x66>
jmp    11f1 <getlinee+0xd1>
cmpl   $0x30,-0x14(%rbp)
jl     119a <getlinee+0x7a>
cmpl   $0x39,-0x14(%rbp)
jle    11c2 <getlinee+0xa2>
cmpl   $0x61,-0x14(%rbp)
jl     11ae <getlinee+0x8e>
cmpl   $0x66,-0x14(%rbp)
jle    11c2 <getlinee+0xa2>
cmpl   $0x41,-0x14(%rbp)
jl     11e0 <getlinee+0xc0>
cmpl   $0x46,-0x14(%rbp)
jg     11e0 <getlinee+0xc0>
mov    -0x14(%rbp),%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11ec <getlinee+0xcc>
lea    0xe19(%rip),%rdi
call   1030 <printf@plt>
jmp    1136 <getlinee+0x16>
mov    -0x10(%rbp),%eax
sub    $0x1,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getlinee>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %ebx,%ebx
cmp    $0x2,%esi
jl     11a4 <getlinee+0x84>
mov    %esi,%ebp
mov    %rdi,%r14
add    $0xffffffff,%ebp
mov    0x2ea7(%rip),%r12
lea    0xeb8(%rip),%r15
movabs $0x3f0000003f,%r13
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    $0xa,%eax
je     11a4 <getlinee+0x84>
cmp    (%r12),%eax
je     11a4 <getlinee+0x84>
lea    -0x30(%rax),%ecx
cmp    $0xa,%ecx
jb     1188 <getlinee+0x68>
lea    -0x41(%rax),%ecx
cmp    $0x25,%ecx
ja     1198 <getlinee+0x78>
bt     %rcx,%r13
jae    1198 <getlinee+0x78>
movslq %ebx,%rbx
mov    %al,(%r14,%rbx,1)
add    $0x1,%ebx
cmp    %ebp,%ebx
jl     1160 <getlinee+0x40>
jmp    11a4 <getlinee+0x84>
mov    %r15,%rdi
call   1030 <puts@plt>
cmp    %ebp,%ebx
jl     1160 <getlinee+0x40>
add    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i32 0
@.str = [75 x i8] c"This is not a hexadecimal number. Please enter a valid hexadecimal number\0A\00"
define i32 @getlinee(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 0, i32* %5
br label %7
7: ; preds = %50, %2
%8 = load i32, i32* %5
%9 = load i32, i32* %4
%10 = sub nsw i32 %9, 1
%11 = icmp slt i32 %8, %10
br i1 %11, label %12, label %19
12: ; preds = %7
%13 = call i32 (...) @getchar()
store i32 %13, i32* %6
%14 = load i32, i32* @EOF
%15 = icmp ne i32 %13, %14
br i1 %15, label %16, label %19
16: ; preds = %12
%17 = load i32, i32* %6
%18 = icmp ne i32 %17, 10
br label %19
19: ; preds = %16, %12, %7
%20 = phi i1 [ false, %12 ], [ false, %7 ], [ %18, %16 ]
br i1 %20, label %21, label %51
21: ; preds = %19
%22 = load i32, i32* %6
%23 = icmp sge i32 %22, 48
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = load i32, i32* %6
%26 = icmp sle i32 %25, 57
br i1 %26, label %39, label %27
27: ; preds = %24, %21
%28 = load i32, i32* %6
%29 = icmp sge i32 %28, 97
br i1 %29, label %30, label %33
30: ; preds = %27
%31 = load i32, i32* %6
%32 = icmp sle i32 %31, 102
br i1 %32, label %39, label %33
33: ; preds = %30, %27
%34 = load i32, i32* %6
%35 = icmp sge i32 %34, 65
br i1 %35, label %36, label %48
36: ; preds = %33
%37 = load i32, i32* %6
%38 = icmp sle i32 %37, 70
br i1 %38, label %39, label %48
39: ; preds = %36, %30, %24
%40 = load i32, i32* %6
%41 = trunc i32 %40 to i8
%42 = load i8*, i8** %3
%43 = load i32, i32* %5
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %42, i64 %44
store i8 %41, i8* %45
%46 = load i32, i32* %5
%47 = add nsw i32 %46, 1
store i32 %47, i32* %5
br label %50
48: ; preds = %36, %33
%49 = call i32 @printf(i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str, i64 0, i64 0))
br label %50
50: ; preds = %48, %39
br label %7
51: ; preds = %19
%52 = load i32, i32* %5
%53 = sub nsw i32 %52, 1
ret i32 %53
}

LLVM IR (-O2):
@EOF = global i32 0
@str = [74 x i8] c"This is not a hexadecimal number. Please enter a valid hexadecimal number\00"
define i32 @getlinee(i8* nocapture writeonly %0, i32 %1) {
%3 = add nsw i32 %1, -1
%4 = icmp sgt i32 %1, 1
br i1 %4, label %5, label %26
5: ; preds = %2, %23
%6 = phi i32 [ %24, %23 ], [ 0, %2 ]
%7 = tail call i32 (...) @getchar()
%8 = load i32, i32* @EOF
%9 = icmp ne i32 %7, %8
%10 = icmp ne i32 %7, 10
%11 = and i1 %10, %9
br i1 %11, label %12, label %26
12: ; preds = %5
%13 = add i32 %7, -48
%14 = icmp ult i32 %13, 10
br i1 %14, label %16, label %15
15: ; preds = %12
switch i32 %7, label %21 [
i32 102, label %16
i32 101, label %16
i32 100, label %16
i32 99, label %16
i32 98, label %16
i32 97, label %16
i32 70, label %16
i32 69, label %16
i32 68, label %16
i32 67, label %16
i32 66, label %16
i32 65, label %16
]
16: ; preds = %15, %15, %15, %15, %15, %15, %15, %15, %15, %15, %15, %15, %12
%17 = trunc i32 %7 to i8
%18 = sext i32 %6 to i64
%19 = getelementptr inbounds i8, i8* %0, i64 %18
store i8 %17, i8* %19
%20 = add nsw i32 %6, 1
br label %23
21: ; preds = %15
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([74 x i8], [74 x i8]* @str, i64 0, i64 0))
br label %23
23: ; preds = %21, %16
%24 = phi i32 [ %20, %16 ], [ %6, %21 ]
%25 = icmp slt i32 %24, %3
br i1 %25, label %5, label %26
26: ; preds = %5, %23, %2
%27 = phi i32 [ 0, %2 ], [ %24, %23 ], [ %6, %5 ]
%28 = add nsw i32 %27, -1
ret i32 %28
}