; LLVM IR from fmela/libdict :: src (hashtable)

; 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.hashtable = type { ptr, ptr, ptr, i64, i32 }

@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [34 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [63 x i8], align 1
@__func__.hashtable_new = external hidden unnamed_addr constant [14 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [9 x i8], align 1
@dict_malloc_func = external global ptr, align 8
@dict_free_func = external global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local ptr @hashtable_new(ptr noundef %0, ptr noundef %1, i32 noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  br label %10

10:                                               ; preds = %3
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = icmp ne ptr %11, null
  %13 = zext i1 %12 to i32
  %14 = sext i32 %13 to i64
  %15 = call i64 @llvm.expect.i64(i64 %14, i64 1)
  %16 = icmp ne i64 %15, 0
  br i1 %16, label %20, label %17

17:                                               ; preds = %10
  %18 = load ptr, ptr @stderr, align 8, !tbaa !5
  %19 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %18, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 112, ptr noundef @__func__.hashtable_new, ptr noundef @.str.2) #7
  call void @abort() #8
  unreachable

20:                                               ; preds = %10
  br label %21

21:                                               ; preds = %20
  br label %22

22:                                               ; preds = %21
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = icmp ne ptr %23, null
  %25 = zext i1 %24 to i32
  %26 = sext i32 %25 to i64
  %27 = call i64 @llvm.expect.i64(i64 %26, i64 1)
  %28 = icmp ne i64 %27, 0
  br i1 %28, label %32, label %29

29:                                               ; preds = %22
  %30 = load ptr, ptr @stderr, align 8, !tbaa !5
  %31 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %30, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 113, ptr noundef @__func__.hashtable_new, ptr noundef @.str.3) #7
  call void @abort() #8
  unreachable

32:                                               ; preds = %22
  br label %33

33:                                               ; preds = %32
  br label %34

34:                                               ; preds = %33
  %35 = load i32, ptr %7, align 4, !tbaa !9
  %36 = icmp ugt i32 %35, 0
  %37 = zext i1 %36 to i32
  %38 = sext i32 %37 to i64
  %39 = call i64 @llvm.expect.i64(i64 %38, i64 1)
  %40 = icmp ne i64 %39, 0
  br i1 %40, label %44, label %41

41:                                               ; preds = %34
  %42 = load ptr, ptr @stderr, align 8, !tbaa !5
  %43 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %42, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 114, ptr noundef @__func__.hashtable_new, ptr noundef @.str.4) #7
  call void @abort() #8
  unreachable

44:                                               ; preds = %34
  br label %45

45:                                               ; preds = %44
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #7
  %46 = load ptr, ptr @dict_malloc_func, align 8, !tbaa !5
  %47 = call ptr %46(i64 noundef 40)
  store ptr %47, ptr %8, align 8, !tbaa !5
  %48 = load ptr, ptr %8, align 8, !tbaa !5
  %49 = icmp ne ptr %48, null
  br i1 %49, label %50, label %88

50:                                               ; preds = %45
  %51 = load i32, ptr %7, align 4, !tbaa !9
  %52 = call i32 @dict_prime_geq(i32 noundef %51)
  %53 = load ptr, ptr %8, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.hashtable, ptr %53, i32 0, i32 4
  store i32 %52, ptr %54, align 8, !tbaa !11
  %55 = load ptr, ptr @dict_malloc_func, align 8, !tbaa !5
  %56 = load ptr, ptr %8, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.hashtable, ptr %56, i32 0, i32 4
  %58 = load i32, ptr %57, align 8, !tbaa !11
  %59 = zext i32 %58 to i64
  %60 = mul i64 %59, 8
  %61 = call ptr %55(i64 noundef %60)
  %62 = load ptr, ptr %8, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.hashtable, ptr %62, i32 0, i32 0
  store ptr %61, ptr %63, align 8, !tbaa !14
  %64 = load ptr, ptr %8, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.hashtable, ptr %64, i32 0, i32 0
  %66 = load ptr, ptr %65, align 8, !tbaa !14
  %67 = icmp ne ptr %66, null
  br i1 %67, label %71, label %68

68:                                               ; preds = %50
  %69 = load ptr, ptr @dict_free_func, align 8, !tbaa !5
  %70 = load ptr, ptr %8, align 8, !tbaa !5
  call void %69(ptr noundef %70)
  store ptr null, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %90

71:                                               ; preds = %50
  %72 = load ptr, ptr %8, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.hashtable, ptr %72, i32 0, i32 0
  %74 = load ptr, ptr %73, align 8, !tbaa !14
  %75 = load ptr, ptr %8, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.hashtable, ptr %75, i32 0, i32 4
  %77 = load i32, ptr %76, align 8, !tbaa !11
  %78 = zext i32 %77 to i64
  %79 = mul i64 %78, 8
  call void @llvm.memset.p0.i64(ptr align 8 %74, i8 0, i64 %79, i1 false)
  %80 = load ptr, ptr %5, align 8, !tbaa !5
  %81 = load ptr, ptr %8, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.hashtable, ptr %81, i32 0, i32 1
  store ptr %80, ptr %82, align 8, !tbaa !15
  %83 = load ptr, ptr %6, align 8, !tbaa !5
  %84 = load ptr, ptr %8, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.hashtable, ptr %84, i32 0, i32 2
  store ptr %83, ptr %85, align 8, !tbaa !16
  %86 = load ptr, ptr %8, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.hashtable, ptr %86, i32 0, i32 3
  store i64 0, ptr %87, align 8, !tbaa !17
  br label %88

