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

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ access_to_frame(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
uint8_t mem_read(uint8_t frame, uint8_t offset) {
  FILE *memory = fopen("memory", "r");
  fseek(memory, frame * 256 + offset, SEEK_SET);
  uint8_t ret;
  fread(&ret, sizeof(uint8_t), 1, memory);
  fclose(memory);
  access_to_frame(frame);
  return ret;
}


x86 assembly (clang, -O0):
<mem_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
lea    0xe9b(%rip),%rdi
lea    0xe9b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%esi
shl    $0x8,%esi
add    -0x8(%rbp),%esi
mov    0x2e57(%rip),%rax
mov    (%rax),%edx
call   1060 <fseek@plt>
mov    -0x10(%rbp),%rcx
lea    -0x14(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1040 <fread@plt>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x4(%rbp),%edi
call   1030 <access_to_frame@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mem_read>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebp
mov    %edi,%r14d
lea    0xe9c(%rip),%rdi
lea    0xe9c(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
mov    %r14d,%esi
shl    $0x8,%esi
add    %ebp,%esi
mov    0x2e5e(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
call   1060 <fseek@plt>
lea    0xc(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    %r14d,%edi
call   1030 <access_to_frame@plt>
mov    0xc(%rsp),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"memory\00"
@.str.1 = [2 x i8] c"r\00"
@SEEK_SET = global i32 0
define i32 @mem_read(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%7 = call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %5
%8 = load i32*, i32** %5
%9 = load i32, i32* %3
%10 = mul nsw i32 %9, 256
%11 = load i32, i32* %4
%12 = add nsw i32 %10, %11
%13 = load i32, i32* @SEEK_SET
%14 = call i32 @fseek(i32* %8, i32 %12, i32 %13)
%15 = load i32*, i32** %5
%16 = call i32 @fread(i32* %6, i32 4, i32 1, i32* %15)
%17 = load i32*, i32** %5
%18 = call i32 @fclose(i32* %17)
%19 = load i32, i32* %3
%20 = call i32 @access_to_frame(i32 %19)
%21 = load i32, i32* %6
ret i32 %21
}

LLVM IR (-O2):
@.str = [7 x i8] c"memory\00"
@.str.1 = [2 x i8] c"r\00"
@SEEK_SET = global i32 0
define i32 @mem_read(i32 %0, i32 %1) {
%3 = alloca i32
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = shl nsw i32 %0, 8
%6 = add nsw i32 %5, %1
%7 = load i32, i32* @SEEK_SET
%8 = tail call i32 @fseek(i32* %4, i32 %6, i32 %7)
%9 = bitcast i32* %3 to i8*
%10 = call i32 @fread(i32* %3, i32 4, i32 1, i32* %4)
%11 = tail call i32 @fclose(i32* %4)
%12 = tail call i32 @access_to_frame(i32 %0)
%13 = load i32, i32* %3
ret i32 %13
}