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


x86 assembly (clang, -O0):
<readword_be>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x8(%rbp)
movb   $0x0,-0x2(%rbp)
movsbl -0x2(%rbp),%eax
cmp    $0x4,%eax
jge    11d1 <readword_be+0xa1>
jmp    1155 <readword_be+0x25>
mov    $0x0,%al
call   1050 <blocking_read@plt>
mov    %al,-0x1(%rbp)
movsbl %al,%eax
cmp    $0x20,%eax
jne    1170 <readword_be+0x40>
jmp    1155 <readword_be+0x25>
movsbl -0x1(%rbp),%edi
call   1030 <parse_ascii_hex@plt>
movsbl %al,%eax
movsbl -0x2(%rbp),%ecx
shl    $0x3,%ecx
add    $0x4,%ecx
shl    %cl,%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1050 <blocking_read@plt>
mov    %al,-0x1(%rbp)
movsbl %al,%eax
cmp    $0x20,%eax
jne    11a9 <readword_be+0x79>
jmp    118e <readword_be+0x5e>
movsbl -0x1(%rbp),%edi
call   1030 <parse_ascii_hex@plt>
movsbl %al,%eax
movsbl -0x2(%rbp),%ecx
shl    $0x3,%ecx
shl    %cl,%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x2(%rbp),%al
add    $0x1,%al
mov    %al,-0x2(%rbp)
jmp    1143 <readword_be+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_be>:
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_be+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_be+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_be+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_be+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_be+0x90>
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     11e0 <readword_be+0xb0>
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     1200 <readword_be+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_be+0xf0>
movzbl %bpl,%ebp
movsbl %bl,%ecx
shl    $0x14,%ecx
movsbl %r15b,%edx
shl    $0xc,%edx
movsbl 0x7(%rsp),%esi
shl    $0x4,%esi
movsbl %r14b,%edi
or     %esi,%edi
movsbl %r12b,%esi
shl    $0x8,%esi
or     %edx,%esi
or     %edi,%esi
movsbl %r13b,%edx
shl    $0x10,%edx
or     %ecx,%edx
shl    $0x1c,%ebp
or     %edx,%ebp
or     %esi,%ebp
movsbl %al,%edi
call   1030 <parse_ascii_hex@plt>
movzbl %al,%ebx
shl    $0x18,%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_be() {
%1 = alloca i8
%2 = alloca i8
%3 = alloca i32
store i32 0, i32* %3
store i8 0, i8* %2
br label %4
4: ; preds = %40, %0
%5 = load i8, i8* %2
%6 = sext i8 %5 to i32
%7 = icmp slt i32 %6, 4
br i1 %7, label %8, label %43
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, 8
%21 = add nsw i32 %20, 4
%22 = shl i32 %17, %21
%23 = load i32, i32* %3
%24 = or i32 %23, %22
store i32 %24, i32* %3
br label %25
25: ; preds = %29, %14
%26 = call signext i8 (...) @blocking_read()
store i8 %26, i8* %1
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 32
br i1 %28, label %29, label %30
29: ; preds = %25
br label %25
30: ; preds = %25
%31 = load i8, i8* %1
%32 = call signext i8 @parse_ascii_hex(i8 signext %31)
%33 = sext i8 %32 to i32
%34 = load i8, i8* %2
%35 = sext i8 %34 to i32
%36 = mul nsw i32 %35, 8
%37 = shl i32 %33, %36
%38 = load i32, i32* %3
%39 = or i32 %38, %37
store i32 %39, i32* %3
br label %40
40: ; preds = %30
%41 = load i8, i8* %2
%42 = add i8 %41, 1
store i8 %42, i8* %2
br label %4
43: ; preds = %4
%44 = load i32, i32* %3
%45 = call i32 @wload_calc_checksum(i32 %44)
%46 = load i32, i32* %3
ret i32 %46
}

LLVM IR (-O2):
define i32 @readword_be() {
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 = zext i8 %35 to i32
%41 = sext i8 %25 to i32
%42 = shl nsw i32 %41, 20
%43 = sext i8 %15 to i32
%44 = shl nsw i32 %43, 12
%45 = sext i8 %5 to i32
%46 = shl nsw i32 %45, 4
%47 = sext i8 %10 to i32
%48 = or i32 %46, %47
%49 = or i32 %44, %48
%50 = sext i8 %20 to i32
%51 = shl nsw i32 %50, 8
%52 = or i32 %49, %51
%53 = or i32 %42, %52
%54 = sext i8 %30 to i32
%55 = shl nsw i32 %54, 16
%56 = or i32 %53, %55
%57 = shl i32 %40, 28
%58 = or i32 %57, %56
%59 = tail call signext i8 @parse_ascii_hex(i8 signext %37)
%60 = zext i8 %59 to i32
%61 = shl nuw i32 %60, 24
%62 = or i32 %58, %61
%63 = tail call i32 @wload_calc_checksum(i32 %62)
ret i32 %62
}