#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*/ memset(int *, int /*<<< orphan*/, int);
unsigned long nibble_sort_word(unsigned long, int *);
void nibble_sort_burton1(unsigned long *buf) {
  int counts[16];
  memset(counts, 0, 16 * sizeof(int));
  for (int i = 0; i < 1024; i++) {
    buf[i] = nibble_sort_word(buf[i], counts);
  }
}


x86 assembly (clang, -O0):
<nibble_sort_burton1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1040 <memset@plt>
movl   $0x0,-0x54(%rbp)
cmpl   $0x400,-0x54(%rbp)
jge    1182 <nibble_sort_burton1+0x62>
mov    -0x8(%rbp),%rax
movslq -0x54(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    -0x50(%rbp),%rsi
call   1030 <nibble_sort_word@plt>
mov    %rax,%rdx
mov    -0x8(%rbp),%rax
movslq -0x54(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    1143 <nibble_sort_burton1+0x23>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nibble_sort_burton1>:
push   %r15
push   %r14
push   %rbx
sub    $0x40,%rsp
mov    %rdi,%r15
mov    %rsp,%r14
xor    %ebx,%ebx
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1040 <memset@plt>
mov    (%r15,%rbx,8),%rdi
mov    %r14,%rsi
call   1030 <nibble_sort_word@plt>
mov    %rax,(%r15,%rbx,8)
add    $0x1,%rbx
cmp    $0x400,%rbx
jne    1140 <nibble_sort_burton1+0x20>
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @nibble_sort_burton1(i64* %0) {
%2 = alloca i64*
%3 = alloca [16 x i32]
%4 = alloca i32
store i64* %0, i64** %2
%5 = getelementptr inbounds [16 x i32], [16 x i32]* %3, i64 0, i64 0
%6 = call i32 @memset(i32* %5, i32 0, i32 64)
store i32 0, i32* %4
br label %7
7: ; preds = %22, %1
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 1024
br i1 %9, label %10, label %25
10: ; preds = %7
%11 = load i64*, i64** %2
%12 = load i32, i32* %4
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i64, i64* %11, i64 %13
%15 = load i64, i64* %14
%16 = getelementptr inbounds [16 x i32], [16 x i32]* %3, i64 0, i64 0
%17 = call i64 @nibble_sort_word(i64 %15, i32* %16)
%18 = load i64*, i64** %2
%19 = load i32, i32* %4
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i64, i64* %18, i64 %20
store i64 %17, i64* %21
br label %22
22: ; preds = %10
%23 = load i32, i32* %4
%24 = add nsw i32 %23, 1
store i32 %24, i32* %4
br label %7
25: ; preds = %7
ret void
}

LLVM IR (-O2):
define void @nibble_sort_burton1(i64* nocapture %0) {
%2 = alloca [16 x i32]
%3 = bitcast [16 x i32]* %2 to i8*
%4 = getelementptr inbounds [16 x i32], [16 x i32]* %2, i64 0, i64 0
%5 = call i32 @memset(i32* %4, i32 0, i32 64)
br label %7
6: ; preds = %7
ret void
7: ; preds = %1, %7
%8 = phi i64 [ 0, %1 ], [ %12, %7 ]
%9 = getelementptr inbounds i64, i64* %0, i64 %8
%10 = load i64, i64* %9
%11 = call i64 @nibble_sort_word(i64 %10, i32* %4)
store i64 %11, i64* %9
%12 = add nuw nsw i64 %8, 1
%13 = icmp eq i64 %12, 1024
br i1 %13, label %6, label %7
}