#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*/ SEEK_SET;
int lseek(int, int, int /*<<< orphan*/);
int read(int, void *, int);
int get_record_handle(int fd, void *rptr, int size, int id) {
  if (lseek(fd, size * (id - 1), SEEK_SET) == -1)
    return -1;
  if (read(fd, rptr, size) != size)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<get_record_handle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%eax
sub    $0x1,%eax
imul   %eax,%esi
mov    0x2e95(%rip),%rax
mov    (%rax),%edx
call   1030 <lseek@plt>
cmp    $0xffffffff,%eax
jne    1167 <get_record_handle+0x47>
movl   $0xffffffff,-0x4(%rbp)
jmp    1192 <get_record_handle+0x72>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <read@plt>
cmp    -0x14(%rbp),%eax
je     118b <get_record_handle+0x6b>
movl   $0xffffffff,-0x4(%rbp)
jmp    1192 <get_record_handle+0x72>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_record_handle>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebx
mov    %rsi,%r14
mov    %edi,%ebp
lea    -0x1(%rcx),%esi
imul   %edx,%esi
mov    0x2ea8(%rip),%rax
mov    (%rax),%edx
call   1030 <lseek@plt>
cmp    $0xffffffff,%eax
je     115d <get_record_handle+0x3d>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %ebx,%edx
call   1040 <read@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    %ebx,%ecx
setne  %al
neg    %eax
jmp    1162 <get_record_handle+0x42>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
define i32 @get_record_handle(i32 %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%10 = load i32, i32* %6
%11 = load i32, i32* %8
%12 = load i32, i32* %9
%13 = sub nsw i32 %12, 1
%14 = mul nsw i32 %11, %13
%15 = load i32, i32* @SEEK_SET
%16 = call i32 @lseek(i32 %10, i32 %14, i32 %15)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %19
18: ; preds = %4
store i32 -1, i32* %5
br label %28
19: ; preds = %4
%20 = load i32, i32* %6
%21 = load i8*, i8** %7
%22 = load i32, i32* %8
%23 = call i32 @read(i32 %20, i8* %21, i32 %22)
%24 = load i32, i32* %8
%25 = icmp ne i32 %23, %24
br i1 %25, label %26, label %27
26: ; preds = %19
store i32 -1, i32* %5
br label %28
27: ; preds = %19
store i32 0, i32* %5
br label %28
28: ; preds = %27, %26, %18
%29 = load i32, i32* %5
ret i32 %29
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
define i32 @get_record_handle(i32 %0, i8* nocapture %1, i32 %2, i32 %3) {
%5 = add nsw i32 %3, -1
%6 = mul nsw i32 %5, %2
%7 = load i32, i32* @SEEK_SET
%8 = tail call i32 @lseek(i32 %0, i32 %6, i32 %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %14, label %10
10: ; preds = %4
%11 = tail call i32 @read(i32 %0, i8* %1, i32 %2)
%12 = icmp ne i32 %11, %2
%13 = sext i1 %12 to i32
br label %14
14: ; preds = %10, %4
%15 = phi i32 [ -1, %4 ], [ %13, %10 ]
ret i32 %15
}