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

@debug_mode = external dso_local global i32, align 4
@vocab_size = external dso_local global i64, align 8
@train_words = external dso_local global i64, align 8
@file_size = external dso_local global i64, align 8
@vocab = external dso_local global ptr, align 8
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@vocab_hash = external dso_local global ptr, align 8
@stdout = external global ptr, align 8
@train_file = external dso_local global [100 x i8], align 16
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [38 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [27 x i8], align 1

; 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 void @ReadWord(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind
declare i32 @feof(ptr noundef) #2

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @SortVocab() #1

; Function Attrs: nounwind uwtable
declare dso_local void @ReduceVocab() #1

declare i32 @fflush(ptr noundef) #3

; Function Attrs: nounwind uwtable
define dso_local void @LearnVocabFromTrainFile() #1 {
  %1 = alloca [100 x i8], align 16
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 100, ptr %1) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  store i64 0, ptr %3, align 8, !tbaa !5
  br label %5

5:                                                ; preds = %12, %0
  %6 = load i64, ptr %3, align 8, !tbaa !5
  %7 = icmp slt i64 %6, 30000000
  br i1 %7, label %8, label %15

8:                                                ; preds = %5
  %9 = load ptr, ptr @vocab_hash, align 8, !tbaa !9
  %10 = load i64, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds i32, ptr %9, i64 %10
  store i32 -1, ptr %11, align 4, !tbaa !11
  br label %12

12:                                               ; preds = %8
  %13 = load i64, ptr %3, align 8, !tbaa !5
  %14 = add nsw i64 %13, 1
  store i64 %14, ptr %3, align 8, !tbaa !5
  br label %5, !llvm.loop !13

15:                                               ; preds = %5
  %16 = call noalias ptr @fopen(ptr noundef @train_file, ptr noundef @.str.1)
  store ptr %16, ptr %2, align 8, !tbaa !9
  %17 = load ptr, ptr %2, align 8, !tbaa !9
  %18 = icmp eq ptr %17, null
  br i1 %18, label %19, label %21

19:                                               ; preds = %15
  %20 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  call void @exit(i32 noundef 1) #6
  unreachable

21:                                               ; preds = %15
  store i64 0, ptr @vocab_size, align 8, !tbaa !5
  %22 = call i32 @AddWordToVocab(ptr noundef @.str)
  br label %23

23:                                               ; preds = %72, %21
  br label %24

24:                                               ; preds = %23
  %25 = getelementptr inbounds [100 x i8], ptr %1, i64 0, i64 0
  %26 = load ptr, ptr %2, align 8, !tbaa !9
  call void @ReadWord(ptr noundef %25, ptr noundef %26)
  %27 = load ptr, ptr %2, align 8, !tbaa !9
  %28 = call i32 @feof(ptr noundef %27) #5
  %29 = icmp ne i32 %28, 0
  br i1 %29, label %30, label %31

30:                                               ; preds = %24
  br label %73

31:                                               ; preds = %24
  %32 = load i64, ptr @train_words, align 8, !tbaa !5
  %33 = add nsw i64 %32, 1
  store i64 %33, ptr @train_words, align 8, !tbaa !5
  %34 = load i32, ptr @debug_mode, align 4, !tbaa !11
  %35 = icmp sgt i32 %34, 1
  br i1 %35, label %36, label %46

36:                                               ; preds = %31
  %37 = load i64, ptr @train_words, align 8, !tbaa !5
  %38 = srem i64 %37, 100000
  %39 = icmp eq i64 %38, 0
  br i1 %39, label %40, label %46

40:                                               ; preds = %36
  %41 = load i64, ptr @train_words, align 8, !tbaa !5
  %42 = sdiv i64 %41, 1000
  %43 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i64 noundef %42, i32 noundef 13)
  %44 = load ptr, ptr @stdout, align 8, !tbaa !9
  %45 = call i32 @fflush(ptr noundef %44)
  br label %46

46:                                               ; preds = %40, %36, %31
  %47 = getelementptr inbounds [100 x i8], ptr %1, i64 0, i64 0
  %48 = call i32 @SearchVocab(ptr noundef %47)
  %49 = sext i32 %48 to i64
  store i64 %49, ptr %4, align 8, !tbaa !5
  %50 = load i64, ptr %4, align 8, !tbaa !5
  %51 = icmp eq i64 %50, -1
  br i1 %51, label %52, label %60

