#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*/ insertionSortSub(int *, int, int, int);
int /*<<< orphan*/ printf(char *, ...);
void shellSort(int data[], int len) {
  int i, j, k, l;
  int gap;
  for (gap = len / 2; gap > 0; gap /= 2) {
    printf("gap: %d\n", gap);
    for (i = 0; i < gap; i++) {
      insertionSortSub(data, len, i, gap);
    }
    printf("\n");
  }
}


x86 assembly (clang, -O0):
<shellSort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jle    11ac <shellSort+0x8c>
mov    -0x20(%rbp),%esi
lea    0xeaf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    118b <shellSort+0x6b>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x20(%rbp),%ecx
call   1040 <insertionSortSub@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    115f <shellSort+0x3f>
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x20(%rbp)
jmp    113d <shellSort+0x1d>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shellSort>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%esi
jl     11a9 <shellSort+0x79>
mov    %esi,%r15d
mov    %rdi,%r12
lea    0xeb3(%rip),%r14
mov    %esi,%r13d
mov    %r15d,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
shr    $0x1f,%ebp
add    %r13d,%ebp
sar    %ebp
mov    %r14,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x2,%r13d
jl     11b8 <shellSort+0x88>
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    %r12,%rdi
mov    %r15d,%esi
mov    %ebx,%edx
mov    %ebp,%ecx
call   1050 <insertionSortSub@plt>
add    $0x1,%ebx
cmp    %ebx,%ebp
jne    1180 <shellSort+0x50>
mov    $0xa,%edi
call   1030 <putchar@plt>
cmp    $0x3,%r13d
mov    %ebp,%r13d
jg     1160 <shellSort+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"gap: %d\0A\00"
@.str.1 = [2 x i8] c"\0A\00"
define void @shellSort(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%10 = load i32, i32* %4
%11 = sdiv i32 %10, 2
store i32 %11, i32* %9
br label %12
12: ; preds = %33, %2
%13 = load i32, i32* %9
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %36
15: ; preds = %12
%16 = load i32, i32* %9
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %16)
store i32 0, i32* %5
br label %18
18: ; preds = %28, %15
%19 = load i32, i32* %5
%20 = load i32, i32* %9
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %31
22: ; preds = %18
%23 = load i32*, i32** %3
%24 = load i32, i32* %4
%25 = load i32, i32* %5
%26 = load i32, i32* %9
%27 = call i32 @insertionSortSub(i32* %23, i32 %24, i32 %25, i32 %26)
br label %28
28: ; preds = %22
%29 = load i32, i32* %5
%30 = add nsw i32 %29, 1
store i32 %30, i32* %5
br label %18
31: ; preds = %18
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %33
33: ; preds = %31
%34 = load i32, i32* %9
%35 = sdiv i32 %34, 2
store i32 %35, i32* %9
br label %12
36: ; preds = %12
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"gap: %d\0A\00"
define void @shellSort(i32* %0, i32 %1) {
%3 = icmp sgt i32 %1, 1
br i1 %3, label %4, label %19
4: ; preds = %2, %16
%5 = phi i32 [ %6, %16 ], [ %1, %2 ]
%6 = sdiv i32 %5, 2
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = icmp sgt i32 %5, 1
br i1 %8, label %11, label %9
9: ; preds = %4
%10 = tail call i32 @putchar(i32 10)
br label %19
11: ; preds = %4, %11
%12 = phi i32 [ %14, %11 ], [ 0, %4 ]
%13 = tail call i32 @insertionSortSub(i32* %0, i32 %1, i32 %12, i32 %6)
%14 = add nuw nsw i32 %12, 1
%15 = icmp eq i32 %14, %6
br i1 %15, label %16, label %11
16: ; preds = %11
%17 = tail call i32 @putchar(i32 10)
%18 = icmp sgt i32 %5, 3
br i1 %18, label %4, label %19
19: ; preds = %16, %9, %2
ret void
}