#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 */
scalar_t__ EAGAIN;
scalar_t__ EWOULDBLOCK;
scalar_t__ errno;
int /*<<< orphan*/ perror(char *);
int read(int, unsigned char *, int);
int elCommRead(int fd) {
  unsigned char c;
  unsigned int i;
  int rv;
  rv = read(fd, &c, 1);
  i = c;
  if (rv > 0)
    return i;
  if (rv < 0) {
    if ((errno != EAGAIN) && (errno != EWOULDBLOCK))
      perror("elCommRead() error:");
  }
  return rv;
}


x86 assembly (clang, -O0):
<elCommRead>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x9(%rbp),%rsi
mov    $0x1,%edx
call   1030 <read@plt>
mov    %eax,-0x14(%rbp)
movzbl -0x9(%rbp),%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    115b <elCommRead+0x3b>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11b0 <elCommRead+0x90>
cmpl   $0x0,-0x14(%rbp)
jge    11aa <elCommRead+0x8a>
mov    0x2e74(%rip),%rax
mov    (%rax),%rax
mov    0x2e52(%rip),%rcx
cmp    (%rcx),%rax
je     11a5 <elCommRead+0x85>
mov    0x2e5a(%rip),%rax
mov    (%rax),%rax
mov    0x2e48(%rip),%rcx
cmp    (%rcx),%rax
je     11a5 <elCommRead+0x85>
lea    0xe60(%rip),%rdi
call   1040 <perror@plt>
jmp    11aa <elCommRead+0x8a>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<elCommRead>:
push   %rbx
sub    $0x10,%rsp
lea    0xf(%rsp),%rsi
mov    $0x1,%edx
call   1030 <read@plt>
test   %eax,%eax
jle    113f <elCommRead+0x1f>
movzbl 0xf(%rsp),%eax
jmp    116b <elCommRead+0x4b>
mov    %eax,%ebx
xor    %eax,%eax
test   %ebx,%ebx
jns    116b <elCommRead+0x4b>
mov    0x2e92(%rip),%rax
mov    (%rax),%rax
mov    0x2e70(%rip),%rcx
cmp    (%rcx),%rax
je     1169 <elCommRead+0x49>
mov    0x2e74(%rip),%rcx
cmp    (%rcx),%rax
jne    1171 <elCommRead+0x51>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe88(%rip),%rdi
call   1040 <perror@plt>
jmp    1169 <elCommRead+0x49>

LLVM IR (-O0):
@errno = global i64 0
@EAGAIN = global i64 0
@EWOULDBLOCK = global i64 0
@.str = [20 x i8] c"elCommRead() error:\00"
define i32 @elCommRead(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
%7 = load i32, i32* %3
%8 = call i32 @read(i32 %7, i8* %4, i32 1)
store i32 %8, i32* %6
%9 = load i8, i8* %4
%10 = zext i8 %9 to i32
store i32 %10, i32* %5
%11 = load i32, i32* %6
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %1
%14 = load i32, i32* %5
store i32 %14, i32* %2
br label %31
15: ; preds = %1
%16 = load i32, i32* %6
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %29
18: ; preds = %15
%19 = load i64, i64* @errno
%20 = load i64, i64* @EAGAIN
%21 = icmp ne i64 %19, %20
br i1 %21, label %22, label %28
22: ; preds = %18
%23 = load i64, i64* @errno
%24 = load i64, i64* @EWOULDBLOCK
%25 = icmp ne i64 %23, %24
br i1 %25, label %26, label %28
26: ; preds = %22
%27 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %28
28: ; preds = %26, %22, %18
br label %29
29: ; preds = %28, %15
%30 = load i32, i32* %6
store i32 %30, i32* %2
br label %31
31: ; preds = %29, %13
%32 = load i32, i32* %2
ret i32 %32
}

LLVM IR (-O2):
@errno = global i64 0
@EAGAIN = global i64 0
@EWOULDBLOCK = global i64 0
@.str = [20 x i8] c"elCommRead() error:\00"
define i32 @elCommRead(i32 %0) {
%2 = alloca i8
%3 = call i32 @read(i32 %0, i8* %2, i32 1)
%4 = icmp sgt i32 %3, 0
br i1 %4, label %5, label %8
5: ; preds = %1
%6 = load i8, i8* %2
%7 = zext i8 %6 to i32
br label %19
8: ; preds = %1
%9 = icmp slt i32 %3, 0
br i1 %9, label %10, label %19
10: ; preds = %8
%11 = load i64, i64* @errno
%12 = load i64, i64* @EAGAIN
%13 = icmp eq i64 %11, %12
%14 = load i64, i64* @EWOULDBLOCK
%15 = icmp eq i64 %11, %14
%16 = select i1 %13, i1 true, i1 %15
br i1 %16, label %19, label %17
17: ; preds = %10
%18 = tail call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %8, %17, %10, %5
%20 = phi i32 [ %7, %5 ], [ %3, %10 ], [ %3, %17 ], [ 0, %8 ]
ret i32 %20
}