#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 EOF;
int getchar();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putchar(char);
int random();
int /*<<< orphan*/ shellsort(int *, int);
int main(void) {
  int c = '0', e, n = 16;
  int rarray[n];
  while (c != EOF) {
    printf("\nUnsorted:\n\t");
    for (e = 0; e < n; ++e) {
      printf("%02d ", rarray[e] = random() & (n - 1));
    }
    putchar('\n');
    printf("Sorting:\n");
    shellsort(rarray, n);
    printf("Press ENTER to see the Shell Sort in action again; press ^D to "
           "exit: ");
    c = getchar();
  }
  putchar('\n');
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x30,-0x8(%rbp)
movl   $0x10,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%eax
mov    0x2e4a(%rip),%rcx
cmp    (%rcx),%eax
je     1240 <main+0xf0>
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11ff <main+0xaf>
mov    $0x0,%al
call   1060 <random@plt>
mov    %eax,%esi
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
and    %ecx,%esi
movslq -0xc(%rbp),%rcx
mov    %esi,(%rax,%rcx,4)
lea    0xe23(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11bb <main+0x6b>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe03(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%esi
call   1070 <shellsort@plt>
lea    0xdf3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %eax,-0x8(%rbp)
jmp    1194 <main+0x44>
mov    $0xa,%edi
call   1030 <putchar@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    0x2e73(%rip),%rbp
cmpl   $0x30,0x0(%rbp)
je     1382 <main+0x222>
lea    0xe7a(%rip),%r14
lea    0xe80(%rip),%rbx
lea    0xec5(%rip),%r15
mov    %rsp,%r12
lea    0xe75(%rip),%r13
xchg   %ax,%ax
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1070 <random@plt>
and    $0xf,%eax
mov    %eax,(%rsp)
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1070 <random@plt>
and    $0xf,%eax
mov    %eax,0x4(%rsp)
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1070 <random@plt>
and    $0xf,%eax
mov    %eax,0x8(%rsp)
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1070 <random@plt>
and    $0xf,%eax
mov    %eax,0xc(%rsp)
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1070 <random@plt>
and    $0xf,%eax
mov    %eax,0x10(%rsp)
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1070 <random@plt>
and    $0xf,%eax
mov    %eax,0x14(%rsp)
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1070 <random@plt>
and    $0xf,%eax
mov    %eax,0x18(%rsp)
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1070 <random@plt>
and    $0xf,%eax
mov    %eax,0x1c(%rsp)
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1070 <random@plt>
and    $0xf,%eax
mov    %eax,0x20(%rsp)
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1070 <random@plt>
and    $0xf,%eax
mov    %eax,0x24(%rsp)
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1070 <random@plt>
and    $0xf,%eax
mov    %eax,0x28(%rsp)
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1070 <random@plt>
and    $0xf,%eax
mov    %eax,0x2c(%rsp)
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1070 <random@plt>
and    $0xf,%eax
mov    %eax,0x30(%rsp)
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1070 <random@plt>
and    $0xf,%eax
mov    %eax,0x34(%rsp)
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1070 <random@plt>
and    $0xf,%eax
mov    %eax,0x38(%rsp)
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1070 <random@plt>
and    $0xf,%eax
mov    %eax,0x3c(%rsp)
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r15,%rdi
call   1040 <puts@plt>
mov    %r12,%rdi
mov    $0x10,%esi
call   1080 <shellsort@plt>
mov    %r13,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
cmp    0x0(%rbp),%eax
jne    11a0 <main+0x40>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i32 0
@.str = [13 x i8] c"\0AUnsorted:\0A\09\00"
@.str.1 = [6 x i8] c"%02d \00"
@.str.2 = [10 x i8] c"Sorting:\0A\00"
@.str.3 = [70 x i8] c"Press ENTER to see the Shell Sort in action again; press ^D to exit: \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
store i32 0, i32* %1
store i32 48, i32* %2
store i32 16, i32* %4
%7 = load i32, i32* %4
%8 = zext i32 %7 to i64
%9 = call i8* @llvm.stacksave()
store i8* %9, i8** %5
%10 = alloca i32, i64 %8
store i64 %8, i64* %6
br label %11
11: ; preds = %33, %0
%12 = load i32, i32* %2
%13 = load i32, i32* @EOF
%14 = icmp ne i32 %12, %13
br i1 %14, label %15, label %40
15: ; preds = %11
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %17
17: ; preds = %30, %15
%18 = load i32, i32* %3
%19 = load i32, i32* %4
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %33
21: ; preds = %17
%22 = call i32 (...) @random()
%23 = load i32, i32* %4
%24 = sub nsw i32 %23, 1
%25 = and i32 %22, %24
%26 = load i32, i32* %3
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i32, i32* %10, i64 %27
store i32 %25, i32* %28
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %25)
br label %30
30: ; preds = %21
%31 = load i32, i32* %3
%32 = add nsw i32 %31, 1
store i32 %32, i32* %3
br label %17
33: ; preds = %17
%34 = call i32 @putchar(i8 signext 10)
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%36 = load i32, i32* %4
%37 = call i32 @shellsort(i32* %10, i32 %36)
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.3, i64 0, i64 0))
%39 = call i32 (...) @getchar()
store i32 %39, i32* %2
br label %11
40: ; preds = %11
%41 = call i32 @putchar(i8 signext 10)
store i32 0, i32* %1
%42 = load i8*, i8** %5
%43 = load i32, i32* %1
ret i32 %43
}

