#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 uint32_t;
typedef int uint16_t;

/* Variables and functions */
int /*<<< orphan*/ ErrorDisplayMessage(char *, int);
int /*<<< orphan*/ checkRegister(int);
void executeARMStoreInstruction(uint32_t instructionAddress,
                                uint32_t targetAddress, uint32_t targetOffset,
                                uint32_t *registerStack) {
  uint32_t instructionCode = *(uint32_t *)instructionAddress;
  uint32_t registerValue;
  targetAddress += targetOffset;
  if ((instructionCode & 0x0C000000) == 0x04000000) {
    uint32_t reg = (instructionCode >> 12) & 0xF;
    checkRegister(reg);
    if ((instructionCode & (1 << 24)) && (instructionCode & (1 << 21)))
      ErrorDisplayMessage("DataHandler: unexpected write-back", 1);
    registerValue = (registerStack[(reg)]);
    *(uint32_t *)targetAddress = registerValue;
  } else if ((instructionCode & 0x0E000000) == 0x00000000) {
    uint32_t reg = (instructionCode >> 12) & 0xF;
    checkRegister(reg);
    if ((instructionCode & (1 << 24)) && (instructionCode & (1 << 21)))
      ErrorDisplayMessage("DataHandler: unexpected write-back", 1);
    registerValue = (registerStack[(reg)]);
    if (instructionCode & (1 << 6)) {
      volatile uint32_t *ptr = (uint32_t *)targetAddress;
      ptr[0] = registerValue;
      registerValue = (registerStack[(reg + 1)]);
      ptr[1] = registerValue;
    } else {
      *(uint16_t *)targetAddress = registerValue;
    }
  } else if ((instructionCode & 0x0E000000) == 0x08000000) {
    for (;;)
      ;
  }
}


