; LLVM IR from hutusi/rethink-c :: test (test_hash_table)

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

@.str.2 = external hidden unnamed_addr constant [47 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [73 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [43 x i8], align 1
@__PRETTY_FUNCTION__.test_hash_table_iterate = external hidden unnamed_addr constant [31 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.23 = external hidden unnamed_addr constant [15 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

declare ptr @hash_table_new(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #1

declare i32 @hash_string(ptr noundef) #1

declare i32 @string_equal(ptr noundef, ptr noundef) #1

declare void @alloc_test_free(ptr noundef) #1

declare ptr @alloc_test_strdup(ptr noundef) #1

declare i32 @hash_table_insert(ptr noundef, ptr noundef, ptr noundef) #1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #2

declare void @hash_table_free(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
declare i32 @sprintf(ptr noundef, ptr noundef, ...) #3

declare i32 @hash_table_size(ptr noundef) #1

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

declare ptr @hash_table_first_entity(ptr noundef) #1

declare ptr @hash_table_next_entity(ptr noundef, ptr noundef) #1

declare ptr @hash_table_last_entity(ptr noundef) #1

declare ptr @hash_table_prev_entity(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @test_hash_table_iterate() #4 {
  %1 = alloca [10 x i8], align 1
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 10, ptr %1) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #5
  %9 = call ptr @hash_table_new(ptr noundef @hash_string, ptr noundef @string_equal, ptr noundef @alloc_test_free, ptr noundef null)
  store ptr %9, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %10

10:                                               ; preds = %29, %0
  %11 = load i32, ptr %3, align 4, !tbaa !9
  %12 = icmp slt i32 %11, 10000
  br i1 %12, label %14, label %13

13:                                               ; preds = %10
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  br label %32

14:                                               ; preds = %10
  %15 = getelementptr inbounds [10 x i8], ptr %1, i64 0, i64 0
  %16 = load i32, ptr %3, align 4, !tbaa !9
  %17 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef %15, ptr noundef @.str.13, i32 noundef %16) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  %18 = getelementptr inbounds [10 x i8], ptr %1, i64 0, i64 0
  %19 = call ptr @alloc_test_strdup(ptr noundef %18)
  store ptr %19, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %20, ptr %5, align 8, !tbaa !5
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = call i32 @hash_table_insert(ptr noundef %21, ptr noundef %22, ptr noundef %23)
  %25 = icmp eq i32 %24, 0
  br i1 %25, label %26, label %27

26:                                               ; preds = %14
  br label %28

27:                                               ; preds = %14
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.3, i32 noundef 135, ptr noundef @__PRETTY_FUNCTION__.test_hash_table_iterate) #6
  unreachable

28:                                               ; preds = %26
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  br label %29

29:                                               ; preds = %28
  %30 = load i32, ptr %3, align 4, !tbaa !9
  %31 = add nsw i32 %30, 1
  store i32 %31, ptr %3, align 4, !tbaa !9
  br label %10, !llvm.loop !11

32:                                               ; preds = %13
  %33 = load ptr, ptr %2, align 8, !tbaa !5
  %34 = call i32 @hash_table_size(ptr noundef %33)
  %35 = icmp ne i32 %34, 10000
  br i1 %35, label %36, label %46

36:                                               ; preds = %32
  %37 = load ptr, ptr %2, align 8, !tbaa !5
  %38 = call i32 @hash_table_size(ptr noundef %37)
  %39 = call i32 (ptr, ...) @printf(ptr noundef @.str.18, i32 noundef %38, i32 noundef 10000)
  %40 = load ptr, ptr %2, align 8, !tbaa !5
  %41 = call i32 @hash_table_size(ptr noundef %40)
  %42 = icmp eq i32 %41, 10000
  br i1 %42, label %43, label %44

43:                                               ; preds = %36
  br label %45

44:                                               ; preds = %36
  call void @__assert_fail(ptr noundef @.str.22, ptr noundef @.str.3, i32 noundef 137, ptr noundef @__PRETTY_FUNCTION__.test_hash_table_iterate) #6
  unreachable

45:                                               ; preds = %43
  br label %46

46:                                               ; preds = %45, %32
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  store i32 0, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %47 = load ptr, ptr %2, align 8, !tbaa !5
  %48 = call ptr @hash_table_first_entity(ptr noundef %47)
  store ptr %48, ptr %7, align 8, !tbaa !5
  br label %49

49:                                               ; preds = %56, %46
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  %51 = icmp ne ptr %50, null
  br i1 %51, label %53, label %52

52:                                               ; preds = %49
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  br label %60

53:                                               ; preds = %49
  %54 = load i32, ptr %6, align 4, !tbaa !9
  %55 = add nsw i32 %54, 1
  store i32 %55, ptr %6, align 4, !tbaa !9
  br label %56

56:                                               ; preds = %53
  %57 = load ptr, ptr %2, align 8, !tbaa !5
  %58 = load ptr, ptr %7, align 8, !tbaa !5
  %59 = call ptr @hash_table_next_entity(ptr noundef %57, ptr noundef %58)
  store ptr %59, ptr %7, align 8, !tbaa !5
  br label %49, !llvm.loop !13

60:                                               ; preds = %52
  %61 = load i32, ptr %6, align 4, !tbaa !9
  %62 = icmp ne i32 %61, 10000
  br i1 %62, label %63, label %71

63:                                               ; preds = %60
  %64 = load i32, ptr %6, align 4, !tbaa !9
  %65 = call i32 (ptr, ...) @printf(ptr noundef @.str.18, i32 noundef %64, i32 noundef 10000)
  %66 = load i32, ptr %6, align 4, !tbaa !9
  %67 = icmp eq i32 %66, 10000
  br i1 %67, label %68, label %69

68:                                               ; preds = %63
  br label %70

69:                                               ; preds = %63
  call void @__assert_fail(ptr noundef @.str.23, ptr noundef @.str.3, i32 noundef 145, ptr noundef @__PRETTY_FUNCTION__.test_hash_table_iterate) #6
  unreachable

70:                                               ; preds = %68
  br label %71

71:                                               ; preds = %70, %60
  store i32 0, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %72 = load ptr, ptr %2, align 8, !tbaa !5
  %73 = call ptr @hash_table_last_entity(ptr noundef %72)
  store ptr %73, ptr %8, align 8, !tbaa !5
  br label %74

74:                                               ; preds = %81, %71
  %75 = load ptr, ptr %8, align 8, !tbaa !5
  %76 = icmp ne ptr %75, null
  br i1 %76, label %78, label %77

77:                                               ; preds = %74
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  br label %85

78:                                               ; preds = %74
  %79 = load i32, ptr %6, align 4, !tbaa !9
  %80 = add nsw i32 %79, 1
  store i32 %80, ptr %6, align 4, !tbaa !9
  br label %81

81:                                               ; preds = %78
  %82 = load ptr, ptr %2, align 8, !tbaa !5
  %83 = load ptr, ptr %8, align 8, !tbaa !5
  %84 = call ptr @hash_table_prev_entity(ptr noundef %82, ptr noundef %83)
  store ptr %84, ptr %8, align 8, !tbaa !5
  br label %74, !llvm.loop !14

85:                                               ; preds = %77
  %86 = load i32, ptr %6, align 4, !tbaa !9
  %87 = icmp ne i32 %86, 10000
  br i1 %87, label %88, label %96

88:                                               ; preds = %85
  %89 = load i32, ptr %6, align 4, !tbaa !9
  %90 = call i32 (ptr, ...) @printf(ptr noundef @.str.18, i32 noundef %89, i32 noundef 10000)
  %91 = load i32, ptr %6, align 4, !tbaa !9
  %92 = icmp eq i32 %91, 10000
  br i1 %92, label %93, label %94

93:                                               ; preds = %88
  br label %95

94:                                               ; preds = %88
  call void @__assert_fail(ptr noundef @.str.23, ptr noundef @.str.3, i32 noundef 153, ptr noundef @__PRETTY_FUNCTION__.test_hash_table_iterate) #6
  unreachable

95:                                               ; preds = %93
  br label %96

96:                                               ; preds = %95, %85
  %97 = load ptr, ptr %2, align 8, !tbaa !5
  call void @hash_table_free(ptr noundef %97)
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #5
  call void @llvm.lifetime.end.p0(i64 10, ptr %1) #5
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #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 #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 = { 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 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 #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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}


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

@.str.2 = external hidden unnamed_addr constant [47 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [73 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [43 x i8], align 1
@__PRETTY_FUNCTION__.test_hash_table_iterate = external hidden unnamed_addr constant [31 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.23 = external hidden unnamed_addr constant [15 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

declare ptr @hash_table_new(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare i32 @hash_string(ptr noundef) #1

declare i32 @string_equal(ptr noundef, ptr noundef) #1

declare void @alloc_test_free(ptr noundef) #1

declare ptr @alloc_test_strdup(ptr noundef) local_unnamed_addr #1

declare i32 @hash_table_insert(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

declare void @hash_table_free(ptr noundef) local_unnamed_addr #1

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

; Function Attrs: nofree nounwind
declare noundef i32 @sprintf(ptr noalias nocapture noundef writeonly, ptr nocapture noundef readonly, ...) local_unnamed_addr #3

declare i32 @hash_table_size(ptr noundef) local_unnamed_addr #1

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

declare ptr @hash_table_first_entity(ptr noundef) local_unnamed_addr #1

declare ptr @hash_table_next_entity(ptr noundef, ptr noundef) local_unnamed_addr #1

declare ptr @hash_table_last_entity(ptr noundef) local_unnamed_addr #1

declare ptr @hash_table_prev_entity(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @test_hash_table_iterate() local_unnamed_addr #4 {
  %1 = alloca [10 x i8], align 1
  call void @llvm.lifetime.start.p0(i64 10, ptr nonnull %1) #5
  %2 = tail call ptr @hash_table_new(ptr noundef nonnull @hash_string, ptr noundef nonnull @string_equal, ptr noundef nonnull @alloc_test_free, ptr noundef null) #5
  br label %7

3:                                                ; preds = %7
  %4 = add nuw nsw i32 %.02833, 1
  %exitcond.not = icmp eq i32 %4, 10000
  br i1 %exitcond.not, label %5, label %7, !llvm.loop !5

5:                                                ; preds = %3
  %6 = call i32 @hash_table_size(ptr noundef %2) #5
  %.not = icmp eq i32 %6, 10000
  br i1 %.not, label %19, label %13

7:                                                ; preds = %0, %3
  %.02833 = phi i32 [ 0, %0 ], [ %4, %3 ]
  %8 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) %1, ptr noundef nonnull dereferenceable(1) @.str.13, i32 noundef %.02833) #5
  %9 = call ptr @alloc_test_strdup(ptr noundef nonnull %1) #5
  %10 = call i32 @hash_table_insert(ptr noundef %2, ptr noundef %9, ptr noundef %9) #5
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %3, label %12

12:                                               ; preds = %7
  call void @__assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.3, i32 noundef 135, ptr noundef nonnull @__PRETTY_FUNCTION__.test_hash_table_iterate) #6
  unreachable

13:                                               ; preds = %5
  %14 = call i32 @hash_table_size(ptr noundef %2) #5
  %15 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.18, i32 noundef %14, i32 noundef 10000)
  %16 = call i32 @hash_table_size(ptr noundef %2) #5
  %17 = icmp eq i32 %16, 10000
  br i1 %17, label %19, label %18

18:                                               ; preds = %13
  call void @__assert_fail(ptr noundef nonnull @.str.22, ptr noundef nonnull @.str.3, i32 noundef 137, ptr noundef nonnull @__PRETTY_FUNCTION__.test_hash_table_iterate) #6
  unreachable

19:                                               ; preds = %13, %5
  %20 = call ptr @hash_table_first_entity(ptr noundef %2) #5
  %.not2934 = icmp eq ptr %20, null
  br i1 %.not2934, label %._crit_edge.thread, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph
  %.not30 = icmp eq i32 %21, 10000
  br i1 %.not30, label %24, label %._crit_edge.thread

.lr.ph:                                           ; preds = %19, %.lr.ph
  %.02636 = phi ptr [ %22, %.lr.ph ], [ %20, %19 ]
  %.02735 = phi i32 [ %21, %.lr.ph ], [ 0, %19 ]
  %21 = add nuw nsw i32 %.02735, 1
  %22 = call ptr @hash_table_next_entity(ptr noundef %2, ptr noundef nonnull %.02636) #5
  %.not29 = icmp eq ptr %22, null
  br i1 %.not29, label %._crit_edge, label %.lr.ph, !llvm.loop !7

._crit_edge.thread:                               ; preds = %19, %._crit_edge
  %.027.lcssa47 = phi i32 [ %21, %._crit_edge ], [ 0, %19 ]
  %23 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.18, i32 noundef %.027.lcssa47, i32 noundef 10000)
  call void @__assert_fail(ptr noundef nonnull @.str.23, ptr noundef nonnull @.str.3, i32 noundef 145, ptr noundef nonnull @__PRETTY_FUNCTION__.test_hash_table_iterate) #6
  unreachable

24:                                               ; preds = %._crit_edge
  %25 = call ptr @hash_table_last_entity(ptr noundef %2) #5
  %.not3137 = icmp eq ptr %25, null
  br i1 %.not3137, label %._crit_edge42.thread, label %.lr.ph41

._crit_edge42:                                    ; preds = %.lr.ph41
  %.not32 = icmp eq i32 %26, 10000
  br i1 %.not32, label %29, label %._crit_edge42.thread

.lr.ph41:                                         ; preds = %24, %.lr.ph41
  %.039 = phi ptr [ %27, %.lr.ph41 ], [ %25, %24 ]
  %.138 = phi i32 [ %26, %.lr.ph41 ], [ 0, %24 ]
  %26 = add nuw nsw i32 %.138, 1
  %27 = call ptr @hash_table_prev_entity(ptr noundef %2, ptr noundef nonnull %.039) #5
  %.not31 = icmp eq ptr %27, null
  br i1 %.not31, label %._crit_edge42, label %.lr.ph41, !llvm.loop !8

._crit_edge42.thread:                             ; preds = %24, %._crit_edge42
  %.1.lcssa50 = phi i32 [ %26, %._crit_edge42 ], [ 0, %24 ]
  %28 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.18, i32 noundef %.1.lcssa50, i32 noundef 10000)
  call void @__assert_fail(ptr noundef nonnull @.str.23, ptr noundef nonnull @.str.3, i32 noundef 153, ptr noundef nonnull @__PRETTY_FUNCTION__.test_hash_table_iterate) #6
  unreachable

29:                                               ; preds = %._crit_edge42
  call void @hash_table_free(ptr noundef %2) #5
  call void @llvm.lifetime.end.p0(i64 10, ptr nonnull %1) #5
  ret void
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #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 #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 = { 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 #4 = { 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 #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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !6}
!8 = distinct !{!8, !6}


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