#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 *, ...);
void shellsort(int v[], int n) {
  int gap = 0;
  int i = 0;
  int j = 0;
  int temp = 0;
  for (gap = n / 2; gap > 0; gap /= 2) {
    printf("gap = %d; \n", gap);
    for (i = gap; i < n; ++i) {
      printf("    i = %d;\n", i);
      for (j = i - gap; j >= 0 && v[j] > v[j + gap]; j -= gap) {
        printf("-----------------------------------------------------------\n");
        printf("        before j = ( i - gap ) = %d; v [ j = %d ] = %d; v [ ( "
               "j + gap ) = %d ] = %d;\n",
               j, j, v[j], j + gap, v[j + gap]);
        temp = v[j];
        v[j] = v[j + gap];
        v[j + gap] = temp;
        printf("         after j = ( j - gap ) = %d; v [ j = %d ] = %d; v [ ( "
               "j + gap ) = %d ] = %d;\n",
               j, j, v[j], j + gap, v[j + gap]);
        printf("         Now array seems so:");
        for (temp = 0; temp < n; ++temp) {
          printf("%d,", v[temp]);
        };
        printf("\n");
      };
    };
  };
}


x86 assembly (clang, -O0):
<shellsort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jle    131b <shellsort+0x20b>
mov    -0x10(%rbp),%esi
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1303 <shellsort+0x1f3>
mov    -0x14(%rbp),%esi
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
sub    -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x18(%rbp)
mov    %al,-0x1d(%rbp)
jl     11c0 <shellsort+0xb0>
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,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    11d0 <shellsort+0xc0>
jmp    12f0 <shellsort+0x1e0>
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
mov    -0x18(%rbp),%r8d
add    -0x10(%rbp),%r8d
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%edi
add    -0x10(%rbp),%edi
movslq %edi,%rdi
mov    (%rax,%rdi,4),%r9d
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    -0x10(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x1c(%rbp),%edx
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    -0x10(%rbp),%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
mov    -0x18(%rbp),%r8d
add    -0x10(%rbp),%r8d
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%edi
add    -0x10(%rbp),%edi
movslq %edi,%rdi
mov    (%rax,%rdi,4),%r9d
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe71(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    12d2 <shellsort+0x1c2>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    129f <shellsort+0x18f>
lea    0xd31(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%ecx
mov    -0x18(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x18(%rbp)
jmp    1190 <shellsort+0x80>
jmp    12f5 <shellsort+0x1e5>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    116a <shellsort+0x5a>
jmp    1308 <shellsort+0x1f8>
mov    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
jmp    1149 <shellsort+0x39>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shellsort>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %esi,0x8(%rsp)
cmp    $0x2,%esi
jl     1294 <shellsort+0x164>
mov    %rdi,%rbx
mov    0x8(%rsp),%eax
mov    %eax,%r13d
lea    0xf86(%rip),%r12
mov    %eax,0x4(%rsp)
jmp    117b <shellsort+0x4b>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmpl   $0x4,0x10(%rsp)
jl     1294 <shellsort+0x164>
mov    0x4(%rsp),%ebp
mov    %ebp,%eax
shr    $0x1f,%ebp
mov    %eax,0x10(%rsp)
add    %eax,%ebp
sar    %ebp
lea    0xe6d(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,0x4(%rsp)
cmp    0x8(%rsp),%ebp
jge    1170 <shellsort+0x40>
mov    0x4(%rsp),%ebp
jmp    11bd <shellsort+0x8d>
nopl   0x0(%rax)
mov    0xc(%rsp),%ebp
add    $0x1,%ebp
cmp    0x8(%rsp),%ebp
je     1170 <shellsort+0x40>
lea    0xe48(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,0xc(%rsp)
mov    %ebp,%r14d
sub    0x4(%rsp),%r14d
js     11b0 <shellsort+0x80>
mov    0xc(%rsp),%eax
nop
movslq %eax,%r15
mov    %r14d,%ecx
mov    %r14d,%r14d
mov    (%rbx,%r14,4),%eax
cmp    (%rbx,%r15,4),%eax
jle    11b0 <shellsort+0x80>
mov    %ecx,0x14(%rsp)
lea    0xee8(%rip),%rdi
call   1040 <puts@plt>
mov    (%rbx,%r14,4),%ecx
mov    (%rbx,%r15,4),%r9d
lea    0xe07(%rip),%rdi
mov    %r14d,%esi
mov    %r14d,%edx
mov    %r15d,%r8d
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%rbx,%r14,4),%r9d
mov    (%rbx,%r15,4),%eax
mov    %eax,(%rbx,%r14,4)
mov    %r9d,(%rbx,%r15,4)
mov    (%rbx,%r14,4),%ecx
lea    0xe32(%rip),%rdi
mov    %r14d,%esi
mov    %r14d,%edx
mov    %r15d,%r8d
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe71(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %ebp,%ebp
nopl   (%rax)
mov    (%rbx,%rbp,4),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%r13
jne    1260 <shellsort+0x130>
mov    $0xa,%edi
call   1030 <putchar@plt>
sub    0x4(%rsp),%r14d
mov    0x14(%rsp),%eax
jns    11e0 <shellsort+0xb0>
jmp    11b0 <shellsort+0x80>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"gap = %d; \0A\00"
@.str.1 = [13 x i8] c" i = %d;\0A\00"
@.str.2 = [61 x i8] c"-----------------------------------------------------------\0A\00"
@.str.3 = [86 x i8] c" before j = ( i - gap ) = %d; v [ j = %d ] = %d; v [ ( j + gap ) = %d ] = %d;\0A\00"
@.str.4 = [86 x i8] c" after j = ( j - gap ) = %d; v [ j = %d ] = %d; v [ ( j + gap ) = %d ] = %d;\0A\00"
@.str.5 = [29 x i8] c" Now array seems so:\00"
@.str.6 = [4 x i8] c"%d,\00"
@.str.7 = [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
store i32* %0, i32** %3
store i32 %1, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
%9 = load i32, i32* %4
%10 = sdiv i32 %9, 2
store i32 %10, i32* %5
br label %11
11: ; preds = %134, %2
%12 = load i32, i32* %5
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %137
14: ; preds = %11
%15 = load i32, i32* %5
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = load i32, i32* %5
store i32 %17, i32* %6
br label %18
18: ; preds = %130, %14
%19 = load i32, i32* %6
%20 = load i32, i32* %4
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %133
22: ; preds = %18
%23 = load i32, i32* %6
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %23)
%25 = load i32, i32* %6
%26 = load i32, i32* %5
%27 = sub nsw i32 %25, %26
store i32 %27, i32* %7
br label %28
28: ; preds = %125, %22
%29 = load i32, i32* %7
%30 = icmp sge i32 %29, 0
br i1 %30, label %31, label %45
31: ; preds = %28
%32 = load i32*, i32** %3
%33 = load i32, i32* %7
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i32, i32* %32, i64 %34
%36 = load i32, i32* %35
%37 = load i32*, i32** %3
%38 = load i32, i32* %7
%39 = load i32, i32* %5
%40 = add nsw i32 %38, %39
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i32, i32* %37, i64 %41
%43 = load i32, i32* %42
%44 = icmp sgt i32 %36, %43
br label %45
45: ; preds = %31, %28
%46 = phi i1 [ false, %28 ], [ %44, %31 ]
br i1 %46, label %47, label %129
47: ; preds = %45
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.2, i64 0, i64 0))
%49 = load i32, i32* %7
%50 = load i32, i32* %7
%51 = load i32*, i32** %3
%52 = load i32, i32* %7
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i32, i32* %51, i64 %53
%55 = load i32, i32* %54
%56 = load i32, i32* %7
%57 = load i32, i32* %5
%58 = add nsw i32 %56, %57
%59 = load i32*, i32** %3
%60 = load i32, i32* %7
%61 = load i32, i32* %5
%62 = add nsw i32 %60, %61
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i32, i32* %59, i64 %63
%65 = load i32, i32* %64
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([86 x i8], [86 x i8]* @.str.3, i64 0, i64 0), i32 %49, i32 %50, i32 %55, i32 %58, i32 %65)
%67 = load i32*, i32** %3
%68 = load i32, i32* %7
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds i32, i32* %67, i64 %69
%71 = load i32, i32* %70
store i32 %71, i32* %8
%72 = load i32*, i32** %3
%73 = load i32, i32* %7
%74 = load i32, i32* %5
%75 = add nsw i32 %73, %74
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds i32, i32* %72, i64 %76
%78 = load i32, i32* %77
%79 = load i32*, i32** %3
%80 = load i32, i32* %7
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds i32, i32* %79, i64 %81
store i32 %78, i32* %82
%83 = load i32, i32* %8
%84 = load i32*, i32** %3
%85 = load i32, i32* %7
%86 = load i32, i32* %5
%87 = add nsw i32 %85, %86
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds i32, i32* %84, i64 %88
store i32 %83, i32* %89
%90 = load i32, i32* %7
%91 = load i32, i32* %7
%92 = load i32*, i32** %3
%93 = load i32, i32* %7
%94 = sext i32 %93 to i64
%95 = getelementptr inbounds i32, i32* %92, i64 %94
%96 = load i32, i32* %95
%97 = load i32, i32* %7
%98 = load i32, i32* %5
%99 = add nsw i32 %97, %98
%100 = load i32*, i32** %3
%101 = load i32, i32* %7
%102 = load i32, i32* %5
%103 = add nsw i32 %101, %102
%104 = sext i32 %103 to i64
%105 = getelementptr inbounds i32, i32* %100, i64 %104
%106 = load i32, i32* %105
%107 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([86 x i8], [86 x i8]* @.str.4, i64 0, i64 0), i32 %90, i32 %91, i32 %96, i32 %99, i32 %106)
%108 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %8
br label %109
109: ; preds = %120, %47
%110 = load i32, i32* %8
%111 = load i32, i32* %4
%112 = icmp slt i32 %110, %111
br i1 %112, label %113, label %123
113: ; preds = %109
%114 = load i32*, i32** %3
%115 = load i32, i32* %8
%116 = sext i32 %115 to i64
%117 = getelementptr inbounds i32, i32* %114, i64 %116
%118 = load i32, i32* %117
%119 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %118)
br label %120
120: ; preds = %113
%121 = load i32, i32* %8
%122 = add nsw i32 %121, 1
store i32 %122, i32* %8
br label %109
123: ; preds = %109
%124 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
br label %125
125: ; preds = %123
%126 = load i32, i32* %5
%127 = load i32, i32* %7
%128 = sub nsw i32 %127, %126
store i32 %128, i32* %7
br label %28
129: ; preds = %45
br label %130
130: ; preds = %129
%131 = load i32, i32* %6
%132 = add nsw i32 %131, 1
store i32 %132, i32* %6
br label %18
133: ; preds = %18
br label %134
134: ; preds = %133
%135 = load i32, i32* %5
%136 = sdiv i32 %135, 2
store i32 %136, i32* %5
br label %11
137: ; preds = %11
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"gap = %d; \0A\00"
@.str.1 = [13 x i8] c" i = %d;\0A\00"
@.str.3 = [86 x i8] c" before j = ( i - gap ) = %d; v [ j = %d ] = %d; v [ ( j + gap ) = %d ] = %d;\0A\00"
@.str.4 = [86 x i8] c" after j = ( j - gap ) = %d; v [ j = %d ] = %d; v [ ( j + gap ) = %d ] = %d;\0A\00"
@.str.5 = [29 x i8] c" Now array seems so:\00"
@.str.6 = [4 x i8] c"%d,\00"
@str = [60 x i8] c"-----------------------------------------------------------\00"
define void @shellsort(i32* nocapture %0, i32 %1) {
%3 = icmp sgt i32 %1, 1
br i1 %3, label %4, label %52
4: ; preds = %2
%5 = zext i32 %1 to i64
br label %8
6: ; preds = %49, %8
%7 = icmp sgt i32 %9, 3
br i1 %7, label %8, label %52
8: ; preds = %4, %6
%9 = phi i32 [ %1, %4 ], [ %10, %6 ]
%10 = sdiv i32 %9, 2
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = icmp slt i32 %10, %1
br i1 %12, label %13, label %6
13: ; preds = %8, %49
%14 = phi i32 [ %50, %49 ], [ %10, %8 ]
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = sub nsw i32 %14, %10
%17 = icmp sgt i32 %16, -1
br i1 %17, label %18, label %49
18: ; preds = %13, %45
%19 = phi i32 [ %47, %45 ], [ %16, %13 ]
%20 = phi i32 [ %19, %45 ], [ %14, %13 ]
%21 = zext i32 %19 to i64
%22 = getelementptr inbounds i32, i32* %0, i64 %21
%23 = load i32, i32* %22
%24 = sext i32 %20 to i64
%25 = getelementptr inbounds i32, i32* %0, i64 %24
%26 = load i32, i32* %25
%27 = icmp sgt i32 %23, %26
br i1 %27, label %28, label %49
28: ; preds = %18
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @str, i64 0, i64 0))
%30 = load i32, i32* %22
%31 = load i32, i32* %25
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([86 x i8], [86 x i8]* @.str.3, i64 0, i64 0), i32 %19, i32 %19, i32 %30, i32 %20, i32 %31)
%33 = load i32, i32* %22
%34 = load i32, i32* %25
store i32 %34, i32* %22
store i32 %33, i32* %25
%35 = load i32, i32* %22
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([86 x i8], [86 x i8]* @.str.4, i64 0, i64 0), i32 %19, i32 %19, i32 %35, i32 %20, i32 %33)
%37 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0))
br label %38
38: ; preds = %28, %38
%39 = phi i64 [ 0, %28 ], [ %43, %38 ]
%40 = getelementptr inbounds i32, i32* %0, i64 %39
%41 = load i32, i32* %40
%42 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %41)
%43 = add nuw nsw i64 %39, 1
%44 = icmp eq i64 %43, %5
br i1 %44, label %45, label %38
45: ; preds = %38
%46 = tail call i32 @putchar(i32 10)
%47 = sub nsw i32 %19, %10
%48 = icmp sgt i32 %47, -1
br i1 %48, label %18, label %49
49: ; preds = %45, %18, %13
%50 = add i32 %14, 1
%51 = icmp eq i32 %50, %1
br i1 %51, label %6, label %13
52: ; preds = %6, %2
ret void
}