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


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   $0x8000000,-0x20(%rbp)
08
jae    119e <malloc_and_break+0x2e>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1311 <malloc_and_break+0x1a1>
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
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
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    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1080 <realloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    $0x3,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,%rdx
mov    $0xcd,%esi
call   1090 <verify@plt>
mov    -0x30(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   1050 <memset@plt>
mov    -0x30(%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    $0x7ffffff,%rdx
jbe    1266 <malloc_and_break+0xf6>
mov    %rdx,%r12
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,%r15
mov    %rbp,%rdi
call   1070 <malloc@plt>
mov    %rax,%r13
mov    %rbx,%rdi
mov    %r15,%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    %r15,%rdi
mov    $0xcd,%esi
mov    %rbp,%rdx
call   1050 <memset@plt>
mov    %r13,%rdi
mov    $0xef,%esi
mov    %rbp,%rdx
call   1050 <memset@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r13,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
mov    $0xcd,%esi
mov    %rbp,%rdx
call   1060 <malloc_and_break@plt>
mov    %rax,%rdi
mov    %r12,%rsi
call   1080 <realloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0xcd,%esi
mov    %rbp,%rdx
call   1090 <verify@plt>
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %r12,%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, 134217728
br i1 %12, label %13, label %15
13: ; preds = %3
%14 = load i8*, i8** %5
store i8* %14, i8** %4
br label %69
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 = call i32 @free(i8* %49)
%51 = load i8*, i8** %10
%52 = call i32 @free(i8* %51)
%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** %9
%58 = load i64, i64* %7
%59 = call i8* @realloc(i8* %57, i64 %58)
store i8* %59, i8** %9
%60 = load i8*, i8** %9
%61 = load i64, i64* %7
%62 = udiv i64 %61, 3
%63 = call i32 @verify(i8* %60, i32 205, i64 %62)
%64 = load i8*, i8** %9
%65 = load i32, i32* %6
%66 = load i64, i64* %7
%67 = call i32 @memset(i8* %64, i32 %65, i64 %66)
%68 = load i8*, i8** %9
store i8* %68, i8** %4
br label %69
69: ; preds = %15, %13
%70 = load i8*, i8** %4
ret i8* %70
}

LLVM IR (-O2):
define i8* @malloc_and_break(i8* %0, i32 %1, i64 %2) {
%4 = icmp ult i64 %2, 134217728
br i1 %4, label %5, label %7
5: ; preds = %3, %7
%6 = phi i8* [ %20, %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* %9)
%18 = tail call i32 @free(i8* %11)
%19 = tail call i8* @malloc_and_break(i8* %10, i32 205, i64 %8)
%20 = tail call i8* @realloc(i8* %19, i64 %2)
%21 = tail call i32 @verify(i8* %20, i32 205, i64 %8)
%22 = tail call i32 @memset(i8* %20, i32 %1, i64 %2)
br label %5
}