#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*/ printf(char *, void *);
int main() {
  void *m1 = malloc(24);
  int t = 0;
  void *ms[200];
  for (t = 0; t < 200; t++)
    ms[t] = malloc(120);
  malloc(24);
  for (t = 0; t < 200; t++)
    free(ms[t]);
  void *m2 = malloc(24);
  printf("%p\n", m1);
  printf("%p\n", m2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x670,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x18,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0xc8,-0x14(%rbp)
jge    1192 <main+0x62>
mov    $0x78,%edi
call   1050 <malloc@plt>
mov    %rax,%rcx
movslq -0x14(%rbp),%rax
mov    %rcx,-0x660(%rbp,%rax,8)
ff
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    115e <main+0x2e>
mov    $0x18,%edi
call   1050 <malloc@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0xc8,-0x14(%rbp)
jge    11cf <main+0x9f>
movslq -0x14(%rbp),%rax
mov    -0x660(%rbp,%rax,8),%rdi
ff
call   1030 <free@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11a3 <main+0x73>
mov    $0x18,%edi
call   1050 <malloc@plt>
mov    %rax,-0x668(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe15(%rip),%rdi
call   1040 <printf@plt>
mov    -0x668(%rbp),%rsi
lea    0xe02(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x670,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x640,%rsp
mov    $0x18,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    $0x78,%edi
call   1050 <malloc@plt>
mov    %rax,(%rsp,%rbx,8)
add    $0x1,%rbx
cmp    $0xc8,%rbx
jne    1150 <main+0x20>
xor    %ebx,%ebx
nopl   (%rax)
mov    (%rsp,%rbx,8),%rdi
call   1030 <free@plt>
add    $0x1,%rbx
cmp    $0xc8,%rbx
jne    1170 <main+0x40>
mov    $0x18,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
lea    0xe66(%rip),%r15
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x640,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%p\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [200 x i8*]
%5 = alloca i8*
store i32 0, i32* %1
%6 = call i8* @malloc(i32 24)
store i8* %6, i8** %2
store i32 0, i32* %3
store i32 0, i32* %3
br label %7
7: ; preds = %15, %0
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 200
br i1 %9, label %10, label %18
10: ; preds = %7
%11 = call i8* @malloc(i32 120)
%12 = load i32, i32* %3
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [200 x i8*], [200 x i8*]* %4, i64 0, i64 %13
store i8* %11, i8** %14
br label %15
15: ; preds = %10
%16 = load i32, i32* %3
%17 = add nsw i32 %16, 1
store i32 %17, i32* %3
br label %7
18: ; preds = %7
%19 = call i8* @malloc(i32 24)
store i32 0, i32* %3
br label %20
20: ; preds = %29, %18
%21 = load i32, i32* %3
%22 = icmp slt i32 %21, 200
br i1 %22, label %23, label %32
23: ; preds = %20
%24 = load i32, i32* %3
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [200 x i8*], [200 x i8*]* %4, i64 0, i64 %25
%27 = load i8*, i8** %26
%28 = call i32 @free(i8* %27)
br label %29
29: ; preds = %23
%30 = load i32, i32* %3
%31 = add nsw i32 %30, 1
store i32 %31, i32* %3
br label %20
32: ; preds = %20
%33 = call i8* @malloc(i32 24)
store i8* %33, i8** %5
%34 = load i8*, i8** %2
%35 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %34)
%36 = load i8*, i8** %5
%37 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %36)
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%p\0A\00"
define i32 @main() {
%1 = alloca [200 x i8*]
%2 = tail call dereferenceable_or_null(24) i8* @malloc(i32 24)
%3 = bitcast [200 x i8*]* %1 to i8*
br label %4
4: ; preds = %0, %4
%5 = phi i64 [ 0, %0 ], [ %8, %4 ]
%6 = tail call dereferenceable_or_null(120) i8* @malloc(i32 120)
%7 = getelementptr inbounds [200 x i8*], [200 x i8*]* %1, i64 0, i64 %5
store i8* %6, i8** %7
%8 = add nuw nsw i64 %5, 1
%9 = icmp eq i64 %8, 200
br i1 %9, label %10, label %4
10: ; preds = %4, %10
%11 = phi i64 [ %15, %10 ], [ 0, %4 ]
%12 = getelementptr inbounds [200 x i8*], [200 x i8*]* %1, i64 0, i64 %11
%13 = load i8*, i8** %12
%14 = tail call i32 @free(i8* %13)
%15 = add nuw nsw i64 %11, 1
%16 = icmp eq i64 %15, 200
br i1 %16, label %17, label %10
17: ; preds = %10
%18 = tail call dereferenceable_or_null(24) i8* @malloc(i32 24)
%19 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %2)
%20 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %18)
ret i32 0
}