#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 */
typedef struct TYPE_7__ TYPE_3__;
typedef struct TYPE_6__ TYPE_2__;
typedef struct TYPE_5__ TYPE_1__;

/* Type definitions */
struct TYPE_5__ {
  int /*<<< orphan*/ gregs;
};
struct TYPE_6__ {
  TYPE_1__ uc_mcontext;
};
typedef TYPE_2__ ucontext_t;
typedef int /*<<< orphan*/ skipped;
struct TYPE_7__ {
  char *si_addr;
};
typedef TYPE_3__ siginfo_t;
typedef int /*<<< orphan*/ patched;
typedef int /*<<< orphan*/ mprotect_write_fail;
typedef int /*<<< orphan*/ mprotect_unwrite_fail;
typedef int greg_t;

/* Variables and functions */
int PROT_EXEC;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ abort();
scalar_t__ mprotect(void *, size_t, int);
size_t snprintf(char *, int, char *, int, int, int, int, int, int, int, int,
                int, int, int, int, int, int, int, int, int, int, int, int, int,
                int, int);
int /*<<< orphan*/ write(int, char const *, int);
void regprinting_illhandler(int signum, siginfo_t *info, void *ucontext) {
  ucontext_t *uc = (ucontext_t *)ucontext;
  greg_t *gregs = (greg_t *)&uc->uc_mcontext.gregs;
  char regdump[1024];
  size_t regdumpsz =
      snprintf(regdump, 1024,
               "rax      = %#018lx\n"
               "rbx      = %#018lx\n"
               "rcx      = %#018lx\n"
               "rdx      = %#018lx\n"
               "rsi      = %#018lx\n"
               "rdi      = %#018lx\n"
               "rbp      = %#018lx\n"
               "rsp      = %#018lx\n"
               "r8       = %#018lx\n"
               "r9       = %#018lx\n"
               "r10      = %#018lx\n"
               "r11      = %#018lx\n"
               "r12      = %#018lx\n"
               "r13      = %#018lx\n"
               "r14      = %#018lx\n"
               "r15      = %#018lx\n"
               "rip      = %#018lx\n"
               "efl      = %#018lx\n"
               "CGGSFS00 = %#018lx\n"
               "err      = %#018lx\n"
               "trapno   = %#018lx\n"
               "oldmask  = %#018lx\n"
               "cr       = %#018lx\n",
               gregs[13], gregs[11], gregs[14], gregs[12], gregs[9], gregs[8],
               gregs[10], gregs[15], gregs[0], gregs[1], gregs[2], gregs[3],
               gregs[4], gregs[5], gregs[6], gregs[7], gregs[16], gregs[17],
               gregs[18], gregs[19], gregs[20], gregs[21], gregs[22]);
  if (regdumpsz < 1024) {
    write(2, regdump, regdumpsz);
  }
  char *manip = info->si_addr;
  if (*manip == 0x06) {
    gregs[16] += 1;
    const char skipped[] = "Skipped 0x06.\n";
    write(2, skipped, sizeof(skipped) - 1);
  } else if (*manip == 0x07) {
    intptr_t page = (intptr_t)info->si_addr;
    intptr_t pagesz = 4096;
    page = page & ~(pagesz - 1);
    void *ppage = (void *)page;
    if (mprotect(ppage, (size_t)pagesz, PROT_READ | PROT_WRITE | PROT_EXEC)) {
      const char mprotect_write_fail[] = "Can't make page writable.\n";
      write(2, mprotect_write_fail, sizeof(mprotect_write_fail) - 1);
    }
    *manip = 0x90;
    if (mprotect(ppage, (size_t)pagesz, PROT_READ | PROT_EXEC)) {
      const char mprotect_unwrite_fail[] = "Can't make page unwritable.\n";
      write(2, mprotect_unwrite_fail, sizeof(mprotect_unwrite_fail) - 1);
    }
    const char patched[] = "Patched 0x07.\n";
    write(2, patched, sizeof(patched) - 1);
  } else {
    abort();
  }
}


