#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 /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
size_t read(int, void *, size_t);
int /*<<< orphan*/ test_msg(char *, char *, int, int, int /*<<< orphan*/);
void read_safe(int fd, void *buf, size_t size) {
  if (read(fd, buf, size) != size) {
    test_msg("ERR: %s:%d: "
             "Unable to read from %d"
             " (errno = %d (%m))\n",
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/kawamuray/criu/refs/heads/master/test/"
             "zdtm/live/static/socket-tcpbuf.c",
             31, fd, errno);
    exit(1);
  }
}


x86 assembly (clang, -O0):
<read_safe>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%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   1040 <read@plt>
cmp    -0x18(%rbp),%rax
je     118c <read_safe+0x5c>
mov    -0x4(%rbp),%ecx
mov    0x2e79(%rip),%rax
mov    (%rax),%r8d
lea    0xe8f(%rip),%rdi
lea    0xebe(%rip),%rsi
mov    $0x1f,%edx
call   1030 <test_msg@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_safe>:
push   %rbp
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %edi,%ebp
call   1040 <read@plt>
cmp    %rbx,%rax
jne    1149 <read_safe+0x19>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e90(%rip),%rax
mov    (%rax),%r8d
lea    0xea6(%rip),%rdi
lea    0xed5(%rip),%rsi
mov    $0x1f,%edx
mov    %ebp,%ecx
call   1030 <test_msg@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [54 x i8] c"ERR: %s:%d: Unable to read from %d (errno = %d (%m))\0A\00"
@.str.1 = [161 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/kawamuray/criu/refs/heads/master/test/zdtm/live/static/socket-tcpbuf.c\00"
@errno = global i32 0
define void @read_safe(i32 %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
store i32 %0, i32* %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%7 = load i32, i32* %4
%8 = load i8*, i8** %5
%9 = load i64, i64* %6
%10 = call i64 @read(i32 %7, i8* %8, i64 %9)
%11 = load i64, i64* %6
%12 = icmp ne i64 %10, %11
br i1 %12, label %13, label %18
13: ; preds = %3
%14 = load i32, i32* %4
%15 = load i32, i32* @errno
%16 = call i32 @test_msg(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([161 x i8], [161 x i8]* @.str.1, i64 0, i64 0), i32 31, i32 %14, i32 %15)
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %3
ret void
}

LLVM IR (-O2):
@.str = [54 x i8] c"ERR: %s:%d: Unable to read from %d (errno = %d (%m))\0A\00"
@.str.1 = [161 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/kawamuray/criu/refs/heads/master/test/zdtm/live/static/socket-tcpbuf.c\00"
@errno = global i32 0
define void @read_safe(i32 %0, i8* nocapture %1, i64 %2) {
%4 = tail call i64 @read(i32 %0, i8* %1, i64 %2)
%5 = icmp eq i64 %4, %2
br i1 %5, label %10, label %6
6: ; preds = %3
%7 = load i32, i32* @errno
%8 = tail call i32 @test_msg(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([161 x i8], [161 x i8]* @.str.1, i64 0, i64 0), i32 31, i32 %0, i32 %7)
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %3
ret void
}