x86 assembly (clang, -O0):
<executeARMStoreInstruction>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
movslq -0x4(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0xc(%rbp),%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x1c(%rbp),%eax
and    $0xc000000,%eax
cmp    $0x4000000,%eax
jne    11bd <executeARMStoreInstruction+0x9d>
mov    -0x1c(%rbp),%eax
sar    $0xc,%eax
and    $0xf,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
call   1040 <checkRegister@plt>
mov    -0x1c(%rbp),%eax
and    $0x1000000,%eax
cmp    $0x0,%eax
je     11a1 <executeARMStoreInstruction+0x81>
mov    -0x1c(%rbp),%eax
and    $0x200000,%eax
cmp    $0x0,%eax
je     11a1 <executeARMStoreInstruction+0x81>
lea    0xe69(%rip),%rdi
mov    $0x1,%esi
call   1030 <ErrorDisplayMessage@plt>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%ecx
movslq -0x8(%rbp),%rax
mov    %ecx,(%rax)
jmp    129a <executeARMStoreInstruction+0x17a>
mov    -0x1c(%rbp),%eax
and    $0xe000000,%eax
cmp    $0x0,%eax
jne    1273 <executeARMStoreInstruction+0x153>
mov    -0x1c(%rbp),%eax
sar    $0xc,%eax
and    $0xf,%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%edi
call   1040 <checkRegister@plt>
mov    -0x1c(%rbp),%eax
and    $0x1000000,%eax
cmp    $0x0,%eax
je     1215 <executeARMStoreInstruction+0xf5>
mov    -0x1c(%rbp),%eax
and    $0x200000,%eax
cmp    $0x0,%eax
je     1215 <executeARMStoreInstruction+0xf5>
lea    0xdf5(%rip),%rdi
mov    $0x1,%esi
call   1030 <ErrorDisplayMessage@plt>
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
and    $0x40,%eax
cmp    $0x0,%eax
je     1265 <executeARMStoreInstruction+0x145>
movslq -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,0x4(%rax)
jmp    126e <executeARMStoreInstruction+0x14e>
mov    -0x20(%rbp),%ecx
movslq -0x8(%rbp),%rax
mov    %ecx,(%rax)
jmp    1295 <executeARMStoreInstruction+0x175>
mov    -0x1c(%rbp),%eax
and    $0xe000000,%eax
cmp    $0x8000000,%eax
jne    1290 <executeARMStoreInstruction+0x170>
jmp    128b <executeARMStoreInstruction+0x16b>
jmp    128b <executeARMStoreInstruction+0x16b>
jmp    1295 <executeARMStoreInstruction+0x175>
jmp    129a <executeARMStoreInstruction+0x17a>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<executeARMStoreInstruction>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %esi,%r15d
movslq %edi,%rax
mov    (%rax),%ebp
add    %edx,%r15d
mov    %ebp,%eax
and    $0xc000000,%eax
cmp    $0x4000000,%eax
jne    1178 <executeARMStoreInstruction+0x58>
mov    %ebp,%ebx
shr    $0xc,%ebx
and    $0xf,%ebx
mov    %ebx,%edi
call   1040 <checkRegister@plt>
not    %ebp
test   $0x1200000,%ebp
jne    116d <executeARMStoreInstruction+0x4d>
lea    0xe9d(%rip),%rdi
mov    $0x1,%esi
call   1030 <ErrorDisplayMessage@plt>
mov    (%r14,%rbx,4),%eax
movslq %r15d,%rcx
mov    %eax,(%rcx)
jmp    11da <executeARMStoreInstruction+0xba>
mov    %ebp,%eax
and    $0xe000000,%eax
je     1192 <executeARMStoreInstruction+0x72>
cmp    $0x8000000,%eax
jne    11da <executeARMStoreInstruction+0xba>
nopl   0x0(%rax,%rax,1)
jmp    1190 <executeARMStoreInstruction+0x70>
mov    %ebp,%ebx
shr    $0xc,%ebx
and    $0xf,%ebx
mov    %ebx,%edi
call   1040 <checkRegister@plt>
mov    %ebp,%eax
not    %eax
test   $0x1200000,%eax
jne    11bd <executeARMStoreInstruction+0x9d>
lea    0xe4d(%rip),%rdi
mov    $0x1,%esi
call   1030 <ErrorDisplayMessage@plt>
mov    (%r14,%rbx,4),%ecx
movslq %r15d,%rax
test   $0x40,%bpl
jne    11ce <executeARMStoreInstruction+0xae>
mov    %ecx,(%rax)
jmp    11da <executeARMStoreInstruction+0xba>
mov    %ecx,(%rax)
mov    %ebx,%ecx
mov    0x4(%r14,%rcx,4),%ecx
mov    %ecx,0x4(%rax)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [35 x i8] c"DataHandler: unexpected write-back\00"
define void @executeARMStoreInstruction(i32 %0, i32 %1, i32 %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32*
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32* %3, i32** %8
%14 = load i32, i32* %5
%15 = sext i32 %14 to i64
%16 = inttoptr i64 %15 to i32*
%17 = load i32, i32* %16
store i32 %17, i32* %9
%18 = load i32, i32* %7
%19 = load i32, i32* %6
%20 = add nsw i32 %19, %18
store i32 %20, i32* %6
%21 = load i32, i32* %9
%22 = and i32 %21, 201326592
%23 = icmp eq i32 %22, 67108864
br i1 %23, label %24, label %49
24: ; preds = %4
%25 = load i32, i32* %9
%26 = ashr i32 %25, 12
%27 = and i32 %26, 15
store i32 %27, i32* %11
%28 = load i32, i32* %11
%29 = call i32 @checkRegister(i32 %28)
%30 = load i32, i32* %9
%31 = and i32 %30, 16777216
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %39
33: ; preds = %24
%34 = load i32, i32* %9
%35 = and i32 %34, 2097152
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %33
%38 = call i32 @ErrorDisplayMessage(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 1)
br label %39
39: ; preds = %37, %33, %24
%40 = load i32*, i32** %8
%41 = load i32, i32* %11
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i32, i32* %40, i64 %42
%44 = load i32, i32* %43
store i32 %44, i32* %10
%45 = load i32, i32* %10
%46 = load i32, i32* %6
%47 = sext i32 %46 to i64
%48 = inttoptr i64 %47 to i32*
store i32 %45, i32* %48
br label %107
49: ; preds = %4
%50 = load i32, i32* %9
%51 = and i32 %50, 234881024
%52 = icmp eq i32 %51, 0
br i1 %52, label %53, label %99
53: ; preds = %49
%54 = load i32, i32* %9
%55 = ashr i32 %54, 12
%56 = and i32 %55, 15
store i32 %56, i32* %12
%57 = load i32, i32* %12
%58 = call i32 @checkRegister(i32 %57)
%59 = load i32, i32* %9
%60 = and i32 %59, 16777216
%61 = icmp ne i32 %60, 0
br i1 %61, label %62, label %68
62: ; preds = %53
%63 = load i32, i32* %9
%64 = and i32 %63, 2097152
%65 = icmp ne i32 %64, 0
br i1 %65, label %66, label %68
66: ; preds = %62
%67 = call i32 @ErrorDisplayMessage(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 1)
br label %68
68: ; preds = %66, %62, %53
%69 = load i32*, i32** %8
%70 = load i32, i32* %12
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds i32, i32* %69, i64 %71
%73 = load i32, i32* %72
store i32 %73, i32* %10
%74 = load i32, i32* %9
%75 = and i32 %74, 64
%76 = icmp ne i32 %75, 0
br i1 %76, label %77, label %93
77: ; preds = %68
%78 = load i32, i32* %6
%79 = sext i32 %78 to i64
%80 = inttoptr i64 %79 to i32*
store i32* %80, i32** %13
%81 = load i32, i32* %10
%82 = load i32*, i32** %13
%83 = getelementptr inbounds i32, i32* %82, i64 0
store volatile i32 %81, i32* %83
%84 = load i32*, i32** %8
%85 = load i32, i32* %12
%86 = add nsw i32 %85, 1
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds i32, i32* %84, i64 %87
%89 = load i32, i32* %88
store i32 %89, i32* %10
%90 = load i32, i32* %10
%91 = load i32*, i32** %13
%92 = getelementptr inbounds i32, i32* %91, i64 1
store volatile i32 %90, i32* %92
br label %98
93: ; preds = %68
%94 = load i32, i32* %10
%95 = load i32, i32* %6
%96 = sext i32 %95 to i64
%97 = inttoptr i64 %96 to i32*
store i32 %94, i32* %97
br label %98
98: ; preds = %93, %77
br label %106
99: ; preds = %49
%100 = load i32, i32* %9
%101 = and i32 %100, 234881024
%102 = icmp eq i32 %101, 134217728
br i1 %102, label %103, label %105
103: ; preds = %99
br label %104
104: ; preds = %104, %103
br label %104
105: ; preds = %99
br label %106
106: ; preds = %105, %98
br label %107
107: ; preds = %106, %39
ret void
}

LLVM IR (-O2):
@.str = [35 x i8] c"DataHandler: unexpected write-back\00"
define void @executeARMStoreInstruction(i32 %0, i32 %1, i32 %2, i32* nocapture %3) {
%5 = sext i32 %0 to i64
%6 = inttoptr i64 %5 to i32*
%7 = load i32, i32* %6
%8 = add nsw i32 %2, %1
%9 = and i32 %7, 201326592
%10 = icmp eq i32 %9, 67108864
br i1 %10, label %11, label %25
11: ; preds = %4
%12 = lshr i32 %7, 12
%13 = and i32 %12, 15
%14 = tail call i32 @checkRegister(i32 %13)
%15 = and i32 %7, 18874368
%16 = icmp eq i32 %15, 18874368
br i1 %16, label %17, label %19
17: ; preds = %11
%18 = tail call i32 @ErrorDisplayMessage(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 1)
br label %19
19: ; preds = %17, %11
%20 = zext i32 %13 to i64
%21 = getelementptr inbounds i32, i32* %3, i64 %20
%22 = load i32, i32* %21
%23 = sext i32 %8 to i64
%24 = inttoptr i64 %23 to i32*
store i32 %22, i32* %24
br label %51
25: ; preds = %4
%26 = and i32 %7, 234881024
switch i32 %26, label %51 [
i32 0, label %27
i32 134217728, label %50
]
27: ; preds = %25
%28 = lshr i32 %7, 12
%29 = and i32 %28, 15
%30 = tail call i32 @checkRegister(i32 %29)
%31 = and i32 %7, 18874368
%32 = icmp eq i32 %31, 18874368
br i1 %32, label %33, label %35
33: ; preds = %27
%34 = tail call i32 @ErrorDisplayMessage(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 1)
br label %35
35: ; preds = %33, %27
%36 = zext i32 %29 to i64
%37 = getelementptr inbounds i32, i32* %3, i64 %36
%38 = load i32, i32* %37
%39 = and i32 %7, 64
%40 = icmp eq i32 %39, 0
%41 = sext i32 %8 to i64
%42 = inttoptr i64 %41 to i32*
br i1 %40, label %49, label %43
43: ; preds = %35
store volatile i32 %38, i32* %42
%44 = add nuw nsw i32 %29, 1
%45 = zext i32 %44 to i64
%46 = getelementptr inbounds i32, i32* %3, i64 %45
%47 = load i32, i32* %46
%48 = getelementptr inbounds i32, i32* %42, i64 1
store volatile i32 %47, i32* %48
br label %51
49: ; preds = %35
store i32 %38, i32* %42
br label %51
50: ; preds = %25, %50
br label %50
51: ; preds = %25, %43, %49, %19
ret void
}