; 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
@__PRETTY_FUNCTION__.test_hash_table_enlarge = external hidden unnamed_addr constant [31 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [51 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 ptr @hash_table_get(ptr noundef, ptr noundef) #1

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 uwtable
define dso_local void @test_hash_table_enlarge() #3 {
  %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
  call void @llvm.lifetime.start.p0(i64 10, ptr %1) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #5
  %7 = call ptr @hash_table_new(ptr noundef @hash_string, ptr noundef @string_equal, ptr noundef @alloc_test_free, ptr noundef null)
  store ptr %7, 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 %8

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

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

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

24:                                               ; preds = %12
  br label %26

25:                                               ; preds = %12
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.3, i32 noundef 63, ptr noundef @__PRETTY_FUNCTION__.test_hash_table_enlarge) #6
  unreachable

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

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

30:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %31

31:                                               ; preds = %48, %30
  %32 = load i32, ptr %6, align 4, !tbaa !9
  %33 = icmp slt i32 %32, 10000
  br i1 %33, label %35, label %34

34:                                               ; preds = %31
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  br label %51

35:                                               ; preds = %31
  %36 = getelementptr inbounds [10 x i8], ptr %1, i64 0, i64 0
  %37 = load i32, ptr %6, align 4, !tbaa !9
  %38 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef %36, ptr noundef @.str.13, i32 noundef %37) #5
  %39 = load ptr, ptr %2, align 8, !tbaa !5
  %40 = getelementptr inbounds [10 x i8], ptr %1, i64 0, i64 0
  %41 = call ptr @hash_table_get(ptr noundef %39, ptr noundef %40)
  %42 = getelementptr inbounds [10 x i8], ptr %1, i64 0, i64 0
  %43 = call i32 @string_equal(ptr noundef %41, ptr noundef %42)
  %44 = icmp ne i32 %43, 0
  br i1 %44, label %45, label %46

45:                                               ; preds = %35
  br label %47

46:                                               ; preds = %35
  call void @__assert_fail(ptr noundef @.str.14, ptr noundef @.str.3, i32 noundef 75, ptr noundef @__PRETTY_FUNCTION__.test_hash_table_enlarge) #6
  unreachable

47:                                               ; preds = %45
  br label %48

48:                                               ; preds = %47
  %49 = load i32, ptr %6, align 4, !tbaa !9
  %50 = add nsw i32 %49, 1
  store i32 %50, ptr %6, align 4, !tbaa !9
  br label %31, !llvm.loop !13

51:                                               ; preds = %34
  %52 = load ptr, ptr %2, align 8, !tbaa !5
  call void @hash_table_free(ptr noundef %52)
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #5
  call void @llvm.lifetime.end.p0(i64 10, ptr %1) #5
  ret void
}

; Function Attrs: nounwind
declare i32 @sprintf(ptr noundef, ptr noundef, ...) #4

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 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 #4 = { 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 = !{!"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}


; 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
@__PRETTY_FUNCTION__.test_hash_table_enlarge = external hidden unnamed_addr constant [31 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [51 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 ptr @hash_table_get(ptr noundef, ptr noundef) local_unnamed_addr #1

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: nounwind uwtable
define dso_local void @test_hash_table_enlarge() local_unnamed_addr #3 {
  %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 %5

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

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

10:                                               ; preds = %5
  call void @__assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.3, i32 noundef 63, ptr noundef nonnull @__PRETTY_FUNCTION__.test_hash_table_enlarge) #6
  unreachable

11:                                               ; preds = %.preheader
  %12 = add nuw nsw i32 %.013, 1
  %exitcond14.not = icmp eq i32 %12, 10000
  br i1 %exitcond14.not, label %13, label %.preheader, !llvm.loop !7

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

.preheader:                                       ; preds = %3, %11
  %.013 = phi i32 [ %12, %11 ], [ 0, %3 ]
  %14 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) %1, ptr noundef nonnull dereferenceable(1) @.str.13, i32 noundef %.013) #5
  %15 = call ptr @hash_table_get(ptr noundef %2, ptr noundef nonnull %1) #5
  %16 = call i32 @string_equal(ptr noundef %15, ptr noundef nonnull %1) #5
  %.not = icmp eq i32 %16, 0
  br i1 %.not, label %17, label %11

17:                                               ; preds = %.preheader
  call void @__assert_fail(ptr noundef nonnull @.str.14, ptr noundef nonnull @.str.3, i32 noundef 75, ptr noundef nonnull @__PRETTY_FUNCTION__.test_hash_table_enlarge) #6
  unreachable
}

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

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 = { 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 #4 = { 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 #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}


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