; 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_reduce = 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
@stdout = external 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
declare void @free(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @ReduceVocab() #1 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %4

4:                                                ; preds = %52, %0
  %5 = load i32, ptr %1, align 4, !tbaa !5
  %6 = sext i32 %5 to i64
  %7 = load i64, ptr @vocab_size, align 8, !tbaa !9
  %8 = icmp slt i64 %6, %7
  br i1 %8, label %9, label %55

9:                                                ; preds = %4
  %10 = load ptr, ptr @vocab, align 8, !tbaa !11
  %11 = load i32, ptr %1, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds %struct.vocab_word, ptr %10, i64 %12
  %14 = getelementptr inbounds %struct.vocab_word, ptr %13, i32 0, i32 0
  %15 = load i64, ptr %14, align 8, !tbaa !13
  %16 = load i32, ptr @min_reduce, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = icmp sgt i64 %15, %17
  br i1 %18, label %19, label %44

19:                                               ; preds = %9
  %20 = load ptr, ptr @vocab, align 8, !tbaa !11
  %21 = load i32, ptr %1, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds %struct.vocab_word, ptr %20, i64 %22
  %24 = getelementptr inbounds %struct.vocab_word, ptr %23, i32 0, i32 0
  %25 = load i64, ptr %24, align 8, !tbaa !13
  %26 = load ptr, ptr @vocab, align 8, !tbaa !11
  %27 = load i32, ptr %2, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds %struct.vocab_word, ptr %26, i64 %28
  %30 = getelementptr inbounds %struct.vocab_word, ptr %29, i32 0, i32 0
  store i64 %25, ptr %30, align 8, !tbaa !13
  %31 = load ptr, ptr @vocab, align 8, !tbaa !11
  %32 = load i32, ptr %1, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds %struct.vocab_word, ptr %31, i64 %33
  %35 = getelementptr inbounds %struct.vocab_word, ptr %34, i32 0, i32 1
  %36 = load ptr, ptr %35, align 8, !tbaa !15
  %37 = load ptr, ptr @vocab, align 8, !tbaa !11
  %38 = load i32, ptr %2, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds %struct.vocab_word, ptr %37, i64 %39
  %41 = getelementptr inbounds %struct.vocab_word, ptr %40, i32 0, i32 1
  store ptr %36, ptr %41, align 8, !tbaa !15
  %42 = load i32, ptr %2, align 4, !tbaa !5
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr %2, align 4, !tbaa !5
  br label %51

44:                                               ; preds = %9
  %45 = load ptr, ptr @vocab, align 8, !tbaa !11
  %46 = load i32, ptr %1, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds %struct.vocab_word, ptr %45, i64 %47
  %49 = getelementptr inbounds %struct.vocab_word, ptr %48, i32 0, i32 1
  %50 = load ptr, ptr %49, align 8, !tbaa !15
  call void @free(ptr noundef %50) #4
  br label %51

51:                                               ; preds = %44, %19
  br label %52

52:                                               ; preds = %51
  %53 = load i32, ptr %1, align 4, !tbaa !5
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr %1, align 4, !tbaa !5
  br label %4, !llvm.loop !16

55:                                               ; preds = %4
  %56 = load i32, ptr %2, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  store i64 %57, ptr @vocab_size, align 8, !tbaa !9
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %58

58:                                               ; preds = %66, %55
  %59 = load i32, ptr %1, align 4, !tbaa !5
  %60 = icmp slt i32 %59, 500000000
  br i1 %60, label %61, label %69

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

66:                                               ; preds = %61
  %67 = load i32, ptr %1, align 4, !tbaa !5
  %68 = add nsw i32 %67, 1
  store i32 %68, ptr %1, align 4, !tbaa !5
  br label %58, !llvm.loop !18

69:                                               ; preds = %58
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %70

70:                                               ; preds = %100, %69
  %71 = load i32, ptr %1, align 4, !tbaa !5
  %72 = sext i32 %71 to i64
  %73 = load i64, ptr @vocab_size, align 8, !tbaa !9
  %74 = icmp slt i64 %72, %73
  br i1 %74, label %75, label %103

75:                                               ; preds = %70
  %76 = load ptr, ptr @vocab, align 8, !tbaa !11
  %77 = load i32, ptr %1, align 4, !tbaa !5
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds %struct.vocab_word, ptr %76, i64 %78
  %80 = getelementptr inbounds %struct.vocab_word, ptr %79, i32 0, i32 1
  %81 = load ptr, ptr %80, align 8, !tbaa !15
  %82 = call i32 @GetWordHash(ptr noundef %81)
  store i32 %82, ptr %3, align 4, !tbaa !5
  br label %83

83:                                               ; preds = %90, %75
  %84 = load ptr, ptr @vocab_hash, align 8, !tbaa !11
  %85 = load i32, ptr %3, align 4, !tbaa !5
  %86 = zext i32 %85 to i64
  %87 = getelementptr inbounds i32, ptr %84, i64 %86
  %88 = load i32, ptr %87, align 4, !tbaa !5
  %89 = icmp ne i32 %88, -1
  br i1 %89, label %90, label %94

90:                                               ; preds = %83
  %91 = load i32, ptr %3, align 4, !tbaa !5
  %92 = add i32 %91, 1
  %93 = urem i32 %92, 500000000
  store i32 %93, ptr %3, align 4, !tbaa !5
  br label %83, !llvm.loop !19

94:                                               ; preds = %83
  %95 = load i32, ptr %1, align 4, !tbaa !5
  %96 = load ptr, ptr @vocab_hash, align 8, !tbaa !11
  %97 = load i32, ptr %3, align 4, !tbaa !5
  %98 = zext i32 %97 to i64
  %99 = getelementptr inbounds i32, ptr %96, i64 %98
  store i32 %95, ptr %99, align 4, !tbaa !5
  br label %100

100:                                              ; preds = %94
  %101 = load i32, ptr %1, align 4, !tbaa !5
  %102 = add nsw i32 %101, 1
  store i32 %102, ptr %1, align 4, !tbaa !5
  br label %70, !llvm.loop !20

103:                                              ; preds = %70
  %104 = load ptr, ptr @stdout, align 8, !tbaa !11
  %105 = call i32 @fflush(ptr noundef %104)
  %106 = load i32, ptr @min_reduce, align 4, !tbaa !5
  %107 = add nsw i32 %106, 1
  store i32 %107, ptr @min_reduce, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #4
  ret void
}

declare i32 @fflush(ptr noundef) #3

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 "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 }

!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 = !{!"int", !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 = !{!"any pointer", !7, i64 0}
!13 = !{!14, !10, i64 0}
!14 = !{!"vocab_word", !10, i64 0, !12, i64 8}
!15 = !{!14, !12, i64 8}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}
!19 = distinct !{!19, !17}
!20 = distinct !{!20, !17}


; 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_reduce = 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
@stdout = external 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("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @ReduceVocab() local_unnamed_addr #0 {
  %1 = load i64, ptr @vocab_size, align 8, !tbaa !5
  %2 = icmp sgt i64 %1, 0
  br i1 %2, label %.lr.ph.preheader, label %._crit_edge.thread

._crit_edge.thread:                               ; preds = %0
  store i64 0, ptr @vocab_size, align 8, !tbaa !5
  %3 = load ptr, ptr @vocab_hash, align 8, !tbaa !9
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(2000000000) %3, i8 -1, i64 2000000000, i1 false), !tbaa !11
  br label %._crit_edge40

.lr.ph.preheader:                                 ; preds = %0
  %.pre48 = load i32, ptr @min_reduce, align 4, !tbaa !11
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %20
  %4 = phi i32 [ %.pre48, %.lr.ph.preheader ], [ %21, %20 ]
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %20 ]
  %.02027 = phi i32 [ 0, %.lr.ph.preheader ], [ %.1, %20 ]
  %5 = load ptr, ptr @vocab, align 8, !tbaa !9
  %6 = getelementptr inbounds %struct.vocab_word, ptr %5, i64 %indvars.iv
  %7 = load i64, ptr %6, align 8, !tbaa !13
  %8 = sext i32 %4 to i64
  %9 = icmp sgt i64 %7, %8
  br i1 %9, label %10, label %17

10:                                               ; preds = %.lr.ph
  %11 = sext i32 %.02027 to i64
  %12 = getelementptr inbounds %struct.vocab_word, ptr %5, i64 %11
  store i64 %7, ptr %12, align 8, !tbaa !13
  %13 = getelementptr inbounds %struct.vocab_word, ptr %5, i64 %indvars.iv, i32 1
  %14 = load ptr, ptr %13, align 8, !tbaa !15
  %15 = getelementptr inbounds %struct.vocab_word, ptr %5, i64 %11, i32 1
  store ptr %14, ptr %15, align 8, !tbaa !15
  %16 = add nsw i32 %.02027, 1
  br label %20

