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

@vocab_max_size = external dso_local global i64, align 8
@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: nounwind
declare ptr @strcpy(ptr noundef, ptr noundef) #1

; 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) #2

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #3

; Function Attrs: nounwind uwtable
define dso_local i32 @AddWordToVocab(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #6
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = call i64 @strlen(ptr noundef %5) #7
  %7 = add i64 %6, 1
  %8 = trunc i64 %7 to i32
  store i32 %8, ptr %4, align 4, !tbaa !9
  %9 = load i32, ptr %4, align 4, !tbaa !9
  %10 = icmp ugt i32 %9, 60
  br i1 %10, label %11, label %12

11:                                               ; preds = %1
  store i32 60, ptr %4, align 4, !tbaa !9
  br label %12

12:                                               ; preds = %11, %1
  %13 = load i32, ptr %4, align 4, !tbaa !9
  %14 = zext i32 %13 to i64
  %15 = call noalias ptr @calloc(i64 noundef %14, i64 noundef 1) #8
  %16 = load ptr, ptr @vocab, align 8, !tbaa !5
  %17 = load i64, ptr @vocab_size, align 8, !tbaa !11
  %18 = getelementptr inbounds %struct.vocab_word, ptr %16, i64 %17
  %19 = getelementptr inbounds %struct.vocab_word, ptr %18, i32 0, i32 1
  store ptr %15, ptr %19, align 8, !tbaa !13
  %20 = load ptr, ptr @vocab, align 8, !tbaa !5
  %21 = load i64, ptr @vocab_size, align 8, !tbaa !11
  %22 = getelementptr inbounds %struct.vocab_word, ptr %20, i64 %21
  %23 = getelementptr inbounds %struct.vocab_word, ptr %22, i32 0, i32 1
  %24 = load ptr, ptr %23, align 8, !tbaa !13
  %25 = load ptr, ptr %2, align 8, !tbaa !5
  %26 = call ptr @strcpy(ptr noundef %24, ptr noundef %25) #6
  %27 = load ptr, ptr @vocab, align 8, !tbaa !5
  %28 = load i64, ptr @vocab_size, align 8, !tbaa !11
  %29 = getelementptr inbounds %struct.vocab_word, ptr %27, i64 %28
  %30 = getelementptr inbounds %struct.vocab_word, ptr %29, i32 0, i32 0
  store i64 0, ptr %30, align 8, !tbaa !15
  %31 = load i64, ptr @vocab_size, align 8, !tbaa !11
  %32 = add nsw i64 %31, 1
  store i64 %32, ptr @vocab_size, align 8, !tbaa !11
  %33 = load i64, ptr @vocab_size, align 8, !tbaa !11
  %34 = add nsw i64 %33, 2
  %35 = load i64, ptr @vocab_max_size, align 8, !tbaa !11
  %36 = icmp sge i64 %34, %35
  br i1 %36, label %37, label %44

37:                                               ; preds = %12
  %38 = load i64, ptr @vocab_max_size, align 8, !tbaa !11
  %39 = add nsw i64 %38, 10000
  store i64 %39, ptr @vocab_max_size, align 8, !tbaa !11
  %40 = load ptr, ptr @vocab, align 8, !tbaa !5
  %41 = load i64, ptr @vocab_max_size, align 8, !tbaa !11
  %42 = mul i64 %41, 16
  %43 = call ptr @realloc(ptr noundef %40, i64 noundef %42) #9
  store ptr %43, ptr @vocab, align 8, !tbaa !5
  br label %44

44:                                               ; preds = %37, %12
  %45 = load ptr, ptr %2, align 8, !tbaa !5
  %46 = call i32 @GetWordHash(ptr noundef %45)
  store i32 %46, ptr %3, align 4, !tbaa !9
  br label %47

47:                                               ; preds = %54, %44
  %48 = load ptr, ptr @vocab_hash, align 8, !tbaa !5
  %49 = load i32, ptr %3, align 4, !tbaa !9
  %50 = zext i32 %49 to i64
  %51 = getelementptr inbounds i32, ptr %48, i64 %50
  %52 = load i32, ptr %51, align 4, !tbaa !9
  %53 = icmp ne i32 %52, -1
  br i1 %53, label %54, label %58

54:                                               ; preds = %47
  %55 = load i32, ptr %3, align 4, !tbaa !9
  %56 = add i32 %55, 1
  %57 = urem i32 %56, 500000000
  store i32 %57, ptr %3, align 4, !tbaa !9
  br label %47, !llvm.loop !16

58:                                               ; preds = %47
  %59 = load i64, ptr @vocab_size, align 8, !tbaa !11
  %60 = sub nsw i64 %59, 1
  %61 = trunc i64 %60 to i32
  %62 = load ptr, ptr @vocab_hash, align 8, !tbaa !5
  %63 = load i32, ptr %3, align 4, !tbaa !9
  %64 = zext i32 %63 to i64
  %65 = getelementptr inbounds i32, ptr %62, i64 %64
  store i32 %61, ptr %65, align 4, !tbaa !9
  %66 = load i64, ptr @vocab_size, align 8, !tbaa !11
  %67 = sub nsw i64 %66, 1
  %68 = trunc i64 %67 to i32
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #6
  ret i32 %68
}

