#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 FACOM_read(char *, int);
int FACOM_checkForErrors(void) {
  char recived[10];
  int bytesRecived = FACOM_read(recived, 9);
  if (bytesRecived < 9)
    return -72;
  char err = recived[5];
  if (err > '0')
    return err == 'A' ? -0x5A : -0x50 - err + '0';
  return 0;
}


x86 assembly (clang, -O0):
<FACOM_checkForErrors>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0xe(%rbp),%rdi
mov    $0x9,%esi
call   1030 <FACOM_read@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x9,-0x14(%rbp)
jge    113f <FACOM_checkForErrors+0x2f>
movl   $0xffffffb8,-0x4(%rbp)
jmp    118f <FACOM_checkForErrors+0x7f>
mov    -0x9(%rbp),%al
mov    %al,-0x15(%rbp)
movsbl -0x15(%rbp),%eax
cmp    $0x30,%eax
jle    1188 <FACOM_checkForErrors+0x78>
movsbl -0x15(%rbp),%eax
cmp    $0x41,%eax
jne    116c <FACOM_checkForErrors+0x5c>
mov    $0xffffffa6,%eax
mov    %eax,-0x1c(%rbp)
jmp    117d <FACOM_checkForErrors+0x6d>
movsbl -0x15(%rbp),%ecx
mov    $0xffffffb0,%eax
sub    %ecx,%eax
add    $0x30,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    118f <FACOM_checkForErrors+0x7f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FACOM_checkForErrors>:
sub    $0x18,%rsp
lea    0xe(%rsp),%rdi
mov    $0x9,%esi
call   1030 <FACOM_read@plt>
mov    %eax,%ecx
mov    $0xffffffb8,%eax
cmp    $0x9,%ecx
jl     114e <FACOM_checkForErrors+0x3e>
movsbl 0x13(%rsp),%ecx
mov    $0xffffffe0,%eax
sub    %ecx,%eax
cmp    $0x41,%ecx
mov    $0xffffffa6,%edx
cmovne %eax,%edx
xor    %eax,%eax
cmp    $0x31,%ecx
cmovge %edx,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
define i32 @FACOM_checkForErrors() {
%1 = alloca i32
%2 = alloca [10 x i8]
%3 = alloca i32
%4 = alloca i8
%5 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%6 = call i32 @FACOM_read(i8* %5, i32 9)
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 9
br i1 %8, label %9, label %10
9: ; preds = %0
store i32 -72, i32* %1
br label %29
10: ; preds = %0
%11 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 5
%12 = load i8, i8* %11
store i8 %12, i8* %4
%13 = load i8, i8* %4
%14 = sext i8 %13 to i32
%15 = icmp sgt i32 %14, 48
br i1 %15, label %16, label %28
16: ; preds = %10
%17 = load i8, i8* %4
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 65
br i1 %19, label %20, label %21
20: ; preds = %16
br label %26
21: ; preds = %16
%22 = load i8, i8* %4
%23 = sext i8 %22 to i32
%24 = sub nsw i32 -80, %23
%25 = add nsw i32 %24, 48
br label %26
26: ; preds = %21, %20
%27 = phi i32 [ -90, %20 ], [ %25, %21 ]
store i32 %27, i32* %1
br label %29
28: ; preds = %10
store i32 0, i32* %1
br label %29
29: ; preds = %28, %26, %9
%30 = load i32, i32* %1
ret i32 %30
}

LLVM IR (-O2):
define i32 @FACOM_checkForErrors() {
%1 = alloca [10 x i8]
%2 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%3 = call i32 @FACOM_read(i8* %2, i32 9)
%4 = icmp slt i32 %3, 9
br i1 %4, label %14, label %5
5: ; preds = %0
%6 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 5
%7 = load i8, i8* %6
%8 = icmp sgt i8 %7, 48
%9 = sext i8 %7 to i32
%10 = icmp eq i8 %7, 65
%11 = sub nsw i32 -32, %9
%12 = select i1 %10, i32 -90, i32 %11
%13 = select i1 %8, i32 %12, i32 0
br label %14
14: ; preds = %0, %5
%15 = phi i32 [ %13, %5 ], [ -72, %0 ]
ret i32 %15
}