#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(void *);
void *malloc(size_t);
int /*<<< orphan*/ memset(void *, int, size_t);
void *realloc(void *, size_t);
int /*<<< orphan*/ verify(void *, int, size_t);
int /*<<< orphan*/ verify_overlap2(void *, void *, size_t);
int /*<<< orphan*/ verify_overlap3(void *, void *, void *, size_t);
void *malloc_and_break(void *region, int c, size_t len) {
  if (len < (256 * 1024 * 1024)) {
    return region;
  }
  void *sr1 = realloc(region, len / 3);
  void *sr2 = malloc(len / 3);
  void *sr3 = malloc(len / 3);
  verify_overlap3(sr1, sr2, sr3, len / 3);
  verify(sr1, c, len / 3);
  memset(sr1, 0xab, len / 3);
  memset(sr2, 0xcd, len / 3);
  memset(sr3, 0xef, len / 3);
  free(sr2);
  sr1 = malloc_and_break(sr1, 0xab, len / 3);
  sr3 = malloc_and_break(sr3, 0xef, len / 3);
  sr1 = realloc(sr1, len / 2);
  sr3 = realloc(sr3, len / 2);
  verify(sr1, 0xab, len / 3);
  verify(sr3, 0xef, len / 3);
  memset(sr1, 0xab, len / 2);
  memset(sr3, 0xef, len / 2);
  verify_overlap2(sr1, sr3, len / 2);
  free(sr3);
  sr1 = realloc(sr1, len);
  verify(sr1, 0xab, len / 2);
  memset(sr1, c, len);
  return sr1;
}


