#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*/ free(int *);
int *get_fragmented_memory_page();
void *page_fault_func(void *t) {
  int i;
  int *allocated[10000];
  while (true) {
    for (i = 0; i < 10000; i++)
      allocated[i] = get_fragmented_memory_page();
    for (i = 0; i < 10000; i++)
      *allocated[i] = 0xFF;
    for (i = 0; i < 10000; i++)
      free(allocated[i]);
  }
  return NULL;
}


x86 assembly (clang, -O0):
<page_fault_func>:
push   %rbp
mov    %rsp,%rbp
sub    $0x13890,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x2710,-0xc(%rbp)
jge    1167 <page_fault_func+0x47>
mov    $0x0,%al
call   1040 <get_fragmented_memory_page@plt>
mov    %rax,%rcx
movslq -0xc(%rbp),%rax
mov    %rcx,-0x13890(%rbp,%rax,8)
ff
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1136 <page_fault_func+0x16>
movl   $0x0,-0xc(%rbp)
cmpl   $0x2710,-0xc(%rbp)
jge    119b <page_fault_func+0x7b>
movslq -0xc(%rbp),%rax
mov    -0x13890(%rbp,%rax,8),%rax
ff
movl   $0xff,(%rax)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    116e <page_fault_func+0x4e>
movl   $0x0,-0xc(%rbp)
cmpl   $0x2710,-0xc(%rbp)
jge    11ce <page_fault_func+0xae>
movslq -0xc(%rbp),%rax
mov    -0x13890(%rbp,%rax,8),%rdi
ff
call   1030 <free@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11a2 <page_fault_func+0x82>
jmp    112f <page_fault_func+0xf>

x86 assembly (clang, -O2):
<page_fault_func>:
push   %rbx
sub    $0x13880,%rsp
nopl   0x0(%rax,%rax,1)
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <get_fragmented_memory_page@plt>
mov    %rax,(%rsp,%rbx,8)
add    $0x1,%rbx
cmp    $0x2710,%rbx
jne    1132 <page_fault_func+0x12>
mov    $0x7,%eax
nop
mov    -0x38(%rsp,%rax,8),%rcx
movl   $0xff,(%rcx)
mov    -0x30(%rsp,%rax,8),%rcx
movl   $0xff,(%rcx)
mov    -0x28(%rsp,%rax,8),%rcx
movl   $0xff,(%rcx)
mov    -0x20(%rsp,%rax,8),%rcx
movl   $0xff,(%rcx)
mov    -0x18(%rsp,%rax,8),%rcx
movl   $0xff,(%rcx)
mov    -0x10(%rsp,%rax,8),%rcx
movl   $0xff,(%rcx)
mov    -0x8(%rsp,%rax,8),%rcx
movl   $0xff,(%rcx)
mov    (%rsp,%rax,8),%rcx
movl   $0xff,(%rcx)
add    $0x8,%rax
cmp    $0x2717,%rax
jne    1150 <page_fault_func+0x30>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%rsp,%rbx,8),%rdi
call   1030 <free@plt>
add    $0x1,%rbx
cmp    $0x2710,%rbx
jne    11c0 <page_fault_func+0xa0>
jmp    1130 <page_fault_func+0x10>

LLVM IR (-O0):
define i8* @page_fault_func(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [10000 x i32*]
store i8* %0, i8** %2
br label %5
5: ; preds = %1, %42
store i32 0, i32* %3
br label %6
6: ; preds = %14, %5
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 10000
br i1 %8, label %9, label %17
9: ; preds = %6
%10 = call i32* (...) @get_fragmented_memory_page()
%11 = load i32, i32* %3
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [10000 x i32*], [10000 x i32*]* %4, i64 0, i64 %12
store i32* %10, i32** %13
br label %14
14: ; preds = %9
%15 = load i32, i32* %3
%16 = add nsw i32 %15, 1
store i32 %16, i32* %3
br label %6
17: ; preds = %6
store i32 0, i32* %3
br label %18
18: ; preds = %26, %17
%19 = load i32, i32* %3
%20 = icmp slt i32 %19, 10000
br i1 %20, label %21, label %29
21: ; preds = %18
%22 = load i32, i32* %3
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [10000 x i32*], [10000 x i32*]* %4, i64 0, i64 %23
%25 = load i32*, i32** %24
store i32 255, i32* %25
br label %26
26: ; preds = %21
%27 = load i32, i32* %3
%28 = add nsw i32 %27, 1
store i32 %28, i32* %3
br label %18
29: ; preds = %18
store i32 0, i32* %3
br label %30
30: ; preds = %39, %29
%31 = load i32, i32* %3
%32 = icmp slt i32 %31, 10000
br i1 %32, label %33, label %42
33: ; preds = %30
%34 = load i32, i32* %3
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [10000 x i32*], [10000 x i32*]* %4, i64 0, i64 %35
%37 = load i32*, i32** %36
%38 = call i32 @free(i32* %37)
br label %39
39: ; preds = %33
%40 = load i32, i32* %3
%41 = add nsw i32 %40, 1
store i32 %41, i32* %3
br label %30
42: ; preds = %30
br label %5
}

