#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 */
struct int_list {
  int dummy;
};

/* Variables and functions */
struct int_list *insert_sorted(struct int_list *, int, unsigned long long);
struct int_list *sort_top(unsigned long long top[200]) {
  int i = 0;
  struct int_list *t = NULL;
  for (; i < 200; i++)
    if (top[i])
      t = insert_sorted(t, i, top[i]);
  return t;
}


x86 assembly (clang, -O0):
<sort_top>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
cmpl   $0xc8,-0xc(%rbp)
jge    117a <sort_top+0x6a>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1167 <sort_top+0x57>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
call   1030 <insert_sorted@plt>
mov    %rax,-0x18(%rbp)
jmp    116c <sort_top+0x5c>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    112b <sort_top+0x1b>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sort_top>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %ebx,%ebx
xor    %eax,%eax
jmp    112d <sort_top+0x1d>
nopl   (%rax)
add    $0x1,%rbx
cmp    $0xc8,%rbx
je     1142 <sort_top+0x32>
mov    (%r14,%rbx,8),%rdx
test   %rdx,%rdx
je     1120 <sort_top+0x10>
mov    %rax,%rdi
mov    %ebx,%esi
call   1030 <insert_sorted@plt>
jmp    1120 <sort_top+0x10>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.int_list = type { i32 }
define %struct.int_list* @sort_top(i64* %0) {
%2 = alloca i64*
%3 = alloca i32
%4 = alloca %struct.int_list*
store i64* %0, i64** %2
store i32 0, i32* %3
store %struct.int_list* null, %struct.int_list** %4
br label %5
5: ; preds = %25, %1
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 200
br i1 %7, label %8, label %28
8: ; preds = %5
%9 = load i64*, i64** %2
%10 = load i32, i32* %3
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i64, i64* %9, i64 %11
%13 = load i64, i64* %12
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %24
15: ; preds = %8
%16 = load %struct.int_list*, %struct.int_list** %4
%17 = load i32, i32* %3
%18 = load i64*, i64** %2
%19 = load i32, i32* %3
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i64, i64* %18, i64 %20
%22 = load i64, i64* %21
%23 = call %struct.int_list* @insert_sorted(%struct.int_list* %16, i32 %17, i64 %22)
store %struct.int_list* %23, %struct.int_list** %4
br label %24
24: ; preds = %15, %8
br label %25
25: ; preds = %24
%26 = load i32, i32* %3
%27 = add nsw i32 %26, 1
store i32 %27, i32* %3
br label %5
28: ; preds = %5
%29 = load %struct.int_list*, %struct.int_list** %4
ret %struct.int_list* %29
}

LLVM IR (-O2):
%struct.int_list = type { i32 }
define %struct.int_list* @sort_top(i64* nocapture %0) {
br label %2
2: ; preds = %1, %11
%3 = phi i64 [ 0, %1 ], [ %13, %11 ]
%4 = phi %struct.int_list* [ null, %1 ], [ %12, %11 ]
%5 = getelementptr inbounds i64, i64* %0, i64 %3
%6 = load i64, i64* %5
%7 = icmp eq i64 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = trunc i64 %3 to i32
%10 = tail call %struct.int_list* @insert_sorted(%struct.int_list* %4, i32 %9, i64 %6)
br label %11
11: ; preds = %2, %8
%12 = phi %struct.int_list* [ %10, %8 ], [ %4, %2 ]
%13 = add nuw nsw i64 %3, 1
%14 = icmp eq i64 %13, 200
br i1 %14, label %15, label %2
15: ; preds = %11
ret %struct.int_list* %12
}