#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 */
typedef int ssize_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ STDERR_FILENO;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int my_strlen(char *);
int read(int, void *, size_t);
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ xwrite(int /*<<< orphan*/, char *, int);
ssize_t xread(int fd, void *buf, size_t count) {
  ssize_t ret;
  char *err;
  ret = read(fd, buf, count);
  if (ret == -1) {
    err = strerror(errno);
    xwrite(STDERR_FILENO, "xread failed: ", sizeof("xread failed: "));
    xwrite(STDERR_FILENO, err, my_strlen(err));
    xwrite(STDERR_FILENO, "\n", 1);
    exit(EXIT_FAILURE);
  }
  return (ret);
}


x86 assembly (clang, -O0):
<xread>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <read@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11ff <xread+0xaf>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    %rax,-0x28(%rbp)
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
lea    0xe5e(%rip),%rsi
mov    $0xf,%edx
call   1040 <xwrite@plt>
mov    0x2e25(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <my_strlen@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
call   1040 <xwrite@plt>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
lea    0xe28(%rip),%rsi
mov    $0x1,%edx
call   1040 <xwrite@plt>
mov    0x2dd8(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x1c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xread>:
push   %rbp
push   %r14
push   %rbx
call   1050 <read@plt>
cmp    $0xffffffff,%eax
je     1163 <xread+0x13>
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2e76(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    %rax,%rbx
mov    0x2e5d(%rip),%r14
mov    (%r14),%edi
lea    0xe7b(%rip),%rsi
mov    $0xf,%edx
call   1040 <xwrite@plt>
mov    (%r14),%ebp
mov    %rbx,%rdi
call   1030 <my_strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <xwrite@plt>
mov    (%r14),%edi
lea    0xe5f(%rip),%rsi
mov    $0x1,%edx
call   1040 <xwrite@plt>
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@errno = global i32 0
@STDERR_FILENO = global i32 0
@.str = [15 x i8] c"xread failed: \00"
@.str.1 = [2 x i8] c"\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @xread(i32 %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i8*
store i32 %0, i32* %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%9 = load i32, i32* %4
%10 = load i8*, i8** %5
%11 = load i64, i64* %6
%12 = call i32 @read(i32 %9, i8* %10, i64 %11)
store i32 %12, i32* %7
%13 = load i32, i32* %7
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %29
15: ; preds = %3
%16 = load i32, i32* @errno
%17 = call i8* @strerror(i32 %16)
store i8* %17, i8** %8
%18 = load i32, i32* @STDERR_FILENO
%19 = call i32 @xwrite(i32 %18, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 15)
%20 = load i32, i32* @STDERR_FILENO
%21 = load i8*, i8** %8
%22 = load i8*, i8** %8
%23 = call i32 @my_strlen(i8* %22)
%24 = call i32 @xwrite(i32 %20, i8* %21, i32 %23)
%25 = load i32, i32* @STDERR_FILENO
%26 = call i32 @xwrite(i32 %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
%27 = load i32, i32* @EXIT_FAILURE
%28 = call i32 @exit(i32 %27)
unreachable
29: ; preds = %3
%30 = load i32, i32* %7
ret i32 %30
}

LLVM IR (-O2):
@errno = global i32 0
@STDERR_FILENO = global i32 0
@.str = [15 x i8] c"xread failed: \00"
@.str.1 = [2 x i8] c"\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @xread(i32 %0, i8* nocapture %1, i64 %2) {
%4 = tail call i32 @read(i32 %0, i8* %1, i64 %2)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %18
6: ; preds = %3
%7 = load i32, i32* @errno
%8 = tail call i8* @strerror(i32 %7)
%9 = load i32, i32* @STDERR_FILENO
%10 = tail call i32 @xwrite(i32 %9, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 15)
%11 = load i32, i32* @STDERR_FILENO
%12 = tail call i32 @my_strlen(i8* %8)
%13 = tail call i32 @xwrite(i32 %11, i8* %8, i32 %12)
%14 = load i32, i32* @STDERR_FILENO
%15 = tail call i32 @xwrite(i32 %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
%16 = load i32, i32* @EXIT_FAILURE
%17 = tail call i32 @exit(i32 %16)
unreachable
18: ; preds = %3
ret i32 %4
}