#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*/ RTExceptions_GetExceptionBlock();
char *RTExceptions_GetTextBuffer(int /*<<< orphan*/);
scalar_t__ RTExceptions_IsInExceptionState();
void EXCEPTIONS_GetMessage(char *text, unsigned int _text_high) {
  unsigned int i;
  unsigned int h;
  char *p;
  if (RTExceptions_IsInExceptionState()) {
    h = _text_high;
    i = 0;
    p = RTExceptions_GetTextBuffer(RTExceptions_GetExceptionBlock());
    while ((p != NULL) && ((*p) != (char)000)) {
      text[i] = (*p);
      i += 1;
      p += 1;
    }
    if (i <= h) {
      text[i] = (char)000;
    }
  } else {
    text[0] = (char)000;
  }
}


x86 assembly (clang, -O0):
<EXCEPTIONS_GetMessage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    $0x0,%al
call   1050 <RTExceptions_IsInExceptionState@plt>
cmp    $0x0,%rax
je     11e5 <EXCEPTIONS_GetMessage+0xb5>
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
mov    $0x0,%al
call   1040 <RTExceptions_GetExceptionBlock@plt>
mov    %eax,%edi
call   1030 <RTExceptions_GetTextBuffer@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x20(%rbp)
mov    %al,-0x21(%rbp)
je     118f <EXCEPTIONS_GetMessage+0x5f>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    119f <EXCEPTIONS_GetMessage+0x6f>
jmp    11c9 <EXCEPTIONS_GetMessage+0x99>
mov    -0x20(%rbp),%rax
mov    (%rax),%dl
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    116f <EXCEPTIONS_GetMessage+0x3f>
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
ja     11e0 <EXCEPTIONS_GetMessage+0xb0>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
movb   $0x0,(%rax,%rcx,1)
jmp    11ec <EXCEPTIONS_GetMessage+0xbc>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<EXCEPTIONS_GetMessage>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %rdi,%rbx
xor    %ebp,%ebp
xor    %eax,%eax
call   1050 <RTExceptions_IsInExceptionState@plt>
test   %rax,%rax
je     118c <EXCEPTIONS_GetMessage+0x5c>
xor    %eax,%eax
call   1040 <RTExceptions_GetExceptionBlock@plt>
mov    %eax,%edi
call   1030 <RTExceptions_GetTextBuffer@plt>
test   %rax,%rax
je     1187 <EXCEPTIONS_GetMessage+0x57>
mov    (%rax),%cl
xor    %ebp,%ebp
test   %cl,%cl
je     1182 <EXCEPTIONS_GetMessage+0x52>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebp,%edx
mov    %cl,(%rbx,%rdx,1)
movzbl 0x1(%rax,%rbp,1),%ecx
add    $0x1,%rbp
test   %cl,%cl
jne    1170 <EXCEPTIONS_GetMessage+0x40>
cmp    %r14d,%ebp
ja     118f <EXCEPTIONS_GetMessage+0x5f>
mov    %ebp,%eax
add    %rax,%rbx
movb   $0x0,(%rbx)
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @EXCEPTIONS_GetMessage(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
%8 = call i64 (...) @RTExceptions_IsInExceptionState()
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %45
10: ; preds = %2
%11 = load i32, i32* %4
store i32 %11, i32* %6
store i32 0, i32* %5
%12 = call i32 (...) @RTExceptions_GetExceptionBlock()
%13 = call i8* @RTExceptions_GetTextBuffer(i32 %12)
store i8* %13, i8** %7
br label %14
14: ; preds = %24, %10
%15 = load i8*, i8** %7
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %22
17: ; preds = %14
%18 = load i8*, i8** %7
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp ne i32 %20, 0
br label %22
22: ; preds = %17, %14
%23 = phi i1 [ false, %14 ], [ %21, %17 ]
br i1 %23, label %24, label %35
24: ; preds = %22
%25 = load i8*, i8** %7
%26 = load i8, i8* %25
%27 = load i8*, i8** %3
%28 = load i32, i32* %5
%29 = zext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
store i8 %26, i8* %30
%31 = load i32, i32* %5
%32 = add i32 %31, 1
store i32 %32, i32* %5
%33 = load i8*, i8** %7
%34 = getelementptr inbounds i8, i8* %33, i64 1
store i8* %34, i8** %7
br label %14
35: ; preds = %22
%36 = load i32, i32* %5
%37 = load i32, i32* %6
%38 = icmp ule i32 %36, %37
br i1 %38, label %39, label %44
39: ; preds = %35
%40 = load i8*, i8** %3
%41 = load i32, i32* %5
%42 = zext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %40, i64 %42
store i8 0, i8* %43
br label %44
44: ; preds = %39, %35
br label %48
45: ; preds = %2
%46 = load i8*, i8** %3
%47 = getelementptr inbounds i8, i8* %46, i64 0
store i8 0, i8* %47
br label %48
48: ; preds = %45, %44
ret void
}

LLVM IR (-O2):
define void @EXCEPTIONS_GetMessage(i8* nocapture writeonly %0, i32 %1) {
%3 = tail call i64 (...) @RTExceptions_IsInExceptionState()
%4 = icmp eq i64 %3, 0
br i1 %4, label %29, label %5
5: ; preds = %2
%6 = tail call i32 (...) @RTExceptions_GetExceptionBlock()
%7 = tail call i8* @RTExceptions_GetTextBuffer(i32 %6)
%8 = icmp eq i8* %7, null
br i1 %8, label %25, label %9
9: ; preds = %5
%10 = load i8, i8* %7
%11 = icmp eq i8 %10, 0
br i1 %11, label %22, label %12
12: ; preds = %9, %12
%13 = phi i8 [ %20, %12 ], [ %10, %9 ]
%14 = phi i32 [ %18, %12 ], [ 0, %9 ]
%15 = phi i8* [ %19, %12 ], [ %7, %9 ]
%16 = zext i32 %14 to i64
%17 = getelementptr inbounds i8, i8* %0, i64 %16
store i8 %13, i8* %17
%18 = add i32 %14, 1
%19 = getelementptr inbounds i8, i8* %15, i64 1
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 0
br i1 %21, label %22, label %12
22: ; preds = %12, %9
%23 = phi i32 [ 0, %9 ], [ %18, %12 ]
%24 = icmp ugt i32 %23, %1
br i1 %24, label %31, label %25
25: ; preds = %5, %22
%26 = phi i32 [ %23, %22 ], [ 0, %5 ]
%27 = zext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %0, i64 %27
br label %29
29: ; preds = %2, %25
%30 = phi i8* [ %28, %25 ], [ %0, %2 ]
store i8 0, i8* %30
br label %31
31: ; preds = %29, %22
ret void
}