; 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
@vocab_hash = external dso_local 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.4 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [27 x i8], align 1
@read_vocab_file = external dso_local global [100 x i8], align 16
@.str.8 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [7 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 @AddWordToVocab(ptr noundef) #1

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

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

; Function Attrs: nounwind uwtable
define dso_local void @ReadVocab() #1 {
  %1 = alloca i64, align 8
  %2 = alloca i64, align 8
  %3 = alloca i8, align 1
  %4 = alloca [100 x i8], align 16
  %5 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #5
  store i64 0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %3) #5
  call void @llvm.lifetime.start.p0(i64 100, ptr %4) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %6 = call noalias ptr @fopen(ptr noundef @read_vocab_file, ptr noundef @.str.1)
  store ptr %6, ptr %5, align 8, !tbaa !9
  %7 = load ptr, ptr %5, align 8, !tbaa !9
  %8 = icmp eq ptr %7, null
  br i1 %8, label %9, label %11

9:                                                ; preds = %0
  %10 = call i32 (ptr, ...) @printf(ptr noundef @.str.8)
  call void @exit(i32 noundef 1) #6
  unreachable

11:                                               ; preds = %0
  store i64 0, ptr %1, align 8, !tbaa !5
  br label %12

12:                                               ; preds = %19, %11
  %13 = load i64, ptr %1, align 8, !tbaa !5
  %14 = icmp slt i64 %13, 30000000
  br i1 %14, label %15, label %22

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

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

22:                                               ; preds = %12
  store i64 0, ptr @vocab_size, align 8, !tbaa !5
  br label %23

23:                                               ; preds = %50, %22
  br label %24

24:                                               ; preds = %23
  %25 = getelementptr inbounds [100 x i8], ptr %4, i64 0, i64 0
  %26 = load ptr, ptr %5, align 8, !tbaa !9
  call void @ReadWord(ptr noundef %25, ptr noundef %26)
  %27 = load ptr, ptr %5, 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 %51

31:                                               ; preds = %24
  %32 = getelementptr inbounds [100 x i8], ptr %4, i64 0, i64 0
  %33 = call i32 @AddWordToVocab(ptr noundef %32)
  %34 = sext i32 %33 to i64
  store i64 %34, ptr %1, align 8, !tbaa !5
  %35 = load ptr, ptr %5, align 8, !tbaa !9
  %36 = load ptr, ptr @vocab, align 8, !tbaa !9
  %37 = load i64, ptr %1, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.vocab_word, ptr %36, i64 %37
  %39 = getelementptr inbounds %struct.vocab_word, ptr %38, i32 0, i32 0
  %40 = call i32 (ptr, ptr, ...) @__isoc99_fscanf(ptr noundef %35, ptr noundef @.str.9, ptr noundef %39, ptr noundef %3)
  %41 = load i64, ptr %2, align 8, !tbaa !5
  %42 = add nsw i64 %41, 1
  store i64 %42, ptr %2, align 8, !tbaa !5
  %43 = load ptr, ptr @vocab, align 8, !tbaa !9
  %44 = load i64, ptr %1, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.vocab_word, ptr %43, i64 %44
  %46 = getelementptr inbounds %struct.vocab_word, ptr %45, i32 0, i32 0
  %47 = load i64, ptr %46, align 8, !tbaa !15
  %48 = icmp slt i64 %47, 50
  br i1 %48, label %49, label %50

49:                                               ; preds = %31
  br label %51

50:                                               ; preds = %31
  br label %23

51:                                               ; preds = %49, %30
  call void @SortVocab()
  %52 = load i32, ptr @debug_mode, align 4, !tbaa !11
  %53 = icmp sgt i32 %52, 0
  br i1 %53, label %54, label %59

54:                                               ; preds = %51
  %55 = load i64, ptr @vocab_size, align 8, !tbaa !5
  %56 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, i64 noundef %55)
  %57 = load i64, ptr @train_words, align 8, !tbaa !5
  %58 = call i32 (ptr, ...) @printf(ptr noundef @.str.5, i64 noundef %57)
  br label %59

59:                                               ; preds = %54, %51
  %60 = call noalias ptr @fopen(ptr noundef @train_file, ptr noundef @.str.1)
  store ptr %60, ptr %5, align 8, !tbaa !9
  %61 = load ptr, ptr %5, align 8, !tbaa !9
  %62 = icmp eq ptr %61, null
  br i1 %62, label %63, label %65

