#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 */
struct diag_l0_device {
  int dummy;
};

/* Variables and functions */
scalar_t__ EINTR;
int diag_iflseterr(char *, int, int);
int diag_tty_read(struct diag_l0_device *, char *, size_t, int);
scalar_t__ errno;
int diag_l1_saferead(struct diag_l0_device *dl0d, char *buf, size_t bufsiz,
                     int timeout) {
  int xferd;
  while ((xferd = diag_tty_read(dl0d, buf, bufsiz, timeout)) < 0) {
    if (errno != EINTR)
      return diag_iflseterr(
          "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
          "2022-01-22/02-19-57/repos/JohnJocke/freediag/refs/heads/master/"
          "scantool/diag_l1.c",
          285, (-16));
    xferd = 0;
  }
  return xferd;
}


x86 assembly (clang, -O0):
<diag_l1_saferead>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
call   1040 <diag_tty_read@plt>
mov    %eax,-0x28(%rbp)
cmp    $0x0,%eax
jge    119b <diag_l1_saferead+0x7b>
mov    0x2e82(%rip),%rax
mov    (%rax),%rax
mov    0x2e70(%rip),%rcx
cmp    (%rcx),%rax
je     118f <diag_l1_saferead+0x6f>
lea    0xe88(%rip),%rdi
mov    $0x11d,%esi
mov    $0xfffffff0,%edx
call   1030 <diag_iflseterr@plt>
mov    %eax,-0x4(%rbp)
jmp    11a1 <diag_l1_saferead+0x81>
movl   $0x0,-0x28(%rbp)
jmp    1137 <diag_l1_saferead+0x17>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<diag_l1_saferead>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %rsi,%rbp
mov    %rdi,%rbx
mov    0x2ea2(%rip),%r12
mov    0x2e93(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r15,%rdx
mov    %r14d,%ecx
call   1040 <diag_tty_read@plt>
test   %eax,%eax
jns    1193 <diag_l1_saferead+0x73>
mov    (%r12),%rax
cmp    0x0(%r13),%rax
je     1150 <diag_l1_saferead+0x30>
lea    0xe8a(%rip),%rdi
mov    $0x11d,%esi
mov    $0xfffffff0,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <diag_iflseterr@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.diag_l0_device = type { i32 }
@errno = global i64 0
@EINTR = global i64 0
@.str = [146 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/JohnJocke/freediag/refs/heads/master/scantool/diag_l1.c\00"
define i32 @diag_l1_saferead(%struct.diag_l0_device* %0, i8* %1, i64 %2, i32 %3) {
%5 = alloca i32
%6 = alloca %struct.diag_l0_device*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
store %struct.diag_l0_device* %0, %struct.diag_l0_device** %6
store i8* %1, i8** %7
store i64 %2, i64* %8
store i32 %3, i32* %9
br label %11
11: ; preds = %24, %4
%12 = load %struct.diag_l0_device*, %struct.diag_l0_device** %6
%13 = load i8*, i8** %7
%14 = load i64, i64* %8
%15 = load i32, i32* %9
%16 = call i32 @diag_tty_read(%struct.diag_l0_device* %12, i8* %13, i64 %14, i32 %15)
store i32 %16, i32* %10
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %25
18: ; preds = %11
%19 = load i64, i64* @errno
%20 = load i64, i64* @EINTR
%21 = icmp ne i64 %19, %20
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = call i32 @diag_iflseterr(i8* getelementptr inbounds ([146 x i8], [146 x i8]* @.str, i64 0, i64 0), i32 285, i32 -16)
store i32 %23, i32* %5
br label %27
24: ; preds = %18
store i32 0, i32* %10
br label %11
25: ; preds = %11
%26 = load i32, i32* %10
store i32 %26, i32* %5
br label %27
27: ; preds = %25, %22
%28 = load i32, i32* %5
ret i32 %28
}

LLVM IR (-O2):
%struct.diag_l0_device = type { i32 }
@errno = global i64 0
@EINTR = global i64 0
@.str = [146 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/JohnJocke/freediag/refs/heads/master/scantool/diag_l1.c\00"
define i32 @diag_l1_saferead(%struct.diag_l0_device* %0, i8* %1, i64 %2, i32 %3) {
br label %5
5: ; preds = %8, %4
%6 = tail call i32 @diag_tty_read(%struct.diag_l0_device* %0, i8* %1, i64 %2, i32 %3)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %14
8: ; preds = %5
%9 = load i64, i64* @errno
%10 = load i64, i64* @EINTR
%11 = icmp eq i64 %9, %10
br i1 %11, label %5, label %12
12: ; preds = %8
%13 = tail call i32 @diag_iflseterr(i8* getelementptr inbounds ([146 x i8], [146 x i8]* @.str, i64 0, i64 0), i32 285, i32 -16)
br label %14
14: ; preds = %5, %12
%15 = phi i32 [ %13, %12 ], [ %6, %5 ]
ret i32 %15
}