#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 */
typedef int /*<<< orphan*/ uint64_t;

/* Variables and functions */
int /*<<< orphan*/ sort_word(int /*<<< orphan*/);
void nibble_sort_jerome(uint64_t *buf) {
  for (int i = 0; i < 1024; i += 4) {
    buf[i] = sort_word(buf[i]);
    buf[i + 1] = sort_word(buf[i + 1]);
    buf[i + 2] = sort_word(buf[i + 2]);
    buf[i + 3] = sort_word(buf[i + 3]);
  }
}


x86 assembly (clang, -O0):
<nibble_sort_jerome>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x400,-0xc(%rbp)
jge    11d0 <nibble_sort_jerome+0xc0>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
call   1030 <sort_word@plt>
mov    %eax,%edx
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%edi
call   1030 <sort_word@plt>
mov    %eax,%edx
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%edi
call   1030 <sort_word@plt>
mov    %eax,%edx
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
add    $0x3,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%edi
call   1030 <sort_word@plt>
mov    %eax,%edx
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
add    $0x3,%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0xc(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0xc(%rbp)
jmp    1123 <nibble_sort_jerome+0x13>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nibble_sort_jerome>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0xfffffffffffffffc,%rbx
xchg   %ax,%ax
mov    0x10(%r14,%rbx,4),%edi
call   1030 <sort_word@plt>
mov    %eax,0x10(%r14,%rbx,4)
mov    0x14(%r14,%rbx,4),%edi
call   1030 <sort_word@plt>
mov    %eax,0x14(%r14,%rbx,4)
mov    0x18(%r14,%rbx,4),%edi
call   1030 <sort_word@plt>
mov    %eax,0x18(%r14,%rbx,4)
mov    0x1c(%r14,%rbx,4),%edi
call   1030 <sort_word@plt>
mov    %eax,0x1c(%r14,%rbx,4)
add    $0x4,%rbx
cmp    $0x3fc,%rbx
jb     1120 <nibble_sort_jerome+0x10>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @nibble_sort_jerome(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
store i32* %0, i32** %2
store i32 0, i32* %3
br label %4
4: ; preds = %54, %1
%5 = load i32, i32* %3
%6 = icmp slt i32 %5, 1024
br i1 %6, label %7, label %57
7: ; preds = %4
%8 = load i32*, i32** %2
%9 = load i32, i32* %3
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i32, i32* %8, i64 %10
%12 = load i32, i32* %11
%13 = call i32 @sort_word(i32 %12)
%14 = load i32*, i32** %2
%15 = load i32, i32* %3
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i32, i32* %14, i64 %16
store i32 %13, i32* %17
%18 = load i32*, i32** %2
%19 = load i32, i32* %3
%20 = add nsw i32 %19, 1
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %18, i64 %21
%23 = load i32, i32* %22
%24 = call i32 @sort_word(i32 %23)
%25 = load i32*, i32** %2
%26 = load i32, i32* %3
%27 = add nsw i32 %26, 1
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32, i32* %25, i64 %28
store i32 %24, i32* %29
%30 = load i32*, i32** %2
%31 = load i32, i32* %3
%32 = add nsw i32 %31, 2
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i32, i32* %30, i64 %33
%35 = load i32, i32* %34
%36 = call i32 @sort_word(i32 %35)
%37 = load i32*, i32** %2
%38 = load i32, i32* %3
%39 = add nsw i32 %38, 2
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i32, i32* %37, i64 %40
store i32 %36, i32* %41
%42 = load i32*, i32** %2
%43 = load i32, i32* %3
%44 = add nsw i32 %43, 3
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i32, i32* %42, i64 %45
%47 = load i32, i32* %46
%48 = call i32 @sort_word(i32 %47)
%49 = load i32*, i32** %2
%50 = load i32, i32* %3
%51 = add nsw i32 %50, 3
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i32, i32* %49, i64 %52
store i32 %48, i32* %53
br label %54
54: ; preds = %7
%55 = load i32, i32* %3
%56 = add nsw i32 %55, 4
store i32 %56, i32* %3
br label %4
57: ; preds = %4
ret void
}

LLVM IR (-O2):
define void @nibble_sort_jerome(i32* nocapture %0) {
br label %3
2: ; preds = %3
ret void
3: ; preds = %1, %3
%4 = phi i64 [ 0, %1 ], [ %20, %3 ]
%5 = getelementptr inbounds i32, i32* %0, i64 %4
%6 = load i32, i32* %5
%7 = tail call i32 @sort_word(i32 %6)
store i32 %7, i32* %5
%8 = or i64 %4, 1
%9 = getelementptr inbounds i32, i32* %0, i64 %8
%10 = load i32, i32* %9
%11 = tail call i32 @sort_word(i32 %10)
store i32 %11, i32* %9
%12 = or i64 %4, 2
%13 = getelementptr inbounds i32, i32* %0, i64 %12
%14 = load i32, i32* %13
%15 = tail call i32 @sort_word(i32 %14)
store i32 %15, i32* %13
%16 = or i64 %4, 3
%17 = getelementptr inbounds i32, i32* %0, i64 %16
%18 = load i32, i32* %17
%19 = tail call i32 @sort_word(i32 %18)
store i32 %19, i32* %17
%20 = add nuw nsw i64 %4, 4
%21 = icmp ult i64 %4, 1020
br i1 %21, label %3, label %2
}