#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 */

/* Variables and functions */
int /*<<< orphan*/ __mriCmd_Send_T_StopResponse();
int /*<<< orphan*/ __mriCore_GdbCommandHandlingLoop();
int __mriCore_IsWaitingForGdbToConnect();
scalar_t__ __mriPlatform_CommCausedInterrupt();
int /*<<< orphan*/ __mriPlatform_CommClearInterrupt();
int /*<<< orphan*/ __mriPlatform_CommHasReceiveData();
int /*<<< orphan*/ __mriPlatform_DisplayFaultCauseToGdbConsole();
int /*<<< orphan*/ __mriPlatform_EnteringDebugger();
int /*<<< orphan*/ __mriPlatform_EnteringDebuggerHook();
int __mriPlatform_IsSingleStepping();
scalar_t__ __mriSemihost_HandleSemihostRequest();
scalar_t__ __mriSemihost_IsDebuggeeMakingSemihostCall();
int /*<<< orphan*/ blockIfGdbHasNotConnected();
int /*<<< orphan*/ determineSignalValue();
scalar_t__ isDebugTrap();
int /*<<< orphan*/ prepareForDebuggerExit();
void __mriDebugException(void) {
  int wasWaitingForGdbToConnect = __mriCore_IsWaitingForGdbToConnect();
  int justSingleStepped = __mriPlatform_IsSingleStepping();
  if (__mriPlatform_CommCausedInterrupt() &&
      !__mriPlatform_CommHasReceiveData()) {
    __mriPlatform_CommClearInterrupt();
    return;
  }
  __mriPlatform_EnteringDebuggerHook();
  blockIfGdbHasNotConnected();
  __mriPlatform_EnteringDebugger();
  determineSignalValue();
  if (isDebugTrap() && __mriSemihost_IsDebuggeeMakingSemihostCall() &&
      __mriSemihost_HandleSemihostRequest() && !justSingleStepped) {
    prepareForDebuggerExit();
    return;
  }
  if (!wasWaitingForGdbToConnect) {
    __mriPlatform_DisplayFaultCauseToGdbConsole();
    __mriCmd_Send_T_StopResponse();
  }
  __mriCore_GdbCommandHandlingLoop();
  prepareForDebuggerExit();
}


x86 assembly (clang, -O0):
<__mriDebugException>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1060 <__mriCore_IsWaitingForGdbToConnect@plt>
mov    %eax,-0x4(%rbp)
mov    $0x0,%al
call   1080 <__mriPlatform_IsSingleStepping@plt>
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1040 <__mriPlatform_CommCausedInterrupt@plt>
cmp    $0x0,%rax
je     1249 <__mriDebugException+0x49>
mov    $0x0,%al
call   1050 <__mriPlatform_CommHasReceiveData@plt>
cmp    $0x0,%eax
jne    1249 <__mriDebugException+0x49>
mov    $0x0,%al
call   10e0 <__mriPlatform_CommClearInterrupt@plt>
jmp    12d4 <__mriDebugException+0xd4>
mov    $0x0,%al
call   1070 <__mriPlatform_EnteringDebuggerHook@plt>
mov    $0x0,%al
call   1120 <blockIfGdbHasNotConnected@plt>
mov    $0x0,%al
call   1090 <__mriPlatform_EnteringDebugger@plt>
mov    $0x0,%al
call   1100 <determineSignalValue@plt>
mov    $0x0,%al
call   1110 <isDebugTrap@plt>
cmp    $0x0,%rax
je     12ae <__mriDebugException+0xae>
mov    $0x0,%al
call   10d0 <__mriSemihost_IsDebuggeeMakingSemihostCall@plt>
cmp    $0x0,%rax
je     12ae <__mriDebugException+0xae>
mov    $0x0,%al
call   10b0 <__mriSemihost_HandleSemihostRequest@plt>
cmp    $0x0,%rax
je     12ae <__mriDebugException+0xae>
cmpl   $0x0,-0x8(%rbp)
jne    12ae <__mriDebugException+0xae>
mov    $0x0,%al
call   10c0 <prepareForDebuggerExit@plt>
jmp    12d4 <__mriDebugException+0xd4>
cmpl   $0x0,-0x4(%rbp)
jne    12c6 <__mriDebugException+0xc6>
mov    $0x0,%al
call   10f0 <__mriPlatform_DisplayFaultCauseToGdbConsole@plt>
mov    $0x0,%al
call   10a0 <__mriCmd_Send_T_StopResponse@plt>
mov    $0x0,%al
call   1030 <__mriCore_GdbCommandHandlingLoop@plt>
mov    $0x0,%al
call   10c0 <prepareForDebuggerExit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__mriDebugException>:
push   %rbp
push   %rbx
push   %rax
xor    %eax,%eax
call   1060 <__mriCore_IsWaitingForGdbToConnect@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1080 <__mriPlatform_IsSingleStepping@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1040 <__mriPlatform_CommCausedInterrupt@plt>
test   %rax,%rax
je     122c <__mriDebugException+0x2c>
xor    %eax,%eax
call   1050 <__mriPlatform_CommHasReceiveData@plt>
test   %eax,%eax
je     1296 <__mriDebugException+0x96>
xor    %eax,%eax
call   1070 <__mriPlatform_EnteringDebuggerHook@plt>
xor    %eax,%eax
call   1120 <blockIfGdbHasNotConnected@plt>
xor    %eax,%eax
call   1090 <__mriPlatform_EnteringDebugger@plt>
xor    %eax,%eax
call   1100 <determineSignalValue@plt>
xor    %eax,%eax
call   1110 <isDebugTrap@plt>
test   %rax,%rax
je     1270 <__mriDebugException+0x70>
xor    %eax,%eax
call   10d0 <__mriSemihost_IsDebuggeeMakingSemihostCall@plt>
test   %rax,%rax
je     1270 <__mriDebugException+0x70>
xor    %eax,%eax
call   10b0 <__mriSemihost_HandleSemihostRequest@plt>
test   %rax,%rax
je     1270 <__mriDebugException+0x70>
test   %ebp,%ebp
je     1289 <__mriDebugException+0x89>
test   %ebx,%ebx
jne    1282 <__mriDebugException+0x82>
xor    %eax,%eax
call   10f0 <__mriPlatform_DisplayFaultCauseToGdbConsole@plt>
xor    %eax,%eax
call   10a0 <__mriCmd_Send_T_StopResponse@plt>
xor    %eax,%eax
call   1030 <__mriCore_GdbCommandHandlingLoop@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    10c0 <prepareForDebuggerExit@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    10e0 <__mriPlatform_CommClearInterrupt@plt>

