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

/* Variables and functions */
int /*<<< orphan*/ uvisor_write16(int /*<<< orphan*/ volatile *,
                                  int /*<<< orphan*/);
int /*<<< orphan*/ uvisor_write32(int /*<<< orphan*/ volatile *,
                                  int /*<<< orphan*/);
int /*<<< orphan*/ uvisor_write8(int /*<<< orphan*/ volatile *,
                                 int /*<<< orphan*/);
__attribute__((always_)) void
__address_write(size_t sizeof_type, volatile uint32_t *addr, uint32_t val) {
  switch (sizeof_type) {
  case 4:
    uvisor_write32((volatile uint32_t *)addr, (uint32_t)val);
    break;
  case 2:
    uvisor_write16((volatile uint16_t *)addr, (uint16_t)val);
    break;
  case 1:
    uvisor_write8((volatile uint8_t *)addr, (uint8_t)val);
    break;
  }
}


x86 assembly (clang, -O0):
<__address_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
sub    $0x1,%rax
je     11a2 <__address_write+0x72>
jmp    115a <__address_write+0x2a>
mov    -0x20(%rbp),%rax
sub    $0x2,%rax
je     1191 <__address_write+0x61>
jmp    116d <__address_write+0x3d>
mov    -0x20(%rbp),%rax
sub    $0x4,%rax
jne    11ae <__address_write+0x7e>
jmp    1180 <__address_write+0x50>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1050 <uvisor_write32@plt>
jmp    11ae <__address_write+0x7e>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <uvisor_write16@plt>
jmp    11ae <__address_write+0x7e>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <uvisor_write8@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__address_write>:
cmp    $0x1,%rdi
je     114c <__address_write+0x1c>
cmp    $0x2,%rdi
je     1156 <__address_write+0x26>
cmp    $0x4,%rdi
jne    1160 <__address_write+0x30>
mov    %rsi,%rdi
mov    %edx,%esi
jmp    1050 <uvisor_write32@plt>
mov    %rsi,%rdi
mov    %edx,%esi
jmp    1040 <uvisor_write8@plt>
mov    %rsi,%rdi
mov    %edx,%esi
jmp    1030 <uvisor_write16@plt>
ret

LLVM IR (-O0):
define void @__address_write(i64 %0, i32* %1, i32 %2) {
%4 = alloca i64
%5 = alloca i32*
%6 = alloca i32
store i64 %0, i64* %4
store i32* %1, i32** %5
store i32 %2, i32* %6
%7 = load i64, i64* %4
switch i64 %7, label %20 [
i64 4, label %8
i64 2, label %12
i64 1, label %16
]
8: ; preds = %3
%9 = load i32*, i32** %5
%10 = load i32, i32* %6
%11 = call i32 @uvisor_write32(i32* %9, i32 %10)
br label %20
12: ; preds = %3
%13 = load i32*, i32** %5
%14 = load i32, i32* %6
%15 = call i32 @uvisor_write16(i32* %13, i32 %14)
br label %20
16: ; preds = %3
%17 = load i32*, i32** %5
%18 = load i32, i32* %6
%19 = call i32 @uvisor_write8(i32* %17, i32 %18)
br label %20
20: ; preds = %3, %16, %12, %8
ret void
}

LLVM IR (-O2):
define void @__address_write(i64 %0, i32* %1, i32 %2) {
switch i64 %0, label %10 [
i64 4, label %4
i64 2, label %6
i64 1, label %8
]
4: ; preds = %3
%5 = tail call i32 @uvisor_write32(i32* %1, i32 %2)
br label %10
6: ; preds = %3
%7 = tail call i32 @uvisor_write16(i32* %1, i32 %2)
br label %10
8: ; preds = %3
%9 = tail call i32 @uvisor_write8(i32* %1, i32 %2)
br label %10
10: ; preds = %3, %8, %6, %4
ret void
}