#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*/ assert(int);
int /*<<< orphan*/ free(int *);
int *malloc(int);
void test_malloc_free() {
  int *p;
  p = malloc(1000);
  for (int i = 0; i < 1000; i++) {
    p[i] = i;
  }
  for (int i = 0; i < 1000; i++) {
    assert(p[i] == i);
  }
  free(p);
}


x86 assembly (clang, -O0):
<test_malloc_free>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x3e8,%edi
call   1050 <malloc@plt>
mov    %rax,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x3e8,-0xc(%rbp)
jge    1176 <test_malloc_free+0x46>
mov    -0xc(%rbp),%edx
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    114d <test_malloc_free+0x1d>
movl   $0x0,-0x10(%rbp)
cmpl   $0x3e8,-0x10(%rbp)
jge    11b3 <test_malloc_free+0x83>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x10(%rbp),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    117d <test_malloc_free+0x4d>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_malloc_free>:
push   %r14
push   %rbx
push   %rax
mov    $0x3e8,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
movdqa 0xeb7(%rip),%xmm0
mov    $0x24,%eax
movdqa 0xeb9(%rip),%xmm8
movdqa 0xec0(%rip),%xmm9
movdqa 0xec7(%rip),%xmm10
movdqa 0xece(%rip),%xmm11
movdqa 0xed5(%rip),%xmm12
movdqa 0xedd(%rip),%xmm6
movdqa 0xee5(%rip),%xmm7
movdqa 0xeed(%rip),%xmm1
movdqa 0xef5(%rip),%xmm2
movdqa 0xefd(%rip),%xmm3
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movdqa %xmm0,%xmm4
paddd  %xmm8,%xmm4
movdqu %xmm0,-0x90(%r14,%rax,4)
ff ff ff
movdqu %xmm4,-0x80(%r14,%rax,4)
movdqa %xmm0,%xmm4
paddd  %xmm9,%xmm4
movdqa %xmm0,%xmm5
paddd  %xmm10,%xmm5
movdqu %xmm4,-0x70(%r14,%rax,4)
movdqu %xmm5,-0x60(%r14,%rax,4)
movdqa %xmm0,%xmm4
paddd  %xmm11,%xmm4
movdqa %xmm0,%xmm5
paddd  %xmm12,%xmm5
movdqu %xmm4,-0x50(%r14,%rax,4)
movdqu %xmm5,-0x40(%r14,%rax,4)
movdqa %xmm0,%xmm4
paddd  %xmm6,%xmm4
movdqa %xmm0,%xmm5
paddd  %xmm7,%xmm5
movdqu %xmm4,-0x30(%r14,%rax,4)
movdqu %xmm5,-0x20(%r14,%rax,4)
movdqa %xmm0,%xmm4
paddd  %xmm1,%xmm4
movdqa %xmm0,%xmm5
paddd  %xmm2,%xmm5
movdqu %xmm4,-0x10(%r14,%rax,4)
movdqu %xmm5,(%r14,%rax,4)
paddd  %xmm3,%xmm0
add    $0x28,%rax
cmp    $0x40c,%rax
jne    11b0 <test_malloc_free+0x80>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    (%r14,%rbx,4),%eax
xor    %edi,%edi
cmp    %rax,%rbx
sete   %dil
call   1040 <assert@plt>
add    $0x1,%rbx
cmp    $0x3e8,%rbx
jne    1260 <test_malloc_free+0x130>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <free@plt>

LLVM IR (-O0):
define void @test_malloc_free() {
%1 = alloca i32*
%2 = alloca i32
%3 = alloca i32
%4 = call i32* @malloc(i32 1000)
store i32* %4, i32** %1
store i32 0, i32* %2
br label %5
5: ; preds = %14, %0
%6 = load i32, i32* %2
%7 = icmp slt i32 %6, 1000
br i1 %7, label %8, label %17
8: ; preds = %5
%9 = load i32, i32* %2
%10 = load i32*, i32** %1
%11 = load i32, i32* %2
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i32, i32* %10, i64 %12
store i32 %9, i32* %13
br label %14
14: ; preds = %8
%15 = load i32, i32* %2
%16 = add nsw i32 %15, 1
store i32 %16, i32* %2
br label %5
17: ; preds = %5
store i32 0, i32* %3
br label %18
18: ; preds = %31, %17
%19 = load i32, i32* %3
%20 = icmp slt i32 %19, 1000
br i1 %20, label %21, label %34
21: ; preds = %18
%22 = load i32*, i32** %1
%23 = load i32, i32* %3
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %22, i64 %24
%26 = load i32, i32* %25
%27 = load i32, i32* %3
%28 = icmp eq i32 %26, %27
%29 = zext i1 %28 to i32
%30 = call i32 @assert(i32 %29)
br label %31
31: ; preds = %21
%32 = load i32, i32* %3
%33 = add nsw i32 %32, 1
store i32 %33, i32* %3
br label %18
34: ; preds = %18
%35 = load i32*, i32** %1
%36 = call i32 @free(i32* %35)
ret void
}

