#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*/ printf(char *, ...);
int /*<<< orphan*/ swap(int *, int, int);
void shellSort(int v[], int n) {
  int gap, i, j;
  for (gap = n / 2; gap > 0; gap /= 2) {
    for (i = gap; i < n; i++) {
      for (j = i - gap; j >= 0 && v[j] > v[j + gap]; j -= gap) {
        swap(v, j, j + gap);
      }
    }
  }
  printf("Shell sorted array ");
  for (i = 0; i < 10; i++) {
    printf("%3d", v[i]);
  }
  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,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jle    11ef <shellSort+0xcf>
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11d7 <shellSort+0xb7>
mov    -0x14(%rbp),%eax
sub    -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x18(%rbp)
mov    %al,-0x19(%rbp)
jl     1192 <shellSort+0x72>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x8(%rbp),%rcx
mov    -0x18(%rbp),%edx
add    -0x10(%rbp),%edx
movslq %edx,%rdx
cmp    (%rcx,%rdx,4),%eax
setg   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    11a2 <shellSort+0x82>
jmp    11c4 <shellSort+0xa4>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x18(%rbp),%edx
add    -0x10(%rbp),%edx
call   1040 <swap@plt>
mov    -0x10(%rbp),%ecx
mov    -0x18(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x18(%rbp)
jmp    1162 <shellSort+0x42>
jmp    11c9 <shellSort+0xa9>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    114d <shellSort+0x2d>
jmp    11dc <shellSort+0xbc>
mov    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
jmp    113d <shellSort+0x1d>
lea    0xe0a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0xa,-0x14(%rbp)
jge    1235 <shellSort+0x115>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xdf4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1204 <shellSort+0xe4>
lea    0xddc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
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
mov    %rdi,%r15
cmp    $0x2,%esi
jl     11a2 <shellSort+0x72>
mov    %esi,%r14d
mov    %esi,%ebx
jmp    1156 <shellSort+0x26>
nopw   0x0(%rax,%rax,1)
cmp    $0x4,%r12d
jl     11a2 <shellSort+0x72>
mov    %ebx,%r12d
shr    $0x1f,%ebx
add    %r12d,%ebx
sar    %ebx
cmp    %r14d,%ebx
jge    1150 <shellSort+0x20>
mov    %ebx,%r13d
jmp    1179 <shellSort+0x49>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r13d
cmp    %r14d,%r13d
je     1150 <shellSort+0x20>
mov    %r13d,%ebp
sub    %ebx,%ebp
js     1170 <shellSort+0x40>
lea    (%rbx,%rbp,1),%edx
mov    %ebp,%eax
mov    (%r15,%rax,4),%eax
movslq %edx,%rcx
cmp    (%r15,%rcx,4),%eax
jle    1170 <shellSort+0x40>
mov    %r15,%rdi
mov    %ebp,%esi
call   1050 <swap@plt>
sub    %ebx,%ebp
jns    1180 <shellSort+0x50>
jmp    1170 <shellSort+0x40>
lea    0xe57(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%r15),%esi
lea    0xe5a(%rip),%r14
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x4(%r15),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%r15),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0xc(%r15),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%r15),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x14(%r15),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x18(%r15),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x1c(%r15),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x20(%r15),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x24(%r15),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
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 = [20 x i8] c"Shell sorted array \00"
@.str.1 = [4 x i8] c"%3d\00"
@.str.2 = [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
store i32* %0, i32** %3
store i32 %1, i32* %4
%8 = load i32, i32* %4
%9 = sdiv i32 %8, 2
store i32 %9, i32* %5
br label %10
10: ; preds = %58, %2
%11 = load i32, i32* %5
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %61
13: ; preds = %10
%14 = load i32, i32* %5
store i32 %14, i32* %6
br label %15
15: ; preds = %54, %13
%16 = load i32, i32* %6
%17 = load i32, i32* %4
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %57
19: ; preds = %15
%20 = load i32, i32* %6
%21 = load i32, i32* %5
%22 = sub nsw i32 %20, %21
store i32 %22, i32* %7
br label %23
23: ; preds = %49, %19
%24 = load i32, i32* %7
%25 = icmp sge i32 %24, 0
br i1 %25, label %26, label %40
26: ; preds = %23
%27 = load i32*, i32** %3
%28 = load i32, i32* %7
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i32, i32* %27, i64 %29
%31 = load i32, i32* %30
%32 = load i32*, i32** %3
%33 = load i32, i32* %7
%34 = load i32, i32* %5
%35 = add nsw i32 %33, %34
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i32, i32* %32, i64 %36
%38 = load i32, i32* %37
%39 = icmp sgt i32 %31, %38
br label %40
40: ; preds = %26, %23
%41 = phi i1 [ false, %23 ], [ %39, %26 ]
br i1 %41, label %42, label %53
42: ; preds = %40
%43 = load i32*, i32** %3
%44 = load i32, i32* %7
%45 = load i32, i32* %7
%46 = load i32, i32* %5
%47 = add nsw i32 %45, %46
%48 = call i32 @swap(i32* %43, i32 %44, i32 %47)
br label %49
49: ; preds = %42
%50 = load i32, i32* %5
%51 = load i32, i32* %7
%52 = sub nsw i32 %51, %50
store i32 %52, i32* %7
br label %23
53: ; preds = %40
br label %54
54: ; preds = %53
%55 = load i32, i32* %6
%56 = add nsw i32 %55, 1
store i32 %56, i32* %6
br label %15
57: ; preds = %15
br label %58
58: ; preds = %57
%59 = load i32, i32* %5
%60 = sdiv i32 %59, 2
store i32 %60, i32* %5
br label %10
61: ; preds = %10
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %6
br label %63
63: ; preds = %73, %61
%64 = load i32, i32* %6
%65 = icmp slt i32 %64, 10
br i1 %65, label %66, label %76
66: ; preds = %63
%67 = load i32*, i32** %3
%68 = load i32, i32* %6
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds i32, i32* %67, i64 %69
%71 = load i32, i32* %70
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %71)
br label %73
73: ; preds = %66
%74 = load i32, i32* %6
%75 = add nsw i32 %74, 1
store i32 %75, i32* %6
br label %63
76: ; preds = %63
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [20 x i8] c"Shell sorted array \00"
@.str.1 = [4 x i8] c"%3d\00"
define void @shellSort(i32* %0, i32 %1) {
%3 = icmp sgt i32 %1, 1
br i1 %3, label %6, label %31
4: ; preds = %28, %6
%5 = icmp sgt i32 %7, 3
br i1 %5, label %6, label %31
6: ; preds = %2, %4
%7 = phi i32 [ %8, %4 ], [ %1, %2 ]
%8 = sdiv i32 %7, 2
%9 = icmp slt i32 %8, %1
br i1 %9, label %10, label %4
10: ; preds = %6, %28
%11 = phi i32 [ %29, %28 ], [ %8, %6 ]
%12 = sub nsw i32 %11, %8
%13 = icmp sgt i32 %12, -1
br i1 %13, label %14, label %28
14: ; preds = %10, %24
%15 = phi i32 [ %26, %24 ], [ %12, %10 ]
%16 = phi i32 [ %15, %24 ], [ %11, %10 ]
%17 = zext i32 %15 to i64
%18 = getelementptr inbounds i32, i32* %0, i64 %17
%19 = load i32, i32* %18
%20 = sext i32 %16 to i64
%21 = getelementptr inbounds i32, i32* %0, i64 %20
%22 = load i32, i32* %21
%23 = icmp sgt i32 %19, %22
br i1 %23, label %24, label %28
24: ; preds = %14
%25 = tail call i32 @swap(i32* %0, i32 %15, i32 %16)
%26 = sub nsw i32 %15, %8
%27 = icmp sgt i32 %26, -1
br i1 %27, label %14, label %28
28: ; preds = %24, %14, %10
%29 = add i32 %11, 1
%30 = icmp eq i32 %29, %1
br i1 %30, label %4, label %10
31: ; preds = %4, %2
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%33 = load i32, i32* %0
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %33)
%35 = getelementptr inbounds i32, i32* %0, i64 1
%36 = load i32, i32* %35
%37 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %36)
%38 = getelementptr inbounds i32, i32* %0, i64 2
%39 = load i32, i32* %38
%40 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %39)
%41 = getelementptr inbounds i32, i32* %0, i64 3
%42 = load i32, i32* %41
%43 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %42)
%44 = getelementptr inbounds i32, i32* %0, i64 4
%45 = load i32, i32* %44
%46 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %45)
%47 = getelementptr inbounds i32, i32* %0, i64 5
%48 = load i32, i32* %47
%49 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %48)
%50 = getelementptr inbounds i32, i32* %0, i64 6
%51 = load i32, i32* %50
%52 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %51)
%53 = getelementptr inbounds i32, i32* %0, i64 7
%54 = load i32, i32* %53
%55 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %54)
%56 = getelementptr inbounds i32, i32* %0, i64 8
%57 = load i32, i32* %56
%58 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %57)
%59 = getelementptr inbounds i32, i32* %0, i64 9
%60 = load i32, i32* %59
%61 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %60)
%62 = tail call i32 @putchar(i32 10)
ret void
}