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

; 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, ptr, ptr, i8 }

@vocab_size = external dso_local global i64, align 8
@table = external dso_local global ptr, align 8
@vocab = external dso_local global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local void @InitUnigramTable() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca double, align 8
  %4 = alloca double, align 8
  %5 = alloca double, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  store double 0.000000e+00, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  store double 7.500000e-01, ptr %5, align 8, !tbaa !5
  %6 = call noalias ptr @malloc(i64 noundef 400000000) #5
  store ptr %6, ptr @table, align 8, !tbaa !9
  store i32 0, ptr %1, align 4, !tbaa !11
  br label %7

7:                                                ; preds = %24, %0
  %8 = load i32, ptr %1, align 4, !tbaa !11
  %9 = sext i32 %8 to i64
  %10 = load i64, ptr @vocab_size, align 8, !tbaa !13
  %11 = icmp slt i64 %9, %10
  br i1 %11, label %12, label %27

12:                                               ; preds = %7
  %13 = load ptr, ptr @vocab, align 8, !tbaa !9
  %14 = load i32, ptr %1, align 4, !tbaa !11
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds %struct.vocab_word, ptr %13, i64 %15
  %17 = getelementptr inbounds %struct.vocab_word, ptr %16, i32 0, i32 0
  %18 = load i64, ptr %17, align 8, !tbaa !15
  %19 = sitofp i64 %18 to double
  %20 = load double, ptr %5, align 8, !tbaa !5
  %21 = call double @pow(double noundef %19, double noundef %20) #4
  %22 = load double, ptr %3, align 8, !tbaa !5
  %23 = fadd double %22, %21
  store double %23, ptr %3, align 8, !tbaa !5
  br label %24

24:                                               ; preds = %12
  %25 = load i32, ptr %1, align 4, !tbaa !11
  %26 = add nsw i32 %25, 1
  store i32 %26, ptr %1, align 4, !tbaa !11
  br label %7, !llvm.loop !17

27:                                               ; preds = %7
  store i32 0, ptr %2, align 4, !tbaa !11
  %28 = load ptr, ptr @vocab, align 8, !tbaa !9
  %29 = load i32, ptr %2, align 4, !tbaa !11
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds %struct.vocab_word, ptr %28, i64 %30
  %32 = getelementptr inbounds %struct.vocab_word, ptr %31, i32 0, i32 0
  %33 = load i64, ptr %32, align 8, !tbaa !15
  %34 = sitofp i64 %33 to double
  %35 = load double, ptr %5, align 8, !tbaa !5
  %36 = call double @pow(double noundef %34, double noundef %35) #4
  %37 = load double, ptr %3, align 8, !tbaa !5
  %38 = fdiv double %36, %37
  store double %38, ptr %4, align 8, !tbaa !5
  store i32 0, ptr %1, align 4, !tbaa !11
  br label %39

39:                                               ; preds = %79, %27
  %40 = load i32, ptr %1, align 4, !tbaa !11
  %41 = icmp slt i32 %40, 100000000
  br i1 %41, label %42, label %82

42:                                               ; preds = %39
  %43 = load i32, ptr %2, align 4, !tbaa !11
  %44 = load ptr, ptr @table, align 8, !tbaa !9
  %45 = load i32, ptr %1, align 4, !tbaa !11
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds i32, ptr %44, i64 %46
  store i32 %43, ptr %47, align 4, !tbaa !11
  %48 = load i32, ptr %1, align 4, !tbaa !11
  %49 = sitofp i32 %48 to double
  %50 = fdiv double %49, 1.000000e+08
  %51 = load double, ptr %4, align 8, !tbaa !5
  %52 = fcmp ogt double %50, %51
  br i1 %52, label %53, label %69

53:                                               ; preds = %42
  %54 = load i32, ptr %2, align 4, !tbaa !11
  %55 = add nsw i32 %54, 1
  store i32 %55, ptr %2, align 4, !tbaa !11
  %56 = load ptr, ptr @vocab, align 8, !tbaa !9
  %57 = load i32, ptr %2, align 4, !tbaa !11
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds %struct.vocab_word, ptr %56, i64 %58
  %60 = getelementptr inbounds %struct.vocab_word, ptr %59, i32 0, i32 0
  %61 = load i64, ptr %60, align 8, !tbaa !15
  %62 = sitofp i64 %61 to double
  %63 = load double, ptr %5, align 8, !tbaa !5
  %64 = call double @pow(double noundef %62, double noundef %63) #4
  %65 = load double, ptr %3, align 8, !tbaa !5
  %66 = fdiv double %64, %65
  %67 = load double, ptr %4, align 8, !tbaa !5
  %68 = fadd double %67, %66
  store double %68, ptr %4, align 8, !tbaa !5
  br label %69

69:                                               ; preds = %53, %42
  %70 = load i32, ptr %2, align 4, !tbaa !11
  %71 = sext i32 %70 to i64
  %72 = load i64, ptr @vocab_size, align 8, !tbaa !13
  %73 = icmp sge i64 %71, %72
  br i1 %73, label %74, label %78

74:                                               ; preds = %69
  %75 = load i64, ptr @vocab_size, align 8, !tbaa !13
  %76 = sub nsw i64 %75, 1
  %77 = trunc i64 %76 to i32
  store i32 %77, ptr %2, align 4, !tbaa !11
  br label %78

78:                                               ; preds = %74, %69
  br label %79

79:                                               ; preds = %78
  %80 = load i32, ptr %1, align 4, !tbaa !11
  %81 = add nsw i32 %80, 1
  store i32 %81, ptr %1, align 4, !tbaa !11
  br label %39, !llvm.loop !19