LLVM IR (-O2):
define void @test_malloc_free() {
%1 = tail call i32* @malloc(i32 1000)
br label %2
2: ; preds = %2, %0
%3 = phi i64 [ 0, %0 ], [ %38, %2 ]
%4 = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, %0 ], [ %39, %2 ]
%5 = add <4 x i32> %4, <i32 4, i32 4, i32 4, i32 4>
%6 = getelementptr inbounds i32, i32* %1, i64 %3
%7 = bitcast i32* %6 to <4 x i32>*
store <4 x i32> %4, <4 x i32>* %7
%8 = getelementptr inbounds i32, i32* %6, i64 4
%9 = bitcast i32* %8 to <4 x i32>*
store <4 x i32> %5, <4 x i32>* %9
%10 = add nuw nsw i64 %3, 8
%11 = add <4 x i32> %4, <i32 8, i32 8, i32 8, i32 8>
%12 = add <4 x i32> %4, <i32 12, i32 12, i32 12, i32 12>
%13 = getelementptr inbounds i32, i32* %1, i64 %10
%14 = bitcast i32* %13 to <4 x i32>*
store <4 x i32> %11, <4 x i32>* %14
%15 = getelementptr inbounds i32, i32* %13, i64 4
%16 = bitcast i32* %15 to <4 x i32>*
store <4 x i32> %12, <4 x i32>* %16
%17 = add nuw nsw i64 %3, 16
%18 = add <4 x i32> %4, <i32 16, i32 16, i32 16, i32 16>
%19 = add <4 x i32> %4, <i32 20, i32 20, i32 20, i32 20>
%20 = getelementptr inbounds i32, i32* %1, i64 %17
%21 = bitcast i32* %20 to <4 x i32>*
store <4 x i32> %18, <4 x i32>* %21
%22 = getelementptr inbounds i32, i32* %20, i64 4
%23 = bitcast i32* %22 to <4 x i32>*
store <4 x i32> %19, <4 x i32>* %23
%24 = add nuw nsw i64 %3, 24
%25 = add <4 x i32> %4, <i32 24, i32 24, i32 24, i32 24>
%26 = add <4 x i32> %4, <i32 28, i32 28, i32 28, i32 28>
%27 = getelementptr inbounds i32, i32* %1, i64 %24
%28 = bitcast i32* %27 to <4 x i32>*
store <4 x i32> %25, <4 x i32>* %28
%29 = getelementptr inbounds i32, i32* %27, i64 4
%30 = bitcast i32* %29 to <4 x i32>*
store <4 x i32> %26, <4 x i32>* %30
%31 = add nuw nsw i64 %3, 32
%32 = add <4 x i32> %4, <i32 32, i32 32, i32 32, i32 32>
%33 = add <4 x i32> %4, <i32 36, i32 36, i32 36, i32 36>
%34 = getelementptr inbounds i32, i32* %1, i64 %31
%35 = bitcast i32* %34 to <4 x i32>*
store <4 x i32> %32, <4 x i32>* %35
%36 = getelementptr inbounds i32, i32* %34, i64 4
%37 = bitcast i32* %36 to <4 x i32>*
store <4 x i32> %33, <4 x i32>* %37
%38 = add nuw nsw i64 %3, 40
%39 = add <4 x i32> %4, <i32 40, i32 40, i32 40, i32 40>
%40 = icmp eq i64 %38, 1000
br i1 %40, label %43, label %2
41: ; preds = %43
%42 = tail call i32 @free(i32* %1)
ret void
43: ; preds = %2, %43
%44 = phi i64 [ %51, %43 ], [ 0, %2 ]
%45 = getelementptr inbounds i32, i32* %1, i64 %44
%46 = load i32, i32* %45
%47 = zext i32 %46 to i64
%48 = icmp eq i64 %44, %47
%49 = zext i1 %48 to i32
%50 = tail call i32 @assert(i32 %49)
%51 = add nuw nsw i64 %44, 1
%52 = icmp eq i64 %51, 1000
br i1 %52, label %41, label %43
}