#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__ reorderLevel(int, char *, int const *, int, int /*<<< orphan*/);
int reorder(int baselevel, char *pszText, const int *plevel, int cch) {
  int ich = 0;
  while (ich < cch) {
    ich += reorderLevel(baselevel, pszText + ich, plevel + ich, cch - ich, 0);
  }
  return ich;
}


x86 assembly (clang, -O0):
<reorder>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%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    1176 <reorder+0x66>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
movslq -0x20(%rbp),%rax
add    %rax,%rsi
mov    -0x18(%rbp),%rdx
movslq -0x20(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdx
mov    -0x1c(%rbp),%ecx
sub    -0x20(%rbp),%ecx
xor    %r8d,%r8d
call   1030 <reorderLevel@plt>
mov    %rax,%rcx
movslq -0x20(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x20(%rbp)
jmp    112d <reorder+0x1d>
mov    -0x20(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reorder>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %ecx,%ecx
jle    1152 <reorder+0x42>
mov    %ecx,%ebx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %edi,%r12d
xor    %eax,%eax
nopl   0x0(%rax)
movslq %eax,%rbp
lea    (%r15,%rbp,1),%rsi
lea    (%r14,%rbp,4),%rdx
mov    %ebx,%ecx
sub    %ebp,%ecx
mov    %r12d,%edi
xor    %r8d,%r8d
call   1030 <reorderLevel@plt>
add    %ebp,%eax
cmp    %ebx,%eax
jl     1130 <reorder+0x20>
jmp    1154 <reorder+0x44>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @reorder(i32 %0, i8* %1, i32* %2, i32 %3) {
%5 = icmp sgt i32 %3, 0
br i1 %5, label %6, label %16
6: ; preds = %4, %6
%7 = phi i32 [ %14, %6 ], [ 0, %4 ]
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %1, i64 %8
%10 = getelementptr inbounds i32, i32* %2, i64 %8
%11 = sub nsw i32 %3, %7
%12 = tail call i64 @reorderLevel(i32 %0, i8* %9, i32* %10, i32 %11, i32 0)
%13 = trunc i64 %12 to i32
%14 = add i32 %7, %13
%15 = icmp slt i32 %14, %3
br i1 %15, label %6, label %16
16: ; preds = %6, %4
%17 = phi i32 [ 0, %4 ], [ %14, %6 ]
ret i32 %17
}