52:                                               ; preds = %46
  %53 = getelementptr inbounds [100 x i8], ptr %1, i64 0, i64 0
  %54 = call i32 @AddWordToVocab(ptr noundef %53)
  %55 = sext i32 %54 to i64
  store i64 %55, ptr %3, align 8, !tbaa !5
  %56 = load ptr, ptr @vocab, align 8, !tbaa !9
  %57 = load i64, ptr %3, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.vocab_word, ptr %56, i64 %57
  %59 = getelementptr inbounds %struct.vocab_word, ptr %58, i32 0, i32 0
  store i64 1, ptr %59, align 8, !tbaa !15
  br label %67

60:                                               ; preds = %46
  %61 = load ptr, ptr @vocab, align 8, !tbaa !9
  %62 = load i64, ptr %4, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.vocab_word, ptr %61, i64 %62
  %64 = getelementptr inbounds %struct.vocab_word, ptr %63, i32 0, i32 0
  %65 = load i64, ptr %64, align 8, !tbaa !15
  %66 = add nsw i64 %65, 1
  store i64 %66, ptr %64, align 8, !tbaa !15
  br label %67

67:                                               ; preds = %60, %52
  %68 = load i64, ptr @vocab_size, align 8, !tbaa !5
  %69 = sitofp i64 %68 to double
  %70 = fcmp ogt double %69, 2.100000e+07
  br i1 %70, label %71, label %72

71:                                               ; preds = %67
  call void @ReduceVocab()
  br label %72

72:                                               ; preds = %71, %67
  br label %23

73:                                               ; preds = %30
  call void @SortVocab()
  %74 = load i32, ptr @debug_mode, align 4, !tbaa !11
  %75 = icmp sgt i32 %74, 0
  br i1 %75, label %76, label %81

76:                                               ; preds = %73
  %77 = load i64, ptr @vocab_size, align 8, !tbaa !5
  %78 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, i64 noundef %77)
  %79 = load i64, ptr @train_words, align 8, !tbaa !5
  %80 = call i32 (ptr, ...) @printf(ptr noundef @.str.5, i64 noundef %79)
  br label %81

81:                                               ; preds = %76, %73
  %82 = load ptr, ptr %2, align 8, !tbaa !9
  %83 = call i64 @ftell(ptr noundef %82)
  store i64 %83, ptr @file_size, align 8, !tbaa !5
  %84 = load ptr, ptr %2, align 8, !tbaa !9
  %85 = call i32 @fclose(ptr noundef %84)
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #5
  call void @llvm.lifetime.end.p0(i64 100, ptr %1) #5
  ret void
}

declare noalias ptr @fopen(ptr noundef, ptr noundef) #3

declare i32 @printf(ptr noundef, ...) #3

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #4

declare i64 @ftell(ptr noundef) #3