LLVM IR (-O2):
@EOF = global i32 0
@.str = [13 x i8] c"\0AUnsorted:\0A\09\00"
@.str.1 = [6 x i8] c"%02d \00"
@.str.3 = [70 x i8] c"Press ENTER to see the Shell Sort in action again; press ^D to exit: \00"
@str = [9 x i8] c"Sorting:\00"
define i32 @main() {
%1 = alloca [16 x i32]
%2 = getelementptr inbounds [16 x i32], [16 x i32]* %1, i64 0, i64 0
%3 = load i32, i32* @EOF
%4 = icmp eq i32 %3, 48
br i1 %4, label %78, label %5
5: ; preds = %0
%6 = getelementptr inbounds [16 x i32], [16 x i32]* %1, i64 0, i64 1
%7 = getelementptr inbounds [16 x i32], [16 x i32]* %1, i64 0, i64 2
%8 = getelementptr inbounds [16 x i32], [16 x i32]* %1, i64 0, i64 3
%9 = getelementptr inbounds [16 x i32], [16 x i32]* %1, i64 0, i64 4
%10 = getelementptr inbounds [16 x i32], [16 x i32]* %1, i64 0, i64 5
%11 = getelementptr inbounds [16 x i32], [16 x i32]* %1, i64 0, i64 6
%12 = getelementptr inbounds [16 x i32], [16 x i32]* %1, i64 0, i64 7
%13 = getelementptr inbounds [16 x i32], [16 x i32]* %1, i64 0, i64 8
%14 = getelementptr inbounds [16 x i32], [16 x i32]* %1, i64 0, i64 9
%15 = getelementptr inbounds [16 x i32], [16 x i32]* %1, i64 0, i64 10
%16 = getelementptr inbounds [16 x i32], [16 x i32]* %1, i64 0, i64 11
%17 = getelementptr inbounds [16 x i32], [16 x i32]* %1, i64 0, i64 12
%18 = getelementptr inbounds [16 x i32], [16 x i32]* %1, i64 0, i64 13
%19 = getelementptr inbounds [16 x i32], [16 x i32]* %1, i64 0, i64 14
%20 = getelementptr inbounds [16 x i32], [16 x i32]* %1, i64 0, i64 15
br label %21
21: ; preds = %5, %21
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%23 = call i32 (...) @random()
%24 = and i32 %23, 15
store i32 %24, i32* %2
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %24)
%26 = call i32 (...) @random()
%27 = and i32 %26, 15
store i32 %27, i32* %6
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %27)
%29 = call i32 (...) @random()
%30 = and i32 %29, 15
store i32 %30, i32* %7
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %30)
%32 = call i32 (...) @random()
%33 = and i32 %32, 15
store i32 %33, i32* %8
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %33)
%35 = call i32 (...) @random()
%36 = and i32 %35, 15
store i32 %36, i32* %9
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %36)
%38 = call i32 (...) @random()
%39 = and i32 %38, 15
store i32 %39, i32* %10
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %39)
%41 = call i32 (...) @random()
%42 = and i32 %41, 15
store i32 %42, i32* %11
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %42)
%44 = call i32 (...) @random()
%45 = and i32 %44, 15
store i32 %45, i32* %12
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %45)
%47 = call i32 (...) @random()
%48 = and i32 %47, 15
store i32 %48, i32* %13
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %48)
%50 = call i32 (...) @random()
%51 = and i32 %50, 15
store i32 %51, i32* %14
%52 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %51)
%53 = call i32 (...) @random()
%54 = and i32 %53, 15
store i32 %54, i32* %15
%55 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %54)
%56 = call i32 (...) @random()
%57 = and i32 %56, 15
store i32 %57, i32* %16
%58 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %57)
%59 = call i32 (...) @random()
%60 = and i32 %59, 15
store i32 %60, i32* %17
%61 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %60)
%62 = call i32 (...) @random()
%63 = and i32 %62, 15
store i32 %63, i32* %18
%64 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %63)
%65 = call i32 (...) @random()
%66 = and i32 %65, 15
store i32 %66, i32* %19
%67 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %66)
%68 = call i32 (...) @random()
%69 = and i32 %68, 15
store i32 %69, i32* %20
%70 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %69)
%71 = call i32 @putchar(i8 signext 10)
%72 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
%73 = call i32 @shellsort(i32* %2, i32 16)
%74 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([70 x i8], [70 x i8]* @.str.3, i64 0, i64 0))
%75 = call i32 (...) @getchar()
%76 = load i32, i32* @EOF
%77 = icmp eq i32 %75, %76
br i1 %77, label %78, label %21
78: ; preds = %21, %0
%79 = call i32 @putchar(i8 signext 10)
ret i32 0
}