#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_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int posix_memalign(void **, int, int);
int /*<<< orphan*/ printf(char *, void *);
int main(int argc, char **argv) {
  int i, r;
  void *ptr;
  for (i = 1; i <= 4; i++) {
    r = posix_memalign(&ptr, 4096, 1000 * i);
    if (r != 0) {
      perror("posfix_memalign() ");
      exit(EXIT_FAILURE);
    } else {
      printf("Address: %10p\n", ptr);
    }
  }
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
cmpl   $0x4,-0x14(%rbp)
jg     11c6 <main+0x86>
imul   $0x3e8,-0x14(%rbp),%edx
lea    -0x20(%rbp),%rdi
mov    $0x1000,%esi
call   1060 <posix_memalign@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     11a3 <main+0x63>
lea    0xe70(%rip),%rdi
call   1040 <perror@plt>
mov    0x2e44(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x20(%rbp),%rsi
lea    0xe65(%rip),%rdi
call   1030 <printf@plt>
jmp    11b8 <main+0x78>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    115d <main+0x1d>
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    %rsp,%rdi
mov    $0x1000,%esi
mov    $0x3e8,%edx
call   1060 <posix_memalign@plt>
test   %eax,%eax
jne    11eb <main+0xab>
mov    (%rsp),%rsi
lea    0xead(%rip),%rdi
call   1030 <printf@plt>
mov    %rsp,%rdi
mov    $0x1000,%esi
mov    $0x7d0,%edx
call   1060 <posix_memalign@plt>
test   %eax,%eax
jne    11eb <main+0xab>
mov    (%rsp),%rsi
lea    0xe87(%rip),%rdi
call   1030 <printf@plt>
mov    %rsp,%rdi
mov    $0x1000,%esi
mov    $0xbb8,%edx
call   1060 <posix_memalign@plt>
test   %eax,%eax
jne    11eb <main+0xab>
mov    (%rsp),%rsi
lea    0xe61(%rip),%rdi
call   1030 <printf@plt>
mov    %rsp,%rdi
mov    $0x1000,%esi
mov    $0xfa0,%edx
call   1060 <posix_memalign@plt>
test   %eax,%eax
jne    11eb <main+0xab>
mov    (%rsp),%rsi
lea    0xe3b(%rip),%rdi
call   1030 <printf@plt>
mov    0x2df4(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
lea    0xe0e(%rip),%rdi
call   1040 <perror@plt>
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [19 x i8] c"posfix_memalign() \00"
@EXIT_FAILURE = global i32 0
@.str.1 = [15 x i8] c"Address: %10p\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %6
br label %9
9: ; preds = %26, %2
%10 = load i32, i32* %6
%11 = icmp sle i32 %10, 4
br i1 %11, label %12, label %29
12: ; preds = %9
%13 = load i32, i32* %6
%14 = mul nsw i32 1000, %13
%15 = call i32 @posix_memalign(i8** %8, i32 4096, i32 %14)
store i32 %15, i32* %7
%16 = load i32, i32* %7
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %12
%19 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %12
%23 = load i8*, i8** %8
%24 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %23)
br label %25
25: ; preds = %22
br label %26
26: ; preds = %25
%27 = load i32, i32* %6
%28 = add nsw i32 %27, 1
store i32 %28, i32* %6
br label %9
29: ; preds = %9
%30 = load i32, i32* @EXIT_SUCCESS
%31 = call i32 @exit(i32 %30)
unreachable
}

LLVM IR (-O2):
@.str = [19 x i8] c"posfix_memalign() \00"
@EXIT_FAILURE = global i32 0
@.str.1 = [15 x i8] c"Address: %10p\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = call i32 @posix_memalign(i8** %3, i32 4096, i32 1000)
%6 = icmp eq i32 %5, 0
br i1 %6, label %11, label %7
7: ; preds = %21, %16, %11, %2
%8 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @EXIT_FAILURE
%10 = call i32 @exit(i32 %9)
unreachable
11: ; preds = %2
%12 = load i8*, i8** %3
%13 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = call i32 @posix_memalign(i8** %3, i32 4096, i32 2000)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %7
16: ; preds = %11
%17 = load i8*, i8** %3
%18 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %17)
%19 = call i32 @posix_memalign(i8** %3, i32 4096, i32 3000)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %7
21: ; preds = %16
%22 = load i8*, i8** %3
%23 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %22)
%24 = call i32 @posix_memalign(i8** %3, i32 4096, i32 4000)
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %7
26: ; preds = %21
%27 = load i8*, i8** %3
%28 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %27)
%29 = load i32, i32* @EXIT_SUCCESS
%30 = call i32 @exit(i32 %29)
unreachable
}