#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;
void *emalloc(unsigned long);
int fread(void *, unsigned long, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(void *);
scalar_t__ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
void *getarea(FILE *fp, long offset, unsigned long size) {
  void *buf;
  if (fseek(fp, offset, SEEK_SET))
    return NULL;
  buf = emalloc(size);
  if (fread(buf, size, 1, fp) != 1) {
    free(buf);
    return NULL;
  }
  return buf;
}


x86 assembly (clang, -O0):
<getarea>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    0x2e7d(%rip),%rax
mov    (%rax),%edx
call   1050 <fseek@plt>
cmp    $0x0,%rax
je     1181 <getarea+0x41>
movq   $0x0,-0x8(%rbp)
jmp    11cb <getarea+0x8b>
mov    -0x20(%rbp),%rdi
call   1060 <emalloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%rcx
mov    $0x1,%edx
call   1040 <fread@plt>
cmp    $0x1,%eax
je     11c3 <getarea+0x83>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    11cb <getarea+0x8b>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getarea>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r15
mov    %rdi,%r14
mov    0x2e8e(%rip),%rax
mov    (%rax),%edx
call   1050 <fseek@plt>
test   %rax,%rax
jne    1189 <getarea+0x49>
mov    %r15,%rdi
call   1060 <emalloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
mov    $0x1,%edx
mov    %r14,%rcx
call   1040 <fread@plt>
cmp    $0x1,%eax
je     118b <getarea+0x4b>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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