#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 /*<<< orphan*/ errmsg(char *);
int lseek(int, long, int /*<<< orphan*/);
int read(int, char *, int);
int rframe_c(int fd, int frame, int npix, int nrast, char *buff) {
  int nbytes = npix * nrast * sizeof(float);
  int c;
  long offset = (frame - 1) * nbytes;
  if ((lseek(fd, offset, SEEK_SET)) == -1) {
    errmsg("Error: Unable to access specified frame number");
    return (-1);
  }
  if ((c = read(fd, buff, nbytes)) != nbytes) {
    errmsg("Error: Reading frame of binary data");
    return (-1);
  }
  return (0);
}


x86 assembly (clang, -O0):
<rframe_c>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8,-0x20(%rbp)
mov    -0x10(%rbp),%eax
imul   -0x14(%rbp),%eax
cltq
shl    $0x2,%rax
mov    %eax,-0x24(%rbp)
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
imul   -0x24(%rbp),%eax
cltq
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    0x2e6a(%rip),%rax
mov    (%rax),%edx
call   1030 <lseek@plt>
cmp    $0xffffffff,%eax
jne    119e <rframe_c+0x6e>
lea    0xe73(%rip),%rdi
call   1050 <errmsg@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d8 <rframe_c+0xa8>
mov    -0x8(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1040 <read@plt>
mov    %eax,-0x28(%rbp)
cmp    -0x24(%rbp),%eax
je     11d1 <rframe_c+0xa1>
lea    0xe6f(%rip),%rdi
call   1050 <errmsg@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d8 <rframe_c+0xa8>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rframe_c>:
push   %rbp
push   %r14
push   %rbx
mov    %r8,%r14
mov    %edx,%ebx
mov    %edi,%ebp
imul   %ecx,%ebx
shl    $0x2,%ebx
add    $0xffffffff,%esi
imul   %ebx,%esi
movslq %esi,%rsi
mov    0x2e8f(%rip),%rax
mov    (%rax),%edx
call   1030 <lseek@plt>
cmp    $0xffffffff,%eax
je     117a <rframe_c+0x4a>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %ebx,%edx
call   1040 <read@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    %ebx,%ecx
je     118b <rframe_c+0x5b>
lea    0xeb7(%rip),%rdi
jmp    1181 <rframe_c+0x51>
lea    0xe7f(%rip),%rdi
call   1050 <errmsg@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
@.str = [47 x i8] c"Error: Unable to access specified frame number\00"
@.str.1 = [36 x i8] c"Error: Reading frame of binary data\00"
define i32 @rframe_c(i32 %0, i32 %1, i32 %2, i32 %3, i8* %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i64
store i32 %0, i32* %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i8* %4, i8** %11
%15 = load i32, i32* %9
%16 = load i32, i32* %10
%17 = mul nsw i32 %15, %16
%18 = sext i32 %17 to i64
%19 = mul i64 %18, 4
%20 = trunc i64 %19 to i32
store i32 %20, i32* %12
%21 = load i32, i32* %8
%22 = sub nsw i32 %21, 1
%23 = load i32, i32* %12
%24 = mul nsw i32 %22, %23
%25 = sext i32 %24 to i64
store i64 %25, i64* %14
%26 = load i32, i32* %7
%27 = load i64, i64* %14
%28 = load i32, i32* @SEEK_SET
%29 = call i32 @lseek(i32 %26, i64 %27, i32 %28)
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %33
31: ; preds = %5
%32 = call i32 @errmsg(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %6
br label %43
33: ; preds = %5
%34 = load i32, i32* %7
%35 = load i8*, i8** %11
%36 = load i32, i32* %12
%37 = call i32 @read(i32 %34, i8* %35, i32 %36)
store i32 %37, i32* %13
%38 = load i32, i32* %12
%39 = icmp ne i32 %37, %38
br i1 %39, label %40, label %42
40: ; preds = %33
%41 = call i32 @errmsg(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %6
br label %43
42: ; preds = %33
store i32 0, i32* %6
br label %43
43: ; preds = %42, %40, %31
%44 = load i32, i32* %6
ret i32 %44
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
@.str = [47 x i8] c"Error: Unable to access specified frame number\00"
@.str.1 = [36 x i8] c"Error: Reading frame of binary data\00"
define i32 @rframe_c(i32 %0, i32 %1, i32 %2, i32 %3, i8* nocapture %4) {
%6 = shl i32 %2, 2
%7 = mul i32 %6, %3
%8 = add nsw i32 %1, -1
%9 = mul nsw i32 %7, %8
%10 = sext i32 %9 to i64
%11 = load i32, i32* @SEEK_SET
%12 = tail call i32 @lseek(i32 %0, i64 %10, i32 %11)
%13 = icmp eq i32 %12, -1
br i1 %13, label %17, label %14
14: ; preds = %5
%15 = tail call i32 @read(i32 %0, i8* %4, i32 %7)
%16 = icmp eq i32 %15, %7
br i1 %16, label %20, label %17
17: ; preds = %14, %5
%18 = phi i8* [ getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), %5 ], [ getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), %14 ]
%19 = tail call i32 @errmsg(i8* %18)
br label %20
20: ; preds = %17, %14
%21 = phi i32 [ 0, %14 ], [ -1, %17 ]
ret i32 %21
}