; Function Attrs: nounwind allocsize(0,1)
declare noalias ptr @calloc(i64 noundef, i64 noundef) #4

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #3 = { nounwind willreturn memory(read) "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 allocsize(0,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 #5 = { 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 #6 = { nounwind }
attributes #7 = { nounwind willreturn memory(read) }
attributes #8 = { nounwind allocsize(0,1) }
attributes #9 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = !{!14, !6, i64 8}
!14 = !{!"vocab_word", !12, i64 0, !6, i64 8}
!15 = !{!14, !12, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


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

@vocab_max_size = external dso_local local_unnamed_addr global i64, align 8
@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: mustprogress nofree nounwind willreturn memory(argmem: readwrite)
declare ptr @strcpy(ptr noalias noundef returned writeonly, ptr noalias nocapture noundef readonly) local_unnamed_addr #0

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local i32 @AddWordToVocab(ptr noundef %0) local_unnamed_addr #1 {
  %2 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #6
  %3 = trunc i64 %2 to i32
  %4 = add i32 %3, 1
  %spec.store.select = tail call i32 @llvm.umin.i32(i32 %4, i32 60)
  %5 = zext nneg i32 %spec.store.select to i64
  %6 = tail call noalias ptr @calloc(i64 noundef %5, i64 noundef 1) #7
  %7 = load ptr, ptr @vocab, align 8, !tbaa !5
  %8 = load i64, ptr @vocab_size, align 8, !tbaa !9
  %9 = getelementptr inbounds %struct.vocab_word, ptr %7, i64 %8, i32 1
  store ptr %6, ptr %9, align 8, !tbaa !11
  %10 = load ptr, ptr @vocab, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.vocab_word, ptr %10, i64 %8, i32 1
  %12 = load ptr, ptr %11, align 8, !tbaa !11
  %13 = tail call ptr @strcpy(ptr noundef nonnull dereferenceable(1) %12, ptr noundef nonnull dereferenceable(1) %0) #8
  %14 = load ptr, ptr @vocab, align 8, !tbaa !5
  %15 = load i64, ptr @vocab_size, align 8, !tbaa !9
  %16 = getelementptr inbounds %struct.vocab_word, ptr %14, i64 %15
  store i64 0, ptr %16, align 8, !tbaa !13
  %17 = load i64, ptr @vocab_size, align 8, !tbaa !9
  %18 = add nsw i64 %17, 1
  store i64 %18, ptr @vocab_size, align 8, !tbaa !9
  %19 = add nsw i64 %17, 3
  %20 = load i64, ptr @vocab_max_size, align 8, !tbaa !9
  %.not = icmp slt i64 %19, %20
  br i1 %.not, label %25, label %21

21:                                               ; preds = %1
  %22 = add nsw i64 %20, 10000
  store i64 %22, ptr @vocab_max_size, align 8, !tbaa !9
  %23 = shl i64 %22, 4
  %24 = tail call ptr @realloc(ptr noundef nonnull %14, i64 noundef %23) #9
  store ptr %24, ptr @vocab, align 8, !tbaa !5
  br label %25

25:                                               ; preds = %21, %1
  %26 = tail call i32 @GetWordHash(ptr noundef %0)
  %27 = load ptr, ptr @vocab_hash, align 8, !tbaa !5
  %28 = zext i32 %26 to i64
  %29 = getelementptr inbounds i32, ptr %27, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !14
  %.not811 = icmp eq i32 %30, -1
  br i1 %.not811, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %25, %.lr.ph
  %.012 = phi i32 [ %32, %.lr.ph ], [ %26, %25 ]
  %31 = add i32 %.012, 1
  %32 = urem i32 %31, 500000000
  %33 = zext nneg i32 %32 to i64
  %34 = getelementptr inbounds i32, ptr %27, i64 %33
  %35 = load i32, ptr %34, align 4, !tbaa !14
  %.not8 = icmp eq i32 %35, -1
  br i1 %.not8, label %._crit_edge, label %.lr.ph, !llvm.loop !16

._crit_edge:                                      ; preds = %.lr.ph, %25
  %.lcssa10 = phi i64 [ %28, %25 ], [ %33, %.lr.ph ]
  %36 = getelementptr inbounds i32, ptr %27, i64 %.lcssa10
  %37 = load i64, ptr @vocab_size, align 8, !tbaa !9
  %38 = trunc i64 %37 to i32
  %39 = add i32 %38, -1
  store i32 %39, ptr %36, align 4, !tbaa !14
  ret i32 %39
}

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

; 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 #4

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umin.i32(i32, i32) #5

attributes #0 = { mustprogress nofree nounwind willreturn memory(argmem: readwrite) "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 = { 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 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) 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 #4 = { 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 #5 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #6 = { nounwind willreturn memory(read) }
attributes #7 = { nounwind allocsize(0,1) }
attributes #8 = { nounwind }
attributes #9 = { 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, !6, i64 8}
!12 = !{!"vocab_word", !10, i64 0, !6, i64 8}
!13 = !{!12, !10, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"int", !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


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