#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 */
struct hw_device {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ device_define(struct hw_device *, int /*<<< orphan*/, int,
                                 int, int);
struct hw_device *disk_create(char *, struct hw_device *);
struct hw_device *hostfile_create(char *, int /*<<< orphan*/);
struct hw_device *imux_create(int);
int /*<<< orphan*/ ioexpand_attach(struct hw_device *, int, struct hw_device *);
struct hw_device *ioexpand_create();
struct hw_device *oscillator_create(struct hw_device *, int /*<<< orphan*/);
struct hw_device *ram_create(int);
struct hw_device *rom_create(char const *, int);
struct hw_device *serial_create();
struct hw_device *small_mmu_create(struct hw_device *);
void eon2_init(const char *boot_rom_file) {
  struct hw_device *dev, *ram_dev, *mmudev, *iodev, *intdev;
  ram_dev = ram_create(0x100000);
  mmudev = small_mmu_create(ram_dev);
  dev = rom_create(boot_rom_file, 0x800);
  device_define(dev, 0, 0xF800, 0x0800, 0x1);
  iodev = ioexpand_create();
  device_define(iodev, 0, 0xFF00, 128, 0x3);
  ioexpand_attach(iodev, 0, serial_create());
  ioexpand_attach(iodev, 1, disk_create("disk.bin", ram_dev));
  ioexpand_attach(iodev, 2, mmudev);
  ioexpand_attach(iodev, 3, intdev = imux_create(1));
  ioexpand_attach(iodev, 9, hostfile_create("hostfile", O_RDWR));
  dev = oscillator_create(intdev, 0);
}


x86 assembly (clang, -O0):
<eon2_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x100000,%edi
call   1070 <ram_create@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1080 <small_mmu_create@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x800,%esi
call   1030 <rom_create@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0xf800,%edx
mov    $0x800,%ecx
mov    $0x1,%r8d
call   10a0 <device_define@plt>
mov    $0x0,%al
call   10b0 <ioexpand_create@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0xff00,%edx
mov    $0x80,%ecx
mov    $0x3,%r8d
call   10a0 <device_define@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    $0x0,%al
call   1060 <serial_create@plt>
mov    -0x50(%rbp),%rdi
mov    %rax,%rdx
xor    %esi,%esi
call   1040 <ioexpand_attach@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xda6(%rip),%rdi
call   1050 <disk_create@plt>
mov    -0x48(%rbp),%rdi
mov    %rax,%rdx
mov    $0x1,%esi
call   1040 <ioexpand_attach@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x2,%esi
call   1040 <ioexpand_attach@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    $0x1,%edi
call   10d0 <imux_create@plt>
mov    -0x40(%rbp),%rdi
mov    %rax,%rdx
mov    %rdx,-0x30(%rbp)
mov    $0x3,%esi
call   1040 <ioexpand_attach@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    0x2d30(%rip),%rax
mov    (%rax),%esi
lea    0xd48(%rip),%rdi
call   10c0 <hostfile_create@plt>
mov    -0x38(%rbp),%rdi
mov    %rax,%rdx
mov    $0x9,%esi
call   1040 <ioexpand_attach@plt>
mov    -0x30(%rbp),%rdi
xor    %esi,%esi
call   1090 <oscillator_create@plt>
mov    %rax,-0x10(%rbp)
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<eon2_init>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
mov    $0x100000,%edi
call   1070 <ram_create@plt>
mov    %rax,%r15
mov    %rax,%rdi
call   1080 <small_mmu_create@plt>
mov    %rax,%r14
mov    %rbx,%rdi
mov    $0x800,%esi
call   1030 <rom_create@plt>
mov    %rax,%rdi
xor    %esi,%esi
mov    $0xf800,%edx
mov    $0x800,%ecx
mov    $0x1,%r8d
call   10a0 <device_define@plt>
xor    %eax,%eax
call   10b0 <ioexpand_create@plt>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    $0xff00,%edx
mov    $0x80,%ecx
mov    $0x3,%r8d
call   10a0 <device_define@plt>
xor    %eax,%eax
call   1060 <serial_create@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    %rax,%rdx
call   1040 <ioexpand_attach@plt>
lea    0xdca(%rip),%rdi
mov    %r15,%rsi
call   1050 <disk_create@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %rax,%rdx
call   1040 <ioexpand_attach@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
mov    %r14,%rdx
call   1040 <ioexpand_attach@plt>
mov    $0x1,%edi
call   10d0 <imux_create@plt>
mov    %rax,%r14
mov    %rbx,%rdi
mov    $0x3,%esi
mov    %rax,%rdx
call   1040 <ioexpand_attach@plt>
mov    0x2d66(%rip),%rax
mov    (%rax),%esi
lea    0xd7e(%rip),%rdi
call   10c0 <hostfile_create@plt>
mov    %rbx,%rdi
mov    $0x9,%esi
mov    %rax,%rdx
call   1040 <ioexpand_attach@plt>
mov    %r14,%rdi
xor    %esi,%esi
pop    %rbx
pop    %r14
pop    %r15
jmp    1090 <oscillator_create@plt>

LLVM IR (-O0):
%struct.hw_device = type { i32 }
@.str = [9 x i8] c"disk.bin\00"
@.str.1 = [9 x i8] c"hostfile\00"
@O_RDWR = global i32 0
define void @eon2_init(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.hw_device*
%4 = alloca %struct.hw_device*
%5 = alloca %struct.hw_device*
%6 = alloca %struct.hw_device*
%7 = alloca %struct.hw_device*
store i8* %0, i8** %2
%8 = call %struct.hw_device* @ram_create(i32 1048576)
store %struct.hw_device* %8, %struct.hw_device** %4
%9 = load %struct.hw_device*, %struct.hw_device** %4
%10 = call %struct.hw_device* @small_mmu_create(%struct.hw_device* %9)
store %struct.hw_device* %10, %struct.hw_device** %5
%11 = load i8*, i8** %2
%12 = call %struct.hw_device* @rom_create(i8* %11, i32 2048)
store %struct.hw_device* %12, %struct.hw_device** %3
%13 = load %struct.hw_device*, %struct.hw_device** %3
%14 = call i32 @device_define(%struct.hw_device* %13, i32 0, i32 63488, i32 2048, i32 1)
%15 = call %struct.hw_device* (...) @ioexpand_create()
store %struct.hw_device* %15, %struct.hw_device** %6
%16 = load %struct.hw_device*, %struct.hw_device** %6
%17 = call i32 @device_define(%struct.hw_device* %16, i32 0, i32 65280, i32 128, i32 3)
%18 = load %struct.hw_device*, %struct.hw_device** %6
%19 = call %struct.hw_device* (...) @serial_create()
%20 = call i32 @ioexpand_attach(%struct.hw_device* %18, i32 0, %struct.hw_device* %19)
%21 = load %struct.hw_device*, %struct.hw_device** %6
%22 = load %struct.hw_device*, %struct.hw_device** %4
%23 = call %struct.hw_device* @disk_create(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), %struct.hw_device* %22)
%24 = call i32 @ioexpand_attach(%struct.hw_device* %21, i32 1, %struct.hw_device* %23)
%25 = load %struct.hw_device*, %struct.hw_device** %6
%26 = load %struct.hw_device*, %struct.hw_device** %5
%27 = call i32 @ioexpand_attach(%struct.hw_device* %25, i32 2, %struct.hw_device* %26)
%28 = load %struct.hw_device*, %struct.hw_device** %6
%29 = call %struct.hw_device* @imux_create(i32 1)
store %struct.hw_device* %29, %struct.hw_device** %7
%30 = call i32 @ioexpand_attach(%struct.hw_device* %28, i32 3, %struct.hw_device* %29)
%31 = load %struct.hw_device*, %struct.hw_device** %6
%32 = load i32, i32* @O_RDWR
%33 = call %struct.hw_device* @hostfile_create(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %32)
%34 = call i32 @ioexpand_attach(%struct.hw_device* %31, i32 9, %struct.hw_device* %33)
%35 = load %struct.hw_device*, %struct.hw_device** %7
%36 = call %struct.hw_device* @oscillator_create(%struct.hw_device* %35, i32 0)
store %struct.hw_device* %36, %struct.hw_device** %3
ret void
}