88:                                               ; preds = %71, %45
  %89 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %89, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %90

90:                                               ; preds = %88, %68
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #7
  %91 = load ptr, ptr %4, align 8
  ret ptr %91
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)
declare i64 @llvm.expect.i64(i64, i64) #1

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #2

; Function Attrs: noreturn nounwind
declare void @abort() #3

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

declare i32 @dict_prime_geq(i32 noundef) #5

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

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

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(none) }
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 = { 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 nosync nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { "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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #7 = { nounwind }
attributes #8 = { 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, !10, i64 32}
!12 = !{!"hashtable", !6, i64 0, !6, i64 8, !6, i64 16, !13, i64 24, !10, i64 32}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !6, i64 0}
!15 = !{!12, !6, i64 8}
!16 = !{!12, !6, i64 16}
!17 = !{!12, !13, i64 24}


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

@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [34 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [63 x i8], align 1
@__func__.hashtable_new = external hidden unnamed_addr constant [14 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [9 x i8], align 1
@dict_malloc_func = external local_unnamed_addr global ptr, align 8
@dict_free_func = external local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local ptr @hashtable_new(ptr noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %4, label %7, !prof !5

4:                                                ; preds = %3
  %5 = load ptr, ptr @stderr, align 8, !tbaa !6
  %6 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %5, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 112, ptr noundef nonnull @__func__.hashtable_new, ptr noundef nonnull @.str.2) #5
  tail call void @abort() #6
  unreachable

7:                                                ; preds = %3
  %.not23 = icmp eq ptr %1, null
  br i1 %.not23, label %8, label %11, !prof !5

8:                                                ; preds = %7
  %9 = load ptr, ptr @stderr, align 8, !tbaa !6
  %10 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %9, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 113, ptr noundef nonnull @__func__.hashtable_new, ptr noundef nonnull @.str.3) #5
  tail call void @abort() #6
  unreachable

11:                                               ; preds = %7
  %.not24 = icmp eq i32 %2, 0
  br i1 %.not24, label %12, label %15, !prof !5

12:                                               ; preds = %11
  %13 = load ptr, ptr @stderr, align 8, !tbaa !6
  %14 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %13, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 114, ptr noundef nonnull @__func__.hashtable_new, ptr noundef nonnull @.str.4) #5
  tail call void @abort() #6
  unreachable

15:                                               ; preds = %11
  %16 = load ptr, ptr @dict_malloc_func, align 8, !tbaa !6
  %17 = tail call ptr %16(i64 noundef 40) #7
  %.not25 = icmp eq ptr %17, null
  br i1 %.not25, label %34, label %18

18:                                               ; preds = %15
  %19 = tail call i32 @dict_prime_geq(i32 noundef %2) #7
  %20 = getelementptr inbounds i8, ptr %17, i64 32
  store i32 %19, ptr %20, align 8, !tbaa !10
  %21 = load ptr, ptr @dict_malloc_func, align 8, !tbaa !6
  %22 = zext i32 %19 to i64
  %23 = shl nuw nsw i64 %22, 3
  %24 = tail call ptr %21(i64 noundef %23) #7
  store ptr %24, ptr %17, align 8, !tbaa !14
  %.not26 = icmp eq ptr %24, null
  br i1 %.not26, label %25, label %27

25:                                               ; preds = %18
  %26 = load ptr, ptr @dict_free_func, align 8, !tbaa !6
  tail call void %26(ptr noundef nonnull %17) #7
  br label %34

27:                                               ; preds = %18
  %28 = load i32, ptr %20, align 8, !tbaa !10
  %29 = zext i32 %28 to i64
  %30 = shl nuw nsw i64 %29, 3
  tail call void @llvm.memset.p0.i64(ptr nonnull align 8 %24, i8 0, i64 %30, i1 false)
  %31 = getelementptr inbounds i8, ptr %17, i64 8
  store ptr %0, ptr %31, align 8, !tbaa !15
  %32 = getelementptr inbounds i8, ptr %17, i64 16
  store ptr %1, ptr %32, align 8, !tbaa !16
  %33 = getelementptr inbounds i8, ptr %17, i64 24
  store i64 0, ptr %33, align 8, !tbaa !17
  br label %34

34:                                               ; preds = %15, %27, %25
  %.0 = phi ptr [ null, %25 ], [ %17, %27 ], [ null, %15 ]
  ret ptr %.0
}

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

; Function Attrs: noreturn nounwind
declare void @abort() local_unnamed_addr #2

declare i32 @dict_prime_geq(i32 noundef) local_unnamed_addr #3

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

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 = { 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 #2 = { 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 #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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { cold nounwind }
attributes #6 = { noreturn nounwind }
attributes #7 = { 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 = !{!"branch_weights", !"expected", i32 1, i32 2000}
!6 = !{!7, !7, i64 0}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !13, i64 32}
!11 = !{!"hashtable", !7, i64 0, !7, i64 8, !7, i64 16, !12, i64 24, !13, i64 32}
!12 = !{!"long", !8, i64 0}
!13 = !{!"int", !8, i64 0}
!14 = !{!11, !7, i64 0}
!15 = !{!11, !7, i64 8}
!16 = !{!11, !7, i64 16}
!17 = !{!11, !12, i64 24}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,LowerExpectIntrinsicPass,SROAPass,SimplifyCFGPass,TailCallElimPass