#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*/ File_Close(int);
int File_Open(char const *);
int /*<<< orphan*/ SEEK_SET;
scalar_t__ lseek(int, int, int /*<<< orphan*/);
int read(int, void *, int);
int File_GetRecordByIndex(const char *FileName, void *Record, int Record_Len,
                          int Record_Index) {
  int fd;
  if ((fd = File_Open(FileName)) < 0)
    return -1;
  if (lseek(fd, (Record_Index * Record_Len), SEEK_SET) < 0) {
    File_Close(fd);
    return -1;
  }
  if (read(fd, Record, Record_Len) != Record_Len) {
    File_Close(fd);
    return -1;
  }
  File_Close(fd);
  return Record_Len;
}


x86 assembly (clang, -O0):
<File_GetRecordByIndex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <File_Open@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jge    1177 <File_GetRecordByIndex+0x37>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e7 <File_GetRecordByIndex+0xa7>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%esi
imul   -0x1c(%rbp),%esi
mov    0x2e58(%rip),%rax
mov    (%rax),%edx
call   1030 <lseek@plt>
cmp    $0x0,%rax
jge    11ad <File_GetRecordByIndex+0x6d>
mov    -0x24(%rbp),%edi
call   1060 <File_Close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e7 <File_GetRecordByIndex+0xa7>
mov    -0x24(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <read@plt>
cmp    -0x1c(%rbp),%eax
je     11d9 <File_GetRecordByIndex+0x99>
mov    -0x24(%rbp),%edi
call   1060 <File_Close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e7 <File_GetRecordByIndex+0xa7>
mov    -0x24(%rbp),%edi
call   1060 <File_Close@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<File_GetRecordByIndex>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%ebp
mov    %edx,%r14d
mov    %rsi,%r15
call   1050 <File_Open@plt>
mov    $0xffffffff,%r12d
test   %eax,%eax
js     11a8 <File_GetRecordByIndex+0x68>
mov    %eax,%ebx
imul   %r14d,%ebp
mov    0x2e74(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
mov    %ebp,%esi
call   1030 <lseek@plt>
test   %rax,%rax
js     11a1 <File_GetRecordByIndex+0x61>
mov    %ebx,%edi
mov    %r15,%rsi
mov    %r14d,%edx
call   1040 <read@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1060 <File_Close@plt>
cmp    %r14d,%ebp
mov    $0xffffffff,%r12d
cmove  %r14d,%r12d
jmp    11a8 <File_GetRecordByIndex+0x68>
mov    %ebx,%edi
call   1060 <File_Close@plt>
mov    %r12d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
define i32 @File_GetRecordByIndex(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%11 = load i8*, i8** %6
%12 = call i32 @File_Open(i8* %11)
store i32 %12, i32* %10
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %4
store i32 -1, i32* %5
br label %40
15: ; preds = %4
%16 = load i32, i32* %10
%17 = load i32, i32* %9
%18 = load i32, i32* %8
%19 = mul nsw i32 %17, %18
%20 = load i32, i32* @SEEK_SET
%21 = call i64 @lseek(i32 %16, i32 %19, i32 %20)
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %15
%24 = load i32, i32* %10
%25 = call i32 @File_Close(i32 %24)
store i32 -1, i32* %5
br label %40
26: ; preds = %15
%27 = load i32, i32* %10
%28 = load i8*, i8** %7
%29 = load i32, i32* %8
%30 = call i32 @read(i32 %27, i8* %28, i32 %29)
%31 = load i32, i32* %8
%32 = icmp ne i32 %30, %31
br i1 %32, label %33, label %36
33: ; preds = %26
%34 = load i32, i32* %10
%35 = call i32 @File_Close(i32 %34)
store i32 -1, i32* %5
br label %40
36: ; preds = %26
%37 = load i32, i32* %10
%38 = call i32 @File_Close(i32 %37)
%39 = load i32, i32* %8
store i32 %39, i32* %5
br label %40
40: ; preds = %36, %33, %23, %14
%41 = load i32, i32* %5
ret i32 %41
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
define i32 @File_GetRecordByIndex(i8* %0, i8* nocapture %1, i32 %2, i32 %3) {
%5 = tail call i32 @File_Open(i8* %0)
%6 = icmp slt i32 %5, 0
br i1 %6, label %19, label %7
7: ; preds = %4
%8 = mul nsw i32 %3, %2
%9 = load i32, i32* @SEEK_SET
%10 = tail call i64 @lseek(i32 %5, i32 %8, i32 %9)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %7
%13 = tail call i32 @File_Close(i32 %5)
br label %19
14: ; preds = %7
%15 = tail call i32 @read(i32 %5, i8* %1, i32 %2)
%16 = icmp eq i32 %15, %2
%17 = tail call i32 @File_Close(i32 %5)
%18 = select i1 %16, i32 %2, i32 -1
br label %19
19: ; preds = %14, %4, %12
%20 = phi i32 [ -1, %12 ], [ -1, %4 ], [ %18, %14 ]
ret i32 %20
}