#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
char *malloc(int);
int /*<<< orphan*/ perror(int /*<<< orphan*/ *);
int /*<<< orphan*/ run(char *, int, int);
void execute(char *fn, int mem_size, int stm_size) {
  FILE *f = fopen(fn, "rb");
  if (f) {
    char *m = malloc(mem_size);
    int prg_size = fread(m + stm_size, 1, mem_size - stm_size, f);
    fclose(f);
    run(m, stm_size, prg_size);
  } else {
    perror(NULL);
    exit(1);
  }
}


x86 assembly (clang, -O0):
<execute>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe73(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11ec <execute+0x7c>
mov    -0xc(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
movslq -0x10(%rbp),%rax
add    %rax,%rdi
mov    -0xc(%rbp),%edx
sub    -0x10(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    -0x24(%rbp),%edx
call   1050 <run@plt>
jmp    11ff <execute+0x8f>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<execute>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r15d
mov    %esi,%ebx
lea    0xe7c(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11d1 <execute+0x61>
mov    %rax,%r14
mov    %ebx,%edi
call   1060 <malloc@plt>
mov    %rax,%r12
movslq %r15d,%rbp
lea    (%rax,%rbp,1),%rdi
sub    %ebp,%ebx
mov    $0x1,%esi
mov    %ebx,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %r12,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <run@plt>
xor    %edi,%edi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
define void @execute(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%10 = load i8*, i8** %4
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %7
%12 = load i32*, i32** %7
%13 = icmp ne i32* %12, null
br i1 %13, label %14, label %32
14: ; preds = %3
%15 = load i32, i32* %5
%16 = call i8* @malloc(i32 %15)
store i8* %16, i8** %8
%17 = load i8*, i8** %8
%18 = load i32, i32* %6
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = load i32, i32* %5
%22 = load i32, i32* %6
%23 = sub nsw i32 %21, %22
%24 = load i32*, i32** %7
%25 = call i32 @fread(i8* %20, i32 1, i32 %23, i32* %24)
store i32 %25, i32* %9
%26 = load i32*, i32** %7
%27 = call i32 @fclose(i32* %26)
%28 = load i8*, i8** %8
%29 = load i32, i32* %6
%30 = load i32, i32* %9
%31 = call i32 @run(i8* %28, i32 %29, i32 %30)
br label %35
32: ; preds = %3
%33 = call i32 @perror(i32* null)
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %14
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
define void @execute(i8* nocapture %0, i32 %1, i32 %2) {
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %14, label %6
6: ; preds = %3
%7 = tail call i8* @malloc(i32 %1)
%8 = sext i32 %2 to i64
%9 = getelementptr inbounds i8, i8* %7, i64 %8
%10 = sub nsw i32 %1, %2
%11 = tail call i32 @fread(i8* %9, i32 1, i32 %10, i32* %4)
%12 = tail call i32 @fclose(i32* %4)
%13 = tail call i32 @run(i8* %7, i32 %2, i32 %11)
ret void
14: ; preds = %3
%15 = tail call i32 @perror(i32* null)
%16 = tail call i32 @exit(i32 1)
unreachable
}