#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*/ __NR_brk;
int /*<<< orphan*/ assert(int);
scalar_t__ brk(void *);
void *sbrk(int /*<<< orphan*/);
scalar_t__ syscall(int /*<<< orphan*/, void *);
int main(void) {
  int i;
  void *orig_ds = sbrk(0);
  void *ds = orig_ds;
  void *vals[10];
  void *res;
  vals[0] = (void *)0;
  vals[1] = (void *)1;
  vals[2] = ds - 0x1;
  vals[3] = ds;
  vals[4] = ds + 0x1000;
  vals[5] = ds + 0x40000000;
  vals[6] = ds + 0x500;
  vals[7] = ds - 0x1;
  vals[8] = ((void *)(~(long)0));
  for (i = 0; ((void *)(~(long)0)) != vals[i]; i++) {
    res = (void *)syscall(__NR_brk, vals[i]);
  }
  assert(0 == brk(orig_ds));
  for (i = 0; ((void *)(~(long)0)) != vals[i]; i++) {
    res = (void *)(long)brk(vals[i]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
xor    %edi,%edi
call   1040 <sbrk@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x70(%rbp)
mov    $0x1,%eax
mov    %rax,-0x68(%rbp)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x60(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1000,%rax
mov    %rax,-0x50(%rbp)
mov    -0x18(%rbp),%rax
add    $0x40000000,%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rax
add    $0x500,%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x38(%rbp)
mov    $0xffffffffffffffff,%rax
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x8(%rbp)
movslq -0x8(%rbp),%rcx
mov    $0xffffffffffffffff,%rax
cmp    -0x70(%rbp,%rcx,8),%rax
je     1211 <main+0xd1>
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
movslq -0x8(%rbp),%rax
mov    -0x70(%rbp,%rax,8),%rsi
call   1060 <syscall@plt>
mov    %rax,-0x78(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11d2 <main+0x92>
mov    -0x10(%rbp),%rdi
call   1030 <brk@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
movl   $0x0,-0x8(%rbp)
movslq -0x8(%rbp),%rcx
mov    $0xffffffffffffffff,%rax
cmp    -0x70(%rbp,%rcx,8),%rax
je     126c <main+0x12c>
movslq -0x8(%rbp),%rax
mov    -0x70(%rbp,%rax,8),%rdi
call   1030 <brk@plt>
mov    %rax,-0x78(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1236 <main+0xf6>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x58,%rsp
xor    %r15d,%r15d
xor    %edi,%edi
call   1040 <sbrk@plt>
mov    %rax,%r14
movq   $0x0,(%rsp)
lea    0x8(%rsp),%rbx
movq   $0x1,0x8(%rsp)
add    $0xffffffffffffffff,%rax
mov    %rax,0x10(%rsp)
mov    %r14,0x18(%rsp)
movq   %r14,%xmm0
pshufd $0x44,%xmm0,%xmm0
paddq  0xe72(%rip),%xmm0
movdqa %xmm0,0x20(%rsp)
mov    %r14,%rcx
add    $0x500,%rcx
mov    %rcx,0x30(%rsp)
mov    %rax,0x38(%rsp)
movq   $0xffffffffffffffff,0x40(%rsp)
ff ff
mov    0x2e28(%rip),%r12
nopl   0x0(%rax,%rax,1)
mov    (%r12),%edi
mov    %r15,%rsi
call   1060 <syscall@plt>
mov    (%rbx),%r15
add    $0x8,%rbx
cmp    $0xffffffffffffffff,%r15
jne    11c0 <main+0x80>
mov    %r14,%rdi
call   1030 <brk@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1050 <assert@plt>
lea    0x8(%rsp),%rbx
xor    %edi,%edi
cs nopw 0x0(%rax,%rax,1)
call   1030 <brk@plt>
mov    (%rbx),%rdi
add    $0x8,%rbx
cmp    $0xffffffffffffffff,%rdi
jne    1200 <main+0xc0>
xor    %eax,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__NR_brk = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [10 x i8*]
%6 = alloca i8*
store i32 0, i32* %1
%7 = call i8* @sbrk(i32 0)
store i8* %7, i8** %3
%8 = load i8*, i8** %3
store i8* %8, i8** %4
%9 = getelementptr inbounds [10 x i8*], [10 x i8*]* %5, i64 0, i64 0
store i8* null, i8** %9
%10 = getelementptr inbounds [10 x i8*], [10 x i8*]* %5, i64 0, i64 1
store i8* inttoptr (i64 1 to i8*), i8** %10
%11 = load i8*, i8** %4
%12 = getelementptr i8, i8* %11, i64 -1
%13 = getelementptr inbounds [10 x i8*], [10 x i8*]* %5, i64 0, i64 2
store i8* %12, i8** %13
%14 = load i8*, i8** %4
%15 = getelementptr inbounds [10 x i8*], [10 x i8*]* %5, i64 0, i64 3
store i8* %14, i8** %15
%16 = load i8*, i8** %4
%17 = getelementptr i8, i8* %16, i64 4096
%18 = getelementptr inbounds [10 x i8*], [10 x i8*]* %5, i64 0, i64 4
store i8* %17, i8** %18
%19 = load i8*, i8** %4
%20 = getelementptr i8, i8* %19, i64 1073741824
%21 = getelementptr inbounds [10 x i8*], [10 x i8*]* %5, i64 0, i64 5
store i8* %20, i8** %21
%22 = load i8*, i8** %4
%23 = getelementptr i8, i8* %22, i64 1280
%24 = getelementptr inbounds [10 x i8*], [10 x i8*]* %5, i64 0, i64 6
store i8* %23, i8** %24
%25 = load i8*, i8** %4
%26 = getelementptr i8, i8* %25, i64 -1
%27 = getelementptr inbounds [10 x i8*], [10 x i8*]* %5, i64 0, i64 7
store i8* %26, i8** %27
%28 = getelementptr inbounds [10 x i8*], [10 x i8*]* %5, i64 0, i64 8
store i8* inttoptr (i64 -1 to i8*), i8** %28
store i32 0, i32* %2
br label %29
29: ; preds = %43, %0
%30 = load i32, i32* %2
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [10 x i8*], [10 x i8*]* %5, i64 0, i64 %31
%33 = load i8*, i8** %32
%34 = icmp ne i8* inttoptr (i64 -1 to i8*), %33
br i1 %34, label %35, label %46
35: ; preds = %29
%36 = load i32, i32* @__NR_brk
%37 = load i32, i32* %2
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [10 x i8*], [10 x i8*]* %5, i64 0, i64 %38
%40 = load i8*, i8** %39
%41 = call i64 @syscall(i32 %36, i8* %40)
%42 = inttoptr i64 %41 to i8*
store i8* %42, i8** %6
br label %43
43: ; preds = %35
%44 = load i32, i32* %2
%45 = add nsw i32 %44, 1
store i32 %45, i32* %2
br label %29
46: ; preds = %29
%47 = load i8*, i8** %3
%48 = call i64 @brk(i8* %47)
%49 = icmp eq i64 0, %48
%50 = zext i1 %49 to i32
%51 = call i32 @assert(i32 %50)
store i32 0, i32* %2
br label %52
52: ; preds = %65, %46
%53 = load i32, i32* %2
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds [10 x i8*], [10 x i8*]* %5, i64 0, i64 %54
%56 = load i8*, i8** %55
%57 = icmp ne i8* inttoptr (i64 -1 to i8*), %56
br i1 %57, label %58, label %68
58: ; preds = %52
%59 = load i32, i32* %2
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds [10 x i8*], [10 x i8*]* %5, i64 0, i64 %60
%62 = load i8*, i8** %61
%63 = call i64 @brk(i8* %62)
%64 = inttoptr i64 %63 to i8*
store i8* %64, i8** %6
br label %65
65: ; preds = %58
%66 = load i32, i32* %2
%67 = add nsw i32 %66, 1
store i32 %67, i32* %2
br label %52
68: ; preds = %52
ret i32 0
}

LLVM IR (-O2):
@__NR_brk = global i32 0
define i32 @main() {
%1 = alloca [10 x i8*]
%2 = tail call i8* @sbrk(i32 0)
%3 = bitcast [10 x i8*]* %1 to i8*
%4 = getelementptr inbounds [10 x i8*], [10 x i8*]* %1, i64 0, i64 0
store i8* null, i8** %4
%5 = getelementptr inbounds [10 x i8*], [10 x i8*]* %1, i64 0, i64 1
store i8* inttoptr (i64 1 to i8*), i8** %5
%6 = getelementptr i8, i8* %2, i64 -1
%7 = getelementptr inbounds [10 x i8*], [10 x i8*]* %1, i64 0, i64 2
store i8* %6, i8** %7
%8 = getelementptr inbounds [10 x i8*], [10 x i8*]* %1, i64 0, i64 3
store i8* %2, i8** %8
%9 = getelementptr inbounds [10 x i8*], [10 x i8*]* %1, i64 0, i64 4
%10 = insertelement <2 x i8*> poison, i8* %2, i64 0
%11 = shufflevector <2 x i8*> %10, <2 x i8*> poison, <2 x i32> zeroinitializer
%12 = getelementptr i8, <2 x i8*> %11, <2 x i64> <i64 4096, i64 1073741824>
%13 = bitcast i8** %9 to <2 x i8*>*
store <2 x i8*> %12, <2 x i8*>* %13
%14 = getelementptr i8, i8* %2, i64 1280
%15 = getelementptr inbounds [10 x i8*], [10 x i8*]* %1, i64 0, i64 6
store i8* %14, i8** %15
%16 = getelementptr inbounds [10 x i8*], [10 x i8*]* %1, i64 0, i64 7
store i8* %6, i8** %16
%17 = getelementptr inbounds [10 x i8*], [10 x i8*]* %1, i64 0, i64 8
store i8* inttoptr (i64 -1 to i8*), i8** %17
br label %18
18: ; preds = %0, %18
%19 = phi i64 [ 0, %0 ], [ %23, %18 ]
%20 = phi i8* [ null, %0 ], [ %25, %18 ]
%21 = load i32, i32* @__NR_brk
%22 = tail call i64 @syscall(i32 %21, i8* %20)
%23 = add nuw i64 %19, 1
%24 = getelementptr inbounds [10 x i8*], [10 x i8*]* %1, i64 0, i64 %23
%25 = load i8*, i8** %24
%26 = icmp eq i8* %25, inttoptr (i64 -1 to i8*)
br i1 %26, label %27, label %18
27: ; preds = %18
%28 = tail call i64 @brk(i8* %2)
%29 = icmp eq i64 %28, 0
%30 = zext i1 %29 to i32
%31 = tail call i32 @assert(i32 %30)
br label %32
32: ; preds = %27, %32
%33 = phi i64 [ 0, %27 ], [ %36, %32 ]
%34 = phi i8* [ null, %27 ], [ %38, %32 ]
%35 = tail call i64 @brk(i8* %34)
%36 = add nuw i64 %33, 1
%37 = getelementptr inbounds [10 x i8*], [10 x i8*]* %1, i64 0, i64 %36
%38 = load i8*, i8** %37
%39 = icmp eq i8* %38, inttoptr (i64 -1 to i8*)
br i1 %39, label %40, label %32
40: ; preds = %32
ret i32 0
}