#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 /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int fread(unsigned char *, int, long, int /*<<< orphan*/ *);
int fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
int read_grib(FILE *file, long pos, long len_grib, unsigned char *buffer) {
  int i;
  if (fseek(file, pos, SEEK_SET) == -1) {
    return 0;
  }
  i = fread(buffer, sizeof(unsigned char), len_grib, file);
  return (i == len_grib);
}


x86 assembly (clang, -O0):
<read_grib>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    0x2e99(%rip),%rax
mov    (%rax),%edx
call   1040 <fseek@plt>
cmp    $0xffffffff,%eax
jne    1163 <read_grib+0x43>
movl   $0x0,-0x4(%rbp)
jmp    118f <read_grib+0x6f>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %eax,-0x2c(%rbp)
movslq -0x2c(%rbp),%rax
cmp    -0x20(%rbp),%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_grib>:
push   %r15
push   %r14
push   %rbx
mov    %rcx,%r15
mov    %rdx,%r14
mov    %rdi,%rbx
mov    0x2eab(%rip),%rax
mov    (%rax),%edx
call   1040 <fseek@plt>
cmp    $0xffffffff,%eax
je     1161 <read_grib+0x41>
mov    %r15,%rdi
mov    $0x1,%esi
mov    %r14,%rdx
mov    %rbx,%rcx
call   1030 <fread@plt>
movslq %eax,%rcx
xor    %eax,%eax
cmp    %r14,%rcx
sete   %al
jmp    1163 <read_grib+0x43>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@SEEK_SET = global i32 0
define i32 @read_grib(i32* nocapture %0, i64 %1, i64 %2, i8* nocapture %3) {
%5 = load i32, i32* @SEEK_SET
%6 = tail call i32 @fseek(i32* %0, i64 %1, i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %13, label %8
8: ; preds = %4
%9 = tail call i32 @fread(i8* %3, i32 1, i64 %2, i32* %0)
%10 = sext i32 %9 to i64
%11 = icmp eq i64 %10, %2
%12 = zext i1 %11 to i32
br label %13
13: ; preds = %4, %8
%14 = phi i32 [ %12, %8 ], [ 0, %4 ]
ret i32 %14
}