#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*/ MAP_PRIVATE;
int /*<<< orphan*/ O_SYNC;
int /*<<< orphan*/ PROT_READ;
int /*<<< orphan*/ free(char *);
char *malloc(int);
int malloc_usable_size(char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
scalar_t__ mmap(int /*<<< orphan*/ *, int, int /*<<< orphan*/,
                int /*<<< orphan*/, int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int, ...);
int main() {
  char *s;
  int i, fd;
  for (i = 1; i < 45; i++) {
    s = malloc(i);
    printf("%d,0x%x %d, usable %d\n", i, *(s - 4), *(s - 4) & 0xfc,
           malloc_usable_size(s));
    free(s);
  }
  i = open("tt", O_SYNC);
  s = (char *)mmap(NULL, 16, PROT_READ, MAP_PRIVATE, i, 0);
  printf("%d, %p\n", i, s);
  memset(s, 0, 10);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x14(%rbp)
cmpl   $0x2d,-0x14(%rbp)
jge    11f7 <main+0x87>
mov    -0x14(%rbp),%edi
call   1080 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
movsbl -0x4(%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movsbl -0x4(%rax),%eax
and    $0xfc,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <malloc_usable_size@plt>
mov    -0x24(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0x1c(%rbp),%ecx
mov    %eax,%r8d
lea    0xe27(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1186 <main+0x16>
mov    0x2de2(%rip),%rax
mov    (%rax),%esi
lea    0xe10(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0x14(%rbp)
mov    0x2de2(%rip),%rax
mov    (%rax),%edx
mov    0x2db1(%rip),%rax
mov    (%rax),%ecx
mov    -0x14(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
mov    $0x10,%esi
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    %rax,-0x10(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%rdx
lea    0xdd2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1060 <memset@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0x1,%ebx
lea    0xe7d(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebx,%edi
call   1080 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
call   1070 <malloc_usable_size@plt>
mov    %r14,%rdi
mov    %ebx,%esi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %eax,%r8d
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
call   1030 <free@plt>
add    $0x1,%ebx
cmp    $0x2d,%ebx
jne    1190 <main+0x20>
mov    0x2e14(%rip),%rax
mov    (%rax),%esi
lea    0xe42(%rip),%rdi
call   1090 <open@plt>
mov    %eax,%ebp
mov    0x2e15(%rip),%rax
mov    (%rax),%edx
mov    0x2de4(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    $0x10,%esi
mov    %ebp,%r8d
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    %rax,%rbx
lea    0xe10(%rip),%rdi
mov    %ebp,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1060 <memset@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [23 x i8] c"%d,0x%x %d, usable %d\0A\00"
@.str.1 = [3 x i8] c"tt\00"
@O_SYNC = global i32 0
@PROT_READ = global i32 0
@MAP_PRIVATE = global i32 0
@.str.2 = [8 x i8] c"%d, %p\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 1, i32* %3
br label %5
5: ; preds = %26, %0
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 45
br i1 %7, label %8, label %29
8: ; preds = %5
%9 = load i32, i32* %3
%10 = call i8* @malloc(i32 %9)
store i8* %10, i8** %2
%11 = load i32, i32* %3
%12 = load i8*, i8** %2
%13 = getelementptr inbounds i8, i8* %12, i64 -4
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = load i8*, i8** %2
%17 = getelementptr inbounds i8, i8* %16, i64 -4
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = and i32 %19, 252
%21 = load i8*, i8** %2
%22 = call i32 @malloc_usable_size(i8* %21)
%23 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %11, i32 %15, i32 %20, i32 %22)
%24 = load i8*, i8** %2
%25 = call i32 @free(i8* %24)
br label %26
26: ; preds = %8
%27 = load i32, i32* %3
%28 = add nsw i32 %27, 1
store i32 %28, i32* %3
br label %5
29: ; preds = %5
%30 = load i32, i32* @O_SYNC
%31 = call i32 @open(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %30)
store i32 %31, i32* %3
%32 = load i32, i32* @PROT_READ
%33 = load i32, i32* @MAP_PRIVATE
%34 = load i32, i32* %3
%35 = call i64 @mmap(i32* null, i32 16, i32 %32, i32 %33, i32 %34, i32 0)
%36 = inttoptr i64 %35 to i8*
store i8* %36, i8** %2
%37 = load i32, i32* %3
%38 = load i8*, i8** %2
%39 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %37, i8* %38)
%40 = load i8*, i8** %2
%41 = call i32 @memset(i8* %40, i32 0, i32 10)
ret i32 0
}

LLVM IR (-O2):
@.str = [23 x i8] c"%d,0x%x %d, usable %d\0A\00"
@.str.1 = [3 x i8] c"tt\00"
@O_SYNC = global i32 0
@PROT_READ = global i32 0
@MAP_PRIVATE = global i32 0
@.str.2 = [8 x i8] c"%d, %p\0A\00"
define i32 @main() {
br label %1
1: ; preds = %0, %1
%2 = phi i32 [ 1, %0 ], [ %7, %1 ]
%3 = tail call i8* @malloc(i32 %2)
%4 = tail call i32 @malloc_usable_size(i8* %3)
%5 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %2, i32 0, i32 0, i32 %4)
%6 = tail call i32 @free(i8* %3)
%7 = add nuw nsw i32 %2, 1
%8 = icmp eq i32 %7, 45
br i1 %8, label %9, label %1
9: ; preds = %1
%10 = load i32, i32* @O_SYNC
%11 = tail call i32 @open(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%12 = load i32, i32* @PROT_READ
%13 = load i32, i32* @MAP_PRIVATE
%14 = tail call i64 @mmap(i32* null, i32 16, i32 %12, i32 %13, i32 %11, i32 0)
%15 = inttoptr i64 %14 to i8*
%16 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %11, i8* %15)
%17 = tail call i32 @memset(i8* %15, i32 0, i32 10)
ret i32 0
}