#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*/ check(int /*<<< orphan*/);
int /*<<< orphan*/ rfree(void *);
scalar_t__ rsize(void *);
int free_remaining_blocks(void *blocks[]) {
  int i = 0;
  int success = 1;
  while (NULL != blocks[i++]) {
    if (rsize(blocks[i - 1]) > 0) {
      check(rfree(blocks[i - 1]));
    }
    if (rsize(blocks[i - 1]) != 0) {
      success = 0;
    }
  }
  return success;
}


x86 assembly (clang, -O0):
<free_remaining_blocks>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
mov    -0x8(%rbp),%rcx
mov    -0xc(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0xc(%rbp)
movslq %eax,%rdx
xor    %eax,%eax
cmp    (%rcx,%rdx,8),%rax
je     11d1 <free_remaining_blocks+0xa1>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <rsize@plt>
cmp    $0x0,%rax
jle    11a5 <free_remaining_blocks+0x75>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   1050 <rfree@plt>
mov    %eax,%edi
call   1040 <check@plt>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <rsize@plt>
cmp    $0x0,%rax
je     11cc <free_remaining_blocks+0x9c>
movl   $0x0,-0x10(%rbp)
jmp    114a <free_remaining_blocks+0x1a>
mov    -0x10(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<free_remaining_blocks>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
mov    (%rdi),%rdi
mov    $0x1,%ebp
test   %rdi,%rdi
je     1187 <free_remaining_blocks+0x57>
xor    %r14d,%r14d
jmp    116c <free_remaining_blocks+0x3c>
nopl   0x0(%rax)
mov    (%rbx),%rdi
call   1030 <rsize@plt>
test   %rax,%rax
cmovne %r14d,%ebp
mov    0x8(%rbx),%rdi
add    $0x8,%rbx
test   %rdi,%rdi
je     1187 <free_remaining_blocks+0x57>
call   1030 <rsize@plt>
test   %rax,%rax
jle    1150 <free_remaining_blocks+0x20>
mov    (%rbx),%rdi
call   1050 <rfree@plt>
mov    %eax,%edi
call   1040 <check@plt>
jmp    1150 <free_remaining_blocks+0x20>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @free_remaining_blocks(i8** nocapture %0) {
%2 = load i8*, i8** %0
%3 = icmp eq i8* %2, null
br i1 %3, label %24, label %4
4: ; preds = %1, %15
%5 = phi i64 [ %20, %15 ], [ 1, %1 ]
%6 = phi i8* [ %22, %15 ], [ %2, %1 ]
%7 = phi i8** [ %21, %15 ], [ %0, %1 ]
%8 = phi i32 [ %19, %15 ], [ 1, %1 ]
%9 = tail call i64 @rsize(i8* %6)
%10 = icmp sgt i64 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %4
%12 = load i8*, i8** %7
%13 = tail call i32 @rfree(i8* %12)
%14 = tail call i32 @check(i32 %13)
br label %15
15: ; preds = %11, %4
%16 = load i8*, i8** %7
%17 = tail call i64 @rsize(i8* %16)
%18 = icmp eq i64 %17, 0
%19 = select i1 %18, i32 %8, i32 0
%20 = add nuw i64 %5, 1
%21 = getelementptr inbounds i8*, i8** %0, i64 %5
%22 = load i8*, i8** %21
%23 = icmp eq i8* %22, null
br i1 %23, label %24, label %4
24: ; preds = %15, %1
%25 = phi i32 [ 1, %1 ], [ %19, %15 ]
ret i32 %25
}