#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*/ free(void *);
void *malloc(int);
int /*<<< orphan*/ memset(void *, int, int);
void nonzero_heap() {
  int i;
  void *ptrs[200];
  for (i = 0; i < 200; i++) {
    ptrs[i] = malloc((i + 1) << 4);
    if (ptrs[i])
      memset(ptrs[i], 0x80, (i + 1) << 4);
  }
  for (i = 0; i < 200; i++) {
    free(ptrs[i]);
  }
}


x86 assembly (clang, -O0):
<nonzero_heap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x650,%rsp
movl   $0x0,-0x4(%rbp)
cmpl   $0xc8,-0x4(%rbp)
jge    11b1 <nonzero_heap+0x81>
mov    -0x4(%rbp),%edi
add    $0x1,%edi
shl    $0x4,%edi
call   1050 <malloc@plt>
mov    %rax,%rcx
movslq -0x4(%rbp),%rax
mov    %rcx,-0x650(%rbp,%rax,8)
ff
movslq -0x4(%rbp),%rax
cmpq   $0x0,-0x650(%rbp,%rax,8)
je     119e <nonzero_heap+0x6e>
movslq -0x4(%rbp),%rax
mov    -0x650(%rbp,%rax,8),%rdi
ff
mov    -0x4(%rbp),%edx
add    $0x1,%edx
shl    $0x4,%edx
mov    $0x80,%esi
call   1040 <memset@plt>
jmp    11a3 <nonzero_heap+0x73>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1142 <nonzero_heap+0x12>
movl   $0x0,-0x4(%rbp)
cmpl   $0xc8,-0x4(%rbp)
jge    11e4 <nonzero_heap+0xb4>
movslq -0x4(%rbp),%rax
mov    -0x650(%rbp,%rax,8),%rdi
ff
call   1030 <free@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11b8 <nonzero_heap+0x88>
add    $0x650,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nonzero_heap>:
push   %r15
push   %r14
push   %rbx
sub    $0x640,%rsp
mov    $0x10,%ebx
xor    %r14d,%r14d
jmp    115c <nonzero_heap+0x2c>
cs nopw 0x0(%rax,%rax,1)
add    $0x10,%ebx
cmp    $0xc8,%r14
je     1184 <nonzero_heap+0x54>
mov    %r14,%r15
add    $0x1,%r14
mov    %ebx,%edi
call   1050 <malloc@plt>
mov    %rax,(%rsp,%r15,8)
test   %rax,%rax
je     1150 <nonzero_heap+0x20>
mov    %rax,%rdi
mov    $0x80,%esi
mov    %ebx,%edx
call   1040 <memset@plt>
jmp    1150 <nonzero_heap+0x20>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    (%rsp,%rbx,8),%rdi
call   1030 <free@plt>
add    $0x1,%rbx
cmp    $0xc8,%rbx
jne    1190 <nonzero_heap+0x60>
add    $0x640,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @nonzero_heap() {
%1 = alloca i32
%2 = alloca [200 x i8*]
store i32 0, i32* %1
br label %3
3: ; preds = %29, %0
%4 = load i32, i32* %1
%5 = icmp slt i32 %4, 200
br i1 %5, label %6, label %32
6: ; preds = %3
%7 = load i32, i32* %1
%8 = add nsw i32 %7, 1
%9 = shl i32 %8, 4
%10 = call i8* @malloc(i32 %9)
%11 = load i32, i32* %1
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [200 x i8*], [200 x i8*]* %2, i64 0, i64 %12
store i8* %10, i8** %13
%14 = load i32, i32* %1
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [200 x i8*], [200 x i8*]* %2, i64 0, i64 %15
%17 = load i8*, i8** %16
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %28
19: ; preds = %6
%20 = load i32, i32* %1
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [200 x i8*], [200 x i8*]* %2, i64 0, i64 %21
%23 = load i8*, i8** %22
%24 = load i32, i32* %1
%25 = add nsw i32 %24, 1
%26 = shl i32 %25, 4
%27 = call i32 @memset(i8* %23, i32 128, i32 %26)
br label %28
28: ; preds = %19, %6
br label %29
29: ; preds = %28
%30 = load i32, i32* %1
%31 = add nsw i32 %30, 1
store i32 %31, i32* %1
br label %3
32: ; preds = %3
store i32 0, i32* %1
br label %33
33: ; preds = %42, %32
%34 = load i32, i32* %1
%35 = icmp slt i32 %34, 200
br i1 %35, label %36, label %45
36: ; preds = %33
%37 = load i32, i32* %1
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [200 x i8*], [200 x i8*]* %2, i64 0, i64 %38
%40 = load i8*, i8** %39
%41 = call i32 @free(i8* %40)
br label %42
42: ; preds = %36
%43 = load i32, i32* %1
%44 = add nsw i32 %43, 1
store i32 %44, i32* %1
br label %33
45: ; preds = %33
ret void
}

LLVM IR (-O2):
define void @nonzero_heap() {
%1 = alloca [200 x i8*]
%2 = bitcast [200 x i8*]* %1 to i8*
br label %3
3: ; preds = %0, %13
%4 = phi i64 [ 0, %0 ], [ %5, %13 ]
%5 = add nuw nsw i64 %4, 1
%6 = trunc i64 %5 to i32
%7 = shl i32 %6, 4
%8 = tail call i8* @malloc(i32 %7)
%9 = getelementptr inbounds [200 x i8*], [200 x i8*]* %1, i64 0, i64 %4
store i8* %8, i8** %9
%10 = icmp eq i8* %8, null
br i1 %10, label %13, label %11
11: ; preds = %3
%12 = tail call i32 @memset(i8* %8, i32 128, i32 %7)
br label %13
13: ; preds = %3, %11
%14 = icmp eq i64 %5, 200
br i1 %14, label %15, label %3
15: ; preds = %13, %15
%16 = phi i64 [ %20, %15 ], [ 0, %13 ]
%17 = getelementptr inbounds [200 x i8*], [200 x i8*]* %1, i64 0, i64 %16
%18 = load i8*, i8** %17
%19 = tail call i32 @free(i8* %18)
%20 = add nuw nsw i64 %16, 1
%21 = icmp eq i64 %20, 200
br i1 %21, label %22, label %15
22: ; preds = %15
ret void
}