#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 */
typedef int uint8_t;
typedef int uint32_t;

/* Variables and functions */
int MAP_ANON;
int *MAP_FAILED;
int MAP_PRIVATE;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ _SC_PAGESIZE;
int /*<<< orphan*/ assert(int);
scalar_t__ mmap(int /*<<< orphan*/ *, int, int, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ munmap(int *, int);
int sysconf(int /*<<< orphan*/);
int tm_ticks();
uint32_t test3pflt(void) {
  uint32_t pgsz, alloc;
  uint8_t *p;
  uint32_t i, s, e;
  pgsz = sysconf(_SC_PAGESIZE);
  alloc = pgsz * 32768;
  p = (uint8_t *)mmap(NULL, alloc, PROT_WRITE | PROT_READ,
                      MAP_PRIVATE | MAP_ANON, -1, 0);
  assert(p != MAP_FAILED);
  e = tm_ticks();
  do {
    s = tm_ticks();
  } while ((s - e) < 1);
  for (i = 0; i < alloc; i += pgsz) {
    p[i] = 0x1F;
  }
  e = tm_ticks();
  i = e - s;
  munmap(p, alloc);
  return i;
}


x86 assembly (clang, -O0):
<test3pflt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2e81(%rip),%rax
mov    (%rax),%edi
call   1060 <sysconf@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
shl    $0xf,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
mov    0x2e54(%rip),%rax
mov    (%rax),%edx
mov    0x2e73(%rip),%rax
or     (%rax),%edx
mov    0x2e32(%rip),%rax
mov    (%rax),%ecx
mov    0x2e31(%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    0x2dfe(%rip),%rcx
cmp    (%rcx),%rax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    $0x0,%al
call   1070 <tm_ticks@plt>
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   1070 <tm_ticks@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
sub    -0x1c(%rbp),%eax
cmp    $0x1,%eax
jl     11d4 <test3pflt+0x84>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    121d <test3pflt+0xcd>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movl   $0x1f,(%rax,%rcx,4)
mov    -0x4(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    11f4 <test3pflt+0xa4>
mov    $0x0,%al
call   1070 <tm_ticks@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
sub    -0x18(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1050 <munmap@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test3pflt>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    0x2e81(%rip),%rax
mov    (%rax),%edi
call   1060 <sysconf@plt>
mov    %eax,%r15d
mov    %eax,%r14d
shl    $0xf,%r14d
mov    0x2e59(%rip),%rax
mov    0x2e7a(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e37(%rip),%rax
mov    0x2e38(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
xor    %edi,%edi
mov    %r14d,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,%r12
mov    0x2e07(%rip),%rax
xor    %edi,%edi
cmp    %r12,(%rax)
setne  %dil
call   1040 <assert@plt>
xor    %eax,%eax
call   1070 <tm_ticks@plt>
mov    %eax,%ebx
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1070 <tm_ticks@plt>
cmp    %ebx,%eax
jle    11d0 <test3pflt+0x80>
mov    %eax,%ebp
test   %r15d,%r15d
jle    12c0 <test3pflt+0x170>
mov    %r15d,%r10d
movslq %r14d,%r8
xor    %edi,%edi
cmp    %r10,%r8
mov    %r10,%rax
cmovg  %r8,%rax
setg   %dil
sub    %rdi,%rax
sub    %r10,%rax
cmp    $0x2,%r10
mov    $0x1,%ecx
cmovae %r10,%rcx
mov    %rax,%rdx
shr    $0x20,%rdx
je     121f <test3pflt+0xcf>
xor    %edx,%edx
div    %rcx
jmp    1223 <test3pflt+0xd3>
xor    %edx,%edx
div    %ecx
lea    (%rax,%rdi,1),%r9
add    $0x1,%r9
xor    %eax,%eax
cmp    $0x8,%r9
jb     12b0 <test3pflt+0x160>
cmp    $0x1,%r15d
jne    12b0 <test3pflt+0x160>
mov    %r9,%r11
and    $0xfffffffffffffff8,%r11
mov    %r11,%rax
imul   %r10,%rax
mov    %r10,%r15
shl    $0x7,%r15
mov    %r10,%rbx
shl    $0x5,%rbx
xor    %edx,%edx
movaps 0xda2(%rip),%xmm0
mov    %r12,%rsi
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movups %xmm0,(%rsi)
movups %xmm0,0x10(%rsi)
lea    (%rsi,%rbx,1),%rdi
movups %xmm0,(%rsi,%rbx,1)
movups %xmm0,0x10(%rsi,%rbx,1)
lea    (%rdi,%rbx,1),%rcx
movups %xmm0,(%rbx,%rdi,1)
movups %xmm0,0x10(%rbx,%rdi,1)
movups %xmm0,(%rbx,%rcx,1)
movups %xmm0,0x10(%rbx,%rcx,1)
add    $0x20,%rdx
add    %r15,%rsi
cmp    %r11,%rdx
jne    1270 <test3pflt+0x120>
cmp    %r11,%r9
je     12c0 <test3pflt+0x170>
nopl   0x0(%rax,%rax,1)
movl   $0x1f,(%r12,%rax,4)
add    %r10,%rax
cmp    %r8,%rax
jl     12b0 <test3pflt+0x160>
xor    %eax,%eax
call   1070 <tm_ticks@plt>
mov    %eax,%ebx
sub    %ebp,%ebx
mov    %r12,%rdi
mov    %r14d,%esi
call   1050 <munmap@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@_SC_PAGESIZE = global i32 0
@PROT_WRITE = global i32 0
@PROT_READ = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_ANON = global i32 0
@MAP_FAILED = global i32* null
define i32 @test3pflt() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = load i32, i32* @_SC_PAGESIZE
%8 = call i32 @sysconf(i32 %7)
store i32 %8, i32* %1
%9 = load i32, i32* %1
%10 = mul nsw i32 %9, 32768
store i32 %10, i32* %2
%11 = load i32, i32* %2
%12 = load i32, i32* @PROT_WRITE
%13 = load i32, i32* @PROT_READ
%14 = or i32 %12, %13
%15 = load i32, i32* @MAP_PRIVATE
%16 = load i32, i32* @MAP_ANON
%17 = or i32 %15, %16
%18 = call i64 @mmap(i32* null, i32 %11, i32 %14, i32 %17, i32 -1, i32 0)
%19 = inttoptr i64 %18 to i32*
store i32* %19, i32** %3
%20 = load i32*, i32** %3
%21 = load i32*, i32** @MAP_FAILED
%22 = icmp ne i32* %20, %21
%23 = zext i1 %22 to i32
%24 = call i32 @assert(i32 %23)
%25 = call i32 (...) @tm_ticks()
store i32 %25, i32* %6
br label %26
26: ; preds = %28, %0
%27 = call i32 (...) @tm_ticks()
store i32 %27, i32* %5
br label %28
28: ; preds = %26
%29 = load i32, i32* %5
%30 = load i32, i32* %6
%31 = sub nsw i32 %29, %30
%32 = icmp slt i32 %31, 1
br i1 %32, label %26, label %33
33: ; preds = %28
store i32 0, i32* %4
br label %34
34: ; preds = %43, %33
%35 = load i32, i32* %4
%36 = load i32, i32* %2
%37 = icmp slt i32 %35, %36
br i1 %37, label %38, label %47
38: ; preds = %34
%39 = load i32*, i32** %3
%40 = load i32, i32* %4
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i32, i32* %39, i64 %41
store i32 31, i32* %42
br label %43
43: ; preds = %38
%44 = load i32, i32* %1
%45 = load i32, i32* %4
%46 = add nsw i32 %45, %44
store i32 %46, i32* %4
br label %34
47: ; preds = %34
%48 = call i32 (...) @tm_ticks()
store i32 %48, i32* %6
%49 = load i32, i32* %6
%50 = load i32, i32* %5
%51 = sub nsw i32 %49, %50
store i32 %51, i32* %4
%52 = load i32*, i32** %3
%53 = load i32, i32* %2
%54 = call i32 @munmap(i32* %52, i32 %53)
%55 = load i32, i32* %4
ret i32 %55
}

LLVM IR (-O2):
@_SC_PAGESIZE = global i32 0
@PROT_WRITE = global i32 0
@PROT_READ = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_ANON = global i32 0
@MAP_FAILED = global i32* null
define i32 @test3pflt() {
%1 = load i32, i32* @_SC_PAGESIZE
%2 = tail call i32 @sysconf(i32 %1)
%3 = shl nsw i32 %2, 15
%4 = load i32, i32* @PROT_WRITE
%5 = load i32, i32* @PROT_READ
%6 = or i32 %5, %4
%7 = load i32, i32* @MAP_PRIVATE
%8 = load i32, i32* @MAP_ANON
%9 = or i32 %8, %7
%10 = tail call i64 @mmap(i32* null, i32 %3, i32 %6, i32 %9, i32 -1, i32 0)
%11 = inttoptr i64 %10 to i32*
%12 = load i32*, i32** @MAP_FAILED
%13 = icmp ne i32* %12, %11
%14 = zext i1 %13 to i32
%15 = tail call i32 @assert(i32 %14)
%16 = tail call i32 (...) @tm_ticks()
br label %17
17: ; preds = %17, %0
%18 = tail call i32 (...) @tm_ticks()
%19 = icmp sgt i32 %18, %16
br i1 %19, label %20, label %17
20: ; preds = %17
%21 = icmp sgt i32 %2, 0
br i1 %21, label %22, label %76
22: ; preds = %20
%23 = zext i32 %2 to i64
%24 = sext i32 %3 to i64
%25 = call i64 @llvm.smax.i64(i64 %24, i64 %23)
%26 = icmp slt i64 %23, %24
%27 = zext i1 %26 to i64
%28 = add nuw nsw i64 %27, %23
%29 = sub nsw i64 %25, %28
%30 = call i64 @llvm.umax.i64(i64 %23, i64 1)
%31 = udiv i64 %29, %30
%32 = add i64 %31, %27
%33 = add i64 %32, 1
%34 = icmp ugt i64 %33, 7
%35 = icmp eq i32 %2, 1
%36 = select i1 %34, i1 %35, i1 false
br i1 %36, label %37, label %69
37: ; preds = %22
%38 = and i64 %33, -8
%39 = mul i64 %38, %23
br label %40
40: ; preds = %40, %37
%41 = phi i64 [ 0, %37 ], [ %65, %40 ]
%42 = mul nuw nsw i64 %41, %23
%43 = getelementptr inbounds i32, i32* %11, i64 %42
%44 = bitcast i32* %43 to <4 x i32>*
store <4 x i32> <i32 31, i32 31, i32 31, i32 31>, <4 x i32>* %44
%45 = getelementptr inbounds i32, i32* %43, i64 4
%46 = bitcast i32* %45 to <4 x i32>*
store <4 x i32> <i32 31, i32 31, i32 31, i32 31>, <4 x i32>* %46
%47 = or i64 %41, 8
%48 = mul nuw nsw i64 %47, %23
%49 = getelementptr inbounds i32, i32* %11, i64 %48
%50 = bitcast i32* %49 to <4 x i32>*
store <4 x i32> <i32 31, i32 31, i32 31, i32 31>, <4 x i32>* %50
%51 = getelementptr inbounds i32, i32* %49, i64 4
%52 = bitcast i32* %51 to <4 x i32>*
store <4 x i32> <i32 31, i32 31, i32 31, i32 31>, <4 x i32>* %52
%53 = or i64 %41, 16
%54 = mul nuw nsw i64 %53, %23
%55 = getelementptr inbounds i32, i32* %11, i64 %54
%56 = bitcast i32* %55 to <4 x i32>*
store <4 x i32> <i32 31, i32 31, i32 31, i32 31>, <4 x i32>* %56
%57 = getelementptr inbounds i32, i32* %55, i64 4
%58 = bitcast i32* %57 to <4 x i32>*
store <4 x i32> <i32 31, i32 31, i32 31, i32 31>, <4 x i32>* %58
%59 = or i64 %41, 24
%60 = mul nuw nsw i64 %59, %23
%61 = getelementptr inbounds i32, i32* %11, i64 %60
%62 = bitcast i32* %61 to <4 x i32>*
store <4 x i32> <i32 31, i32 31, i32 31, i32 31>, <4 x i32>* %62
%63 = getelementptr inbounds i32, i32* %61, i64 4
%64 = bitcast i32* %63 to <4 x i32>*
store <4 x i32> <i32 31, i32 31, i32 31, i32 31>, <4 x i32>* %64
%65 = add nuw nsw i64 %41, 32
%66 = icmp eq i64 %65, %38
br i1 %66, label %67, label %40
67: ; preds = %40
%68 = icmp eq i64 %33, %38
br i1 %68, label %76, label %69
69: ; preds = %22, %67
%70 = phi i64 [ 0, %22 ], [ %39, %67 ]
br label %71
71: ; preds = %69, %71
%72 = phi i64 [ %74, %71 ], [ %70, %69 ]
%73 = getelementptr inbounds i32, i32* %11, i64 %72
store i32 31, i32* %73
%74 = add nuw nsw i64 %72, %23
%75 = icmp slt i64 %74, %24
br i1 %75, label %71, label %76
76: ; preds = %71, %67, %20
%77 = tail call i32 (...) @tm_ticks()
%78 = sub nsw i32 %77, %18
%79 = tail call i32 @munmap(i32* %11, i32 %3)
ret i32 %78
}