x86 assembly (clang, -O0):
<malloc_and_break>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x10000000,-0x20(%rbp)
10
jae    11ae <malloc_and_break+0x2e>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    13e4 <malloc_and_break+0x264>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    $0x3,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,%rsi
call   1080 <realloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    $0x3,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    $0x3,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rax
mov    $0x3,%ecx
xor    %edx,%edx
div    %rcx
mov    -0x40(%rbp),%rdx
mov    %rax,%rcx
call   1040 <verify_overlap3@plt>
mov    -0x28(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rax
mov    $0x3,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,%rdx
call   1090 <verify@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    $0x3,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,%rdx
mov    $0xab,%esi
call   1050 <memset@plt>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    $0x3,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,%rdx
mov    $0xcd,%esi
call   1050 <memset@plt>
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    $0x3,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,%rdx
mov    $0xef,%esi
call   1050 <memset@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    $0x3,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,%rdx
mov    $0xab,%esi
call   1060 <malloc_and_break@plt>
mov    %rax,-0x28(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    $0x3,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,%rdx
mov    $0xef,%esi
call   1060 <malloc_and_break@plt>
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
shr    $0x1,%rsi
call   1080 <realloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rsi
shr    $0x1,%rsi
call   1080 <realloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    $0x3,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,%rdx
mov    $0xab,%esi
call   1090 <verify@plt>
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    $0x3,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,%rdx
mov    $0xef,%esi
call   1090 <verify@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rdx
shr    $0x1,%rdx
mov    $0xab,%esi
call   1050 <memset@plt>
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rdx
shr    $0x1,%rdx
mov    $0xef,%esi
call   1050 <memset@plt>
mov    -0x28(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x20(%rbp),%rdx
shr    $0x1,%rdx
call   10a0 <verify_overlap2@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1080 <realloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rdx
shr    $0x1,%rdx
mov    $0xab,%esi
call   1090 <verify@plt>
mov    -0x28(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   1050 <memset@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<malloc_and_break>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
cmp    $0xfffffff,%rdx
jbe    1302 <malloc_and_break+0x182>
mov    %rdx,%r14
mov    %esi,%r15d
movabs $0xaaaaaaaaaaaaaaab,%rcx
aa aa aa
mov    %rdx,%rax
mul    %rcx
mov    %rdx,%rbp
shr    %rbp
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1080 <realloc@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
call   1070 <malloc@plt>
mov    %rax,%r13
mov    %rbp,%rdi
call   1070 <malloc@plt>
mov    %rax,%r12
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %rax,%rdx
mov    %rbp,%rcx
call   1040 <verify_overlap3@plt>
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %rbp,%rdx
call   1090 <verify@plt>
mov    %rbx,%rdi
mov    $0xab,%esi
mov    %rbp,%rdx
call   1050 <memset@plt>
mov    %r13,%rdi
mov    $0xcd,%esi
mov    %rbp,%rdx
call   1050 <memset@plt>
mov    %r12,%rdi
mov    $0xef,%esi
mov    %rbp,%rdx
call   1050 <memset@plt>
mov    %r13,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
mov    $0xab,%esi
mov    %rbp,%rdx
call   1060 <malloc_and_break@plt>
mov    %rax,%r13
mov    %r12,%rdi
mov    $0xef,%esi
mov    %rbp,%rdx
call   1060 <malloc_and_break@plt>
mov    %rax,%rbx
mov    %r15d,0x4(%rsp)
mov    %r14,%r15
shr    %r15
mov    %r13,%rdi
mov    %r15,%rsi
call   1080 <realloc@plt>
mov    %rax,%r12
mov    %rbx,%rdi
mov    %r15,%rsi
call   1080 <realloc@plt>
mov    %rax,%r13
mov    %r12,%rdi
mov    $0xab,%esi
mov    %rbp,%rdx
call   1090 <verify@plt>
mov    %r13,%rdi
mov    $0xef,%esi
mov    %rbp,%rdx
call   1090 <verify@plt>
mov    %r12,%rdi
mov    $0xab,%esi
mov    %r15,%rdx
call   1050 <memset@plt>
mov    %r13,%rdi
mov    $0xef,%esi
mov    %r15,%rdx
call   1050 <memset@plt>
mov    %r12,%rdi
mov    %r13,%rsi
mov    %r15,%rdx
call   10a0 <verify_overlap2@plt>
mov    %r13,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
mov    %r14,%rsi
call   1080 <realloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0xab,%esi
mov    %r15,%rdx
call   1090 <verify@plt>
mov    %rbx,%rdi
mov    0x4(%rsp),%esi
mov    %r14,%rdx
call   1050 <memset@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @malloc_and_break(i8* %0, i32 %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i64 %2, i64* %7
%11 = load i64, i64* %7
%12 = icmp ult i64 %11, 268435456
br i1 %12, label %13, label %15
13: ; preds = %3
%14 = load i8*, i8** %5
store i8* %14, i8** %4
br label %102
15: ; preds = %3
%16 = load i8*, i8** %5
%17 = load i64, i64* %7
%18 = udiv i64 %17, 3
%19 = call i8* @realloc(i8* %16, i64 %18)
store i8* %19, i8** %8
%20 = load i64, i64* %7
%21 = udiv i64 %20, 3
%22 = call i8* @malloc(i64 %21)
store i8* %22, i8** %9
%23 = load i64, i64* %7
%24 = udiv i64 %23, 3
%25 = call i8* @malloc(i64 %24)
store i8* %25, i8** %10
%26 = load i8*, i8** %8
%27 = load i8*, i8** %9
%28 = load i8*, i8** %10
%29 = load i64, i64* %7
%30 = udiv i64 %29, 3
%31 = call i32 @verify_overlap3(i8* %26, i8* %27, i8* %28, i64 %30)
%32 = load i8*, i8** %8
%33 = load i32, i32* %6
%34 = load i64, i64* %7
%35 = udiv i64 %34, 3
%36 = call i32 @verify(i8* %32, i32 %33, i64 %35)
%37 = load i8*, i8** %8
%38 = load i64, i64* %7
%39 = udiv i64 %38, 3
%40 = call i32 @memset(i8* %37, i32 171, i64 %39)
%41 = load i8*, i8** %9
%42 = load i64, i64* %7
%43 = udiv i64 %42, 3
%44 = call i32 @memset(i8* %41, i32 205, i64 %43)
%45 = load i8*, i8** %10
%46 = load i64, i64* %7
%47 = udiv i64 %46, 3
%48 = call i32 @memset(i8* %45, i32 239, i64 %47)
%49 = load i8*, i8** %9
%50 = call i32 @free(i8* %49)
%51 = load i8*, i8** %8
%52 = load i64, i64* %7
%53 = udiv i64 %52, 3
%54 = call i8* @malloc_and_break(i8* %51, i32 171, i64 %53)
store i8* %54, i8** %8
%55 = load i8*, i8** %10
%56 = load i64, i64* %7
%57 = udiv i64 %56, 3
%58 = call i8* @malloc_and_break(i8* %55, i32 239, i64 %57)
store i8* %58, i8** %10
%59 = load i8*, i8** %8
%60 = load i64, i64* %7
%61 = udiv i64 %60, 2
%62 = call i8* @realloc(i8* %59, i64 %61)
store i8* %62, i8** %8
%63 = load i8*, i8** %10
%64 = load i64, i64* %7
%65 = udiv i64 %64, 2
%66 = call i8* @realloc(i8* %63, i64 %65)
store i8* %66, i8** %10
%67 = load i8*, i8** %8
%68 = load i64, i64* %7
%69 = udiv i64 %68, 3
%70 = call i32 @verify(i8* %67, i32 171, i64 %69)
%71 = load i8*, i8** %10
%72 = load i64, i64* %7
%73 = udiv i64 %72, 3
%74 = call i32 @verify(i8* %71, i32 239, i64 %73)
%75 = load i8*, i8** %8
%76 = load i64, i64* %7
%77 = udiv i64 %76, 2
%78 = call i32 @memset(i8* %75, i32 171, i64 %77)
%79 = load i8*, i8** %10
%80 = load i64, i64* %7
%81 = udiv i64 %80, 2
%82 = call i32 @memset(i8* %79, i32 239, i64 %81)
%83 = load i8*, i8** %8
%84 = load i8*, i8** %10
%85 = load i64, i64* %7
%86 = udiv i64 %85, 2
%87 = call i32 @verify_overlap2(i8* %83, i8* %84, i64 %86)
%88 = load i8*, i8** %10
%89 = call i32 @free(i8* %88)
%90 = load i8*, i8** %8
%91 = load i64, i64* %7
%92 = call i8* @realloc(i8* %90, i64 %91)
store i8* %92, i8** %8
%93 = load i8*, i8** %8
%94 = load i64, i64* %7
%95 = udiv i64 %94, 2
%96 = call i32 @verify(i8* %93, i32 171, i64 %95)
%97 = load i8*, i8** %8
%98 = load i32, i32* %6
%99 = load i64, i64* %7
%100 = call i32 @memset(i8* %97, i32 %98, i64 %99)
%101 = load i8*, i8** %8
store i8* %101, i8** %4
br label %102
102: ; preds = %15, %13
%103 = load i8*, i8** %4
ret i8* %103
}

LLVM IR (-O2):
define i8* @malloc_and_break(i8* %0, i32 %1, i64 %2) {
%4 = icmp ult i64 %2, 268435456
br i1 %4, label %5, label %7
5: ; preds = %3, %7
%6 = phi i8* [ %29, %7 ], [ %0, %3 ]
ret i8* %6
7: ; preds = %3
%8 = udiv i64 %2, 3
%9 = tail call i8* @realloc(i8* %0, i64 %8)
%10 = tail call i8* @malloc(i64 %8)
%11 = tail call i8* @malloc(i64 %8)
%12 = tail call i32 @verify_overlap3(i8* %9, i8* %10, i8* %11, i64 %8)
%13 = tail call i32 @verify(i8* %9, i32 %1, i64 %8)
%14 = tail call i32 @memset(i8* %9, i32 171, i64 %8)
%15 = tail call i32 @memset(i8* %10, i32 205, i64 %8)
%16 = tail call i32 @memset(i8* %11, i32 239, i64 %8)
%17 = tail call i32 @free(i8* %10)
%18 = tail call i8* @malloc_and_break(i8* %9, i32 171, i64 %8)
%19 = tail call i8* @malloc_and_break(i8* %11, i32 239, i64 %8)
%20 = lshr i64 %2, 1
%21 = tail call i8* @realloc(i8* %18, i64 %20)
%22 = tail call i8* @realloc(i8* %19, i64 %20)
%23 = tail call i32 @verify(i8* %21, i32 171, i64 %8)
%24 = tail call i32 @verify(i8* %22, i32 239, i64 %8)
%25 = tail call i32 @memset(i8* %21, i32 171, i64 %20)
%26 = tail call i32 @memset(i8* %22, i32 239, i64 %20)
%27 = tail call i32 @verify_overlap2(i8* %21, i8* %22, i64 %20)
%28 = tail call i32 @free(i8* %22)
%29 = tail call i8* @realloc(i8* %21, i64 %2)
%30 = tail call i32 @verify(i8* %29, i32 171, i64 %20)
%31 = tail call i32 @memset(i8* %29, i32 %1, i64 %2)
br label %5
}