82:                                               ; preds = %39
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, 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
}

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

; Function Attrs: nounwind
declare double @pow(double noundef, double noundef) #3

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nounwind allocsize(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 #3 = { 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 #4 = { nounwind }
attributes #5 = { nounwind allocsize(0) }

!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 = !{!"double", !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, !14, i64 0}
!14 = !{!"long long", !7, i64 0}
!15 = !{!16, !14, i64 0}
!16 = !{!"vocab_word", !14, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !7, i64 32}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}


; 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, ptr, ptr, i8 }

@vocab_size = external dso_local local_unnamed_addr global i64, align 8
@table = external dso_local local_unnamed_addr global ptr, align 8
@vocab = external dso_local local_unnamed_addr global ptr, align 8

; Function Attrs: nofree nounwind uwtable
define dso_local void @InitUnigramTable() local_unnamed_addr #0 {
  %1 = tail call noalias dereferenceable_or_null(400000000) ptr @malloc(i64 noundef 400000000) #3
  store ptr %1, ptr @table, align 8, !tbaa !5
  %2 = load i64, ptr @vocab_size, align 8, !tbaa !9
  %3 = icmp sgt i64 %2, 0
  br i1 %3, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %0 ]
  %.02126 = phi double [ %9, %.lr.ph ], [ 0.000000e+00, %0 ]
  %4 = load ptr, ptr @vocab, align 8, !tbaa !5
  %5 = getelementptr inbounds %struct.vocab_word, ptr %4, i64 %indvars.iv
  %6 = load i64, ptr %5, align 8, !tbaa !11
  %7 = sitofp i64 %6 to double
  %8 = tail call double @pow(double noundef %7, double noundef 7.500000e-01) #4
  %9 = fadd double %.02126, %8
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %10 = load i64, ptr @vocab_size, align 8, !tbaa !9
  %11 = icmp sgt i64 %10, %indvars.iv.next
  br i1 %11, label %.lr.ph, label %._crit_edge, !llvm.loop !13

._crit_edge:                                      ; preds = %.lr.ph, %0
  %.021.lcssa = phi double [ 0.000000e+00, %0 ], [ %9, %.lr.ph ]
  %12 = load ptr, ptr @vocab, align 8, !tbaa !5
  %13 = load i64, ptr %12, align 8, !tbaa !11
  %14 = sitofp i64 %13 to double
  %15 = tail call double @pow(double noundef %14, double noundef 7.500000e-01) #4
  %16 = fdiv double %15, %.021.lcssa
  %.pre35 = load ptr, ptr @table, align 8, !tbaa !5
  br label %17

17:                                               ; preds = %._crit_edge, %34
  %18 = phi ptr [ %.pre35, %._crit_edge ], [ %35, %34 ]
  %indvars.iv32 = phi i64 [ 0, %._crit_edge ], [ %indvars.iv.next33, %34 ]
  %.01929 = phi double [ %16, %._crit_edge ], [ %.120, %34 ]
  %.02228 = phi i32 [ 0, %._crit_edge ], [ %.2, %34 ]
  %19 = getelementptr inbounds i32, ptr %18, i64 %indvars.iv32
  store i32 %.02228, ptr %19, align 4, !tbaa !15
  %20 = trunc nuw nsw i64 %indvars.iv32 to i32
  %21 = uitofp nneg i32 %20 to double
  %22 = fdiv double %21, 1.000000e+08
  %23 = fcmp ogt double %22, %.01929
  br i1 %23, label %24, label %._crit_edge36

._crit_edge36:                                    ; preds = %17
  %.pre37 = sext i32 %.02228 to i64
  br label %34

24:                                               ; preds = %17
  %25 = add nsw i32 %.02228, 1
  %26 = load ptr, ptr @vocab, align 8, !tbaa !5
  %27 = sext i32 %25 to i64
  %28 = getelementptr inbounds %struct.vocab_word, ptr %26, i64 %27
  %29 = load i64, ptr %28, align 8, !tbaa !11
  %30 = sitofp i64 %29 to double
  %31 = tail call double @pow(double noundef %30, double noundef 7.500000e-01) #4
  %32 = fdiv double %31, %.021.lcssa
  %33 = fadd double %.01929, %32
  %.pre = load ptr, ptr @table, align 8, !tbaa !5
  br label %34

34:                                               ; preds = %._crit_edge36, %24
  %.pre-phi = phi i64 [ %.pre37, %._crit_edge36 ], [ %27, %24 ]
  %35 = phi ptr [ %18, %._crit_edge36 ], [ %.pre, %24 ]
  %.123 = phi i32 [ %.02228, %._crit_edge36 ], [ %25, %24 ]
  %.120 = phi double [ %.01929, %._crit_edge36 ], [ %33, %24 ]
  %36 = load i64, ptr @vocab_size, align 8, !tbaa !9
  %.not = icmp sgt i64 %36, %.pre-phi
  %37 = trunc i64 %36 to i32
  %38 = add i32 %37, -1
  %.2 = select i1 %.not, i32 %.123, i32 %38
  %indvars.iv.next33 = add nuw nsw i64 %indvars.iv32, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next33, 100000000
  br i1 %exitcond.not, label %39, label %17, !llvm.loop !17

39:                                               ; preds = %34
  ret void
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @pow(double noundef, double noundef) local_unnamed_addr #2

attributes #0 = { nofree 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 nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(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 = { mustprogress nofree nounwind willreturn memory(write) "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 = { nounwind allocsize(0) }
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 = !{!"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, !10, i64 0}
!12 = !{!"vocab_word", !10, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !7, i64 32}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!16, !16, i64 0}
!16 = !{!"int", !7, i64 0}
!17 = distinct !{!17, !14}


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