#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*/ insertionsortinc(long *, int, int);
void shellsort(long *array, int length) {
  int increment = 1;
  while (increment < length) {
    increment = increment * 3 + 1;
  }
  while (increment > 1) {
    increment /= 3;
    insertionsortinc(array, length, increment);
  }
}


x86 assembly (clang, -O0):
<shellsort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1141 <shellsort+0x31>
imul   $0x3,-0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1126 <shellsort+0x16>
jmp    1146 <shellsort+0x36>
cmpl   $0x1,-0x10(%rbp)
jle    1172 <shellsort+0x62>
mov    -0x10(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1030 <insertionsortinc@plt>
jmp    1146 <shellsort+0x36>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shellsort>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
cmp    $0x2,%esi
jl     116e <shellsort+0x5e>
mov    %esi,%r15d
mov    %rdi,%r14
mov    $0x1,%ebp
nopl   0x0(%rax,%rax,1)
mov    %ebp,%eax
lea    (%rax,%rax,2),%ebp
add    $0x1,%ebp
cmp    %r15d,%ebp
jl     1130 <shellsort+0x20>
test   %eax,%eax
jle    116e <shellsort+0x5e>
mov    $0xaaaaaaab,%r12d
nopw   0x0(%rax,%rax,1)
mov    %ebp,%ebx
imul   %r12,%rbx
shr    $0x21,%rbx
mov    %r14,%rdi
mov    %r15d,%esi
mov    %ebx,%edx
call   1030 <insertionsortinc@plt>
cmp    $0x5,%ebp
mov    %ebx,%ebp
ja     1150 <shellsort+0x40>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @shellsort(i64* %0, i32 %1) {
%3 = alloca i64*
%4 = alloca i32
%5 = alloca i32
store i64* %0, i64** %3
store i32 %1, i32* %4
store i32 1, i32* %5
br label %6
6: ; preds = %10, %2
%7 = load i32, i32* %5
%8 = load i32, i32* %4
%9 = icmp slt i32 %7, %8
br i1 %9, label %10, label %14
10: ; preds = %6
%11 = load i32, i32* %5
%12 = mul nsw i32 %11, 3
%13 = add nsw i32 %12, 1
store i32 %13, i32* %5
br label %6
14: ; preds = %6
br label %15
15: ; preds = %18, %14
%16 = load i32, i32* %5
%17 = icmp sgt i32 %16, 1
br i1 %17, label %18, label %25
18: ; preds = %15
%19 = load i32, i32* %5
%20 = sdiv i32 %19, 3
store i32 %20, i32* %5
%21 = load i64*, i64** %3
%22 = load i32, i32* %4
%23 = load i32, i32* %5
%24 = call i32 @insertionsortinc(i64* %21, i32 %22, i32 %23)
br label %15
25: ; preds = %15
ret void
}

LLVM IR (-O2):
define void @shellsort(i64* %0, i32 %1) {
%3 = icmp sgt i32 %1, 1
br i1 %3, label %6, label %16
4: ; preds = %6
%5 = icmp sgt i32 %7, 0
br i1 %5, label %11, label %16
6: ; preds = %2, %6
%7 = phi i32 [ %9, %6 ], [ 1, %2 ]
%8 = mul nsw i32 %7, 3
%9 = add nsw i32 %8, 1
%10 = icmp slt i32 %9, %1
br i1 %10, label %6, label %4
11: ; preds = %4, %11
%12 = phi i32 [ %13, %11 ], [ %9, %4 ]
%13 = udiv i32 %12, 3
%14 = tail call i32 @insertionsortinc(i64* %0, i32 %1, i32 %13)
%15 = icmp ugt i32 %12, 5
br i1 %15, label %11, label %16
16: ; preds = %11, %2, %4
ret void
}