#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__ EINTR;
scalar_t__ errno;
int /*<<< orphan*/ get_device_status(int);
int /*<<< orphan*/ printf(char *);
int read(int, char *, size_t);
int com_read(int fd, char *pszIn, size_t tLen) {
  int iNrRead;
  do {
    if (!get_device_status(fd)) {
      printf("\nDevice disconnected!\n");
      return -1;
    }
    iNrRead = read(fd, pszIn, tLen);
  } while ((iNrRead < 0) && (errno == EINTR));
  return (iNrRead);
}


x86 assembly (clang, -O0):
<com_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <get_device_status@plt>
cmp    $0x0,%eax
jne    116c <com_read+0x3c>
lea    0xea5(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b9 <com_read+0x89>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <read@plt>
mov    %eax,-0x1c(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x1c(%rbp)
mov    %al,-0x1d(%rbp)
jge    11a8 <com_read+0x78>
mov    0x2e4b(%rip),%rax
mov    (%rax),%rax
mov    0x2e39(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    1143 <com_read+0x13>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<com_read>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2e99(%rip),%r15
mov    0x2e8a(%rip),%r12
xchg   %ax,%ax
mov    %ebp,%edi
call   1050 <get_device_status@plt>
test   %eax,%eax
je     1177 <com_read+0x47>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1040 <read@plt>
test   %eax,%eax
jns    1188 <com_read+0x58>
mov    (%r12),%rcx
cmp    %rcx,(%r15)
je     1150 <com_read+0x20>
jmp    1188 <com_read+0x58>
lea    0xe82(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@errno = global i64 0
@EINTR = global i64 0
@str = [22 x i8] c"\0ADevice disconnected!\00"
define i32 @com_read(i32 %0, i8* nocapture %1, i64 %2) {
br label %4
4: ; preds = %9, %3
%5 = tail call i32 @get_device_status(i32 %0)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
br label %16
9: ; preds = %4
%10 = tail call i32 @read(i32 %0, i8* %1, i64 %2)
%11 = icmp slt i32 %10, 0
%12 = load i64, i64* @errno
%13 = load i64, i64* @EINTR
%14 = icmp eq i64 %12, %13
%15 = select i1 %11, i1 %14, i1 false
br i1 %15, label %4, label %16
16: ; preds = %9, %7
%17 = phi i32 [ -1, %7 ], [ %10, %9 ]
ret i32 %17
}