#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 PROT_EXEC;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ mprotect(void *, int, int);
void destroy_main() {
  char *start = (char *)0x8048517;
  char *end = (char *)0x8048569;
  mprotect((void *)(((int)start) & (-0x1000)), 0x1000,
           PROT_READ | PROT_WRITE | PROT_EXEC);
  while (start != end) {
    *start = '\xff';
    start++;
  }
  mprotect((void *)(((int)start) & (-0x1000)), 0x1000, PROT_READ | PROT_EXEC);
}


x86 assembly (clang, -O0):
<destroy_main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x8048517,%eax
mov    %rax,-0x8(%rbp)
mov    $0x8048569,%eax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
and    $0xfffff000,%eax
movslq %eax,%rdi
mov    0x2ebb(%rip),%rax
mov    (%rax),%edx
mov    0x2e8a(%rip),%rax
or     (%rax),%edx
mov    0x2e91(%rip),%rax
or     (%rax),%edx
mov    $0x1000,%esi
call   1030 <mprotect@plt>
mov    -0x8(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     1181 <destroy_main+0x71>
mov    -0x8(%rbp),%rax
movb   $0xff,(%rax)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    115b <destroy_main+0x4b>
mov    -0x8(%rbp),%rax
and    $0xfffff000,%eax
movslq %eax,%rdi
mov    0x2e64(%rip),%rax
mov    (%rax),%edx
mov    0x2e43(%rip),%rax
or     (%rax),%edx
mov    $0x1000,%esi
call   1030 <mprotect@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<destroy_main>:
push   %r14
push   %rbx
push   %rax
mov    0x2edd(%rip),%r14
mov    0x2eae(%rip),%rax
mov    (%rax),%edx
or     (%r14),%edx
mov    0x2eb2(%rip),%rbx
or     (%rbx),%edx
mov    $0x8048000,%edi
mov    $0x1000,%esi
call   1030 <mprotect@plt>
pcmpeqd %xmm0,%xmm0
movdqu %xmm0,0x8048517
04 08
movdqu %xmm0,0x8048527
04 08
movdqu %xmm0,0x8048537
04 08
movdqu %xmm0,0x8048547
04 08
movdqu %xmm0,0x8048557
04 08
movw   $0xffff,0x8048567
08 ff ff
mov    (%rbx),%edx
or     (%r14),%edx
mov    $0x8048000,%edi
mov    $0x1000,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <mprotect@plt>

LLVM IR (-O0):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@PROT_EXEC = global i32 0
define void @destroy_main() {
%1 = alloca i8*
%2 = alloca i8*
store i8* inttoptr (i64 134513943 to i8*), i8** %1
store i8* inttoptr (i64 134514025 to i8*), i8** %2
%3 = load i8*, i8** %1
%4 = ptrtoint i8* %3 to i32
%5 = and i32 %4, -4096
%6 = sext i32 %5 to i64
%7 = inttoptr i64 %6 to i8*
%8 = load i32, i32* @PROT_READ
%9 = load i32, i32* @PROT_WRITE
%10 = or i32 %8, %9
%11 = load i32, i32* @PROT_EXEC
%12 = or i32 %10, %11
%13 = call i32 @mprotect(i8* %7, i32 4096, i32 %12)
br label %14
14: ; preds = %18, %0
%15 = load i8*, i8** %1
%16 = load i8*, i8** %2
%17 = icmp ne i8* %15, %16
br i1 %17, label %18, label %22
18: ; preds = %14
%19 = load i8*, i8** %1
store i8 -1, i8* %19
%20 = load i8*, i8** %1
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %1
br label %14
22: ; preds = %14
%23 = load i8*, i8** %1
%24 = ptrtoint i8* %23 to i32
%25 = and i32 %24, -4096
%26 = sext i32 %25 to i64
%27 = inttoptr i64 %26 to i8*
%28 = load i32, i32* @PROT_READ
%29 = load i32, i32* @PROT_EXEC
%30 = or i32 %28, %29
%31 = call i32 @mprotect(i8* %27, i32 4096, i32 %30)
ret void
}

LLVM IR (-O2):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@PROT_EXEC = global i32 0
define void @destroy_main() {
%1 = load i32, i32* @PROT_READ
%2 = load i32, i32* @PROT_WRITE
%3 = or i32 %2, %1
%4 = load i32, i32* @PROT_EXEC
%5 = or i32 %3, %4
%6 = tail call i32 @mprotect(i8* inttoptr (i64 134512640 to i8*), i32 4096, i32 %5)
%7 = load i32, i32* @PROT_READ
%8 = load i32, i32* @PROT_EXEC
%9 = or i32 %8, %7
%10 = tail call i32 @mprotect(i8* inttoptr (i64 134512640 to i8*), i32 4096, i32 %9)
ret void
}