LLVM IR (-O2):
%struct.hw_device = type { i32 }
@.str = [9 x i8] c"disk.bin\00"
@.str.1 = [9 x i8] c"hostfile\00"
@O_RDWR = global i32 0
define void @eon2_init(i8* %0) {
%2 = tail call %struct.hw_device* @ram_create(i32 1048576)
%3 = tail call %struct.hw_device* @small_mmu_create(%struct.hw_device* %2)
%4 = tail call %struct.hw_device* @rom_create(i8* %0, i32 2048)
%5 = tail call i32 @device_define(%struct.hw_device* %4, i32 0, i32 63488, i32 2048, i32 1)
%6 = tail call %struct.hw_device* (...) @ioexpand_create()
%7 = tail call i32 @device_define(%struct.hw_device* %6, i32 0, i32 65280, i32 128, i32 3)
%8 = tail call %struct.hw_device* (...) @serial_create()
%9 = tail call i32 @ioexpand_attach(%struct.hw_device* %6, i32 0, %struct.hw_device* %8)
%10 = tail call %struct.hw_device* @disk_create(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), %struct.hw_device* %2)
%11 = tail call i32 @ioexpand_attach(%struct.hw_device* %6, i32 1, %struct.hw_device* %10)
%12 = tail call i32 @ioexpand_attach(%struct.hw_device* %6, i32 2, %struct.hw_device* %3)
%13 = tail call %struct.hw_device* @imux_create(i32 1)
%14 = tail call i32 @ioexpand_attach(%struct.hw_device* %6, i32 3, %struct.hw_device* %13)
%15 = load i32, i32* @O_RDWR
%16 = tail call %struct.hw_device* @hostfile_create(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = tail call i32 @ioexpand_attach(%struct.hw_device* %6, i32 9, %struct.hw_device* %16)
%18 = tail call %struct.hw_device* @oscillator_create(%struct.hw_device* %13, i32 0)
ret void
}