#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*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int);
void *sbrk(int);
int main(int argc, char *argv[]) {
  void *brk = 0;
  void *last_brk;
  char c = 'a';
  int count = 0;
  for (;;) {
    c++;
    if (c > 'z')
      c = 'a';
    last_brk = brk;
    brk = sbrk(1024 * 1024);
    if ((int)brk == -1)
      break;
    count++;
    *(unsigned char *)(brk - 1) = c;
    printf("%c", *(unsigned char *)(brk - 1));
  }
  printf("\nLast value of sbrk() was 0x%08x\n", (unsigned int)last_brk);
  printf("%d MByte successfully aquired\n", count);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movb   $0x61,-0x21(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x21(%rbp),%al
add    $0x1,%al
mov    %al,-0x21(%rbp)
movsbl -0x21(%rbp),%eax
cmp    $0x7a,%eax
jle    1172 <main+0x42>
movb   $0x61,-0x21(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    $0x100000,%edi
call   1040 <sbrk@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    $0xffffffff,%eax
jne    119a <main+0x6a>
jmp    11c6 <main+0x96>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x21(%rbp),%cl
mov    -0x18(%rbp),%rax
mov    %cl,-0x1(%rax)
mov    -0x18(%rbp),%rax
movzbl -0x1(%rax),%esi
lea    0xe44(%rip),%rdi
call   1030 <printf@plt>
jmp    1159 <main+0x29>
mov    -0x20(%rbp),%rax
mov    %eax,%esi
lea    0xe30(%rip),%rdi
call   1030 <printf@plt>
mov    -0x28(%rbp),%esi
lea    0xe43(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1050 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    $0x100000,%edi
call   1040 <sbrk@plt>
xor    %r15d,%r15d
mov    $0x0,%ebx
cmp    $0xffffffff,%eax
je     11a7 <main+0x77>
xor    %ebx,%ebx
mov    $0x62,%bpl
lea    0xea5(%rip),%r14
mov    $0x61,%r12d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %eax,%r15d
add    $0x1,%ebx
mov    %bpl,-0x1(%rax)
movzbl %bpl,%ebp
mov    %r14,%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
add    $0x1,%bpl
cmp    $0x7b,%bpl
movzbl %bpl,%ebp
cmovge %r12d,%ebp
mov    $0x100000,%edi
call   1040 <sbrk@plt>
cmp    $0xffffffff,%eax
jne    1170 <main+0x40>
lea    0xe55(%rip),%rdi
mov    %r15d,%esi
call   1030 <printf@plt>
lea    0xe68(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
xor    %edi,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%c\00"
@.str.1 = [34 x i8] c"\0ALast value of sbrk() was 0x%08x\0A\00"
@.str.2 = [31 x i8] c"%d MByte successfully aquired\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %6
store i8 97, i8* %8
store i32 0, i32* %9
br label %10
10: ; preds = %24, %2
%11 = load i8, i8* %8
%12 = add i8 %11, 1
store i8 %12, i8* %8
%13 = load i8, i8* %8
%14 = sext i8 %13 to i32
%15 = icmp sgt i32 %14, 122
br i1 %15, label %16, label %17
16: ; preds = %10
store i8 97, i8* %8
br label %17
17: ; preds = %16, %10
%18 = load i8*, i8** %6
store i8* %18, i8** %7
%19 = call i8* @sbrk(i32 1048576)
store i8* %19, i8** %6
%20 = load i8*, i8** %6
%21 = ptrtoint i8* %20 to i32
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %24
23: ; preds = %17
br label %35
24: ; preds = %17
%25 = load i32, i32* %9
%26 = add nsw i32 %25, 1
store i32 %26, i32* %9
%27 = load i8, i8* %8
%28 = load i8*, i8** %6
%29 = getelementptr i8, i8* %28, i64 -1
store i8 %27, i8* %29
%30 = load i8*, i8** %6
%31 = getelementptr i8, i8* %30, i64 -1
%32 = load i8, i8* %31
%33 = zext i8 %32 to i32
%34 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %33)
br label %10
35: ; preds = %23
%36 = load i8*, i8** %7
%37 = ptrtoint i8* %36 to i32
%38 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 %37)
%39 = load i32, i32* %9
%40 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %39)
%41 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [3 x i8] c"%c\00"
@.str.1 = [34 x i8] c"\0ALast value of sbrk() was 0x%08x\0A\00"
@.str.2 = [31 x i8] c"%d MByte successfully aquired\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i8* @sbrk(i32 1048576)
%4 = ptrtoint i8* %3 to i64
%5 = trunc i64 %4 to i32
%6 = icmp eq i32 %5, -1
br i1 %6, label %23, label %7
7: ; preds = %2, %7
%8 = phi i32 [ %21, %7 ], [ %5, %2 ]
%9 = phi i8* [ %19, %7 ], [ %3, %2 ]
%10 = phi i8 [ %18, %7 ], [ 98, %2 ]
%11 = phi i32 [ %12, %7 ], [ 0, %2 ]
%12 = add nuw nsw i32 %11, 1
%13 = getelementptr i8, i8* %9, i64 -1
store i8 %10, i8* %13
%14 = zext i8 %10 to i32
%15 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = add i8 %10, 1
%17 = icmp sgt i8 %16, 122
%18 = select i1 %17, i8 97, i8 %16
%19 = tail call i8* @sbrk(i32 1048576)
%20 = ptrtoint i8* %19 to i64
%21 = trunc i64 %20 to i32
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %7
23: ; preds = %7, %2
%24 = phi i32 [ 0, %2 ], [ %8, %7 ]
%25 = phi i32 [ 0, %2 ], [ %12, %7 ]
%26 = tail call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 %24)
%27 = tail call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %25)
%28 = tail call i32 @exit(i32 0)
unreachable
}