#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 *);
int /*<<< orphan*/ mm_showmallinfo();
int /*<<< orphan*/ printf(char *, int, void *, int const);
void do_frees(void **mem, const int *size, const int *seq, int n) {
  int i;
  int j;
  for (i = 0; i < n; i++) {
    j = seq[i];
    printf("(%d)Releasing memory at %p (size=%d bytes)\n", i, mem[j], size[j]);
    free(mem[j]);
    mem[j] = NULL;
    mm_showmallinfo();
  }
}


x86 assembly (clang, -O0):
<do_frees>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11c4 <do_frees+0x94>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%esi
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
lea    0xe77(%rip),%rdi
call   1050 <printf@plt>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    $0x0,%al
call   1040 <mm_showmallinfo@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    114e <do_frees+0x1e>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_frees>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %ecx,%ecx
jle    118e <do_frees+0x5e>
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r13
mov    %ecx,%ebp
xor    %ebx,%ebx
nopl   0x0(%rax)
movslq (%r14,%rbx,4),%r12
mov    0x0(%r13,%r12,8),%rdx
mov    (%r15,%r12,4),%ecx
lea    0xe9c(%rip),%rdi
mov    %ebx,%esi
call   1050 <printf@plt>
mov    0x0(%r13,%r12,8),%rdi
call   1030 <free@plt>
movq   $0x0,0x0(%r13,%r12,8)
xor    %eax,%eax
call   1040 <mm_showmallinfo@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1150 <do_frees+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [44 x i8] c"(%d)Releasing memory at %p (size=%d bytes)\0A\00"
define void @do_frees(i8** %0, i32* %1, i32* %2, i32 %3) {
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i8** %0, i8*** %5
store i32* %1, i32** %6
store i32* %2, i32** %7
store i32 %3, i32* %8
store i32 0, i32* %9
br label %11
11: ; preds = %44, %4
%12 = load i32, i32* %9
%13 = load i32, i32* %8
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %47
15: ; preds = %11
%16 = load i32*, i32** %7
%17 = load i32, i32* %9
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i32, i32* %16, i64 %18
%20 = load i32, i32* %19
store i32 %20, i32* %10
%21 = load i32, i32* %9
%22 = load i8**, i8*** %5
%23 = load i32, i32* %10
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8*, i8** %22, i64 %24
%26 = load i8*, i8** %25
%27 = load i32*, i32** %6
%28 = load i32, i32* %10
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i32, i32* %27, i64 %29
%31 = load i32, i32* %30
%32 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i32 %21, i8* %26, i32 %31)
%33 = load i8**, i8*** %5
%34 = load i32, i32* %10
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8*, i8** %33, i64 %35
%37 = load i8*, i8** %36
%38 = call i32 @free(i8* %37)
%39 = load i8**, i8*** %5
%40 = load i32, i32* %10
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8*, i8** %39, i64 %41
store i8* null, i8** %42
%43 = call i32 (...) @mm_showmallinfo()
br label %44
44: ; preds = %15
%45 = load i32, i32* %9
%46 = add nsw i32 %45, 1
store i32 %46, i32* %9
br label %11
47: ; preds = %11
ret void
}

LLVM IR (-O2):
@.str = [44 x i8] c"(%d)Releasing memory at %p (size=%d bytes)\0A\00"
define void @do_frees(i8** nocapture %0, i32* nocapture %1, i32* nocapture %2, i32 %3) {
%5 = icmp sgt i32 %3, 0
br i1 %5, label %6, label %24
6: ; preds = %4
%7 = zext i32 %3 to i64
br label %8
8: ; preds = %6, %8
%9 = phi i64 [ 0, %6 ], [ %22, %8 ]
%10 = getelementptr inbounds i32, i32* %2, i64 %9
%11 = load i32, i32* %10
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8*, i8** %0, i64 %12
%14 = load i8*, i8** %13
%15 = getelementptr inbounds i32, i32* %1, i64 %12
%16 = load i32, i32* %15
%17 = trunc i64 %9 to i32
%18 = tail call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i32 %17, i8* %14, i32 %16)
%19 = load i8*, i8** %13
%20 = tail call i32 @free(i8* %19)
store i8* null, i8** %13
%21 = tail call i32 (...) @mm_showmallinfo()
%22 = add nuw nsw i64 %9, 1
%23 = icmp eq i64 %22, %7
br i1 %23, label %24, label %8
24: ; preds = %8, %4
ret void
}