#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 document {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ bubble_sort(struct document **, int);
int /*<<< orphan*/ free(struct document **);
struct document **hv_aloc_doc_matrix(int);
scalar_t__ hv_get_cos(struct document *);
char *hv_get_name(struct document *);
int /*<<< orphan*/ printf(char *, char *);
void sort_docs(struct document **docs, int ndocs) {
  struct document **d = hv_aloc_doc_matrix(ndocs);
  int i;
  for (i = 0; i < ndocs; i++) {
    d[i] = docs[i];
  }
  bubble_sort(d, ndocs);
  for (i = 0; i < ndocs; i++) {
    if (hv_get_cos(d[i]) != 0) {
      printf("%s\n", hv_get_name(d[i]));
    }
  }
  free(d);
}


x86 assembly (clang, -O0):
<sort_docs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1060 <hv_aloc_doc_matrix@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11b4 <sort_docs+0x54>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1182 <sort_docs+0x22>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1080 <bubble_sort@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1221 <sort_docs+0xc1>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1040 <hv_get_cos@plt>
cmp    $0x0,%rax
je     120e <sort_docs+0xae>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1070 <hv_get_name@plt>
mov    %rax,%rsi
lea    0xdf7(%rip),%rdi
call   1050 <printf@plt>
jmp    1213 <sort_docs+0xb3>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11c7 <sort_docs+0x67>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sort_docs>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%rbp
mov    %esi,%edi
call   1060 <hv_aloc_doc_matrix@plt>
mov    %rax,%rbx
test   %r14d,%r14d
jle    1215 <sort_docs+0xb5>
mov    %r14d,%r15d
cmp    $0x4,%r14d
jb     11aa <sort_docs+0x4a>
lea    0x0(,%r15,8),%rax
add    %rbp,%rax
cmp    %rax,%rbx
jae    1225 <sort_docs+0xc5>
lea    (%rbx,%r15,8),%rax
cmp    %rbp,%rax
jbe    1225 <sort_docs+0xc5>
xor    %eax,%eax
mov    %rax,%rcx
not    %rcx
add    %r15,%rcx
mov    %r15,%rdx
and    $0x3,%rdx
je     11d3 <sort_docs+0x73>
xchg   %ax,%ax
mov    0x0(%rbp,%rax,8),%rsi
mov    %rsi,(%rbx,%rax,8)
add    $0x1,%rax
add    $0xffffffffffffffff,%rdx
jne    11c0 <sort_docs+0x60>
cmp    $0x3,%rcx
jb     12f4 <sort_docs+0x194>
nopl   (%rax)
mov    0x0(%rbp,%rax,8),%rcx
mov    %rcx,(%rbx,%rax,8)
mov    0x8(%rbp,%rax,8),%rcx
mov    %rcx,0x8(%rbx,%rax,8)
mov    0x10(%rbp,%rax,8),%rcx
mov    %rcx,0x10(%rbx,%rax,8)
mov    0x18(%rbp,%rax,8),%rcx
mov    %rcx,0x18(%rbx,%rax,8)
add    $0x4,%rax
cmp    %rax,%r15
jne    11e0 <sort_docs+0x80>
jmp    12f4 <sort_docs+0x194>
mov    %rbx,%rdi
mov    %r14d,%esi
call   1080 <bubble_sort@plt>
jmp    133d <sort_docs+0x1dd>
mov    %r15d,%eax
and    $0xfffffffc,%eax
lea    -0x4(%rax),%rsi
mov    %rsi,%rdx
shr    $0x2,%rdx
add    $0x1,%rdx
mov    %edx,%ecx
and    $0x3,%ecx
cmp    $0xc,%rsi
jae    1249 <sort_docs+0xe9>
xor    %esi,%esi
jmp    12a9 <sort_docs+0x149>
and    $0xfffffffffffffffc,%rdx
xor    %esi,%esi
nop
movups 0x0(%rbp,%rsi,8),%xmm0
movups 0x10(%rbp,%rsi,8),%xmm1
movups %xmm0,(%rbx,%rsi,8)
movups %xmm1,0x10(%rbx,%rsi,8)
movups 0x20(%rbp,%rsi,8),%xmm0
movups 0x30(%rbp,%rsi,8),%xmm1
movups %xmm0,0x20(%rbx,%rsi,8)
movups %xmm1,0x30(%rbx,%rsi,8)
movups 0x40(%rbp,%rsi,8),%xmm0
movups 0x50(%rbp,%rsi,8),%xmm1
movups %xmm0,0x40(%rbx,%rsi,8)
movups %xmm1,0x50(%rbx,%rsi,8)
movups 0x60(%rbp,%rsi,8),%xmm0
movups 0x70(%rbp,%rsi,8),%xmm1
movups %xmm0,0x60(%rbx,%rsi,8)
movups %xmm1,0x70(%rbx,%rsi,8)
add    $0x10,%rsi
add    $0xfffffffffffffffc,%rdx
jne    1250 <sort_docs+0xf0>
test   %rcx,%rcx
je     12eb <sort_docs+0x18b>
lea    (%rbx,%rsi,8),%rdx
add    $0x10,%rdx
lea    0x10(,%rsi,8),%rsi
add    %rbp,%rsi
shl    $0x5,%rcx
xor    %edi,%edi
nopw   0x0(%rax,%rax,1)
movups -0x10(%rsi,%rdi,1),%xmm0
movups (%rsi,%rdi,1),%xmm1
movups %xmm0,-0x10(%rdx,%rdi,1)
movups %xmm1,(%rdx,%rdi,1)
add    $0x20,%rdi
cmp    %rdi,%rcx
jne    12d0 <sort_docs+0x170>
cmp    %r15,%rax
jne    11ac <sort_docs+0x4c>
mov    %rbx,%rdi
mov    %r14d,%esi
call   1080 <bubble_sort@plt>
test   %r14d,%r14d
jle    133d <sort_docs+0x1dd>
xor    %ebp,%ebp
lea    0xcf3(%rip),%r14
jmp    1319 <sort_docs+0x1b9>
nop
add    $0x1,%rbp
cmp    %rbp,%r15
je     133d <sort_docs+0x1dd>
mov    (%rbx,%rbp,8),%rdi
call   1040 <hv_get_cos@plt>
test   %rax,%rax
je     1310 <sort_docs+0x1b0>
mov    (%rbx,%rbp,8),%rdi
call   1070 <hv_get_name@plt>
mov    %r14,%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
jmp    1310 <sort_docs+0x1b0>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
%struct.document = type { i32 }
@.str = [4 x i8] c"%s\0A\00"
define void @sort_docs(%struct.document** %0, i32 %1) {
%3 = alloca %struct.document**
%4 = alloca i32
%5 = alloca %struct.document**
%6 = alloca i32
store %struct.document** %0, %struct.document*** %3
store i32 %1, i32* %4
%7 = load i32, i32* %4
%8 = call %struct.document** @hv_aloc_doc_matrix(i32 %7)
store %struct.document** %8, %struct.document*** %5
store i32 0, i32* %6
br label %9
9: ; preds = %23, %2
%10 = load i32, i32* %6
%11 = load i32, i32* %4
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %26
13: ; preds = %9
%14 = load %struct.document**, %struct.document*** %3
%15 = load i32, i32* %6
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds %struct.document*, %struct.document** %14, i64 %16
%18 = load %struct.document*, %struct.document** %17
%19 = load %struct.document**, %struct.document*** %5
%20 = load i32, i32* %6
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds %struct.document*, %struct.document** %19, i64 %21
store %struct.document* %18, %struct.document** %22
br label %23
23: ; preds = %13
%24 = load i32, i32* %6
%25 = add nsw i32 %24, 1
store i32 %25, i32* %6
br label %9
26: ; preds = %9
%27 = load %struct.document**, %struct.document*** %5
%28 = load i32, i32* %4
%29 = call i32 @bubble_sort(%struct.document** %27, i32 %28)
store i32 0, i32* %6
br label %30
30: ; preds = %51, %26
%31 = load i32, i32* %6
%32 = load i32, i32* %4
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %54
34: ; preds = %30
%35 = load %struct.document**, %struct.document*** %5
%36 = load i32, i32* %6
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds %struct.document*, %struct.document** %35, i64 %37
%39 = load %struct.document*, %struct.document** %38
%40 = call i64 @hv_get_cos(%struct.document* %39)
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %50
42: ; preds = %34
%43 = load %struct.document**, %struct.document*** %5
%44 = load i32, i32* %6
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds %struct.document*, %struct.document** %43, i64 %45
%47 = load %struct.document*, %struct.document** %46
%48 = call i8* @hv_get_name(%struct.document* %47)
%49 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %48)
br label %50
50: ; preds = %42, %34
br label %51
51: ; preds = %50
%52 = load i32, i32* %6
%53 = add nsw i32 %52, 1
store i32 %53, i32* %6
br label %30
54: ; preds = %30
%55 = load %struct.document**, %struct.document*** %5
%56 = call i32 @free(%struct.document** %55)
ret void
}

