; LLVM IR from thunlp/SE-WRL :: word2vec (word2phrase)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%struct.vocab_word = type { i64, ptr }

@min_count = external dso_local global i32, align 4
@vocab_size = external dso_local global i64, align 8
@vocab_hash = external dso_local global ptr, align 8
@vocab = external dso_local global ptr, align 8

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @GetWordHash(ptr noundef) #1

; Function Attrs: nounwind allocsize(1)
declare ptr @realloc(ptr noundef, i64 noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local i32 @VocabCompare(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @SortVocab() #1 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  %3 = load ptr, ptr @vocab, align 8, !tbaa !5
  %4 = getelementptr inbounds %struct.vocab_word, ptr %3, i64 1
  %5 = load i64, ptr @vocab_size, align 8, !tbaa !9
  %6 = sub nsw i64 %5, 1
  call void @qsort(ptr noundef %4, i64 noundef %6, i64 noundef 16, ptr noundef @VocabCompare)
  store i32 0, ptr %1, align 4, !tbaa !11
  br label %7

7:                                                ; preds = %15, %0
  %8 = load i32, ptr %1, align 4, !tbaa !11
  %9 = icmp slt i32 %8, 500000000
  br i1 %9, label %10, label %18

10:                                               ; preds = %7
  %11 = load ptr, ptr @vocab_hash, align 8, !tbaa !5
  %12 = load i32, ptr %1, align 4, !tbaa !11
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds i32, ptr %11, i64 %13
  store i32 -1, ptr %14, align 4, !tbaa !11
  br label %15

15:                                               ; preds = %10
  %16 = load i32, ptr %1, align 4, !tbaa !11
  %17 = add nsw i32 %16, 1
  store i32 %17, ptr %1, align 4, !tbaa !11
  br label %7, !llvm.loop !13

18:                                               ; preds = %7
  store i32 0, ptr %1, align 4, !tbaa !11
  br label %19

19:                                               ; preds = %68, %18
  %20 = load i32, ptr %1, align 4, !tbaa !11
  %21 = sext i32 %20 to i64
  %22 = load i64, ptr @vocab_size, align 8, !tbaa !9
  %23 = icmp slt i64 %21, %22
  br i1 %23, label %24, label %71

24:                                               ; preds = %19
  %25 = load ptr, ptr @vocab, align 8, !tbaa !5
  %26 = load i32, ptr %1, align 4, !tbaa !11
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds %struct.vocab_word, ptr %25, i64 %27
  %29 = getelementptr inbounds %struct.vocab_word, ptr %28, i32 0, i32 0
  %30 = load i64, ptr %29, align 8, !tbaa !15
  %31 = load i32, ptr @min_count, align 4, !tbaa !11
  %32 = sext i32 %31 to i64
  %33 = icmp slt i64 %30, %32
  br i1 %33, label %34, label %42

34:                                               ; preds = %24
  %35 = load i64, ptr @vocab_size, align 8, !tbaa !9
  %36 = add nsw i64 %35, -1
  store i64 %36, ptr @vocab_size, align 8, !tbaa !9
  %37 = load ptr, ptr @vocab, align 8, !tbaa !5
  %38 = load i64, ptr @vocab_size, align 8, !tbaa !9
  %39 = getelementptr inbounds %struct.vocab_word, ptr %37, i64 %38
  %40 = getelementptr inbounds %struct.vocab_word, ptr %39, i32 0, i32 1
  %41 = load ptr, ptr %40, align 8, !tbaa !17
  call void @free(ptr noundef %41) #5
  br label %67

42:                                               ; preds = %24
  %43 = load ptr, ptr @vocab, align 8, !tbaa !5
  %44 = load i32, ptr %1, align 4, !tbaa !11
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds %struct.vocab_word, ptr %43, i64 %45
  %47 = getelementptr inbounds %struct.vocab_word, ptr %46, i32 0, i32 1
  %48 = load ptr, ptr %47, align 8, !tbaa !17
  %49 = call i32 @GetWordHash(ptr noundef %48)
  store i32 %49, ptr %2, align 4, !tbaa !11
  br label %50

50:                                               ; preds = %57, %42
  %51 = load ptr, ptr @vocab_hash, align 8, !tbaa !5
  %52 = load i32, ptr %2, align 4, !tbaa !11
  %53 = zext i32 %52 to i64
  %54 = getelementptr inbounds i32, ptr %51, i64 %53
  %55 = load i32, ptr %54, align 4, !tbaa !11
  %56 = icmp ne i32 %55, -1
  br i1 %56, label %57, label %61

57:                                               ; preds = %50
  %58 = load i32, ptr %2, align 4, !tbaa !11
  %59 = add i32 %58, 1
  %60 = urem i32 %59, 500000000
  store i32 %60, ptr %2, align 4, !tbaa !11
  br label %50, !llvm.loop !18

61:                                               ; preds = %50
  %62 = load i32, ptr %1, align 4, !tbaa !11
  %63 = load ptr, ptr @vocab_hash, align 8, !tbaa !5
  %64 = load i32, ptr %2, align 4, !tbaa !11
  %65 = zext i32 %64 to i64
  %66 = getelementptr inbounds i32, ptr %63, i64 %65
  store i32 %62, ptr %66, align 4, !tbaa !11
  br label %67

67:                                               ; preds = %61, %34
  br label %68

68:                                               ; preds = %67
  %69 = load i32, ptr %1, align 4, !tbaa !11
  %70 = add nsw i32 %69, 1
  store i32 %70, ptr %1, align 4, !tbaa !11
  br label %19, !llvm.loop !19

71:                                               ; preds = %19
  %72 = load ptr, ptr @vocab, align 8, !tbaa !5
  %73 = load i64, ptr @vocab_size, align 8, !tbaa !9
  %74 = mul i64 %73, 16
  %75 = call ptr @realloc(ptr noundef %72, i64 noundef %74) #6
  store ptr %75, ptr @vocab, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #5
  ret void
}

declare void @qsort(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #3

; Function Attrs: nounwind
declare void @free(ptr noundef) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { nounwind allocsize(1) "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #4 = { nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #5 = { nounwind }
attributes #6 = { nounwind allocsize(1) }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!16, !10, i64 0}
!16 = !{!"vocab_word", !10, i64 0, !6, i64 8}
!17 = !{!16, !6, i64 8}
!18 = distinct !{!18, !14}
!19 = distinct !{!19, !14}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%struct.vocab_word = type { i64, ptr }

@min_count = external dso_local local_unnamed_addr global i32, align 4
@vocab_size = external dso_local local_unnamed_addr global i64, align 8
@vocab_hash = external dso_local local_unnamed_addr global ptr, align 8
@vocab = external dso_local local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
declare dso_local i32 @GetWordHash(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias noundef ptr @realloc(ptr allocptr nocapture noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @VocabCompare(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local void @SortVocab() local_unnamed_addr #0 {
.preheader:
  %0 = load ptr, ptr @vocab, align 8, !tbaa !5
  %1 = getelementptr inbounds i8, ptr %0, i64 16
  %2 = load i64, ptr @vocab_size, align 8, !tbaa !9
  %3 = add nsw i64 %2, -1
  tail call void @qsort(ptr noundef nonnull %1, i64 noundef %3, i64 noundef 16, ptr noundef nonnull @VocabCompare) #5
  %4 = load ptr, ptr @vocab_hash, align 8, !tbaa !5
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(2000000000) %4, i8 -1, i64 2000000000, i1 false), !tbaa !11
  %5 = load i64, ptr @vocab_size, align 8, !tbaa !9
  %6 = icmp sgt i64 %5, 0
  br i1 %6, label %.lr.ph23, label %._crit_edge24

.lr.ph23:                                         ; preds = %.preheader, %33
  %indvars.iv = phi i64 [ %indvars.iv.next, %33 ], [ 0, %.preheader ]
  %7 = phi i64 [ %34, %33 ], [ %5, %.preheader ]
  %8 = load ptr, ptr @vocab, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.vocab_word, ptr %8, i64 %indvars.iv
  %10 = load i64, ptr %9, align 8, !tbaa !13
  %11 = load i32, ptr @min_count, align 4, !tbaa !11
  %12 = sext i32 %11 to i64
  %13 = icmp slt i64 %10, %12
  br i1 %13, label %14, label %18

14:                                               ; preds = %.lr.ph23
  %15 = add nsw i64 %7, -1
  store i64 %15, ptr @vocab_size, align 8, !tbaa !9
  %16 = getelementptr inbounds %struct.vocab_word, ptr %8, i64 %15, i32 1
  %17 = load ptr, ptr %16, align 8, !tbaa !15
  tail call void @free(ptr noundef %17) #5
  br label %33

18:                                               ; preds = %.lr.ph23
  %19 = getelementptr inbounds i8, ptr %9, i64 8
  %20 = load ptr, ptr %19, align 8, !tbaa !15
  %21 = tail call i32 @GetWordHash(ptr noundef %20)
  %22 = load ptr, ptr @vocab_hash, align 8, !tbaa !5
  %23 = zext i32 %21 to i64
  %24 = getelementptr inbounds i32, ptr %22, i64 %23
  %25 = load i32, ptr %24, align 4, !tbaa !11
  %.not19 = icmp eq i32 %25, -1
  br i1 %.not19, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %18, %.lr.ph
  %.020 = phi i32 [ %27, %.lr.ph ], [ %21, %18 ]
  %26 = add i32 %.020, 1
  %27 = urem i32 %26, 500000000
  %28 = zext nneg i32 %27 to i64
  %29 = getelementptr inbounds i32, ptr %22, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !11
  %.not = icmp eq i32 %30, -1
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !16

._crit_edge:                                      ; preds = %.lr.ph, %18
  %.lcssa18 = phi i64 [ %23, %18 ], [ %28, %.lr.ph ]
  %31 = getelementptr inbounds i32, ptr %22, i64 %.lcssa18
  %32 = trunc nuw nsw i64 %indvars.iv to i32
  store i32 %32, ptr %31, align 4, !tbaa !11
  br label %33

33:                                               ; preds = %14, %._crit_edge
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %34 = load i64, ptr @vocab_size, align 8, !tbaa !9
  %35 = icmp sgt i64 %34, %indvars.iv.next
  br i1 %35, label %.lr.ph23, label %._crit_edge24, !llvm.loop !18

._crit_edge24:                                    ; preds = %33, %.preheader
  %.lcssa15 = phi i64 [ %5, %.preheader ], [ %34, %33 ]
  %36 = load ptr, ptr @vocab, align 8, !tbaa !5
  %37 = shl i64 %.lcssa15, 4
  %38 = tail call ptr @realloc(ptr noundef %36, i64 noundef %37) #6
  store ptr %38, ptr @vocab, align 8, !tbaa !5
  ret void
}

; Function Attrs: nofree
declare void @qsort(ptr noundef, i64 noundef, i64 noundef, ptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #3

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

attributes #0 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { nofree "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #4 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { nounwind }
attributes #6 = { nounwind allocsize(1) }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !10, i64 0}
!14 = !{!"vocab_word", !10, i64 0, !6, i64 8}
!15 = !{!14, !6, i64 8}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopIdiomRecognizePass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass