#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 MAP_ANONYMOUS;
char *MAP_FAILED;
int MAP_PRIVATE;
int /*<<< orphan*/ PROT_NONE;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ _SC_PAGESIZE;
char *mmap(void *, int, int /*<<< orphan*/, int, int, int /*<<< orphan*/);
scalar_t__ mprotect(char *, long, int);
long sysconf(int /*<<< orphan*/);
int /*<<< orphan*/ test_func(double *, int, int, int, int);
int main() {
  char *p;
  int L, m, n, N;
  long l;
  L = 10000000;
  n = 4;
  N = 100 * n;
  long pgsz = sysconf(_SC_PAGESIZE);
  if (pgsz < sizeof(double) || pgsz > L * sizeof(double))
    return 0;
  p = mmap((void *)0, L * n * sizeof(double), PROT_NONE,
           MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
  if (p == MAP_FAILED)
    return 0;
  if (mprotect(p, pgsz, PROT_READ | PROT_WRITE))
    return 0;
  l = (L * sizeof(double)) / pgsz * pgsz;
  if (mprotect(p + l, pgsz, PROT_READ | PROT_WRITE))
    return 0;
  l = (2 * L * sizeof(double)) / pgsz * pgsz;
  if (mprotect(p + l, pgsz, PROT_READ | PROT_WRITE))
    return 0;
  l = (3 * L * sizeof(double)) / pgsz * pgsz;
  if (mprotect(p + l, pgsz, PROT_READ | PROT_WRITE))
    return 0;
  for (m = 0; m < N; m += n)
    test_func((double *)p, L, m, n, N);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x989680,-0x14(%rbp)
movl   $0x4,-0x1c(%rbp)
imul   $0x64,-0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2e6d(%rip),%rax
mov    (%rax),%edi
call   1060 <sysconf@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x8,-0x30(%rbp)
jb     1196 <main+0x56>
mov    -0x30(%rbp),%rax
movslq -0x14(%rbp),%rcx
shl    $0x3,%rcx
cmp    %rcx,%rax
jbe    11a2 <main+0x62>
movl   $0x0,-0x4(%rbp)
jmp    1371 <main+0x231>
mov    -0x14(%rbp),%eax
imul   -0x1c(%rbp),%eax
cltq
shl    $0x3,%rax
mov    %eax,%esi
mov    0x2e30(%rip),%rax
mov    (%rax),%edx
mov    0x2df7(%rip),%rax
mov    (%rax),%ecx
mov    0x2e06(%rip),%rax
or     (%rax),%ecx
xor    %eax,%eax
mov    %eax,%edi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2dc3(%rip),%rcx
cmp    (%rcx),%rax
jne    1202 <main+0xc2>
movl   $0x0,-0x4(%rbp)
jmp    1371 <main+0x231>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    0x2de7(%rip),%rax
mov    (%rax),%edx
mov    0x2da6(%rip),%rax
or     (%rax),%edx
call   1050 <mprotect@plt>
cmp    $0x0,%rax
je     1237 <main+0xf7>
movl   $0x0,-0x4(%rbp)
jmp    1371 <main+0x231>
movslq -0x14(%rbp),%rax
shl    $0x3,%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x30(%rbp)
imul   -0x30(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
add    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    0x2d95(%rip),%rax
mov    (%rax),%edx
mov    0x2d54(%rip),%rax
or     (%rax),%edx
call   1050 <mprotect@plt>
cmp    $0x0,%rax
je     1289 <main+0x149>
movl   $0x0,-0x4(%rbp)
jmp    1371 <main+0x231>
mov    -0x14(%rbp),%eax
shl    $0x1,%eax
cltq
shl    $0x3,%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x30(%rbp)
imul   -0x30(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
add    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    0x2d3f(%rip),%rax
mov    (%rax),%edx
mov    0x2cfe(%rip),%rax
or     (%rax),%edx
call   1050 <mprotect@plt>
cmp    $0x0,%rax
je     12df <main+0x19f>
movl   $0x0,-0x4(%rbp)
jmp    1371 <main+0x231>
imul   $0x3,-0x14(%rbp),%eax
cltq
shl    $0x3,%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x30(%rbp)
imul   -0x30(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
add    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    0x2ceb(%rip),%rax
mov    (%rax),%edx
mov    0x2caa(%rip),%rax
or     (%rax),%edx
call   1050 <mprotect@plt>
cmp    $0x0,%rax
je     1333 <main+0x1f3>
movl   $0x0,-0x4(%rbp)
jmp    1371 <main+0x231>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    136a <main+0x22a>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%r8d
call   1040 <test_func@plt>
mov    -0x1c(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    133a <main+0x1fa>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    0x2e89(%rip),%rax
mov    (%rax),%edi
call   1060 <sysconf@plt>
mov    %rax,%rbx
add    $0xfffffffffb3b4bff,%rax
cmp    $0xfffffffffb3b4c07,%rax
jb     127f <main+0x13f>
mov    0x2e76(%rip),%rax
mov    (%rax),%edx
mov    0x2e3d(%rip),%rax
mov    0x2e4e(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
xor    %edi,%edi
mov    $0x1312d000,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,%r14
mov    0x2e0b(%rip),%rax
cmp    (%rax),%r14
je     127f <main+0x13f>
mov    0x2e43(%rip),%r15
mov    0x2e04(%rip),%r12
mov    (%r12),%edx
or     (%r15),%edx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <mprotect@plt>
test   %rax,%rax
jne    127f <main+0x13f>
mov    $0x4c4b400,%eax
xor    %edx,%edx
div    %ebx
mov    %r14,%rdi
sub    %rdx,%rdi
add    $0x4c4b400,%rdi
mov    (%r12),%edx
or     (%r15),%edx
mov    %rbx,%rsi
call   1050 <mprotect@plt>
test   %rax,%rax
jne    127f <main+0x13f>
mov    $0x9896800,%eax
xor    %edx,%edx
div    %ebx
mov    %r14,%rdi
sub    %rdx,%rdi
add    $0x9896800,%rdi
mov    (%r12),%edx
or     (%r15),%edx
mov    %rbx,%rsi
call   1050 <mprotect@plt>
test   %rax,%rax
jne    127f <main+0x13f>
mov    $0xe4e1c00,%eax
xor    %edx,%edx
div    %ebx
mov    %r14,%rdi
sub    %rdx,%rdi
add    $0xe4e1c00,%rdi
mov    (%r12),%edx
or     (%r15),%edx
mov    %rbx,%rsi
call   1050 <mprotect@plt>
test   %rax,%rax
jne    127f <main+0x13f>
mov    $0xfffffffc,%ebx
add    $0x4,%ebx
mov    %r14,%rdi
mov    $0x989680,%esi
mov    %ebx,%edx
mov    $0x4,%ecx
mov    $0x190,%r8d
call   1040 <test_func@plt>
cmp    $0x18c,%ebx
jb     125a <main+0x11a>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@_SC_PAGESIZE = global i32 0
@PROT_NONE = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_ANONYMOUS = global i32 0
@MAP_FAILED = global i8* null
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i64
%8 = alloca i64
store i32 0, i32* %1
store i32 10000000, i32* %3
store i32 4, i32* %5
%9 = load i32, i32* %5
%10 = mul nsw i32 100, %9
store i32 %10, i32* %6
%11 = load i32, i32* @_SC_PAGESIZE
%12 = call i64 @sysconf(i32 %11)
store i64 %12, i64* %8
%13 = load i64, i64* %8
%14 = icmp ult i64 %13, 8
br i1 %14, label %21, label %15
15: ; preds = %0
%16 = load i64, i64* %8
%17 = load i32, i32* %3
%18 = sext i32 %17 to i64
%19 = mul i64 %18, 8
%20 = icmp ugt i64 %16, %19
br i1 %20, label %21, label %22
21: ; preds = %15, %0
store i32 0, i32* %1
br label %121
22: ; preds = %15
%23 = load i32, i32* %3
%24 = load i32, i32* %5
%25 = mul nsw i32 %23, %24
%26 = sext i32 %25 to i64
%27 = mul i64 %26, 8
%28 = trunc i64 %27 to i32
%29 = load i32, i32* @PROT_NONE
%30 = load i32, i32* @MAP_PRIVATE
%31 = load i32, i32* @MAP_ANONYMOUS
%32 = or i32 %30, %31
%33 = call i8* @mmap(i8* null, i32 %28, i32 %29, i32 %32, i32 -1, i32 0)
store i8* %33, i8** %2
%34 = load i8*, i8** %2
%35 = load i8*, i8** @MAP_FAILED
%36 = icmp eq i8* %34, %35
br i1 %36, label %37, label %38
37: ; preds = %22
store i32 0, i32* %1
br label %121
38: ; preds = %22
%39 = load i8*, i8** %2
%40 = load i64, i64* %8
%41 = load i32, i32* @PROT_READ
%42 = load i32, i32* @PROT_WRITE
%43 = or i32 %41, %42
%44 = call i64 @mprotect(i8* %39, i64 %40, i32 %43)
%45 = icmp ne i64 %44, 0
br i1 %45, label %46, label %47
46: ; preds = %38
store i32 0, i32* %1
br label %121
47: ; preds = %38
%48 = load i32, i32* %3
%49 = sext i32 %48 to i64
%50 = mul i64 %49, 8
%51 = load i64, i64* %8
%52 = udiv i64 %50, %51
%53 = load i64, i64* %8
%54 = mul i64 %52, %53
store i64 %54, i64* %7
%55 = load i8*, i8** %2
%56 = load i64, i64* %7
%57 = getelementptr inbounds i8, i8* %55, i64 %56
%58 = load i64, i64* %8
%59 = load i32, i32* @PROT_READ
%60 = load i32, i32* @PROT_WRITE
%61 = or i32 %59, %60
%62 = call i64 @mprotect(i8* %57, i64 %58, i32 %61)
%63 = icmp ne i64 %62, 0
br i1 %63, label %64, label %65
64: ; preds = %47
store i32 0, i32* %1
br label %121
65: ; preds = %47
%66 = load i32, i32* %3
%67 = mul nsw i32 2, %66
%68 = sext i32 %67 to i64
%69 = mul i64 %68, 8
%70 = load i64, i64* %8
%71 = udiv i64 %69, %70
%72 = load i64, i64* %8
%73 = mul i64 %71, %72
store i64 %73, i64* %7
%74 = load i8*, i8** %2
%75 = load i64, i64* %7
%76 = getelementptr inbounds i8, i8* %74, i64 %75
%77 = load i64, i64* %8
%78 = load i32, i32* @PROT_READ
%79 = load i32, i32* @PROT_WRITE
%80 = or i32 %78, %79
%81 = call i64 @mprotect(i8* %76, i64 %77, i32 %80)
%82 = icmp ne i64 %81, 0
br i1 %82, label %83, label %84
83: ; preds = %65
store i32 0, i32* %1
br label %121
84: ; preds = %65
%85 = load i32, i32* %3
%86 = mul nsw i32 3, %85
%87 = sext i32 %86 to i64
%88 = mul i64 %87, 8
%89 = load i64, i64* %8
%90 = udiv i64 %88, %89
%91 = load i64, i64* %8
%92 = mul i64 %90, %91
store i64 %92, i64* %7
%93 = load i8*, i8** %2
%94 = load i64, i64* %7
%95 = getelementptr inbounds i8, i8* %93, i64 %94
%96 = load i64, i64* %8
%97 = load i32, i32* @PROT_READ
%98 = load i32, i32* @PROT_WRITE
%99 = or i32 %97, %98
%100 = call i64 @mprotect(i8* %95, i64 %96, i32 %99)
%101 = icmp ne i64 %100, 0
br i1 %101, label %102, label %103
102: ; preds = %84
store i32 0, i32* %1
br label %121
103: ; preds = %84
store i32 0, i32* %4
br label %104
104: ; preds = %116, %103
%105 = load i32, i32* %4
%106 = load i32, i32* %6
%107 = icmp slt i32 %105, %106
br i1 %107, label %108, label %120
108: ; preds = %104
%109 = load i8*, i8** %2
%110 = bitcast i8* %109 to double*
%111 = load i32, i32* %3
%112 = load i32, i32* %4
%113 = load i32, i32* %5
%114 = load i32, i32* %6
%115 = call i32 @test_func(double* %110, i32 %111, i32 %112, i32 %113, i32 %114)
br label %116
116: ; preds = %108
%117 = load i32, i32* %5
%118 = load i32, i32* %4
%119 = add nsw i32 %118, %117
store i32 %119, i32* %4
br label %104
120: ; preds = %104
store i32 0, i32* %1
br label %121
121: ; preds = %120, %102, %83, %64, %46, %37, %21
%122 = load i32, i32* %1
ret i32 %122
}

LLVM IR (-O2):
@_SC_PAGESIZE = global i32 0
@PROT_NONE = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_ANONYMOUS = global i32 0
@MAP_FAILED = global i8* null
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
define i32 @main() {
%1 = load i32, i32* @_SC_PAGESIZE
%2 = tail call i64 @sysconf(i32 %1)
%3 = add i64 %2, -80000001
%4 = icmp ult i64 %3, -79999993
br i1 %4, label %57, label %5
5: ; preds = %0
%6 = load i32, i32* @PROT_NONE
%7 = load i32, i32* @MAP_PRIVATE
%8 = load i32, i32* @MAP_ANONYMOUS
%9 = or i32 %8, %7
%10 = tail call i8* @mmap(i8* null, i32 320000000, i32 %6, i32 %9, i32 -1, i32 0)
%11 = load i8*, i8** @MAP_FAILED
%12 = icmp eq i8* %10, %11
br i1 %12, label %57, label %13
13: ; preds = %5
%14 = load i32, i32* @PROT_READ
%15 = load i32, i32* @PROT_WRITE
%16 = or i32 %15, %14
%17 = tail call i64 @mprotect(i8* %10, i64 %2, i32 %16)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %57
19: ; preds = %13
%20 = trunc i64 %2 to i32
%21 = urem i32 80000000, %20
%22 = zext i32 %21 to i64
%23 = sub nuw nsw i64 80000000, %22
%24 = getelementptr inbounds i8, i8* %10, i64 %23
%25 = load i32, i32* @PROT_READ
%26 = load i32, i32* @PROT_WRITE
%27 = or i32 %26, %25
%28 = tail call i64 @mprotect(i8* %24, i64 %2, i32 %27)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %57
30: ; preds = %19
%31 = urem i32 160000000, %20
%32 = zext i32 %31 to i64
%33 = sub nuw nsw i64 160000000, %32
%34 = getelementptr inbounds i8, i8* %10, i64 %33
%35 = load i32, i32* @PROT_READ
%36 = load i32, i32* @PROT_WRITE
%37 = or i32 %36, %35
%38 = tail call i64 @mprotect(i8* %34, i64 %2, i32 %37)
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %57
40: ; preds = %30
%41 = urem i32 240000000, %20
%42 = zext i32 %41 to i64
%43 = sub nuw nsw i64 240000000, %42
%44 = getelementptr inbounds i8, i8* %10, i64 %43
%45 = load i32, i32* @PROT_READ
%46 = load i32, i32* @PROT_WRITE
%47 = or i32 %46, %45
%48 = tail call i64 @mprotect(i8* %44, i64 %2, i32 %47)
%49 = icmp eq i64 %48, 0
br i1 %49, label %50, label %57
50: ; preds = %40
%51 = bitcast i8* %10 to double*
br label %52
52: ; preds = %50, %52
%53 = phi i32 [ 0, %50 ], [ %55, %52 ]
%54 = tail call i32 @test_func(double* %51, i32 10000000, i32 %53, i32 4, i32 400)
%55 = add nuw nsw i32 %53, 4
%56 = icmp ult i32 %53, 396
br i1 %56, label %52, label %57
57: ; preds = %52, %40, %30, %19, %13, %5, %0
ret i32 0
}