LLVM IR (-O2):
%struct.document = type { i32 }
@.str = [4 x i8] c"%s\0A\00"
define void @sort_docs(%struct.document** nocapture %0, i32 %1) {
%3 = tail call %struct.document** @hv_aloc_doc_matrix(i32 %1)
%4 = icmp sgt i32 %1, 0
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i32 @bubble_sort(%struct.document** %3, i32 %1)
br label %149
7: ; preds = %2
%8 = zext i32 %1 to i64
%9 = icmp ult i32 %1, 4
br i1 %9, label %95, label %10
10: ; preds = %7
%11 = getelementptr %struct.document*, %struct.document** %3, i64 %8
%12 = getelementptr %struct.document*, %struct.document** %0, i64 %8
%13 = icmp ult %struct.document** %3, %12
%14 = icmp ugt %struct.document** %11, %0
%15 = and i1 %13, %14
br i1 %15, label %95, label %16
16: ; preds = %10
%17 = and i64 %8, 4294967292
%18 = add nsw i64 %17, -4
%19 = lshr exact i64 %18, 2
%20 = add nuw nsw i64 %19, 1
%21 = and i64 %20, 3
%22 = icmp ult i64 %18, 12
br i1 %22, label %74, label %23
23: ; preds = %16
%24 = and i64 %20, 9223372036854775804
br label %25
25: ; preds = %25, %23
%26 = phi i64 [ 0, %23 ], [ %71, %25 ]
%27 = phi i64 [ 0, %23 ], [ %72, %25 ]
%28 = getelementptr inbounds %struct.document*, %struct.document** %0, i64 %26
%29 = bitcast %struct.document** %28 to <2 x %struct.document*>*
%30 = load <2 x %struct.document*>, <2 x %struct.document*>* %29
%31 = getelementptr inbounds %struct.document*, %struct.document** %28, i64 2
%32 = bitcast %struct.document** %31 to <2 x %struct.document*>*
%33 = load <2 x %struct.document*>, <2 x %struct.document*>* %32
%34 = getelementptr inbounds %struct.document*, %struct.document** %3, i64 %26
%35 = bitcast %struct.document** %34 to <2 x %struct.document*>*
store <2 x %struct.document*> %30, <2 x %struct.document*>* %35
%36 = getelementptr inbounds %struct.document*, %struct.document** %34, i64 2
%37 = bitcast %struct.document** %36 to <2 x %struct.document*>*
store <2 x %struct.document*> %33, <2 x %struct.document*>* %37
%38 = or i64 %26, 4
%39 = getelementptr inbounds %struct.document*, %struct.document** %0, i64 %38
%40 = bitcast %struct.document** %39 to <2 x %struct.document*>*
%41 = load <2 x %struct.document*>, <2 x %struct.document*>* %40
%42 = getelementptr inbounds %struct.document*, %struct.document** %39, i64 2
%43 = bitcast %struct.document** %42 to <2 x %struct.document*>*
%44 = load <2 x %struct.document*>, <2 x %struct.document*>* %43
%45 = getelementptr inbounds %struct.document*, %struct.document** %3, i64 %38
%46 = bitcast %struct.document** %45 to <2 x %struct.document*>*
store <2 x %struct.document*> %41, <2 x %struct.document*>* %46
%47 = getelementptr inbounds %struct.document*, %struct.document** %45, i64 2
%48 = bitcast %struct.document** %47 to <2 x %struct.document*>*
store <2 x %struct.document*> %44, <2 x %struct.document*>* %48
%49 = or i64 %26, 8
%50 = getelementptr inbounds %struct.document*, %struct.document** %0, i64 %49
%51 = bitcast %struct.document** %50 to <2 x %struct.document*>*
%52 = load <2 x %struct.document*>, <2 x %struct.document*>* %51
%53 = getelementptr inbounds %struct.document*, %struct.document** %50, i64 2
%54 = bitcast %struct.document** %53 to <2 x %struct.document*>*
%55 = load <2 x %struct.document*>, <2 x %struct.document*>* %54
%56 = getelementptr inbounds %struct.document*, %struct.document** %3, i64 %49
%57 = bitcast %struct.document** %56 to <2 x %struct.document*>*
store <2 x %struct.document*> %52, <2 x %struct.document*>* %57
%58 = getelementptr inbounds %struct.document*, %struct.document** %56, i64 2
%59 = bitcast %struct.document** %58 to <2 x %struct.document*>*
store <2 x %struct.document*> %55, <2 x %struct.document*>* %59
%60 = or i64 %26, 12
%61 = getelementptr inbounds %struct.document*, %struct.document** %0, i64 %60
%62 = bitcast %struct.document** %61 to <2 x %struct.document*>*
%63 = load <2 x %struct.document*>, <2 x %struct.document*>* %62
%64 = getelementptr inbounds %struct.document*, %struct.document** %61, i64 2
%65 = bitcast %struct.document** %64 to <2 x %struct.document*>*
%66 = load <2 x %struct.document*>, <2 x %struct.document*>* %65
%67 = getelementptr inbounds %struct.document*, %struct.document** %3, i64 %60
%68 = bitcast %struct.document** %67 to <2 x %struct.document*>*
store <2 x %struct.document*> %63, <2 x %struct.document*>* %68
%69 = getelementptr inbounds %struct.document*, %struct.document** %67, i64 2
%70 = bitcast %struct.document** %69 to <2 x %struct.document*>*
store <2 x %struct.document*> %66, <2 x %struct.document*>* %70
%71 = add nuw i64 %26, 16
%72 = add nuw i64 %27, 4
%73 = icmp eq i64 %72, %24
br i1 %73, label %74, label %25
74: ; preds = %25, %16
%75 = phi i64 [ 0, %16 ], [ %71, %25 ]
%76 = icmp eq i64 %21, 0
br i1 %76, label %93, label %77
77: ; preds = %74, %77
%78 = phi i64 [ %90, %77 ], [ %75, %74 ]
%79 = phi i64 [ %91, %77 ], [ 0, %74 ]
%80 = getelementptr inbounds %struct.document*, %struct.document** %0, i64 %78
%81 = bitcast %struct.document** %80 to <2 x %struct.document*>*
%82 = load <2 x %struct.document*>, <2 x %struct.document*>* %81
%83 = getelementptr inbounds %struct.document*, %struct.document** %80, i64 2
%84 = bitcast %struct.document** %83 to <2 x %struct.document*>*
%85 = load <2 x %struct.document*>, <2 x %struct.document*>* %84
%86 = getelementptr inbounds %struct.document*, %struct.document** %3, i64 %78
%87 = bitcast %struct.document** %86 to <2 x %struct.document*>*
store <2 x %struct.document*> %82, <2 x %struct.document*>* %87
%88 = getelementptr inbounds %struct.document*, %struct.document** %86, i64 2
%89 = bitcast %struct.document** %88 to <2 x %struct.document*>*
store <2 x %struct.document*> %85, <2 x %struct.document*>* %89
%90 = add nuw i64 %78, 4
%91 = add i64 %79, 1
%92 = icmp eq i64 %91, %21
br i1 %92, label %93, label %77
93: ; preds = %77, %74
%94 = icmp eq i64 %17, %8
br i1 %94, label %132, label %95
95: ; preds = %10, %7, %93
%96 = phi i64 [ 0, %10 ], [ 0, %7 ], [ %17, %93 ]
%97 = xor i64 %96, -1
%98 = add nsw i64 %97, %8
%99 = and i64 %8, 3
%100 = icmp eq i64 %99, 0
br i1 %100, label %110, label %101
101: ; preds = %95, %101
%102 = phi i64 [ %107, %101 ], [ %96, %95 ]
%103 = phi i64 [ %108, %101 ], [ 0, %95 ]
%104 = getelementptr inbounds %struct.document*, %struct.document** %0, i64 %102
%105 = load %struct.document*, %struct.document** %104
%106 = getelementptr inbounds %struct.document*, %struct.document** %3, i64 %102
store %struct.document* %105, %struct.document** %106
%107 = add nuw nsw i64 %102, 1
%108 = add i64 %103, 1
%109 = icmp eq i64 %108, %99
br i1 %109, label %110, label %101
110: ; preds = %101, %95
%111 = phi i64 [ %96, %95 ], [ %107, %101 ]
%112 = icmp ult i64 %98, 3
br i1 %112, label %132, label %113
113: ; preds = %110, %113
%114 = phi i64 [ %130, %113 ], [ %111, %110 ]
%115 = getelementptr inbounds %struct.document*, %struct.document** %0, i64 %114
%116 = load %struct.document*, %struct.document** %115
%117 = getelementptr inbounds %struct.document*, %struct.document** %3, i64 %114
store %struct.document* %116, %struct.document** %117
%118 = add nuw nsw i64 %114, 1
%119 = getelementptr inbounds %struct.document*, %struct.document** %0, i64 %118
%120 = load %struct.document*, %struct.document** %119
%121 = getelementptr inbounds %struct.document*, %struct.document** %3, i64 %118
store %struct.document* %120, %struct.document** %121
%122 = add nuw nsw i64 %114, 2
%123 = getelementptr inbounds %struct.document*, %struct.document** %0, i64 %122
%124 = load %struct.document*, %struct.document** %123
%125 = getelementptr inbounds %struct.document*, %struct.document** %3, i64 %122
store %struct.document* %124, %struct.document** %125
%126 = add nuw nsw i64 %114, 3
%127 = getelementptr inbounds %struct.document*, %struct.document** %0, i64 %126
%128 = load %struct.document*, %struct.document** %127
%129 = getelementptr inbounds %struct.document*, %struct.document** %3, i64 %126
store %struct.document* %128, %struct.document** %129
%130 = add nuw nsw i64 %114, 4
%131 = icmp eq i64 %130, %8
br i1 %131, label %132, label %113
132: ; preds = %110, %113, %93
%133 = tail call i32 @bubble_sort(%struct.document** %3, i32 %1)
br i1 %4, label %134, label %149
134: ; preds = %132
%135 = zext i32 %1 to i64
br label %136
136: ; preds = %134, %146
%137 = phi i64 [ 0, %134 ], [ %147, %146 ]
%138 = getelementptr inbounds %struct.document*, %struct.document** %3, i64 %137
%139 = load %struct.document*, %struct.document** %138
%140 = tail call i64 @hv_get_cos(%struct.document* %139)
%141 = icmp eq i64 %140, 0
br i1 %141, label %146, label %142
142: ; preds = %136
%143 = load %struct.document*, %struct.document** %138
%144 = tail call i8* @hv_get_name(%struct.document* %143)
%145 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %144)
br label %146
146: ; preds = %136, %142
%147 = add nuw nsw i64 %137, 1
%148 = icmp eq i64 %147, %135
br i1 %148, label %149, label %136
149: ; preds = %146, %5, %132
%150 = tail call i32 @free(%struct.document** %3)
ret void
}