x86 assembly (clang, -O0):
<regprinting_illhandler>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x588,%rsp
mov    %edi,-0x2c(%rbp)
mov    %rsi,-0x38(%rbp)
mov    %rdx,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,-0x50(%rbp)
lea    -0x450(%rbp),%rdi
mov    -0x50(%rbp),%rax
mov    0x34(%rax),%ecx
mov    -0x50(%rbp),%rax
mov    0x2c(%rax),%r8d
mov    -0x50(%rbp),%rax
mov    0x38(%rax),%r9d
mov    -0x50(%rbp),%rax
mov    0x30(%rax),%eax
mov    -0x50(%rbp),%rdx
mov    0x24(%rdx),%edx
mov    %edx,-0x510(%rbp)
mov    -0x50(%rbp),%rdx
mov    0x20(%rdx),%edx
mov    %edx,-0x50c(%rbp)
mov    -0x50(%rbp),%rdx
mov    0x28(%rdx),%edx
mov    %edx,-0x508(%rbp)
mov    -0x50(%rbp),%rdx
mov    0x3c(%rdx),%edx
mov    %edx,-0x504(%rbp)
mov    -0x50(%rbp),%rdx
mov    (%rdx),%edx
mov    %edx,-0x500(%rbp)
mov    -0x50(%rbp),%rdx
mov    0x4(%rdx),%edx
mov    %edx,-0x4fc(%rbp)
mov    -0x50(%rbp),%rdx
mov    0x8(%rdx),%edx
mov    %edx,-0x4f8(%rbp)
mov    -0x50(%rbp),%rdx
mov    0xc(%rdx),%edx
mov    %edx,-0x4f4(%rbp)
mov    -0x50(%rbp),%rdx
mov    0x10(%rdx),%edx
mov    %edx,-0x4f0(%rbp)
mov    -0x50(%rbp),%rdx
mov    0x14(%rdx),%edx
mov    %edx,-0x4ec(%rbp)
mov    -0x50(%rbp),%rdx
mov    0x18(%rdx),%edx
mov    %edx,-0x4e8(%rbp)
mov    -0x50(%rbp),%rdx
mov    0x1c(%rdx),%r13d
mov    -0x50(%rbp),%rdx
mov    0x40(%rdx),%r12d
mov    -0x50(%rbp),%rdx
mov    0x44(%rdx),%r15d
mov    -0x50(%rbp),%rdx
mov    0x48(%rdx),%r14d
mov    -0x50(%rbp),%rdx
mov    0x4c(%rdx),%ebx
mov    -0x50(%rbp),%rdx
mov    0x50(%rdx),%r11d
mov    -0x50(%rbp),%rdx
mov    0x54(%rdx),%r10d
mov    -0x50(%rbp),%rdx
mov    0x58(%rdx),%edx
mov    %edx,-0x4e4(%rbp)
mov    $0x400,%esi
lea    0xd8e(%rip),%rdx
mov    %eax,(%rsp)
mov    -0x510(%rbp),%eax
mov    %eax,0x8(%rsp)
mov    -0x50c(%rbp),%eax
mov    %eax,0x10(%rsp)
mov    -0x508(%rbp),%eax
mov    %eax,0x18(%rsp)
mov    -0x504(%rbp),%eax
mov    %eax,0x20(%rsp)
mov    -0x500(%rbp),%eax
mov    %eax,0x28(%rsp)
mov    -0x4fc(%rbp),%eax
mov    %eax,0x30(%rsp)
mov    -0x4f8(%rbp),%eax
mov    %eax,0x38(%rsp)
mov    -0x4f4(%rbp),%eax
mov    %eax,0x40(%rsp)
mov    -0x4f0(%rbp),%eax
mov    %eax,0x48(%rsp)
mov    -0x4ec(%rbp),%eax
mov    %eax,0x50(%rsp)
mov    -0x4e8(%rbp),%eax
mov    %eax,0x58(%rsp)
mov    -0x4e4(%rbp),%eax
mov    %r13d,0x60(%rsp)
mov    %r12d,0x68(%rsp)
mov    %r15d,0x70(%rsp)
mov    %r14d,0x78(%rsp)
mov    %ebx,0x80(%rsp)
mov    %r11d,0x88(%rsp)
mov    %r10d,0x90(%rsp)
mov    %eax,0x98(%rsp)
call   1050 <snprintf@plt>
mov    %rax,-0x458(%rbp)
cmpq   $0x400,-0x458(%rbp)
jae    1352 <regprinting_illhandler+0x212>
lea    -0x450(%rbp),%rsi
mov    -0x458(%rbp),%rax
mov    %eax,%edx
mov    $0x2,%edi
call   1040 <write@plt>
mov    -0x38(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x460(%rbp)
mov    -0x460(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x6,%eax
jne    13cf <regprinting_illhandler+0x28f>
mov    -0x50(%rbp),%rax
mov    0x40(%rax),%ecx
add    $0x1,%ecx
mov    %ecx,0x40(%rax)
mov    0xe2f(%rip),%rax
mov    %rax,-0x46f(%rbp)
mov    0xe2a(%rip),%eax
mov    %eax,-0x467(%rbp)
mov    0xe21(%rip),%ax
mov    %ax,-0x463(%rbp)
mov    0xe16(%rip),%al
mov    %al,-0x461(%rbp)
lea    -0x46f(%rbp),%rsi
mov    $0x2,%edi
mov    $0xe,%edx
call   1040 <write@plt>
jmp    15a7 <regprinting_illhandler+0x467>
mov    -0x460(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x7,%eax
jne    159b <regprinting_illhandler+0x45b>
mov    -0x38(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x478(%rbp)
movq   $0x1000,-0x480(%rbp)
mov    -0x478(%rbp),%rax
mov    -0x480(%rbp),%rcx
sub    $0x1,%rcx
xor    $0xffffffffffffffff,%rcx
and    %rcx,%rax
mov    %rax,-0x478(%rbp)
mov    -0x478(%rbp),%rax
mov    %rax,-0x488(%rbp)
mov    -0x488(%rbp),%rdi
mov    -0x480(%rbp),%rsi
mov    0x2bba(%rip),%rax
mov    (%rax),%edx
mov    0x2b89(%rip),%rax
or     (%rax),%edx
mov    0x2b90(%rip),%rax
or     (%rax),%edx
call   1060 <mprotect@plt>
cmp    $0x0,%rax
je     14bb <regprinting_illhandler+0x37b>
mov    0xd78(%rip),%rax
mov    %rax,-0x4b0(%rbp)
mov    0xd72(%rip),%rax
mov    %rax,-0x4a8(%rbp)
mov    0xd6c(%rip),%rax
mov    %rax,-0x4a0(%rbp)
mov    0xd66(%rip),%ax
mov    %ax,-0x498(%rbp)
mov    0xd5b(%rip),%al
mov    %al,-0x496(%rbp)
lea    -0x4b0(%rbp),%rsi
mov    $0x2,%edi
mov    $0x1a,%edx
call   1040 <write@plt>
mov    -0x460(%rbp),%rax
movb   $0x90,(%rax)
mov    -0x488(%rbp),%rdi
mov    -0x480(%rbp),%rsi
mov    0x2b1e(%rip),%rax
mov    (%rax),%edx
mov    0x2afd(%rip),%rax
or     (%rax),%edx
call   1060 <mprotect@plt>
cmp    $0x0,%rax
je     154c <regprinting_illhandler+0x40c>
mov    0xd05(%rip),%rax
mov    %rax,-0x4d0(%rbp)
mov    0xcff(%rip),%rax
mov    %rax,-0x4c8(%rbp)
mov    0xcf9(%rip),%rax
mov    %rax,-0x4c0(%rbp)
mov    0xcf4(%rip),%eax
mov    %eax,-0x4b8(%rbp)
mov    0xcec(%rip),%al
mov    %al,-0x4b4(%rbp)
lea    -0x4d0(%rbp),%rsi
mov    $0x2,%edi
mov    $0x1c,%edx
call   1040 <write@plt>
mov    0xc72(%rip),%rax
mov    %rax,-0x4df(%rbp)
mov    0xc6d(%rip),%eax
mov    %eax,-0x4d7(%rbp)
mov    0xc64(%rip),%ax
mov    %ax,-0x4d3(%rbp)
mov    0xc59(%rip),%al
mov    %al,-0x4d1(%rbp)
lea    -0x4df(%rbp),%rsi
mov    $0x2,%edi
mov    $0xe,%edx
call   1040 <write@plt>
jmp    15a2 <regprinting_illhandler+0x462>
mov    $0x0,%al
call   1030 <abort@plt>
jmp    15a7 <regprinting_illhandler+0x467>
add    $0x588,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

x86 assembly (clang, -O2):
<regprinting_illhandler>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x498,%rsp
mov    %rdx,%rbx
mov    %rsi,0x88(%rsp)
mov    0x34(%rdx),%ecx
mov    0x2c(%rdx),%r8d
mov    0x38(%rdx),%r9d
mov    0x30(%rdx),%eax
mov    %rax,0x80(%rsp)
mov    0x24(%rdx),%eax
mov    %rax,0x78(%rsp)
mov    0x20(%rdx),%eax
mov    %rax,0x70(%rsp)
mov    0x28(%rdx),%eax
mov    %rax,0x68(%rsp)
mov    0x3c(%rdx),%eax
mov    %rax,0x60(%rsp)
mov    (%rdx),%eax
mov    %rax,0x58(%rsp)
mov    0x4(%rdx),%eax
mov    %rax,0x50(%rsp)
mov    0x8(%rdx),%eax
mov    %rax,0x48(%rsp)
mov    0xc(%rdx),%eax
mov    %rax,0x40(%rsp)
mov    0x10(%rdx),%eax
mov    %rax,0x38(%rsp)
mov    0x14(%rdx),%eax
mov    %rax,0x30(%rsp)
mov    0x18(%rdx),%eax
mov    %rax,0x28(%rsp)
mov    0x1c(%rdx),%r13d
mov    0x40(%rdx),%eax
mov    0x44(%rdx),%ebp
mov    0x48(%rdx),%r14d
mov    0x4c(%rdx),%r10d
mov    0x50(%rdx),%r11d
mov    0x54(%rdx),%r15d
mov    0x58(%rdx),%r12d
lea    0xe12(%rip),%rdx
lea    0x90(%rsp),%rdi
mov    $0x400,%esi
push   %r12
push   %r15
push   %r11
push   %r10
push   %r14
push   %rbp
push   %rax
push   %r13
push   0x68(%rsp)
push   0x78(%rsp)
push   0x88(%rsp)
push   0x98(%rsp)
push   0xa8(%rsp)
push   0xb8(%rsp)
push   0xc8(%rsp)
push   0xd8(%rsp)
push   0xe8(%rsp)
push   0xf8(%rsp)
push   0x108(%rsp)
push   0x118(%rsp)
call   1050 <snprintf@plt>
add    $0xa0,%rsp
cmp    $0x3ff,%rax
ja     127f <regprinting_illhandler+0x13f>
lea    0x90(%rsp),%rsi
mov    $0x2,%edi
mov    %eax,%edx
call   1040 <write@plt>
mov    0x88(%rsp),%rax
mov    (%rax),%rbp
mov    0x0(%rbp),%al
cmp    $0x7,%al
je     12bb <regprinting_illhandler+0x17b>
cmp    $0x6,%al
jne    13a3 <regprinting_illhandler+0x263>
addl   $0x1,0x40(%rbx)
movabs $0xa2e3630783020,%rax
mov    %rax,0x7(%rsp)
movabs $0x2064657070696b53,%rax
65 64 20
jmp    137b <regprinting_illhandler+0x23b>
mov    %rbp,%rbx
mov    0x2d33(%rip),%r14
mov    0x2d04(%rip),%rax
mov    (%rax),%edx
or     (%r14),%edx
and    $0xfffffffffffff000,%rbx
mov    0x2d01(%rip),%r15
or     (%r15),%edx
mov    $0x1000,%esi
mov    %rbx,%rdi
call   1060 <mprotect@plt>
test   %rax,%rax
je     131d <regprinting_illhandler+0x1dd>
movups 0xef0(%rip),%xmm0
movups %xmm0,0xb(%rsp)
movaps 0xed9(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%rsi
mov    $0x2,%edi
mov    $0x1a,%edx
call   1040 <write@plt>
movb   $0x90,0x0(%rbp)
mov    (%r15),%edx
or     (%r14),%edx
mov    $0x1000,%esi
mov    %rbx,%rdi
call   1060 <mprotect@plt>
test   %rax,%rax
je     1362 <regprinting_illhandler+0x222>
movups 0xecd(%rip),%xmm0
movups %xmm0,0xd(%rsp)
movaps 0xeb4(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%rsi
mov    $0x2,%edi
mov    $0x1c,%edx
call   1040 <write@plt>
movabs $0xa2e3730783020,%rax
mov    %rax,0x7(%rsp)
movabs $0x2064656863746150,%rax
65 64 20
mov    %rax,(%rsp)
mov    %rsp,%rsi
mov    $0x2,%edi
mov    $0xe,%edx
call   1040 <write@plt>
add    $0x498,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
%struct.TYPE_7__ = type { i8* }
%struct.TYPE_6__ = type { %struct.TYPE_5__ }
%struct.TYPE_5__ = type { i32 }
@.str = [438 x i8] c"rax = %lx\0Arbx = %lx\0Arcx = %lx\0Ardx = %lx\0Arsi = %lx\0Ardi = %lx\0Arbp = %lx\0Arsp = %lx\0Ar8 = %lx\0Ar9 = %lx\0Ar10 = %lx\0Ar11 = %lx\0Ar12 = %lx\0Ar13 = %lx\0Ar14 = %lx\0Ar15 = %lx\0Arip = %lx\0Aefl = %lx\0ACGGSFS00 = %lx\0Aerr = %lx\0Atrapno = %lx\0Aoldmask = %lx\0Acr = %lx\0A\00"
@__const.regprinting_illhandler.skipped = [15 x i8] c"Skipped 0x06.\0A\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@PROT_EXEC = global i32 0
@__const.regprinting_illhandler.mprotect_write_fail = [27 x i8] c"Can't make page writable.\0A\00"
@__const.regprinting_illhandler.mprotect_unwrite_fail = [29 x i8] c"Can't make page unwritable.\0A\00"
@__const.regprinting_illhandler.patched = [15 x i8] c"Patched 0x07.\0A\00"
define void @regprinting_illhandler(i32 %0, %struct.TYPE_7__* %1, i8* %2) {
%4 = alloca i32
%5 = alloca %struct.TYPE_7__*
%6 = alloca i8*
%7 = alloca %struct.TYPE_6__*
%8 = alloca i32*
%9 = alloca [1024 x i8]
%10 = alloca i64
%11 = alloca i8*
%12 = alloca [15 x i8]
%13 = alloca i64
%14 = alloca i64
%15 = alloca i8*
%16 = alloca [27 x i8]
%17 = alloca [29 x i8]
%18 = alloca [15 x i8]
store i32 %0, i32* %4
store %struct.TYPE_7__* %1, %struct.TYPE_7__** %5
store i8* %2, i8** %6
%19 = load i8*, i8** %6
%20 = bitcast i8* %19 to %struct.TYPE_6__*
store %struct.TYPE_6__* %20, %struct.TYPE_6__** %7
%21 = load %struct.TYPE_6__*, %struct.TYPE_6__** %7
%22 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %21, i32 0, i32 0
%23 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %22, i32 0, i32 0
store i32* %23, i32** %8
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%25 = load i32*, i32** %8
%26 = getelementptr inbounds i32, i32* %25, i64 13
%27 = load i32, i32* %26
%28 = load i32*, i32** %8
%29 = getelementptr inbounds i32, i32* %28, i64 11
%30 = load i32, i32* %29
%31 = load i32*, i32** %8
%32 = getelementptr inbounds i32, i32* %31, i64 14
%33 = load i32, i32* %32
%34 = load i32*, i32** %8
%35 = getelementptr inbounds i32, i32* %34, i64 12
%36 = load i32, i32* %35
%37 = load i32*, i32** %8
%38 = getelementptr inbounds i32, i32* %37, i64 9
%39 = load i32, i32* %38
%40 = load i32*, i32** %8
%41 = getelementptr inbounds i32, i32* %40, i64 8
%42 = load i32, i32* %41
%43 = load i32*, i32** %8
%44 = getelementptr inbounds i32, i32* %43, i64 10
%45 = load i32, i32* %44
%46 = load i32*, i32** %8
%47 = getelementptr inbounds i32, i32* %46, i64 15
%48 = load i32, i32* %47
%49 = load i32*, i32** %8
%50 = getelementptr inbounds i32, i32* %49, i64 0
%51 = load i32, i32* %50
%52 = load i32*, i32** %8
%53 = getelementptr inbounds i32, i32* %52, i64 1
%54 = load i32, i32* %53
%55 = load i32*, i32** %8
%56 = getelementptr inbounds i32, i32* %55, i64 2
%57 = load i32, i32* %56
%58 = load i32*, i32** %8
%59 = getelementptr inbounds i32, i32* %58, i64 3
%60 = load i32, i32* %59
%61 = load i32*, i32** %8
%62 = getelementptr inbounds i32, i32* %61, i64 4
%63 = load i32, i32* %62
%64 = load i32*, i32** %8
%65 = getelementptr inbounds i32, i32* %64, i64 5
%66 = load i32, i32* %65
%67 = load i32*, i32** %8
%68 = getelementptr inbounds i32, i32* %67, i64 6
%69 = load i32, i32* %68
%70 = load i32*, i32** %8
%71 = getelementptr inbounds i32, i32* %70, i64 7
%72 = load i32, i32* %71
%73 = load i32*, i32** %8
%74 = getelementptr inbounds i32, i32* %73, i64 16
%75 = load i32, i32* %74
%76 = load i32*, i32** %8
%77 = getelementptr inbounds i32, i32* %76, i64 17
%78 = load i32, i32* %77
%79 = load i32*, i32** %8
%80 = getelementptr inbounds i32, i32* %79, i64 18
%81 = load i32, i32* %80
%82 = load i32*, i32** %8
%83 = getelementptr inbounds i32, i32* %82, i64 19
%84 = load i32, i32* %83
%85 = load i32*, i32** %8
%86 = getelementptr inbounds i32, i32* %85, i64 20
%87 = load i32, i32* %86
%88 = load i32*, i32** %8
%89 = getelementptr inbounds i32, i32* %88, i64 21
%90 = load i32, i32* %89
%91 = load i32*, i32** %8
%92 = getelementptr inbounds i32, i32* %91, i64 22
%93 = load i32, i32* %92
%94 = call i64 @snprintf(i8* %24, i32 1024, i8* getelementptr inbounds ([438 x i8], [438 x i8]* @.str, i64 0, i64 0), i32 %27, i32 %30, i32 %33, i32 %36, i32 %39, i32 %42, i32 %45, i32 %48, i32 %51, i32 %54, i32 %57, i32 %60, i32 %63, i32 %66, i32 %69, i32 %72, i32 %75, i32 %78, i32 %81, i32 %84, i32 %87, i32 %90, i32 %93)
store i64 %94, i64* %10
%95 = load i64, i64* %10
%96 = icmp ult i64 %95, 1024
br i1 %96, label %97, label %102
97: ; preds = %3
%98 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%99 = load i64, i64* %10
%100 = trunc i64 %99 to i32
%101 = call i32 @write(i32 2, i8* %98, i32 %100)
br label %102
102: ; preds = %97, %3
%103 = load %struct.TYPE_7__*, %struct.TYPE_7__** %5
%104 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %103, i32 0, i32 0
%105 = load i8*, i8** %104
store i8* %105, i8** %11
%106 = load i8*, i8** %11
%107 = load i8, i8* %106
%108 = sext i8 %107 to i32
%109 = icmp eq i32 %108, 6
br i1 %109, label %110, label %118
110: ; preds = %102
%111 = load i32*, i32** %8
%112 = getelementptr inbounds i32, i32* %111, i64 16
%113 = load i32, i32* %112
%114 = add nsw i32 %113, 1
store i32 %114, i32* %112
%115 = bitcast [15 x i8]* %12 to i8*
%116 = getelementptr inbounds [15 x i8], [15 x i8]* %12, i64 0, i64 0
%117 = call i32 @write(i32 2, i8* %116, i32 14)
br label %168
118: ; preds = %102
%119 = load i8*, i8** %11
%120 = load i8, i8* %119
%121 = sext i8 %120 to i32
%122 = icmp eq i32 %121, 7
br i1 %122, label %123, label %165
123: ; preds = %118
%124 = load %struct.TYPE_7__*, %struct.TYPE_7__** %5
%125 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %124, i32 0, i32 0
%126 = load i8*, i8** %125
%127 = ptrtoint i8* %126 to i64
store i64 %127, i64* %13
store i64 4096, i64* %14
%128 = load i64, i64* %13
%129 = load i64, i64* %14
%130 = sub nsw i64 %129, 1
%131 = xor i64 %130, -1
%132 = and i64 %128, %131
store i64 %132, i64* %13
%133 = load i64, i64* %13
%134 = inttoptr i64 %133 to i8*
store i8* %134, i8** %15
%135 = load i8*, i8** %15
%136 = load i64, i64* %14
%137 = load i32, i32* @PROT_READ
%138 = load i32, i32* @PROT_WRITE
%139 = or i32 %137, %138
%140 = load i32, i32* @PROT_EXEC
%141 = or i32 %139, %140
%142 = call i64 @mprotect(i8* %135, i64 %136, i32 %141)
%143 = icmp ne i64 %142, 0
br i1 %143, label %144, label %148
144: ; preds = %123
%145 = bitcast [27 x i8]* %16 to i8*
%146 = getelementptr inbounds [27 x i8], [27 x i8]* %16, i64 0, i64 0
%147 = call i32 @write(i32 2, i8* %146, i32 26)
br label %148
148: ; preds = %144, %123
%149 = load i8*, i8** %11
store i8 -112, i8* %149
%150 = load i8*, i8** %15
%151 = load i64, i64* %14
%152 = load i32, i32* @PROT_READ
%153 = load i32, i32* @PROT_EXEC
%154 = or i32 %152, %153
%155 = call i64 @mprotect(i8* %150, i64 %151, i32 %154)
%156 = icmp ne i64 %155, 0
br i1 %156, label %157, label %161
157: ; preds = %148
%158 = bitcast [29 x i8]* %17 to i8*
%159 = getelementptr inbounds [29 x i8], [29 x i8]* %17, i64 0, i64 0
%160 = call i32 @write(i32 2, i8* %159, i32 28)
br label %161
161: ; preds = %157, %148
%162 = bitcast [15 x i8]* %18 to i8*
%163 = getelementptr inbounds [15 x i8], [15 x i8]* %18, i64 0, i64 0
%164 = call i32 @write(i32 2, i8* %163, i32 14)
br label %167
165: ; preds = %118
%166 = call i32 (...) @abort()
unreachable
167: ; preds = %161
br label %168
168: ; preds = %167, %110
ret void
}

LLVM IR (-O2):
%struct.TYPE_7__ = type { i8* }
@.str = [438 x i8] c"rax = %lx\0Arbx = %lx\0Arcx = %lx\0Ardx = %lx\0Arsi = %lx\0Ardi = %lx\0Arbp = %lx\0Arsp = %lx\0Ar8 = %lx\0Ar9 = %lx\0Ar10 = %lx\0Ar11 = %lx\0Ar12 = %lx\0Ar13 = %lx\0Ar14 = %lx\0Ar15 = %lx\0Arip = %lx\0Aefl = %lx\0ACGGSFS00 = %lx\0Aerr = %lx\0Atrapno = %lx\0Aoldmask = %lx\0Acr = %lx\0A\00"
@__const.regprinting_illhandler.skipped = [15 x i8] c"Skipped 0x06.\0A\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@PROT_EXEC = global i32 0
@__const.regprinting_illhandler.mprotect_write_fail = [27 x i8] c"Can't make page writable.\0A\00"
@__const.regprinting_illhandler.mprotect_unwrite_fail = [29 x i8] c"Can't make page unwritable.\0A\00"
@__const.regprinting_illhandler.patched = [15 x i8] c"Patched 0x07.\0A\00"
define void @regprinting_illhandler(i32 %0, %struct.TYPE_7__* nocapture %1, i8* %2) {
%4 = alloca [1024 x i8]
%5 = alloca [15 x i8]
%6 = alloca [27 x i8]
%7 = alloca [29 x i8]
%8 = alloca [15 x i8]
%9 = bitcast i8* %2 to i32*
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%11 = getelementptr inbounds i8, i8* %2, i64 52
%12 = bitcast i8* %11 to i32*
%13 = load i32, i32* %12
%14 = getelementptr inbounds i8, i8* %2, i64 44
%15 = bitcast i8* %14 to i32*
%16 = load i32, i32* %15
%17 = getelementptr inbounds i8, i8* %2, i64 56
%18 = bitcast i8* %17 to i32*
%19 = load i32, i32* %18
%20 = getelementptr inbounds i8, i8* %2, i64 48
%21 = bitcast i8* %20 to i32*
%22 = load i32, i32* %21
%23 = getelementptr inbounds i8, i8* %2, i64 36
%24 = bitcast i8* %23 to i32*
%25 = load i32, i32* %24
%26 = getelementptr inbounds i8, i8* %2, i64 32
%27 = bitcast i8* %26 to i32*
%28 = load i32, i32* %27
%29 = getelementptr inbounds i8, i8* %2, i64 40
%30 = bitcast i8* %29 to i32*
%31 = load i32, i32* %30
%32 = getelementptr inbounds i8, i8* %2, i64 60
%33 = bitcast i8* %32 to i32*
%34 = load i32, i32* %33
%35 = load i32, i32* %9
%36 = getelementptr inbounds i8, i8* %2, i64 4
%37 = bitcast i8* %36 to i32*
%38 = load i32, i32* %37
%39 = getelementptr inbounds i8, i8* %2, i64 8
%40 = bitcast i8* %39 to i32*
%41 = load i32, i32* %40
%42 = getelementptr inbounds i8, i8* %2, i64 12
%43 = bitcast i8* %42 to i32*
%44 = load i32, i32* %43
%45 = getelementptr inbounds i8, i8* %2, i64 16
%46 = bitcast i8* %45 to i32*
%47 = load i32, i32* %46
%48 = getelementptr inbounds i8, i8* %2, i64 20
%49 = bitcast i8* %48 to i32*
%50 = load i32, i32* %49
%51 = getelementptr inbounds i8, i8* %2, i64 24
%52 = bitcast i8* %51 to i32*
%53 = load i32, i32* %52
%54 = getelementptr inbounds i8, i8* %2, i64 28
%55 = bitcast i8* %54 to i32*
%56 = load i32, i32* %55
%57 = getelementptr inbounds i8, i8* %2, i64 64
%58 = bitcast i8* %57 to i32*
%59 = load i32, i32* %58
%60 = getelementptr inbounds i8, i8* %2, i64 68
%61 = bitcast i8* %60 to i32*
%62 = load i32, i32* %61
%63 = getelementptr inbounds i8, i8* %2, i64 72
%64 = bitcast i8* %63 to i32*
%65 = load i32, i32* %64
%66 = getelementptr inbounds i8, i8* %2, i64 76
%67 = bitcast i8* %66 to i32*
%68 = load i32, i32* %67
%69 = getelementptr inbounds i8, i8* %2, i64 80
%70 = bitcast i8* %69 to i32*
%71 = load i32, i32* %70
%72 = getelementptr inbounds i8, i8* %2, i64 84
%73 = bitcast i8* %72 to i32*
%74 = load i32, i32* %73
%75 = getelementptr inbounds i8, i8* %2, i64 88
%76 = bitcast i8* %75 to i32*
%77 = load i32, i32* %76
%78 = call i64 @snprintf(i8* %10, i32 1024, i8* getelementptr inbounds ([438 x i8], [438 x i8]* @.str, i64 0, i64 0), i32 %13, i32 %16, i32 %19, i32 %22, i32 %25, i32 %28, i32 %31, i32 %34, i32 %35, i32 %38, i32 %41, i32 %44, i32 %47, i32 %50, i32 %53, i32 %56, i32 %59, i32 %62, i32 %65, i32 %68, i32 %71, i32 %74, i32 %77)
%79 = icmp ult i64 %78, 1024
br i1 %79, label %80, label %83
80: ; preds = %3
%81 = trunc i64 %78 to i32
%82 = call i32 @write(i32 2, i8* %10, i32 %81)
br label %83
83: ; preds = %80, %3
%84 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %1, i64 0, i32 0
%85 = load i8*, i8** %84
%86 = load i8, i8* %85
switch i8 %86, label %118 [
i8 6, label %87
i8 7, label %92
]
87: ; preds = %83
%88 = load i32, i32* %58
%89 = add nsw i32 %88, 1
store i32 %89, i32* %58
%90 = getelementptr inbounds [15 x i8], [15 x i8]* %5, i64 0, i64 0
%91 = call i32 @write(i32 2, i8* %90, i32 14)
br label %120
92: ; preds = %83
%93 = ptrtoint i8* %85 to i64
%94 = and i64 %93, -4096
%95 = inttoptr i64 %94 to i8*
%96 = load i32, i32* @PROT_READ
%97 = load i32, i32* @PROT_WRITE
%98 = or i32 %97, %96
%99 = load i32, i32* @PROT_EXEC
%100 = or i32 %98, %99
%101 = call i64 @mprotect(i8* %95, i64 4096, i32 %100)
%102 = icmp eq i64 %101, 0
br i1 %102, label %106, label %103
103: ; preds = %92
%104 = getelementptr inbounds [27 x i8], [27 x i8]* %6, i64 0, i64 0
%105 = call i32 @write(i32 2, i8* %104, i32 26)
br label %106
106: ; preds = %103, %92
store i8 -112, i8* %85
%107 = load i32, i32* @PROT_READ
%108 = load i32, i32* @PROT_EXEC
%109 = or i32 %108, %107
%110 = call i64 @mprotect(i8* %95, i64 4096, i32 %109)
%111 = icmp eq i64 %110, 0
br i1 %111, label %115, label %112
112: ; preds = %106
%113 = getelementptr inbounds [29 x i8], [29 x i8]* %7, i64 0, i64 0
%114 = call i32 @write(i32 2, i8* %113, i32 28)
br label %115
115: ; preds = %112, %106
%116 = getelementptr inbounds [15 x i8], [15 x i8]* %8, i64 0, i64 0
%117 = call i32 @write(i32 2, i8* %116, i32 14)
br label %120
118: ; preds = %83
%119 = call i32 (...) @abort()
unreachable
120: ; preds = %115, %87
ret void
}