declare i32 @fclose(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 = { noreturn 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 = { noreturn 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 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!16, !6, i64 0}
!16 = !{!"vocab_word", !6, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !7, i64 32}


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

@debug_mode = external dso_local local_unnamed_addr global i32, align 4
@vocab_size = external dso_local local_unnamed_addr global i64, align 8
@train_words = external dso_local local_unnamed_addr global i64, align 8
@file_size = external dso_local local_unnamed_addr global i64, align 8
@vocab = external dso_local local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@vocab_hash = external dso_local local_unnamed_addr global ptr, align 8
@stdout = external local_unnamed_addr global ptr, align 8
@train_file = external dso_local global [100 x i8], align 16
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [38 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [27 x i8], align 1

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

; Function Attrs: mustprogress 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 void @ReadWord(ptr noundef, ptr noundef) local_unnamed_addr #1

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @SortVocab() local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @ReduceVocab() local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
define dso_local void @LearnVocabFromTrainFile() local_unnamed_addr #1 {
  %1 = alloca [100 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 100, ptr nonnull %1) #5
  %2 = load ptr, ptr @vocab_hash, align 8, !tbaa !5
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(120000000) %2, i8 -1, i64 120000000, i1 false), !tbaa !9
  %3 = tail call noalias ptr @fopen(ptr noundef nonnull @train_file, ptr noundef nonnull @.str.1)
  %4 = icmp eq ptr %3, null
  br i1 %4, label %5, label %7

5:                                                ; preds = %0
  %6 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  tail call void @exit(i32 noundef 1) #6
  unreachable

7:                                                ; preds = %0
  store i64 0, ptr @vocab_size, align 8, !tbaa !11
  %8 = tail call i32 @AddWordToVocab(ptr noundef nonnull @.str)
  call void @ReadWord(ptr noundef nonnull %1, ptr noundef nonnull %3)
  %9 = call i32 @feof(ptr noundef nonnull %3) #5
  %.not14 = icmp eq i32 %9, 0
  br i1 %.not14, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %7, %39
  %10 = load i64, ptr @train_words, align 8, !tbaa !11
  %11 = add nsw i64 %10, 1
  store i64 %11, ptr @train_words, align 8, !tbaa !11
  %12 = load i32, ptr @debug_mode, align 4, !tbaa !9
  %13 = icmp sgt i32 %12, 1
  %14 = srem i64 %11, 100000
  %15 = icmp eq i64 %14, 0
  %or.cond = select i1 %13, i1 %15, i1 false
  br i1 %or.cond, label %16, label %21

16:                                               ; preds = %.lr.ph
  %17 = sdiv i64 %11, 1000
  %18 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i64 noundef %17, i32 noundef 13)
  %19 = load ptr, ptr @stdout, align 8, !tbaa !5
  %20 = call i32 @fflush(ptr noundef %19)
  br label %21

21:                                               ; preds = %16, %.lr.ph
  %22 = call i32 @SearchVocab(ptr noundef nonnull %1)
  %23 = icmp eq i32 %22, -1
  br i1 %23, label %24, label %29

24:                                               ; preds = %21
  %25 = call i32 @AddWordToVocab(ptr noundef nonnull %1)
  %26 = sext i32 %25 to i64
  %27 = load ptr, ptr @vocab, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.vocab_word, ptr %27, i64 %26
  store i64 1, ptr %28, align 8, !tbaa !13
  br label %35

29:                                               ; preds = %21
  %30 = sext i32 %22 to i64
  %31 = load ptr, ptr @vocab, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.vocab_word, ptr %31, i64 %30
  %33 = load i64, ptr %32, align 8, !tbaa !13
  %34 = add nsw i64 %33, 1
  store i64 %34, ptr %32, align 8, !tbaa !13
  br label %35

35:                                               ; preds = %29, %24
  %36 = load i64, ptr @vocab_size, align 8, !tbaa !11
  %37 = icmp sgt i64 %36, 21000000
  br i1 %37, label %38, label %39

38:                                               ; preds = %35
  call void @ReduceVocab()
  br label %39

39:                                               ; preds = %38, %35
  call void @ReadWord(ptr noundef nonnull %1, ptr noundef nonnull %3)
  %40 = call i32 @feof(ptr noundef nonnull %3) #5
  %.not = icmp eq i32 %40, 0
  br i1 %.not, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %39, %7
  call void @SortVocab()
  %41 = load i32, ptr @debug_mode, align 4, !tbaa !9
  %42 = icmp sgt i32 %41, 0
  br i1 %42, label %43, label %48

43:                                               ; preds = %._crit_edge
  %44 = load i64, ptr @vocab_size, align 8, !tbaa !11
  %45 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, i64 noundef %44)
  %46 = load i64, ptr @train_words, align 8, !tbaa !11
  %47 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5, i64 noundef %46)
  br label %48

48:                                               ; preds = %43, %._crit_edge
  %49 = call i64 @ftell(ptr noundef nonnull %3)
  store i64 %49, ptr @file_size, align 8, !tbaa !11
  %50 = call i32 @fclose(ptr noundef nonnull %3)
  call void @llvm.lifetime.end.p0(i64 100, ptr nonnull %1) #5
  ret void
}

; Function Attrs: nofree nounwind
declare noalias noundef ptr @fopen(ptr nocapture noundef readonly, ptr nocapture noundef readonly) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #3

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

; Function Attrs: nofree nounwind
declare noundef i32 @fclose(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) #4

attributes #0 = { mustprogress 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 = { 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 = { noreturn 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { nounwind }
attributes #6 = { noreturn 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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = !{!14, !12, i64 0}
!14 = !{!"vocab_word", !12, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !7, i64 32}


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