#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 */
char blocking_read();
char parse_ascii_hex(char);
int /*<<< orphan*/ wload_calc_checksum(int);
int readword_le() {
  char buf, i;
  int valbuf = 0;
  for (i = 7; i >= 0; i--) {
    while ((buf = blocking_read()) == ' ')
      ;
    valbuf |= (parse_ascii_hex(buf) << (i * 4));
  }
  wload_calc_checksum(valbuf);
  return valbuf;
}


x86 assembly (clang, -O0):
<readword_le>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x8(%rbp)
movb   $0x7,-0x2(%rbp)
movsbl -0x2(%rbp),%eax
cmp    $0x0,%eax
jl     1198 <readword_le+0x68>
jmp    1155 <readword_le+0x25>
mov    $0x0,%al
call   1050 <blocking_read@plt>
mov    %al,-0x1(%rbp)
movsbl %al,%eax
cmp    $0x20,%eax
jne    1170 <readword_le+0x40>
jmp    1155 <readword_le+0x25>
movsbl -0x1(%rbp),%edi
call   1030 <parse_ascii_hex@plt>
movsbl %al,%eax
movsbl -0x2(%rbp),%ecx
shl    $0x2,%ecx
shl    %cl,%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x2(%rbp),%al
add    $0xff,%al
mov    %al,-0x2(%rbp)
jmp    1143 <readword_le+0x13>
mov    -0x8(%rbp),%edi
call   1040 <wload_calc_checksum@plt>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readword_le>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <blocking_read@plt>
cmp    $0x20,%al
je     1140 <readword_le+0x10>
movsbl %al,%edi
call   1030 <parse_ascii_hex@plt>
mov    %al,0x7(%rsp)
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <blocking_read@plt>
cmp    $0x20,%al
je     1160 <readword_le+0x30>
movsbl %al,%edi
call   1030 <parse_ascii_hex@plt>
mov    %eax,%r14d
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <blocking_read@plt>
cmp    $0x20,%al
je     1180 <readword_le+0x50>
movsbl %al,%edi
call   1030 <parse_ascii_hex@plt>
mov    %eax,%r15d
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <blocking_read@plt>
cmp    $0x20,%al
je     11a0 <readword_le+0x70>
movsbl %al,%edi
call   1030 <parse_ascii_hex@plt>
mov    %eax,%r12d
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <blocking_read@plt>
cmp    $0x20,%al
je     11c0 <readword_le+0x90>
movsbl %al,%edi
call   1030 <parse_ascii_hex@plt>
mov    %eax,%r13d
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <blocking_read@plt>
cmp    $0x20,%al
je     11e0 <readword_le+0xb0>
movsbl %al,%edi
call   1030 <parse_ascii_hex@plt>
mov    %eax,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1050 <blocking_read@plt>
cmp    $0x20,%al
je     1200 <readword_le+0xd0>
movsbl %al,%edi
call   1030 <parse_ascii_hex@plt>
mov    %eax,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1050 <blocking_read@plt>
cmp    $0x20,%al
je     1220 <readword_le+0xf0>
movsbl %bpl,%ecx
shl    $0x4,%ecx
movsbl %bl,%edx
shl    $0x8,%edx
movsbl %r13b,%esi
shl    $0xc,%esi
or     %edx,%esi
or     %ecx,%esi
movsbl %r12b,%ecx
shl    $0x10,%ecx
movsbl %r15b,%edx
shl    $0x14,%edx
or     %ecx,%edx
movzbl %r14b,%ecx
shl    $0x18,%ecx
movzbl 0x7(%rsp),%ebp
shl    $0x1c,%ebp
or     %ecx,%ebp
or     %edx,%ebp
or     %esi,%ebp
movsbl %al,%edi
call   1030 <parse_ascii_hex@plt>
movsbl %al,%ebx
or     %ebp,%ebx
mov    %ebx,%edi
call   1040 <wload_calc_checksum@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @readword_le() {
%1 = alloca i8
%2 = alloca i8
%3 = alloca i32
store i32 0, i32* %3
store i8 7, i8* %2
br label %4
4: ; preds = %24, %0
%5 = load i8, i8* %2
%6 = sext i8 %5 to i32
%7 = icmp sge i32 %6, 0
br i1 %7, label %8, label %27
8: ; preds = %4
br label %9
9: ; preds = %13, %8
%10 = call signext i8 (...) @blocking_read()
store i8 %10, i8* %1
%11 = sext i8 %10 to i32
%12 = icmp eq i32 %11, 32
br i1 %12, label %13, label %14
13: ; preds = %9
br label %9
14: ; preds = %9
%15 = load i8, i8* %1
%16 = call signext i8 @parse_ascii_hex(i8 signext %15)
%17 = sext i8 %16 to i32
%18 = load i8, i8* %2
%19 = sext i8 %18 to i32
%20 = mul nsw i32 %19, 4
%21 = shl i32 %17, %20
%22 = load i32, i32* %3
%23 = or i32 %22, %21
store i32 %23, i32* %3
br label %24
24: ; preds = %14
%25 = load i8, i8* %2
%26 = add i8 %25, -1
store i8 %26, i8* %2
br label %4
27: ; preds = %4
%28 = load i32, i32* %3
%29 = call i32 @wload_calc_checksum(i32 %28)
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
define i32 @readword_le() {
br label %1
1: ; preds = %0, %1
%2 = tail call signext i8 (...) @blocking_read()
%3 = icmp eq i8 %2, 32
br i1 %3, label %1, label %4
4: ; preds = %1
%5 = tail call signext i8 @parse_ascii_hex(i8 signext %2)
br label %6
6: ; preds = %6, %4
%7 = tail call signext i8 (...) @blocking_read()
%8 = icmp eq i8 %7, 32
br i1 %8, label %6, label %9
9: ; preds = %6
%10 = tail call signext i8 @parse_ascii_hex(i8 signext %7)
br label %11
11: ; preds = %11, %9
%12 = tail call signext i8 (...) @blocking_read()
%13 = icmp eq i8 %12, 32
br i1 %13, label %11, label %14
14: ; preds = %11
%15 = tail call signext i8 @parse_ascii_hex(i8 signext %12)
br label %16
16: ; preds = %16, %14
%17 = tail call signext i8 (...) @blocking_read()
%18 = icmp eq i8 %17, 32
br i1 %18, label %16, label %19
19: ; preds = %16
%20 = tail call signext i8 @parse_ascii_hex(i8 signext %17)
br label %21
21: ; preds = %21, %19
%22 = tail call signext i8 (...) @blocking_read()
%23 = icmp eq i8 %22, 32
br i1 %23, label %21, label %24
24: ; preds = %21
%25 = tail call signext i8 @parse_ascii_hex(i8 signext %22)
br label %26
26: ; preds = %26, %24
%27 = tail call signext i8 (...) @blocking_read()
%28 = icmp eq i8 %27, 32
br i1 %28, label %26, label %29
29: ; preds = %26
%30 = tail call signext i8 @parse_ascii_hex(i8 signext %27)
br label %31
31: ; preds = %31, %29
%32 = tail call signext i8 (...) @blocking_read()
%33 = icmp eq i8 %32, 32
br i1 %33, label %31, label %34
34: ; preds = %31
%35 = tail call signext i8 @parse_ascii_hex(i8 signext %32)
br label %36
36: ; preds = %36, %34
%37 = tail call signext i8 (...) @blocking_read()
%38 = icmp eq i8 %37, 32
br i1 %38, label %36, label %39
39: ; preds = %36
%40 = sext i8 %35 to i32
%41 = shl nsw i32 %40, 4
%42 = sext i8 %30 to i32
%43 = shl nsw i32 %42, 8
%44 = sext i8 %25 to i32
%45 = shl nsw i32 %44, 12
%46 = sext i8 %20 to i32
%47 = shl nsw i32 %46, 16
%48 = sext i8 %15 to i32
%49 = shl nsw i32 %48, 20
%50 = zext i8 %10 to i32
%51 = shl nuw i32 %50, 24
%52 = zext i8 %5 to i32
%53 = shl i32 %52, 28
%54 = or i32 %51, %53
%55 = or i32 %49, %54
%56 = or i32 %47, %55
%57 = or i32 %45, %56
%58 = or i32 %43, %57
%59 = or i32 %41, %58
%60 = tail call signext i8 @parse_ascii_hex(i8 signext %37)
%61 = sext i8 %60 to i32
%62 = or i32 %59, %61
%63 = tail call i32 @wload_calc_checksum(i32 %62)
ret i32 %62
}