#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 */
scalar_t__ blockAllocated(int *);
int /*<<< orphan*/ blockMarked(int *);
int *isPtr(int *);
int length(int *);
int /*<<< orphan*/ markBlock(int *);
void mark(int *p) {
  int i = 0, size;
  int *ptr;
  ptr = isPtr(p);
  if (ptr != NULL && blockAllocated(ptr)) {
    if (!blockMarked(ptr)) {
      markBlock(ptr);
    }
    size = length(ptr) / 4;
    while (++i < size) {
      mark(ptr + i);
    }
  }
}


x86 assembly (clang, -O0):
<mark>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <isPtr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11fd <mark+0x9d>
mov    -0x18(%rbp),%rdi
call   1080 <blockAllocated@plt>
cmp    $0x0,%rax
je     11fd <mark+0x9d>
mov    -0x18(%rbp),%rdi
call   1060 <blockMarked@plt>
cmp    $0x0,%eax
jne    11b9 <mark+0x59>
mov    -0x18(%rbp),%rdi
call   1070 <markBlock@plt>
mov    -0x18(%rbp),%rdi
call   1030 <length@plt>
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
cmp    -0x10(%rbp),%eax
jge    11f8 <mark+0x98>
mov    -0x18(%rbp),%rdi
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
call   1050 <mark@plt>
jmp    11cd <mark+0x6d>
jmp    11fd <mark+0x9d>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mark>:
push   %r14
push   %rbx
push   %rax
call   1040 <isPtr@plt>
test   %rax,%rax
je     11c2 <mark+0x62>
mov    %rax,%r14
mov    %rax,%rdi
call   1080 <blockAllocated@plt>
test   %rax,%rax
je     11c2 <mark+0x62>
mov    %r14,%rdi
call   1060 <blockMarked@plt>
test   %eax,%eax
jne    1192 <mark+0x32>
mov    %r14,%rdi
call   1070 <markBlock@plt>
mov    %r14,%rdi
call   1030 <length@plt>
cmp    $0x8,%eax
jl     11c2 <mark+0x62>
mov    %eax,%ebx
shr    $0x2,%ebx
add    $0x4,%r14
add    $0xffffffffffffffff,%rbx
nopl   0x0(%rax)
mov    %r14,%rdi
call   1050 <mark@plt>
add    $0x4,%r14
add    $0xffffffffffffffff,%rbx
jne    11b0 <mark+0x50>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define void @mark(i32* %0) {
%2 = tail call i32* @isPtr(i32* %0)
%3 = icmp eq i32* %2, null
br i1 %3, label %23, label %4
4: ; preds = %1
%5 = tail call i64 @blockAllocated(i32* %2)
%6 = icmp eq i64 %5, 0
br i1 %6, label %23, label %7
7: ; preds = %4
%8 = tail call i32 @blockMarked(i32* %2)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 @markBlock(i32* %2)
br label %12
12: ; preds = %10, %7
%13 = tail call i32 @length(i32* %2)
%14 = icmp sgt i32 %13, 7
br i1 %14, label %15, label %23
15: ; preds = %12
%16 = lshr i32 %13, 2
%17 = zext i32 %16 to i64
br label %18
18: ; preds = %15, %18
%19 = phi i64 [ 1, %15 ], [ %21, %18 ]
%20 = getelementptr inbounds i32, i32* %2, i64 %19
tail call void @mark(i32* %20)
%21 = add nuw nsw i64 %19, 1
%22 = icmp eq i64 %21, %17
br i1 %22, label %23, label %18
23: ; preds = %18, %12, %4, %1
ret void
}