#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*/ err_exit(char *);
int /*<<< orphan*/ fmt_err_exit(char *, char *);
int read(int, unsigned char *, size_t);
void get_record(int fd, unsigned char *rec, size_t rec_size) {
  ssize_t n_read;
  n_read = read(fd, rec, rec_size);
  if (n_read == -1)
    err_exit("read");
  else if ((size_t)n_read < rec_size)
    fmt_err_exit("%s", "Error reading input file");
}


x86 assembly (clang, -O0):
<get_record>:
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   1030 <read@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1171 <get_record+0x41>
lea    0xe99(%rip),%rdi
call   1040 <err_exit@plt>
jmp    1197 <get_record+0x67>
movslq -0x1c(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1192 <get_record+0x62>
lea    0xe7f(%rip),%rdi
lea    0xe7b(%rip),%rsi
call   1050 <fmt_err_exit@plt>
jmp    1197 <get_record+0x67>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_record>:
push   %rbx
mov    %rdx,%rbx
call   1030 <read@plt>
cmp    $0xffffffff,%eax
je     1159 <get_record+0x29>
cltq
cmp    %rbx,%rax
jae    1166 <get_record+0x36>
lea    0xeb9(%rip),%rdi
lea    0xeb5(%rip),%rsi
pop    %rbx
jmp    1050 <fmt_err_exit@plt>
lea    0xea0(%rip),%rdi
pop    %rbx
jmp    1040 <err_exit@plt>
pop    %rbx
ret

LLVM IR (-O0):
@.str = [5 x i8] c"read\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [25 x i8] c"Error reading input file\00"
define void @get_record(i32 %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%8 = load i32, i32* %4
%9 = load i8*, i8** %5
%10 = load i64, i64* %6
%11 = call i32 @read(i32 %8, i8* %9, i64 %10)
store i32 %11, i32* %7
%12 = load i32, i32* %7
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %3
%15 = call i32 @err_exit(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %24
16: ; preds = %3
%17 = load i32, i32* %7
%18 = sext i32 %17 to i64
%19 = load i64, i64* %6
%20 = icmp ult i64 %18, %19
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = call i32 @fmt_err_exit(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %23
23: ; preds = %21, %16
br label %24
24: ; preds = %23, %14
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"read\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [25 x i8] c"Error reading input file\00"
define void @get_record(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 %8
6: ; preds = %3
%7 = tail call i32 @err_exit(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %13
8: ; preds = %3
%9 = sext i32 %4 to i64
%10 = icmp ult i64 %9, %2
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = tail call i32 @fmt_err_exit(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %13
13: ; preds = %8, %11, %6
ret void
}