#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*/ assert(int);
int /*<<< orphan*/ memset(char *, int, int);
char *sbrk(int);
void sbrk_good(void) {
  char *a1 = sbrk(10);
  memset(a1, 1, 10);
  char *a2 = sbrk(40);
  assert(a2 == a1 + 10);
  char *a3 = sbrk(50);
  assert(a3 == a2 + 40);
  char *a4 = sbrk(-90);
  assert((char *)sbrk(0) == a2);
  sbrk(90);
  assert((char *)sbrk(0) == a4);
  char *a5 = sbrk(0x5000);
  assert(a5 == a3 + 50);
  memset(a5, -1, 0x5000);
  assert(*(a1 + 5) == 1);
  sbrk(-1 * (10 + 40 + 50 + 0x5000));
  char *a6 = sbrk(0);
  assert(a1 == a6);
}


x86 assembly (clang, -O0):
<sbrk_good>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    $0xa,%edi
call   1040 <sbrk@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x1,%esi
mov    $0xa,%edx
call   1030 <memset@plt>
mov    $0x28,%edi
call   1040 <sbrk@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
add    $0xa,%rcx
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    $0x32,%edi
call   1040 <sbrk@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
add    $0x28,%rcx
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    $0xffffffa6,%edi
call   1040 <sbrk@plt>
mov    %rax,-0x20(%rbp)
xor    %edi,%edi
call   1040 <sbrk@plt>
cmp    -0x10(%rbp),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    $0x5a,%edi
call   1040 <sbrk@plt>
xor    %edi,%edi
call   1040 <sbrk@plt>
cmp    -0x20(%rbp),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    $0x5000,%edi
call   1040 <sbrk@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
add    $0x32,%rcx
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x28(%rbp),%rdi
mov    $0xffffffff,%esi
mov    $0x5000,%edx
call   1030 <memset@plt>
mov    -0x8(%rbp),%rax
movsbl 0x5(%rax),%eax
cmp    $0x1,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    $0xffffaf9c,%edi
call   1040 <sbrk@plt>
xor    %edi,%edi
call   1040 <sbrk@plt>
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
cmp    -0x30(%rbp),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sbrk_good>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    $0xa,%edi
call   1040 <sbrk@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    $0x1,%esi
mov    $0xa,%edx
call   1030 <memset@plt>
mov    $0x28,%edi
call   1040 <sbrk@plt>
mov    %rax,%rbx
lea    0xa(%r14),%rax
xor    %edi,%edi
cmp    %rax,%rbx
sete   %dil
call   1050 <assert@plt>
mov    $0x32,%edi
call   1040 <sbrk@plt>
mov    %rax,%r15
lea    0x28(%rbx),%rax
xor    %edi,%edi
cmp    %rax,%r15
sete   %dil
call   1050 <assert@plt>
mov    $0xffffffa6,%edi
call   1040 <sbrk@plt>
mov    %rax,%r12
xor    %edi,%edi
call   1040 <sbrk@plt>
xor    %edi,%edi
cmp    %rbx,%rax
sete   %dil
call   1050 <assert@plt>
mov    $0x5a,%edi
call   1040 <sbrk@plt>
xor    %edi,%edi
call   1040 <sbrk@plt>
xor    %edi,%edi
cmp    %r12,%rax
sete   %dil
call   1050 <assert@plt>
mov    $0x5000,%edi
call   1040 <sbrk@plt>
mov    %rax,%rbx
add    $0x32,%r15
xor    %edi,%edi
cmp    %r15,%rax
sete   %dil
call   1050 <assert@plt>
mov    %rbx,%rdi
mov    $0xffffffff,%esi
mov    $0x5000,%edx
call   1030 <memset@plt>
xor    %edi,%edi
cmpb   $0x1,0x5(%r14)
sete   %dil
call   1050 <assert@plt>
mov    $0xffffaf9c,%edi
call   1040 <sbrk@plt>
xor    %edi,%edi
call   1040 <sbrk@plt>
xor    %edi,%edi
cmp    %rax,%r14
sete   %dil
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1050 <assert@plt>