63:                                               ; preds = %59
  %64 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  call void @exit(i32 noundef 1) #6
  unreachable

65:                                               ; preds = %59
  %66 = load ptr, ptr %5, align 8, !tbaa !9
  %67 = call i32 @fseek(ptr noundef %66, i64 noundef 0, i32 noundef 2)
  %68 = load ptr, ptr %5, align 8, !tbaa !9
  %69 = call i64 @ftell(ptr noundef %68)
  store i64 %69, ptr @file_size, align 8, !tbaa !5
  %70 = load ptr, ptr %5, align 8, !tbaa !9
  %71 = call i32 @fclose(ptr noundef %70)
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 100, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 1, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #5
  ret void
}

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

declare i32 @fseek(ptr noundef, i64 noundef, i32 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
@vocab_hash = external dso_local 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.4 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [27 x i8], align 1
@read_vocab_file = external dso_local global [100 x i8], align 16
@.str.8 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [7 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 @AddWordToVocab(ptr noundef) local_unnamed_addr #1

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

; 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: nounwind uwtable
define dso_local void @ReadVocab() local_unnamed_addr #1 {
  %1 = alloca i8, align 1
  %2 = alloca [100 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %1) #6
  call void @llvm.lifetime.start.p0(i64 100, ptr nonnull %2) #6
  %3 = tail call noalias ptr @fopen(ptr noundef nonnull @read_vocab_file, ptr noundef nonnull @.str.1)
  %4 = icmp eq ptr %3, null
  br i1 %4, label %6, label %.preheader

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

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

8:                                                ; preds = %10, %.preheader
  call void @ReadWord(ptr noundef nonnull %2, ptr noundef nonnull %3)
  %9 = call i32 @feof(ptr noundef nonnull %3) #6
  %.not = icmp eq i32 %9, 0
  br i1 %.not, label %10, label %20

10:                                               ; preds = %8
  %11 = call i32 @AddWordToVocab(ptr noundef nonnull %2)
  %12 = sext i32 %11 to i64
  %13 = load ptr, ptr @vocab, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.vocab_word, ptr %13, i64 %12
  %15 = call i32 (ptr, ptr, ...) @__isoc99_fscanf(ptr noundef nonnull %3, ptr noundef nonnull @.str.9, ptr noundef %14, ptr noundef nonnull %1) #6
  %16 = load ptr, ptr @vocab, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.vocab_word, ptr %16, i64 %12
  %18 = load i64, ptr %17, align 8, !tbaa !13
  %19 = icmp slt i64 %18, 50
  br i1 %19, label %20, label %8

20:                                               ; preds = %10, %8
  call void @SortVocab()
  %21 = load i32, ptr @debug_mode, align 4, !tbaa !9
  %22 = icmp sgt i32 %21, 0
  br i1 %22, label %23, label %28

23:                                               ; preds = %20
  %24 = load i64, ptr @vocab_size, align 8, !tbaa !11
  %25 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, i64 noundef %24)
  %26 = load i64, ptr @train_words, align 8, !tbaa !11
  %27 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5, i64 noundef %26)
  br label %28

28:                                               ; preds = %23, %20
  %29 = call noalias ptr @fopen(ptr noundef nonnull @train_file, ptr noundef nonnull @.str.1)
  %30 = icmp eq ptr %29, null
  br i1 %30, label %31, label %33

31:                                               ; preds = %28
  %32 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  call void @exit(i32 noundef 1) #7
  unreachable

33:                                               ; preds = %28
  %34 = call i32 @fseek(ptr noundef nonnull %29, i64 noundef 0, i32 noundef 2)
  %35 = call i64 @ftell(ptr noundef nonnull %29)
  store i64 %35, ptr @file_size, align 8, !tbaa !11
  %36 = call i32 @fclose(ptr noundef nonnull %29)
  call void @llvm.lifetime.end.p0(i64 100, ptr nonnull %2) #6
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %1) #6
  ret void
}

declare i32 @__isoc99_fscanf(ptr noundef, ptr noundef, ...) local_unnamed_addr #4

; Function Attrs: nofree nounwind
declare noundef i32 @fseek(ptr nocapture noundef, i64 noundef, i32 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) #5

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 = { "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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #6 = { nounwind }
attributes #7 = { 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,LICMPass,LoopIdiomRecognizePass,LoopRotatePass,LoopSimplifyPass,SROAPass,SimplifyCFGPass,TailCallElimPass