#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 */
scalar_t__ memalign(int, int);
int /*<<< orphan*/ printf(char *, void *);
int main() {
  void *p;
  int i;
  for (i = 0; i < 100; i++) {
    p = (void *)memalign(4096, 4096);
    printf("***** %x *****\n", p);
  }
  for (i = 0; i < 100; i++) {
    p = (void *)memalign(2048, 1024);
    printf("===== %x =====\n", p);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x64,-0x14(%rbp)
jge    116e <main+0x4e>
mov    $0x1000,%esi
mov    %esi,%edi
call   1040 <memalign@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xea5(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1136 <main+0x16>
movl   $0x0,-0x14(%rbp)
cmpl   $0x64,-0x14(%rbp)
jge    11b0 <main+0x90>
mov    $0x800,%edi
mov    $0x400,%esi
call   1040 <memalign@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe73(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1175 <main+0x55>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    $0x64,%ebp
lea    0xed1(%rip),%rbx
nop
mov    $0x1000,%edi
mov    $0x1000,%esi
call   1040 <memalign@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
add    $0xffffffff,%ebp
jne    1130 <main+0x10>
mov    $0x64,%ebp
lea    0xeb5(%rip),%rbx
nopl   0x0(%rax,%rax,1)
mov    $0x800,%edi
mov    $0x400,%esi
call   1040 <memalign@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
add    $0xffffffff,%ebp
jne    1160 <main+0x40>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"***** %x *****\0A\00"
@.str.1 = [16 x i8] c"===== %x =====\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
br label %4
4: ; preds = %12, %0
%5 = load i32, i32* %3
%6 = icmp slt i32 %5, 100
br i1 %6, label %7, label %15
7: ; preds = %4
%8 = call i64 @memalign(i32 4096, i32 4096)
%9 = inttoptr i64 %8 to i8*
store i8* %9, i8** %2
%10 = load i8*, i8** %2
%11 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %10)
br label %12
12: ; preds = %7
%13 = load i32, i32* %3
%14 = add nsw i32 %13, 1
store i32 %14, i32* %3
br label %4
15: ; preds = %4
store i32 0, i32* %3
br label %16
16: ; preds = %24, %15
%17 = load i32, i32* %3
%18 = icmp slt i32 %17, 100
br i1 %18, label %19, label %27
19: ; preds = %16
%20 = call i64 @memalign(i32 2048, i32 1024)
%21 = inttoptr i64 %20 to i8*
store i8* %21, i8** %2
%22 = load i8*, i8** %2
%23 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %22)
br label %24
24: ; preds = %19
%25 = load i32, i32* %3
%26 = add nsw i32 %25, 1
store i32 %26, i32* %3
br label %16
27: ; preds = %16
ret i32 0
}

LLVM IR (-O2):
@.str = [16 x i8] c"***** %x *****\0A\00"
@.str.1 = [16 x i8] c"===== %x =====\0A\00"
define i32 @main() {
br label %1
1: ; preds = %0, %1
%2 = phi i32 [ 0, %0 ], [ %6, %1 ]
%3 = tail call i64 @memalign(i32 4096, i32 4096)
%4 = inttoptr i64 %3 to i8*
%5 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %4)
%6 = add nuw nsw i32 %2, 1
%7 = icmp eq i32 %6, 100
br i1 %7, label %8, label %1
8: ; preds = %1, %8
%9 = phi i32 [ %13, %8 ], [ 0, %1 ]
%10 = tail call i64 @memalign(i32 2048, i32 1024)
%11 = inttoptr i64 %10 to i8*
%12 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%13 = add nuw nsw i32 %9, 1
%14 = icmp eq i32 %13, 100
br i1 %14, label %15, label %8
15: ; preds = %8
ret i32 0
}