#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*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fwrite(int *, int, int, int /*<<< orphan*/ *);
void mem_write(uint8_t frame, uint8_t offset, uint8_t input) {
  FILE *memory = fopen("memory", "r+");
  fseek(memory, frame * 256 + offset, SEEK_SET);
  fwrite(&input, sizeof(uint8_t), 1, memory);
  fclose(memory);
  access_to_frame(frame);
}


x86 assembly (clang, -O0):
<mem_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
lea    0xe98(%rip),%rdi
lea    0xe98(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x4(%rbp),%esi
shl    $0x8,%esi
add    -0x8(%rbp),%esi
mov    0x2e54(%rip),%rax
mov    (%rax),%edx
call   1050 <fseek@plt>
mov    -0x18(%rbp),%rcx
lea    -0xc(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1070 <fwrite@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x4(%rbp),%edi
call   1030 <access_to_frame@plt>
add    $0x20,%rsp
pop    %rbp
ret

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

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

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