#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__ malloc(int);
void example_func() {
  int i;
  for (i = 0; i < 8; ++i) {
    int *p = (int *)malloc(128 * 1024 + (i % 2 ? 1 : -1));
    p[1] = 5;
  }
}


x86 assembly (clang, -O0):
<example_func>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
cmpl   $0x8,-0x4(%rbp)
jge    116c <example_func+0x5c>
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    $0xffffffff,%edi
mov    $0x1,%eax
cmp    $0x0,%edx
cmovne %eax,%edi
add    $0x20000,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movl   $0x5,0x4(%rax)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    111f <example_func+0xf>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<example_func>:
push   %rax
mov    $0x1ffff,%edi
call   1030 <malloc@plt>
movl   $0x5,0x4(%rax)
mov    $0x20001,%edi
call   1030 <malloc@plt>
movl   $0x5,0x4(%rax)
mov    $0x1ffff,%edi
call   1030 <malloc@plt>
movl   $0x5,0x4(%rax)
mov    $0x20001,%edi
call   1030 <malloc@plt>
movl   $0x5,0x4(%rax)
mov    $0x1ffff,%edi
call   1030 <malloc@plt>
movl   $0x5,0x4(%rax)
mov    $0x20001,%edi
call   1030 <malloc@plt>
movl   $0x5,0x4(%rax)
mov    $0x1ffff,%edi
call   1030 <malloc@plt>
movl   $0x5,0x4(%rax)
mov    $0x20001,%edi
call   1030 <malloc@plt>
movl   $0x5,0x4(%rax)
pop    %rax
ret

LLVM IR (-O0):
define void @example_func() {
%1 = alloca i32
%2 = alloca i32*
store i32 0, i32* %1
br label %3
3: ; preds = %17, %0
%4 = load i32, i32* %1
%5 = icmp slt i32 %4, 8
br i1 %5, label %6, label %20
6: ; preds = %3
%7 = load i32, i32* %1
%8 = srem i32 %7, 2
%9 = icmp ne i32 %8, 0
%10 = zext i1 %9 to i64
%11 = select i1 %9, i32 1, i32 -1
%12 = add nsw i32 131072, %11
%13 = call i64 @malloc(i32 %12)
%14 = inttoptr i64 %13 to i32*
store i32* %14, i32** %2
%15 = load i32*, i32** %2
%16 = getelementptr inbounds i32, i32* %15, i64 1
store i32 5, i32* %16
br label %17
17: ; preds = %6
%18 = load i32, i32* %1
%19 = add nsw i32 %18, 1
store i32 %19, i32* %1
br label %3
20: ; preds = %3
ret void
}

LLVM IR (-O2):
define void @example_func() {
%1 = tail call i64 @malloc(i32 131071)
%2 = inttoptr i64 %1 to i32*
%3 = getelementptr inbounds i32, i32* %2, i64 1
store i32 5, i32* %3
%4 = tail call i64 @malloc(i32 131073)
%5 = inttoptr i64 %4 to i32*
%6 = getelementptr inbounds i32, i32* %5, i64 1
store i32 5, i32* %6
%7 = tail call i64 @malloc(i32 131071)
%8 = inttoptr i64 %7 to i32*
%9 = getelementptr inbounds i32, i32* %8, i64 1
store i32 5, i32* %9
%10 = tail call i64 @malloc(i32 131073)
%11 = inttoptr i64 %10 to i32*
%12 = getelementptr inbounds i32, i32* %11, i64 1
store i32 5, i32* %12
%13 = tail call i64 @malloc(i32 131071)
%14 = inttoptr i64 %13 to i32*
%15 = getelementptr inbounds i32, i32* %14, i64 1
store i32 5, i32* %15
%16 = tail call i64 @malloc(i32 131073)
%17 = inttoptr i64 %16 to i32*
%18 = getelementptr inbounds i32, i32* %17, i64 1
store i32 5, i32* %18
%19 = tail call i64 @malloc(i32 131071)
%20 = inttoptr i64 %19 to i32*
%21 = getelementptr inbounds i32, i32* %20, i64 1
store i32 5, i32* %21
%22 = tail call i64 @malloc(i32 131073)
%23 = inttoptr i64 %22 to i32*
%24 = getelementptr inbounds i32, i32* %23, i64 1
store i32 5, i32* %24
ret void
}