#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 EINVAL;
void *aligned_alloc(size_t, size_t);
int /*<<< orphan*/ assert(void *);
int /*<<< orphan*/ free(void *);
void *memalign(int, int);
int posix_memalign(void **, int, int);
void *realloc(void *, int);
int /*<<< orphan*/ strcmp(char *, char *);
int main(int argc, char **argv) {
  void *p = NULL;
  size_t alignment = 1U << 12;
  size_t size = 1U << 12;
  int err;
  assert(argc == 2);
  if (!strcmp(argv[1], "valid")) {
    posix_memalign(&p, alignment, size);
    assert(p);
    assert(((uintptr_t)p & (alignment - 1)) == 0);
    free(p);
    p = aligned_alloc(alignment, size);
    assert(p);
    assert(((uintptr_t)p & (alignment - 1)) == 0);
    free(p);
    for (int i = (sizeof(void *) == 4) ? 3 : 4; i < 19; i++) {
      alignment = 1U << i;
      for (int j = 1; j < 33; j++) {
        size = 0x800 * j;
        for (int k = 0; k < 3; k++) {
          p = memalign(alignment, size - (2 * sizeof(void *) * k));
          assert(p);
          assert(((uintptr_t)p & (alignment - 1)) == 0);
          free(p);
        }
      }
    }
    for (int i = 19; i <= 24; i++) {
      alignment = 1U << i;
      for (int k = 0; k < 3; k++) {
        p = memalign(alignment, 0x1000 - (2 * sizeof(void *) * k));
        assert(p);
        assert(((uintptr_t)p & (alignment - 1)) == 0);
        free(p);
      }
    }
  }
  if (!strcmp(argv[1], "invalid")) {
    p = memalign(alignment - 1, size);
    assert(!p);
    p = aligned_alloc(alignment, size >> 1);
    assert(!p);
    void *p_unchanged = (void *)0x42UL;
    p = p_unchanged;
    err = posix_memalign(&p, 3, size);
    assert(p == p_unchanged);
    assert(err == EINVAL);
    err = posix_memalign(&p, 2, size);
    assert(p == p_unchanged);
    assert(err == EINVAL);
  }
  if (!strcmp(argv[1], "double-free")) {
    void *p = NULL;
    posix_memalign(&p, 0x100, sizeof(int));
    assert(p);
    free(p);
    free(p);
  }
  if (!strcmp(argv[1], "realloc")) {
    void *p = memalign(16, 16);
    assert(p);
    p = realloc(p, 32);
    free(p);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x1000,-0x20(%rbp)
movq   $0x1000,-0x28(%rbp)
cmpl   $0x2,-0x8(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%eax
movslq %eax,%rdi
call   1050 <assert@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe41(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    13e5 <main+0x275>
mov    -0x20(%rbp),%rax
mov    %eax,%esi
mov    -0x28(%rbp),%rax
mov    %eax,%edx
lea    -0x18(%rbp),%rdi
call   1080 <posix_memalign@plt>
mov    -0x18(%rbp),%rdi
call   1050 <assert@plt>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    $0x1,%rcx
and    %rcx,%rax
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
movslq %eax,%rdi
call   1050 <assert@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1090 <aligned_alloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <assert@plt>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    $0x1,%rcx
and    %rcx,%rax
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
movslq %eax,%rdi
call   1050 <assert@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movl   $0x4,-0x30(%rbp)
cmpl   $0x13,-0x30(%rbp)
jge    1337 <main+0x1c7>
mov    -0x30(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,%eax
mov    %rax,-0x20(%rbp)
movl   $0x1,-0x34(%rbp)
cmpl   $0x21,-0x34(%rbp)
jge    1324 <main+0x1b4>
mov    -0x34(%rbp),%eax
shl    $0xb,%eax
cltq
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x38(%rbp)
cmpl   $0x3,-0x38(%rbp)
jge    1311 <main+0x1a1>
mov    -0x20(%rbp),%rax
mov    %eax,%edi
mov    -0x28(%rbp),%rax
movslq -0x38(%rbp),%rcx
shl    $0x4,%rcx
sub    %rcx,%rax
mov    %eax,%esi
call   1060 <memalign@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <assert@plt>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    $0x1,%rcx
and    %rcx,%rax
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
movslq %eax,%rdi
call   1050 <assert@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    12a4 <main+0x134>
jmp    1316 <main+0x1a6>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1287 <main+0x117>
jmp    1329 <main+0x1b9>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1266 <main+0xf6>
movl   $0x13,-0x3c(%rbp)
cmpl   $0x18,-0x3c(%rbp)
jg     13e0 <main+0x270>
mov    -0x3c(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,%eax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x40(%rbp)
cmpl   $0x3,-0x40(%rbp)
jge    13cd <main+0x25d>
mov    -0x20(%rbp),%rax
mov    %eax,%edi
movslq -0x40(%rbp),%rcx
shl    $0x4,%rcx
mov    $0x1000,%eax
sub    %rcx,%rax
mov    %eax,%esi
call   1060 <memalign@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <assert@plt>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    $0x1,%rcx
and    %rcx,%rax
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
movslq %eax,%rdi
call   1050 <assert@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    135f <main+0x1ef>
jmp    13d2 <main+0x262>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    133e <main+0x1ce>
jmp    13e5 <main+0x275>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xc0c(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    1505 <main+0x395>
mov    -0x20(%rbp),%rax
sub    $0x1,%rax
mov    %eax,%edi
mov    -0x28(%rbp),%rax
mov    %eax,%esi
call   1060 <memalign@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
movslq %eax,%rdi
call   1050 <assert@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
shr    $0x1,%rsi
call   1090 <aligned_alloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
movslq %eax,%rdi
call   1050 <assert@plt>
mov    $0x42,%eax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x28(%rbp),%rax
mov    %eax,%edx
lea    -0x18(%rbp),%rdi
mov    $0x3,%esi
call   1080 <posix_memalign@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x48(%rbp),%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
movslq %eax,%rdi
call   1050 <assert@plt>
mov    -0x2c(%rbp),%eax
mov    0x2b38(%rip),%rcx
cmp    (%rcx),%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
movslq %eax,%rdi
call   1050 <assert@plt>
mov    -0x28(%rbp),%rax
mov    %eax,%edx
lea    -0x18(%rbp),%rdi
mov    $0x2,%esi
call   1080 <posix_memalign@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x48(%rbp),%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
movslq %eax,%rdi
call   1050 <assert@plt>
mov    -0x2c(%rbp),%eax
mov    0x2aed(%rip),%rcx
cmp    (%rcx),%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
movslq %eax,%rdi
call   1050 <assert@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xaf4(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    1558 <main+0x3e8>
movq   $0x0,-0x50(%rbp)
lea    -0x50(%rbp),%rdi
mov    $0x100,%esi
mov    $0x4,%edx
call   1080 <posix_memalign@plt>
mov    -0x50(%rbp),%rdi
call   1050 <assert@plt>
mov    -0x50(%rbp),%rdi
call   1030 <free@plt>
mov    -0x50(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xaad(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    15a9 <main+0x439>
mov    $0x10,%esi
mov    %esi,%edi
call   1060 <memalign@plt>
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rdi
call   1050 <assert@plt>
mov    -0x58(%rbp),%rdi
mov    $0x20,%esi
call   1070 <realloc@plt>
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
movq   $0x0,(%rsp)
xor    %eax,%eax
cmp    $0x2,%edi
sete   %al
mov    %rax,%rdi
call   1050 <assert@plt>
mov    0x8(%r14),%rbp
lea    0xe60(%rip),%rsi
mov    %rbp,%rdi
call   1040 <strcmp@plt>
mov    $0x1000,%r15d
mov    $0x1000,%ebx
test   %eax,%eax
jne    13ce <main+0x25e>
mov    %rsp,%rdi
mov    $0x1000,%esi
mov    $0x1000,%edx
call   1080 <posix_memalign@plt>
mov    (%rsp),%rdi
call   1050 <assert@plt>
xor    %edi,%edi
testl  $0xfff,(%rsp)
sete   %dil
call   1050 <assert@plt>
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    $0x1000,%edi
mov    $0x1000,%esi
call   1090 <aligned_alloc@plt>
mov    %rax,(%rsp)
mov    %rax,%rdi
call   1050 <assert@plt>
xor    %edi,%edi
testl  $0xfff,(%rsp)
sete   %dil
call   1050 <assert@plt>
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    $0x4,%r15d
nop
mov    $0x1,%ebx
mov    %r15d,%ecx
shl    %cl,%ebx
lea    -0x1(%rbx),%r12
mov    $0x800,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebx,%edi
mov    %ebp,%esi
call   1060 <memalign@plt>
mov    %rax,(%rsp)
mov    %rax,%rdi
call   1050 <assert@plt>
xor    %edi,%edi
mov    (%rsp),%rax
and    %r12,%rax
sete   %dil
call   1050 <assert@plt>
mov    (%rsp),%rdi
call   1030 <free@plt>
lea    -0x10(%rbp),%esi
mov    %ebx,%edi
call   1060 <memalign@plt>
mov    %rax,(%rsp)
mov    %rax,%rdi
call   1050 <assert@plt>
xor    %edi,%edi
mov    (%rsp),%rax
and    %r12,%rax
sete   %dil
call   1050 <assert@plt>
mov    (%rsp),%rdi
call   1030 <free@plt>
lea    -0x20(%rbp),%esi
mov    %ebx,%edi
call   1060 <memalign@plt>
mov    %rax,(%rsp)
mov    %rax,%rdi
call   1050 <assert@plt>
xor    %edi,%edi
mov    (%rsp),%rax
and    %r12,%rax
sete   %dil
call   1050 <assert@plt>
mov    (%rsp),%rdi
call   1030 <free@plt>
add    $0x800,%ebp
cmp    $0x10800,%ebp
jne    1250 <main+0xe0>
add    $0x1,%r15d
cmp    $0x13,%r15d
jne    1230 <main+0xc0>
mov    $0x13,%ebp
nopw   0x0(%rax,%rax,1)
mov    $0x1,%ebx
mov    %ebp,%ecx
shl    %cl,%ebx
lea    -0x1(%rbx),%r15
mov    %ebx,%edi
mov    $0x1000,%esi
call   1060 <memalign@plt>
mov    %rax,(%rsp)
mov    %rax,%rdi
call   1050 <assert@plt>
xor    %edi,%edi
mov    (%rsp),%rax
and    %r15,%rax
sete   %dil
call   1050 <assert@plt>
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    %ebx,%edi
mov    $0xff0,%esi
call   1060 <memalign@plt>
mov    %rax,(%rsp)
mov    %rax,%rdi
call   1050 <assert@plt>
xor    %edi,%edi
mov    (%rsp),%rax
and    %r15,%rax
sete   %dil
call   1050 <assert@plt>
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    %ebx,%edi
mov    $0xfe0,%esi
call   1060 <memalign@plt>
mov    %rax,(%rsp)
mov    %rax,%rdi
call   1050 <assert@plt>
xor    %edi,%edi
and    (%rsp),%r15
sete   %dil
call   1050 <assert@plt>
mov    (%rsp),%rdi
call   1030 <free@plt>
add    $0x1,%ebp
cmp    $0x19,%ebp
jne    1310 <main+0x1a0>
mov    0x8(%r14),%rbp
mov    $0x1000000,%ebx
mov    $0x10000,%r15d
lea    0xc2b(%rip),%rsi
mov    %rbp,%rdi
call   1040 <strcmp@plt>
test   %eax,%eax
jne    149a <main+0x32a>
lea    -0x1(%rbx),%edi
mov    %r15d,%esi
call   1060 <memalign@plt>
mov    %rax,(%rsp)
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1050 <assert@plt>
mov    %r15,%rsi
shr    %rsi
mov    %rbx,%rdi
call   1090 <aligned_alloc@plt>
mov    %rax,(%rsp)
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1050 <assert@plt>
movq   $0x42,(%rsp)
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x3,%esi
mov    %r15d,%edx
call   1080 <posix_memalign@plt>
mov    %eax,%ebp
xor    %edi,%edi
cmpq   $0x42,(%rsp)
sete   %dil
call   1050 <assert@plt>
mov    0x2b8a(%rip),%r12
xor    %edi,%edi
cmp    (%r12),%ebp
sete   %dil
call   1050 <assert@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
mov    %r15d,%edx
call   1080 <posix_memalign@plt>
mov    %eax,%ebx
xor    %edi,%edi
cmpq   $0x42,(%rsp)
sete   %dil
call   1050 <assert@plt>
xor    %edi,%edi
cmp    (%r12),%ebx
sete   %dil
call   1050 <assert@plt>
mov    0x8(%r14),%rbp
lea    0xb67(%rip),%rsi
mov    %rbp,%rdi
call   1040 <strcmp@plt>
test   %eax,%eax
jne    14ec <main+0x37c>
movq   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rdi
mov    $0x100,%esi
mov    $0x4,%edx
call   1080 <posix_memalign@plt>
mov    0x8(%rsp),%rdi
call   1050 <assert@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    0x8(%r14),%rbp
lea    0xb21(%rip),%rsi
mov    %rbp,%rdi
call   1040 <strcmp@plt>
test   %eax,%eax
jne    152e <main+0x3be>
mov    $0x10,%edi
mov    $0x10,%esi
call   1060 <memalign@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <assert@plt>
mov    %rbx,%rdi
mov    $0x20,%esi
call   1070 <realloc@plt>
mov    %rax,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"valid\00"
@.str.1 = [8 x i8] c"invalid\00"
@EINVAL = global i32 0
@.str.2 = [12 x i8] c"double-free\00"
@.str.3 = [8 x i8] c"realloc\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i8*
%16 = alloca i8*
%17 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %6
store i64 4096, i64* %7
store i64 4096, i64* %8
%18 = load i32, i32* %4
%19 = icmp eq i32 %18, 2
%20 = zext i1 %19 to i32
%21 = sext i32 %20 to i64
%22 = inttoptr i64 %21 to i8*
%23 = call i32 @assert(i8* %22)
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32 @strcmp(i8* %26, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%28 = icmp ne i32 %27, 0
br i1 %28, label %160, label %29
29: ; preds = %2
%30 = load i64, i64* %7
%31 = trunc i64 %30 to i32
%32 = load i64, i64* %8
%33 = trunc i64 %32 to i32
%34 = call i32 @posix_memalign(i8** %6, i32 %31, i32 %33)
%35 = load i8*, i8** %6
%36 = call i32 @assert(i8* %35)
%37 = load i8*, i8** %6
%38 = ptrtoint i8* %37 to i64
%39 = load i64, i64* %7
%40 = sub i64 %39, 1
%41 = and i64 %38, %40
%42 = icmp eq i64 %41, 0
%43 = zext i1 %42 to i32
%44 = sext i32 %43 to i64
%45 = inttoptr i64 %44 to i8*
%46 = call i32 @assert(i8* %45)
%47 = load i8*, i8** %6
%48 = call i32 @free(i8* %47)
%49 = load i64, i64* %7
%50 = load i64, i64* %8
%51 = call i8* @aligned_alloc(i64 %49, i64 %50)
store i8* %51, i8** %6
%52 = load i8*, i8** %6
%53 = call i32 @assert(i8* %52)
%54 = load i8*, i8** %6
%55 = ptrtoint i8* %54 to i64
%56 = load i64, i64* %7
%57 = sub i64 %56, 1
%58 = and i64 %55, %57
%59 = icmp eq i64 %58, 0
%60 = zext i1 %59 to i32
%61 = sext i32 %60 to i64
%62 = inttoptr i64 %61 to i8*
%63 = call i32 @assert(i8* %62)
%64 = load i8*, i8** %6
%65 = call i32 @free(i8* %64)
store i32 4, i32* %10
br label %66
66: ; preds = %115, %29
%67 = load i32, i32* %10
%68 = icmp slt i32 %67, 19
br i1 %68, label %69, label %118
69: ; preds = %66
%70 = load i32, i32* %10
%71 = shl i32 1, %70
%72 = zext i32 %71 to i64
store i64 %72, i64* %7
store i32 1, i32* %11
br label %73
73: ; preds = %111, %69
%74 = load i32, i32* %11
%75 = icmp slt i32 %74, 33
br i1 %75, label %76, label %114
76: ; preds = %73
%77 = load i32, i32* %11
%78 = mul nsw i32 2048, %77
%79 = sext i32 %78 to i64
store i64 %79, i64* %8
store i32 0, i32* %12
br label %80
80: ; preds = %107, %76
%81 = load i32, i32* %12
%82 = icmp slt i32 %81, 3
br i1 %82, label %83, label %110
83: ; preds = %80
%84 = load i64, i64* %7
%85 = trunc i64 %84 to i32
%86 = load i64, i64* %8
%87 = load i32, i32* %12
%88 = sext i32 %87 to i64
%89 = mul i64 16, %88
%90 = sub i64 %86, %89
%91 = trunc i64 %90 to i32
%92 = call i8* @memalign(i32 %85, i32 %91)
store i8* %92, i8** %6
%93 = load i8*, i8** %6
%94 = call i32 @assert(i8* %93)
%95 = load i8*, i8** %6
%96 = ptrtoint i8* %95 to i64
%97 = load i64, i64* %7
%98 = sub i64 %97, 1
%99 = and i64 %96, %98
%100 = icmp eq i64 %99, 0
%101 = zext i1 %100 to i32
%102 = sext i32 %101 to i64
%103 = inttoptr i64 %102 to i8*
%104 = call i32 @assert(i8* %103)
%105 = load i8*, i8** %6
%106 = call i32 @free(i8* %105)
br label %107
107: ; preds = %83
%108 = load i32, i32* %12
%109 = add nsw i32 %108, 1
store i32 %109, i32* %12
br label %80
110: ; preds = %80
br label %111
111: ; preds = %110
%112 = load i32, i32* %11
%113 = add nsw i32 %112, 1
store i32 %113, i32* %11
br label %73
114: ; preds = %73
br label %115
115: ; preds = %114
%116 = load i32, i32* %10
%117 = add nsw i32 %116, 1
store i32 %117, i32* %10
br label %66
118: ; preds = %66
store i32 19, i32* %13
br label %119
119: ; preds = %156, %118
%120 = load i32, i32* %13
%121 = icmp sle i32 %120, 24
br i1 %121, label %122, label %159
122: ; preds = %119
%123 = load i32, i32* %13
%124 = shl i32 1, %123
%125 = zext i32 %124 to i64
store i64 %125, i64* %7
store i32 0, i32* %14
br label %126
126: ; preds = %152, %122
%127 = load i32, i32* %14
%128 = icmp slt i32 %127, 3
br i1 %128, label %129, label %155
129: ; preds = %126
%130 = load i64, i64* %7
%131 = trunc i64 %130 to i32
%132 = load i32, i32* %14
%133 = sext i32 %132 to i64
%134 = mul i64 16, %133
%135 = sub i64 4096, %134
%136 = trunc i64 %135 to i32
%137 = call i8* @memalign(i32 %131, i32 %136)
store i8* %137, i8** %6
%138 = load i8*, i8** %6
%139 = call i32 @assert(i8* %138)
%140 = load i8*, i8** %6
%141 = ptrtoint i8* %140 to i64
%142 = load i64, i64* %7
%143 = sub i64 %142, 1
%144 = and i64 %141, %143
%145 = icmp eq i64 %144, 0
%146 = zext i1 %145 to i32
%147 = sext i32 %146 to i64
%148 = inttoptr i64 %147 to i8*
%149 = call i32 @assert(i8* %148)
%150 = load i8*, i8** %6
%151 = call i32 @free(i8* %150)
br label %152
152: ; preds = %129
%153 = load i32, i32* %14
%154 = add nsw i32 %153, 1
store i32 %154, i32* %14
br label %126
155: ; preds = %126
br label %156
156: ; preds = %155
%157 = load i32, i32* %13
%158 = add nsw i32 %157, 1
store i32 %158, i32* %13
br label %119
159: ; preds = %119
br label %160
160: ; preds = %159, %2
%161 = load i8**, i8*** %5
%162 = getelementptr inbounds i8*, i8** %161, i64 1
%163 = load i8*, i8** %162
%164 = call i32 @strcmp(i8* %163, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%165 = icmp ne i32 %164, 0
br i1 %165, label %226, label %166
166: ; preds = %160
%167 = load i64, i64* %7
%168 = sub i64 %167, 1
%169 = trunc i64 %168 to i32
%170 = load i64, i64* %8
%171 = trunc i64 %170 to i32
%172 = call i8* @memalign(i32 %169, i32 %171)
store i8* %172, i8** %6
%173 = load i8*, i8** %6
%174 = icmp ne i8* %173, null
%175 = xor i1 %174, true
%176 = zext i1 %175 to i32
%177 = sext i32 %176 to i64
%178 = inttoptr i64 %177 to i8*
%179 = call i32 @assert(i8* %178)
%180 = load i64, i64* %7
%181 = load i64, i64* %8
%182 = lshr i64 %181, 1
%183 = call i8* @aligned_alloc(i64 %180, i64 %182)
store i8* %183, i8** %6
%184 = load i8*, i8** %6
%185 = icmp ne i8* %184, null
%186 = xor i1 %185, true
%187 = zext i1 %186 to i32
%188 = sext i32 %187 to i64
%189 = inttoptr i64 %188 to i8*
%190 = call i32 @assert(i8* %189)
store i8* inttoptr (i64 66 to i8*), i8** %15
%191 = load i8*, i8** %15
store i8* %191, i8** %6
%192 = load i64, i64* %8
%193 = trunc i64 %192 to i32
%194 = call i32 @posix_memalign(i8** %6, i32 3, i32 %193)
store i32 %194, i32* %9
%195 = load i8*, i8** %6
%196 = load i8*, i8** %15
%197 = icmp eq i8* %195, %196
%198 = zext i1 %197 to i32
%199 = sext i32 %198 to i64
%200 = inttoptr i64 %199 to i8*
%201 = call i32 @assert(i8* %200)
%202 = load i32, i32* %9
%203 = load i32, i32* @EINVAL
%204 = icmp eq i32 %202, %203
%205 = zext i1 %204 to i32
%206 = sext i32 %205 to i64
%207 = inttoptr i64 %206 to i8*
%208 = call i32 @assert(i8* %207)
%209 = load i64, i64* %8
%210 = trunc i64 %209 to i32
%211 = call i32 @posix_memalign(i8** %6, i32 2, i32 %210)
store i32 %211, i32* %9
%212 = load i8*, i8** %6
%213 = load i8*, i8** %15
%214 = icmp eq i8* %212, %213
%215 = zext i1 %214 to i32
%216 = sext i32 %215 to i64
%217 = inttoptr i64 %216 to i8*
%218 = call i32 @assert(i8* %217)
%219 = load i32, i32* %9
%220 = load i32, i32* @EINVAL
%221 = icmp eq i32 %219, %220
%222 = zext i1 %221 to i32
%223 = sext i32 %222 to i64
%224 = inttoptr i64 %223 to i8*
%225 = call i32 @assert(i8* %224)
br label %226
226: ; preds = %166, %160
%227 = load i8**, i8*** %5
%228 = getelementptr inbounds i8*, i8** %227, i64 1
%229 = load i8*, i8** %228
%230 = call i32 @strcmp(i8* %229, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%231 = icmp ne i32 %230, 0
br i1 %231, label %240, label %232
232: ; preds = %226
store i8* null, i8** %16
%233 = call i32 @posix_memalign(i8** %16, i32 256, i32 4)
%234 = load i8*, i8** %16
%235 = call i32 @assert(i8* %234)
%236 = load i8*, i8** %16
%237 = call i32 @free(i8* %236)
%238 = load i8*, i8** %16
%239 = call i32 @free(i8* %238)
br label %240
240: ; preds = %232, %226
%241 = load i8**, i8*** %5
%242 = getelementptr inbounds i8*, i8** %241, i64 1
%243 = load i8*, i8** %242
%244 = call i32 @strcmp(i8* %243, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%245 = icmp ne i32 %244, 0
br i1 %245, label %254, label %246
246: ; preds = %240
%247 = call i8* @memalign(i32 16, i32 16)
store i8* %247, i8** %17
%248 = load i8*, i8** %17
%249 = call i32 @assert(i8* %248)
%250 = load i8*, i8** %17
%251 = call i8* @realloc(i8* %250, i32 32)
store i8* %251, i8** %17
%252 = load i8*, i8** %17
%253 = call i32 @free(i8* %252)
br label %254
254: ; preds = %246, %240
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"valid\00"
@.str.1 = [8 x i8] c"invalid\00"
@EINVAL = global i32 0
@.str.2 = [12 x i8] c"double-free\00"
@.str.3 = [8 x i8] c"realloc\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%6 = icmp eq i32 %0, 2
%7 = zext i1 %6 to i64
%8 = inttoptr i64 %7 to i8*
%9 = tail call i32 @assert(i8* %8)
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @strcmp(i8* dereferenceable(1) %11, i8* dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %128
14: ; preds = %2
%15 = call i32 @posix_memalign(i8** %3, i32 4096, i32 4096)
%16 = load i8*, i8** %3
%17 = call i32 @assert(i8* %16)
%18 = load i8*, i8** %3
%19 = ptrtoint i8* %18 to i64
%20 = and i64 %19, 4095
%21 = icmp eq i64 %20, 0
%22 = zext i1 %21 to i64
%23 = inttoptr i64 %22 to i8*
%24 = call i32 @assert(i8* %23)
%25 = load i8*, i8** %3
%26 = call i32 @free(i8* %25)
%27 = call align 4096 dereferenceable_or_null(4096) i8* @aligned_alloc(i64 4096, i64 4096)
store i8* %27, i8** %3
%28 = call i32 @assert(i8* %27)
%29 = load i8*, i8** %3
%30 = ptrtoint i8* %29 to i64
%31 = and i64 %30, 4095
%32 = icmp eq i64 %31, 0
%33 = zext i1 %32 to i64
%34 = inttoptr i64 %33 to i8*
%35 = call i32 @assert(i8* %34)
%36 = load i8*, i8** %3
%37 = call i32 @free(i8* %36)
br label %38
38: ; preds = %14, %43
%39 = phi i32 [ 4, %14 ], [ %44, %43 ]
%40 = shl nuw nsw i32 1, %39
%41 = zext i32 %40 to i64
%42 = add nsw i64 %41, -1
br label %46
43: ; preds = %46
%44 = add nuw nsw i32 %39, 1
%45 = icmp eq i32 %44, 19
br i1 %45, label %86, label %38
46: ; preds = %38, %46
%47 = phi i32 [ 1, %38 ], [ %84, %46 ]
%48 = shl nuw nsw i32 %47, 11
%49 = call i8* @memalign(i32 %40, i32 %48)
store i8* %49, i8** %3
%50 = call i32 @assert(i8* %49)
%51 = load i8*, i8** %3
%52 = ptrtoint i8* %51 to i64
%53 = and i64 %42, %52
%54 = icmp eq i64 %53, 0
%55 = zext i1 %54 to i64
%56 = inttoptr i64 %55 to i8*
%57 = call i32 @assert(i8* %56)
%58 = load i8*, i8** %3
%59 = call i32 @free(i8* %58)
%60 = add nsw i32 %48, -16
%61 = call i8* @memalign(i32 %40, i32 %60)
store i8* %61, i8** %3
%62 = call i32 @assert(i8* %61)
%63 = load i8*, i8** %3
%64 = ptrtoint i8* %63 to i64
%65 = and i64 %42, %64
%66 = icmp eq i64 %65, 0
%67 = zext i1 %66 to i64
%68 = inttoptr i64 %67 to i8*
%69 = call i32 @assert(i8* %68)
%70 = load i8*, i8** %3
%71 = call i32 @free(i8* %70)
%72 = add nsw i32 %48, -32
%73 = call i8* @memalign(i32 %40, i32 %72)
store i8* %73, i8** %3
%74 = call i32 @assert(i8* %73)
%75 = load i8*, i8** %3
%76 = ptrtoint i8* %75 to i64
%77 = and i64 %42, %76
%78 = icmp eq i64 %77, 0
%79 = zext i1 %78 to i64
%80 = inttoptr i64 %79 to i8*
%81 = call i32 @assert(i8* %80)
%82 = load i8*, i8** %3
%83 = call i32 @free(i8* %82)
%84 = add nuw nsw i32 %47, 1
%85 = icmp eq i32 %84, 33
br i1 %85, label %43, label %46
86: ; preds = %43, %86
%87 = phi i32 [ %124, %86 ], [ 19, %43 ]
%88 = shl nuw nsw i32 1, %87
%89 = zext i32 %88 to i64
%90 = add nsw i64 %89, -1
%91 = call dereferenceable_or_null(4096) i8* @memalign(i32 %88, i32 4096)
store i8* %91, i8** %3
%92 = call i32 @assert(i8* %91)
%93 = load i8*, i8** %3
%94 = ptrtoint i8* %93 to i64
%95 = and i64 %90, %94
%96 = icmp eq i64 %95, 0
%97 = zext i1 %96 to i64
%98 = inttoptr i64 %97 to i8*
%99 = call i32 @assert(i8* %98)
%100 = load i8*, i8** %3
%101 = call i32 @free(i8* %100)
%102 = call dereferenceable_or_null(4080) i8* @memalign(i32 %88, i32 4080)
store i8* %102, i8** %3
%103 = call i32 @assert(i8* %102)
%104 = load i8*, i8** %3
%105 = ptrtoint i8* %104 to i64
%106 = and i64 %90, %105
%107 = icmp eq i64 %106, 0
%108 = zext i1 %107 to i64
%109 = inttoptr i64 %108 to i8*
%110 = call i32 @assert(i8* %109)
%111 = load i8*, i8** %3
%112 = call i32 @free(i8* %111)
%113 = call dereferenceable_or_null(4064) i8* @memalign(i32 %88, i32 4064)
store i8* %113, i8** %3
%114 = call i32 @assert(i8* %113)
%115 = load i8*, i8** %3
%116 = ptrtoint i8* %115 to i64
%117 = and i64 %90, %116
%118 = icmp eq i64 %117, 0
%119 = zext i1 %118 to i64
%120 = inttoptr i64 %119 to i8*
%121 = call i32 @assert(i8* %120)
%122 = load i8*, i8** %3
%123 = call i32 @free(i8* %122)
%124 = add nuw nsw i32 %87, 1
%125 = icmp eq i32 %124, 25
br i1 %125, label %126, label %86
126: ; preds = %86
%127 = load i8*, i8** %10
br label %128
128: ; preds = %126, %2
%129 = phi i8* [ %11, %2 ], [ %127, %126 ]
%130 = phi i64 [ 4096, %2 ], [ 65536, %126 ]
%131 = phi i64 [ 4096, %2 ], [ 16777216, %126 ]
%132 = call i32 @strcmp(i8* dereferenceable(1) %129, i8* dereferenceable(8) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%133 = icmp eq i32 %132, 0
br i1 %133, label %134, label %172
134: ; preds = %128
%135 = trunc i64 %131 to i32
%136 = add nsw i32 %135, -1
%137 = trunc i64 %130 to i32
%138 = call i8* @memalign(i32 %136, i32 %137)
store i8* %138, i8** %3
%139 = icmp eq i8* %138, null
%140 = zext i1 %139 to i64
%141 = inttoptr i64 %140 to i8*
%142 = call i32 @assert(i8* %141)
%143 = lshr exact i64 %130, 1
%144 = call i8* @aligned_alloc(i64 %131, i64 %143)
store i8* %144, i8** %3
%145 = icmp eq i8* %144, null
%146 = zext i1 %145 to i64
%147 = inttoptr i64 %146 to i8*
%148 = call i32 @assert(i8* %147)
store i8* inttoptr (i64 66 to i8*), i8** %3
%149 = call i32 @posix_memalign(i8** %3, i32 3, i32 %137)
%150 = load i8*, i8** %3
%151 = icmp eq i8* %150, inttoptr (i64 66 to i8*)
%152 = zext i1 %151 to i64
%153 = inttoptr i64 %152 to i8*
%154 = call i32 @assert(i8* %153)
%155 = load i32, i32* @EINVAL
%156 = icmp eq i32 %149, %155
%157 = zext i1 %156 to i64
%158 = inttoptr i64 %157 to i8*
%159 = call i32 @assert(i8* %158)
%160 = call i32 @posix_memalign(i8** %3, i32 2, i32 %137)
%161 = load i8*, i8** %3
%162 = icmp eq i8* %161, inttoptr (i64 66 to i8*)
%163 = zext i1 %162 to i64
%164 = inttoptr i64 %163 to i8*
%165 = call i32 @assert(i8* %164)
%166 = load i32, i32* @EINVAL
%167 = icmp eq i32 %160, %166
%168 = zext i1 %167 to i64
%169 = inttoptr i64 %168 to i8*
%170 = call i32 @assert(i8* %169)
%171 = load i8*, i8** %10
br label %172
172: ; preds = %134, %128
%173 = phi i8* [ %171, %134 ], [ %129, %128 ]
%174 = call i32 @strcmp(i8* dereferenceable(1) %173, i8* dereferenceable(12) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%175 = icmp eq i32 %174, 0
br i1 %175, label %176, label %186
176: ; preds = %172
%177 = bitcast i8** %4 to i8*
store i8* null, i8** %4
%178 = call i32 @posix_memalign(i8** %4, i32 256, i32 4)
%179 = load i8*, i8** %4
%180 = call i32 @assert(i8* %179)
%181 = load i8*, i8** %4
%182 = call i32 @free(i8* %181)
%183 = load i8*, i8** %4
%184 = call i32 @free(i8* %183)
%185 = load i8*, i8** %10
br label %186
186: ; preds = %176, %172
%187 = phi i8* [ %185, %176 ], [ %173, %172 ]
%188 = call i32 @strcmp(i8* dereferenceable(1) %187, i8* dereferenceable(8) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%189 = icmp eq i32 %188, 0
br i1 %189, label %190, label %195
190: ; preds = %186
%191 = call align 16 dereferenceable_or_null(16) i8* @memalign(i32 16, i32 16)
%192 = call i32 @assert(i8* %191)
%193 = call i8* @realloc(i8* %191, i32 32)
%194 = call i32 @free(i8* %193)
br label %195
195: ; preds = %190, %186
ret i32 0
}