#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_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);
  sr1 = malloc_and_break(sr1, 0xab, len / 3);
  sr2 = malloc_and_break(sr2, 0xcd, len / 3);
  sr3 = malloc_and_break(sr3, 0xef, len / 3);
  free(sr1);
  free(sr2);
  sr3 = realloc(sr3, len);
  verify(sr3, 0xef, len / 3);
  memset(sr3, c, len);
  return sr3;
}


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    119e <malloc_and_break+0x2e>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1357 <malloc_and_break+0x1e7>
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    -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    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    $0x3,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,%rdx
mov    $0xcd,%esi
call   1060 <malloc_and_break@plt>
mov    %rax,-0x30(%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
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1080 <realloc@plt>
mov    %rax,-0x38(%rbp)
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    -0x38(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   1050 <memset@plt>
mov    -0x38(%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    1295 <malloc_and_break+0x125>
mov    %rdx,%r15
mov    %esi,%r14d
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    %r14d,%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    %rbx,%rdi
mov    $0xab,%esi
mov    %rbp,%rdx
call   1060 <malloc_and_break@plt>
mov    %r14d,0x4(%rsp)
mov    %rax,%r14
mov    %r13,%rdi
mov    $0xcd,%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    %r14,%rdi
call   1030 <free@plt>
mov    %r13,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1080 <realloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0xef,%esi
mov    %rbp,%rdx
call   1090 <verify@plt>
mov    %rbx,%rdi
mov    0x4(%rsp),%esi
mov    %r15,%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 %77
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** %8
%50 = load i64, i64* %7
%51 = udiv i64 %50, 3
%52 = call i8* @malloc_and_break(i8* %49, i32 171, i64 %51)
store i8* %52, i8** %8
%53 = load i8*, i8** %9
%54 = load i64, i64* %7
%55 = udiv i64 %54, 3
%56 = call i8* @malloc_and_break(i8* %53, i32 205, i64 %55)
store i8* %56, i8** %9
%57 = load i8*, i8** %10
%58 = load i64, i64* %7
%59 = udiv i64 %58, 3
%60 = call i8* @malloc_and_break(i8* %57, i32 239, i64 %59)
store i8* %60, i8** %10
%61 = load i8*, i8** %8
%62 = call i32 @free(i8* %61)
%63 = load i8*, i8** %9
%64 = call i32 @free(i8* %63)
%65 = load i8*, i8** %10
%66 = load i64, i64* %7
%67 = call i8* @realloc(i8* %65, i64 %66)
store i8* %67, i8** %10
%68 = load i8*, i8** %10
%69 = load i64, i64* %7
%70 = udiv i64 %69, 3
%71 = call i32 @verify(i8* %68, i32 239, i64 %70)
%72 = load i8*, i8** %10
%73 = load i32, i32* %6
%74 = load i64, i64* %7
%75 = call i32 @memset(i8* %72, i32 %73, i64 %74)
%76 = load i8*, i8** %10
store i8* %76, i8** %4
br label %77
77: ; preds = %15, %13
%78 = load i8*, i8** %4
ret i8* %78
}

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* [ %22, %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 i8* @malloc_and_break(i8* %9, i32 171, i64 %8)
%18 = tail call i8* @malloc_and_break(i8* %10, i32 205, i64 %8)
%19 = tail call i8* @malloc_and_break(i8* %11, i32 239, i64 %8)
%20 = tail call i32 @free(i8* %17)
%21 = tail call i32 @free(i8* %18)
%22 = tail call i8* @realloc(i8* %19, i64 %2)
%23 = tail call i32 @verify(i8* %22, i32 239, i64 %8)
%24 = tail call i32 @memset(i8* %22, i32 %1, i64 %2)
br label %5
}