LLVM IR (-O2):
define noalias i8* @page_fault_func(i8* nocapture readnone %0) {
%2 = alloca [10000 x i32*]
%3 = bitcast [10000 x i32*]* %2 to i8*
br label %4
4: ; preds = %10, %1
%5 = phi i64 [ 0, %1 ], [ %11, %10 ]
%6 = tail call i32* (...) @get_fragmented_memory_page()
%7 = getelementptr inbounds [10000 x i32*], [10000 x i32*]* %2, i64 0, i64 %5
store i32* %6, i32** %7
%8 = add nuw nsw i64 %5, 1
%9 = icmp eq i64 %8, 10000
br i1 %9, label %12, label %10
10: ; preds = %39, %4
%11 = phi i64 [ %8, %4 ], [ 0, %39 ]
br label %4
12: ; preds = %4, %12
%13 = phi i64 [ %37, %12 ], [ 0, %4 ]
%14 = getelementptr inbounds [10000 x i32*], [10000 x i32*]* %2, i64 0, i64 %13
%15 = load i32*, i32** %14
store i32 255, i32* %15
%16 = or i64 %13, 1
%17 = getelementptr inbounds [10000 x i32*], [10000 x i32*]* %2, i64 0, i64 %16
%18 = load i32*, i32** %17
store i32 255, i32* %18
%19 = or i64 %13, 2
%20 = getelementptr inbounds [10000 x i32*], [10000 x i32*]* %2, i64 0, i64 %19
%21 = load i32*, i32** %20
store i32 255, i32* %21
%22 = or i64 %13, 3
%23 = getelementptr inbounds [10000 x i32*], [10000 x i32*]* %2, i64 0, i64 %22
%24 = load i32*, i32** %23
store i32 255, i32* %24
%25 = or i64 %13, 4
%26 = getelementptr inbounds [10000 x i32*], [10000 x i32*]* %2, i64 0, i64 %25
%27 = load i32*, i32** %26
store i32 255, i32* %27
%28 = or i64 %13, 5
%29 = getelementptr inbounds [10000 x i32*], [10000 x i32*]* %2, i64 0, i64 %28
%30 = load i32*, i32** %29
store i32 255, i32* %30
%31 = or i64 %13, 6
%32 = getelementptr inbounds [10000 x i32*], [10000 x i32*]* %2, i64 0, i64 %31
%33 = load i32*, i32** %32
store i32 255, i32* %33
%34 = or i64 %13, 7
%35 = getelementptr inbounds [10000 x i32*], [10000 x i32*]* %2, i64 0, i64 %34
%36 = load i32*, i32** %35
store i32 255, i32* %36
%37 = add nuw nsw i64 %13, 8
%38 = icmp eq i64 %37, 10000
br i1 %38, label %39, label %12
39: ; preds = %12, %39
%40 = phi i64 [ %44, %39 ], [ 0, %12 ]
%41 = getelementptr inbounds [10000 x i32*], [10000 x i32*]* %2, i64 0, i64 %40
%42 = load i32*, i32** %41
%43 = tail call i32 @free(i32* %42)
%44 = add nuw nsw i64 %40, 1
%45 = icmp eq i64 %44, 10000
br i1 %45, label %10, label %39
}