#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);
int test_sbrk() {
  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(0x5000);
  assert(a4 == a3 + 50);
  memset(a4, -1, 0x5000);
  assert(*(a1 + 5) == 1);
  return 0;
}


x86 assembly (clang, -O0):
<test_sbrk>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%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    $0x5000,%edi
call   1040 <sbrk@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%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    -0x20(%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>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_sbrk>:
push   %r15
push   %r14
push   %rbx
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
add    $0x28,%rbx
xor    %edi,%edi
cmp    %rbx,%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>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i32 @test_sbrk() {
%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 20480)
%14 = getelementptr inbounds i8, i8* %8, i64 50
%15 = icmp eq i8* %13, %14
%16 = zext i1 %15 to i32
%17 = tail call i32 @assert(i32 %16)
%18 = tail call i32 @memset(i8* %13, i32 -1, i32 20480)
%19 = getelementptr inbounds i8, i8* %1, i64 5
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 1
%22 = zext i1 %21 to i32
%23 = tail call i32 @assert(i32 %22)
ret i32 0
}