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

; 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 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [72 x i8], align 1
@__PRETTY_FUNCTION__.test_skip_list_insert = external hidden unnamed_addr constant [29 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [40 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @test_skip_list_insert() #0 {
  %1 = alloca ptr, align 8
  %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
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #4
  %8 = call ptr @skip_list_new(ptr noundef @int_compare, ptr noundef null, ptr noundef null)
  store ptr %8, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  %9 = call ptr @generate_random_numbers(i32 noundef 0, i32 noundef 99)
  store ptr %9, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %10

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

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

14:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = load i32, ptr %3, align 4, !tbaa !9
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds i32, ptr %15, i64 %17
  store ptr %18, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %19, ptr %5, align 8, !tbaa !5
  %20 = load ptr, ptr %1, align 8, !tbaa !5
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = call ptr @skip_list_insert(ptr noundef %20, ptr noundef %21, ptr noundef %22)
  %24 = icmp ne ptr %23, null
  br i1 %24, label %25, label %26

25:                                               ; preds = %14
  br label %27

26:                                               ; preds = %14
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 17, ptr noundef @__PRETTY_FUNCTION__.test_skip_list_insert) #5
  unreachable

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

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

31:                                               ; preds = %13
  %32 = load ptr, ptr %1, align 8, !tbaa !5
  call void @skip_list_print(ptr noundef %32)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 20, ptr %6, align 4, !tbaa !9
  %33 = load i32, ptr %6, align 4, !tbaa !9
  %34 = load ptr, ptr %1, align 8, !tbaa !5
  %35 = call ptr @skip_list_find(ptr noundef %34, ptr noundef %6)
  %36 = load i32, ptr %35, align 4, !tbaa !9
  %37 = icmp eq i32 %33, %36
  br i1 %37, label %38, label %39

38:                                               ; preds = %31
  br label %40

39:                                               ; preds = %31
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 23, ptr noundef @__PRETTY_FUNCTION__.test_skip_list_insert) #5
  unreachable

40:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %41 = load ptr, ptr %1, align 8, !tbaa !5
  %42 = load ptr, ptr %2, align 8, !tbaa !5
  %43 = getelementptr inbounds i32, ptr %42, i64 9
  %44 = call ptr @skip_list_remove_node(ptr noundef %41, ptr noundef %43)
  store ptr %44, ptr %7, align 8, !tbaa !5
  %45 = load ptr, ptr %1, align 8, !tbaa !5
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  call void @skip_list_free_node(ptr noundef %45, ptr noundef %46)
  %47 = load ptr, ptr %1, align 8, !tbaa !5
  call void @skip_list_print(ptr noundef %47)
  %48 = load ptr, ptr %1, align 8, !tbaa !5
  call void @skip_list_free(ptr noundef %48)
  %49 = load ptr, ptr %2, align 8, !tbaa !5
  call void @alloc_test_free(ptr noundef %49)
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #4
  ret void
}

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

declare ptr @skip_list_new(ptr noundef, ptr noundef, ptr noundef) #2

declare i32 @int_compare(ptr noundef, ptr noundef) #2

declare ptr @generate_random_numbers(i32 noundef, i32 noundef) #2

declare ptr @skip_list_insert(ptr noundef, ptr noundef, ptr noundef) #2

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

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

declare void @skip_list_print(ptr noundef) #2

declare ptr @skip_list_find(ptr noundef, ptr noundef) #2

declare ptr @skip_list_remove_node(ptr noundef, ptr noundef) #2

declare void @skip_list_free_node(ptr noundef, ptr noundef) #2

declare void @skip_list_free(ptr noundef) #2

declare void @alloc_test_free(ptr noundef) #2

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(argmem: readwrite) }
attributes #2 = { "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 = { nounwind }
attributes #5 = { 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"}


; 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 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [72 x i8], align 1
@__PRETTY_FUNCTION__.test_skip_list_insert = external hidden unnamed_addr constant [29 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [40 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @test_skip_list_insert() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  %2 = tail call ptr @skip_list_new(ptr noundef nonnull @int_compare, ptr noundef null, ptr noundef null) #4
  %3 = tail call ptr @generate_random_numbers(i32 noundef 0, i32 noundef 99) #4
  br label %9

4:                                                ; preds = %9
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 100
  br i1 %exitcond.not, label %5, label %9, !llvm.loop !5

5:                                                ; preds = %4
  tail call void @skip_list_print(ptr noundef %2) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  store i32 20, ptr %1, align 4, !tbaa !7
  %6 = call ptr @skip_list_find(ptr noundef %2, ptr noundef nonnull %1) #4
  %7 = load i32, ptr %6, align 4, !tbaa !7
  %8 = icmp eq i32 %7, 20
  br i1 %8, label %14, label %13

9:                                                ; preds = %0, %4
  %indvars.iv = phi i64 [ 0, %0 ], [ %indvars.iv.next, %4 ]
  %10 = getelementptr inbounds i32, ptr %3, i64 %indvars.iv
  %11 = tail call ptr @skip_list_insert(ptr noundef %2, ptr noundef %10, ptr noundef %10) #4
  %.not = icmp eq ptr %11, null
  br i1 %.not, label %12, label %4

12:                                               ; preds = %9
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 17, ptr noundef nonnull @__PRETTY_FUNCTION__.test_skip_list_insert) #5
  unreachable

13:                                               ; preds = %5
  call void @__assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 23, ptr noundef nonnull @__PRETTY_FUNCTION__.test_skip_list_insert) #5
  unreachable

14:                                               ; preds = %5
  %15 = getelementptr inbounds i8, ptr %3, i64 36
  %16 = call ptr @skip_list_remove_node(ptr noundef %2, ptr noundef nonnull %15) #4
  call void @skip_list_free_node(ptr noundef %2, ptr noundef %16) #4
  call void @skip_list_print(ptr noundef %2) #4
  call void @skip_list_free(ptr noundef %2) #4
  call void @alloc_test_free(ptr noundef %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #4
  ret void
}

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

declare ptr @skip_list_new(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

declare i32 @int_compare(ptr noundef, ptr noundef) #2

declare ptr @generate_random_numbers(i32 noundef, i32 noundef) local_unnamed_addr #2

declare ptr @skip_list_insert(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

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

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

declare void @skip_list_print(ptr noundef) local_unnamed_addr #2

declare ptr @skip_list_find(ptr noundef, ptr noundef) local_unnamed_addr #2

declare ptr @skip_list_remove_node(ptr noundef, ptr noundef) local_unnamed_addr #2

declare void @skip_list_free_node(ptr noundef, ptr noundef) local_unnamed_addr #2

declare void @skip_list_free(ptr noundef) local_unnamed_addr #2

declare void @alloc_test_free(ptr noundef) local_unnamed_addr #2

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = { nounwind }
attributes #5 = { 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 = !{!8, !8, i64 0}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}


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