LLVM IR (-O0):
define void @sbrk_good() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = call i8* @sbrk(i32 10)
store i8* %7, i8** %1
%8 = load i8*, i8** %1
%9 = call i32 @memset(i8* %8, i32 1, i32 10)
%10 = call i8* @sbrk(i32 40)
store i8* %10, i8** %2
%11 = load i8*, i8** %2
%12 = load i8*, i8** %1
%13 = getelementptr inbounds i8, i8* %12, i64 10
%14 = icmp eq i8* %11, %13
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
%17 = call i8* @sbrk(i32 50)
store i8* %17, i8** %3
%18 = load i8*, i8** %3
%19 = load i8*, i8** %2
%20 = getelementptr inbounds i8, i8* %19, i64 40
%21 = icmp eq i8* %18, %20
%22 = zext i1 %21 to i32
%23 = call i32 @assert(i32 %22)
%24 = call i8* @sbrk(i32 -90)
store i8* %24, i8** %4
%25 = call i8* @sbrk(i32 0)
%26 = load i8*, i8** %2
%27 = icmp eq i8* %25, %26
%28 = zext i1 %27 to i32
%29 = call i32 @assert(i32 %28)
%30 = call i8* @sbrk(i32 90)
%31 = call i8* @sbrk(i32 0)
%32 = load i8*, i8** %4
%33 = icmp eq i8* %31, %32
%34 = zext i1 %33 to i32
%35 = call i32 @assert(i32 %34)
%36 = call i8* @sbrk(i32 20480)
store i8* %36, i8** %5
%37 = load i8*, i8** %5
%38 = load i8*, i8** %3
%39 = getelementptr inbounds i8, i8* %38, i64 50
%40 = icmp eq i8* %37, %39
%41 = zext i1 %40 to i32
%42 = call i32 @assert(i32 %41)
%43 = load i8*, i8** %5
%44 = call i32 @memset(i8* %43, i32 -1, i32 20480)
%45 = load i8*, i8** %1
%46 = getelementptr inbounds i8, i8* %45, i64 5
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = icmp eq i32 %48, 1
%50 = zext i1 %49 to i32
%51 = call i32 @assert(i32 %50)
%52 = call i8* @sbrk(i32 -20580)
%53 = call i8* @sbrk(i32 0)
store i8* %53, i8** %6
%54 = load i8*, i8** %1
%55 = load i8*, i8** %6
%56 = icmp eq i8* %54, %55
%57 = zext i1 %56 to i32
%58 = call i32 @assert(i32 %57)
ret void
}

LLVM IR (-O2):
define void @sbrk_good() {
%1 = tail call i8* @sbrk(i32 10)
%2 = tail call i32 @memset(i8* %1, i32 1, i32 10)
%3 = tail call i8* @sbrk(i32 40)
%4 = getelementptr inbounds i8, i8* %1, i64 10
%5 = icmp eq i8* %3, %4
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = tail call i8* @sbrk(i32 50)
%9 = getelementptr inbounds i8, i8* %3, i64 40
%10 = icmp eq i8* %8, %9
%11 = zext i1 %10 to i32
%12 = tail call i32 @assert(i32 %11)
%13 = tail call i8* @sbrk(i32 -90)
%14 = tail call i8* @sbrk(i32 0)
%15 = icmp eq i8* %14, %3
%16 = zext i1 %15 to i32
%17 = tail call i32 @assert(i32 %16)
%18 = tail call i8* @sbrk(i32 90)
%19 = tail call i8* @sbrk(i32 0)
%20 = icmp eq i8* %19, %13
%21 = zext i1 %20 to i32
%22 = tail call i32 @assert(i32 %21)
%23 = tail call i8* @sbrk(i32 20480)
%24 = getelementptr inbounds i8, i8* %8, i64 50
%25 = icmp eq i8* %23, %24
%26 = zext i1 %25 to i32
%27 = tail call i32 @assert(i32 %26)
%28 = tail call i32 @memset(i8* %23, i32 -1, i32 20480)
%29 = getelementptr inbounds i8, i8* %1, i64 5
%30 = load i8, i8* %29
%31 = icmp eq i8 %30, 1
%32 = zext i1 %31 to i32
%33 = tail call i32 @assert(i32 %32)
%34 = tail call i8* @sbrk(i32 -20580)
%35 = tail call i8* @sbrk(i32 0)
%36 = icmp eq i8* %1, %35
%37 = zext i1 %36 to i32
%38 = tail call i32 @assert(i32 %37)
ret void
}