LLVM IR (-O0):
define void @__mriDebugException() {
%1 = alloca i32
%2 = alloca i32
%3 = call i32 (...) @__mriCore_IsWaitingForGdbToConnect()
store i32 %3, i32* %1
%4 = call i32 (...) @__mriPlatform_IsSingleStepping()
store i32 %4, i32* %2
%5 = call i64 (...) @__mriPlatform_CommCausedInterrupt()
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %12
7: ; preds = %0
%8 = call i32 (...) @__mriPlatform_CommHasReceiveData()
%9 = icmp ne i32 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = call i32 (...) @__mriPlatform_CommClearInterrupt()
br label %39
12: ; preds = %7, %0
%13 = call i32 (...) @__mriPlatform_EnteringDebuggerHook()
%14 = call i32 (...) @blockIfGdbHasNotConnected()
%15 = call i32 (...) @__mriPlatform_EnteringDebugger()
%16 = call i32 (...) @determineSignalValue()
%17 = call i64 (...) @isDebugTrap()
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %30
19: ; preds = %12
%20 = call i64 (...) @__mriSemihost_IsDebuggeeMakingSemihostCall()
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %30
22: ; preds = %19
%23 = call i64 (...) @__mriSemihost_HandleSemihostRequest()
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %22
%26 = load i32, i32* %2
%27 = icmp ne i32 %26, 0
br i1 %27, label %30, label %28
28: ; preds = %25
%29 = call i32 (...) @prepareForDebuggerExit()
br label %39
30: ; preds = %25, %22, %19, %12
%31 = load i32, i32* %1
%32 = icmp ne i32 %31, 0
br i1 %32, label %36, label %33
33: ; preds = %30
%34 = call i32 (...) @__mriPlatform_DisplayFaultCauseToGdbConsole()
%35 = call i32 (...) @__mriCmd_Send_T_StopResponse()
br label %36
36: ; preds = %33, %30
%37 = call i32 (...) @__mriCore_GdbCommandHandlingLoop()
%38 = call i32 (...) @prepareForDebuggerExit()
br label %39
39: ; preds = %36, %28, %10
ret void
}

LLVM IR (-O2):
define void @__mriDebugException() {
%1 = tail call i32 (...) @__mriCore_IsWaitingForGdbToConnect()
%2 = tail call i32 (...) @__mriPlatform_IsSingleStepping()
%3 = tail call i64 (...) @__mriPlatform_CommCausedInterrupt()
%4 = icmp eq i64 %3, 0
br i1 %4, label %10, label %5
5: ; preds = %0
%6 = tail call i32 (...) @__mriPlatform_CommHasReceiveData()
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = tail call i32 (...) @__mriPlatform_CommClearInterrupt()
br label %35
10: ; preds = %5, %0
%11 = tail call i32 (...) @__mriPlatform_EnteringDebuggerHook()
%12 = tail call i32 (...) @blockIfGdbHasNotConnected()
%13 = tail call i32 (...) @__mriPlatform_EnteringDebugger()
%14 = tail call i32 (...) @determineSignalValue()
%15 = tail call i64 (...) @isDebugTrap()
%16 = icmp eq i64 %15, 0
br i1 %16, label %27, label %17
17: ; preds = %10
%18 = tail call i64 (...) @__mriSemihost_IsDebuggeeMakingSemihostCall()
%19 = icmp eq i64 %18, 0
br i1 %19, label %27, label %20
20: ; preds = %17
%21 = tail call i64 (...) @__mriSemihost_HandleSemihostRequest()
%22 = icmp eq i64 %21, 0
%23 = icmp ne i32 %2, 0
%24 = select i1 %22, i1 true, i1 %23
br i1 %24, label %27, label %25
25: ; preds = %20
%26 = tail call i32 (...) @prepareForDebuggerExit()
br label %35
27: ; preds = %20, %17, %10
%28 = icmp eq i32 %1, 0
br i1 %28, label %29, label %32
29: ; preds = %27
%30 = tail call i32 (...) @__mriPlatform_DisplayFaultCauseToGdbConsole()
%31 = tail call i32 (...) @__mriCmd_Send_T_StopResponse()
br label %32
32: ; preds = %29, %27
%33 = tail call i32 (...) @__mriCore_GdbCommandHandlingLoop()
%34 = tail call i32 (...) @prepareForDebuggerExit()
br label %35
35: ; preds = %32, %25, %8
ret void
}