17:                                               ; preds = %.lr.ph
  %18 = getelementptr inbounds i8, ptr %6, i64 8
  %19 = load ptr, ptr %18, align 8, !tbaa !15
  tail call void @free(ptr noundef %19) #4
  %.pre = load i32, ptr @min_reduce, align 4, !tbaa !11
  br label %20

20:                                               ; preds = %10, %17
  %21 = phi i32 [ %4, %10 ], [ %.pre, %17 ]
  %.1 = phi i32 [ %16, %10 ], [ %.02027, %17 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %22 = load i64, ptr @vocab_size, align 8, !tbaa !5
  %23 = icmp sgt i64 %22, %indvars.iv.next
  br i1 %23, label %.lr.ph, label %._crit_edge, !llvm.loop !16

._crit_edge:                                      ; preds = %20
  %24 = sext i32 %.1 to i64
  store i64 %24, ptr @vocab_size, align 8, !tbaa !5
  %25 = load ptr, ptr @vocab_hash, align 8, !tbaa !9
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(2000000000) %25, i8 -1, i64 2000000000, i1 false), !tbaa !11
  %26 = icmp sgt i32 %.1, 0
  br i1 %26, label %.lr.ph39, label %._crit_edge40

.lr.ph39:                                         ; preds = %._crit_edge, %._crit_edge35
  %indvars.iv45 = phi i64 [ %indvars.iv.next46, %._crit_edge35 ], [ 0, %._crit_edge ]
  %27 = load ptr, ptr @vocab, align 8, !tbaa !9
  %28 = getelementptr inbounds %struct.vocab_word, ptr %27, i64 %indvars.iv45, i32 1
  %29 = load ptr, ptr %28, align 8, !tbaa !15
  %30 = tail call i32 @GetWordHash(ptr noundef %29)
  %31 = load ptr, ptr @vocab_hash, align 8, !tbaa !9
  %32 = zext i32 %30 to i64
  %33 = getelementptr inbounds i32, ptr %31, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !11
  %.not31 = icmp eq i32 %34, -1
  br i1 %.not31, label %._crit_edge35, label %.lr.ph34

.lr.ph34:                                         ; preds = %.lr.ph39, %.lr.ph34
  %.032 = phi i32 [ %36, %.lr.ph34 ], [ %30, %.lr.ph39 ]
  %35 = add i32 %.032, 1
  %36 = urem i32 %35, 500000000
  %37 = zext nneg i32 %36 to i64
  %38 = getelementptr inbounds i32, ptr %31, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !11
  %.not = icmp eq i32 %39, -1
  br i1 %.not, label %._crit_edge35, label %.lr.ph34, !llvm.loop !18

._crit_edge35:                                    ; preds = %.lr.ph34, %.lr.ph39
  %.lcssa30 = phi i64 [ %32, %.lr.ph39 ], [ %37, %.lr.ph34 ]
  %40 = getelementptr inbounds i32, ptr %31, i64 %.lcssa30
  %41 = trunc nuw nsw i64 %indvars.iv45 to i32
  store i32 %41, ptr %40, align 4, !tbaa !11
  %indvars.iv.next46 = add nuw nsw i64 %indvars.iv45, 1
  %42 = load i64, ptr @vocab_size, align 8, !tbaa !5
  %43 = icmp sgt i64 %42, %indvars.iv.next46
  br i1 %43, label %.lr.ph39, label %._crit_edge40, !llvm.loop !19

._crit_edge40:                                    ; preds = %._crit_edge35, %._crit_edge.thread, %._crit_edge
  %44 = load ptr, ptr @stdout, align 8, !tbaa !9
  %45 = tail call i32 @fflush(ptr noundef %44)
  %46 = load i32, ptr @min_reduce, align 4, !tbaa !11
  %47 = add nsw i32 %46, 1
  store i32 %47, ptr @min_reduce, align 4, !tbaa !11
  ret void
}

; Function Attrs: nofree nounwind
declare noundef i32 @fflush(ptr nocapture noundef) local_unnamed_addr #2

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

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("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 #2 = { nofree 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 #3 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { nounwind }

!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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"vocab_word", !6, i64 0, !10, i64 8}
!15 = !{!14, !10, i64 8}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}
!19 = distinct !{!19, !17}


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