; LLVM IR from ryanlayer/giggle :: src (lists)

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

@.str.21 = external hidden unnamed_addr constant [37 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

; Function Attrs: noreturn
declare void @err(i32 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 allocsize(1)
declare ptr @realloc(ptr noundef, i64 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local ptr @ordered_set_add(ptr noundef %0, ptr noundef %1) #3 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  store ptr null, ptr %6, align 8, !tbaa !5
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.ordered_set, ptr %10, i32 0, i32 1
  %12 = load i32, ptr %11, align 8, !tbaa !9
  %13 = icmp ne i32 %12, 0
  br i1 %13, label %14, label %27

14:                                               ; preds = %2
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.ordered_set, ptr %16, i32 0, i32 0
  %18 = load ptr, ptr %17, align 8, !tbaa !12
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.ordered_set, ptr %19, i32 0, i32 1
  %21 = load i32, ptr %20, align 8, !tbaa !9
  %22 = zext i32 %21 to i64
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.ordered_set, ptr %23, i32 0, i32 4
  %25 = load ptr, ptr %24, align 8, !tbaa !13
  %26 = call ptr @bsearch(ptr noundef %15, ptr noundef %18, i64 noundef %22, i64 noundef 8, ptr noundef %25)
  store ptr %26, ptr %6, align 8, !tbaa !5
  br label %27

27:                                               ; preds = %14, %2
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = icmp ne ptr %28, null
  br i1 %29, label %30, label %33

30:                                               ; preds = %27
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = load ptr, ptr %31, align 8, !tbaa !5
  store ptr %32, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %115

33:                                               ; preds = %27
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.ordered_set, ptr %34, i32 0, i32 1
  %36 = load i32, ptr %35, align 8, !tbaa !9
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.ordered_set, ptr %37, i32 0, i32 2
  %39 = load i32, ptr %38, align 4, !tbaa !14
  %40 = sub i32 %39, 1
  %41 = icmp eq i32 %36, %40
  br i1 %41, label %42, label %66

42:                                               ; preds = %33
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.ordered_set, ptr %43, i32 0, i32 2
  %45 = load i32, ptr %44, align 4, !tbaa !14
  %46 = mul i32 %45, 2
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.ordered_set, ptr %47, i32 0, i32 2
  store i32 %46, ptr %48, align 4, !tbaa !14
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.ordered_set, ptr %49, i32 0, i32 0
  %51 = load ptr, ptr %50, align 8, !tbaa !12
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.ordered_set, ptr %52, i32 0, i32 2
  %54 = load i32, ptr %53, align 4, !tbaa !14
  %55 = zext i32 %54 to i64
  %56 = mul i64 %55, 8
  %57 = call ptr @realloc(ptr noundef %51, i64 noundef %56) #6
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.ordered_set, ptr %58, i32 0, i32 0
  store ptr %57, ptr %59, align 8, !tbaa !12
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.ordered_set, ptr %60, i32 0, i32 0
  %62 = load ptr, ptr %61, align 8, !tbaa !12
  %63 = icmp eq ptr %62, null
  br i1 %63, label %64, label %65

64:                                               ; preds = %42
  call void (i32, ptr, ...) @err(i32 noundef 1, ptr noundef @.str.21) #7
  unreachable

65:                                               ; preds = %42
  br label %66

66:                                               ; preds = %65, %33
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  %67 = load ptr, ptr %4, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.ordered_set, ptr %67, i32 0, i32 1
  %69 = load i32, ptr %68, align 8, !tbaa !9
  store i32 %69, ptr %8, align 4, !tbaa !15
  br label %70

70:                                               ; preds = %99, %66
  %71 = load i32, ptr %8, align 4, !tbaa !15
  %72 = icmp sgt i32 %71, 0
  br i1 %72, label %73, label %102

73:                                               ; preds = %70
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %74 = load ptr, ptr %4, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.ordered_set, ptr %74, i32 0, i32 0
  %76 = load ptr, ptr %75, align 8, !tbaa !12
  %77 = load i32, ptr %8, align 4, !tbaa !15
  %78 = sub nsw i32 %77, 1
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds ptr, ptr %76, i64 %79
  %81 = load ptr, ptr %80, align 8, !tbaa !5
  store ptr %81, ptr %9, align 8, !tbaa !5
  %82 = load ptr, ptr %4, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.ordered_set, ptr %82, i32 0, i32 3
  %84 = load ptr, ptr %83, align 8, !tbaa !16
  %85 = call i32 %84(ptr noundef %5, ptr noundef %9)
  %86 = icmp sge i32 %85, 0
  br i1 %86, label %87, label %88

87:                                               ; preds = %73
  store i32 2, ptr %7, align 4
  br label %96

88:                                               ; preds = %73
  %89 = load ptr, ptr %9, align 8, !tbaa !5
  %90 = load ptr, ptr %4, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.ordered_set, ptr %90, i32 0, i32 0
  %92 = load ptr, ptr %91, align 8, !tbaa !12
  %93 = load i32, ptr %8, align 4, !tbaa !15
  %94 = sext i32 %93 to i64
  %95 = getelementptr inbounds ptr, ptr %92, i64 %94
  store ptr %89, ptr %95, align 8, !tbaa !5
  store i32 0, ptr %7, align 4
  br label %96

96:                                               ; preds = %88, %87
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  %97 = load i32, ptr %7, align 4
  switch i32 %97, label %117 [
    i32 0, label %98
    i32 2, label %102
  ]

98:                                               ; preds = %96
  br label %99

99:                                               ; preds = %98
  %100 = load i32, ptr %8, align 4, !tbaa !15
  %101 = add nsw i32 %100, -1
  store i32 %101, ptr %8, align 4, !tbaa !15
  br label %70, !llvm.loop !17

102:                                              ; preds = %96, %70
  %103 = load ptr, ptr %5, align 8, !tbaa !5
  %104 = load ptr, ptr %4, align 8, !tbaa !5
  %105 = getelementptr inbounds %struct.ordered_set, ptr %104, i32 0, i32 0
  %106 = load ptr, ptr %105, align 8, !tbaa !12
  %107 = load i32, ptr %8, align 4, !tbaa !15
  %108 = sext i32 %107 to i64
  %109 = getelementptr inbounds ptr, ptr %106, i64 %108
  store ptr %103, ptr %109, align 8, !tbaa !5
  %110 = load ptr, ptr %4, align 8, !tbaa !5
  %111 = getelementptr inbounds %struct.ordered_set, ptr %110, i32 0, i32 1
  %112 = load i32, ptr %111, align 8, !tbaa !9
  %113 = add i32 %112, 1
  store i32 %113, ptr %111, align 8, !tbaa !9
  %114 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %114, ptr %3, align 8
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  br label %115

115:                                              ; preds = %102, %30
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  %116 = load ptr, ptr %3, align 8
  ret ptr %116

117:                                              ; preds = %96
  unreachable
}

; Function Attrs: inlinehint nounwind uwtable
declare ptr @bsearch(ptr noundef nonnull, ptr noundef nonnull, i64 noundef, i64 noundef, ptr noundef nonnull) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { noreturn "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 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 #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 = { inlinehint 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 = { nounwind allocsize(1) }
attributes #7 = { noreturn }

!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, !11, i64 8}
!10 = !{!"ordered_set", !6, i64 0, !11, i64 8, !11, i64 12, !6, i64 16, !6, i64 24, !6, i64 32}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 0}
!13 = !{!10, !6, i64 24}
!14 = !{!10, !11, i64 12}
!15 = !{!11, !11, i64 0}
!16 = !{!10, !6, i64 16}
!17 = distinct !{!17, !18}
!18 = !{!"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.21 = external hidden unnamed_addr constant [37 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

; Function Attrs: noreturn
declare void @err(i32 noundef, 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: 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 #2

; Function Attrs: nounwind uwtable
define dso_local ptr @ordered_set_add(ptr nocapture noundef %0, ptr noundef %1) local_unnamed_addr #3 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  store ptr %1, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load i32, ptr %5, align 8, !tbaa !9
  %.not = icmp eq i32 %6, 0
  br i1 %.not, label %.thread, label %7

7:                                                ; preds = %2
  %8 = load ptr, ptr %0, align 8, !tbaa !12
  %9 = zext i32 %6 to i64
  %10 = getelementptr inbounds i8, ptr %0, i64 24
  %11 = load ptr, ptr %10, align 8, !tbaa !13
  %12 = tail call ptr @bsearch(ptr noundef %1, ptr noundef %8, i64 noundef %9, i64 noundef 8, ptr noundef %11)
  %.not30 = icmp eq ptr %12, null
  br i1 %.not30, label %..thread_crit_edge, label %._crit_edge42

._crit_edge42:                                    ; preds = %7
  %.028.pre = load ptr, ptr %12, align 8, !tbaa !5
  br label %53

..thread_crit_edge:                               ; preds = %7
  %.pre = load i32, ptr %5, align 8, !tbaa !9
  br label %.thread

.thread:                                          ; preds = %..thread_crit_edge, %2
  %13 = phi i32 [ %.pre, %..thread_crit_edge ], [ 0, %2 ]
  %14 = getelementptr inbounds i8, ptr %0, i64 12
  %15 = load i32, ptr %14, align 4, !tbaa !14
  %16 = add i32 %15, -1
  %17 = icmp eq i32 %13, %16
  br i1 %17, label %18, label %26

18:                                               ; preds = %.thread
  %19 = shl i32 %15, 1
  store i32 %19, ptr %14, align 4, !tbaa !14
  %20 = load ptr, ptr %0, align 8, !tbaa !12
  %21 = zext i32 %19 to i64
  %22 = shl nuw nsw i64 %21, 3
  %23 = tail call ptr @realloc(ptr noundef %20, i64 noundef %22) #5
  store ptr %23, ptr %0, align 8, !tbaa !12
  %24 = icmp eq ptr %23, null
  br i1 %24, label %25, label %._crit_edge

._crit_edge:                                      ; preds = %18
  %.pre41 = load i32, ptr %5, align 8, !tbaa !9
  br label %26

25:                                               ; preds = %18
  tail call void (i32, ptr, ...) @err(i32 noundef 1, ptr noundef nonnull @.str.21) #6
  unreachable

26:                                               ; preds = %._crit_edge, %.thread
  %27 = phi i32 [ %.pre41, %._crit_edge ], [ %13, %.thread ]
  %28 = icmp sgt i32 %27, 0
  br i1 %28, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %26
  %29 = getelementptr inbounds i8, ptr %0, i64 16
  %30 = zext nneg i32 %27 to i64
  br label %31

31:                                               ; preds = %.lr.ph, %41
  %indvars.iv = phi i64 [ %30, %.lr.ph ], [ %indvars.iv.next, %41 ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #7
  %32 = load ptr, ptr %0, align 8, !tbaa !12
  %33 = getelementptr ptr, ptr %32, i64 %indvars.iv
  %34 = getelementptr i8, ptr %33, i64 -8
  %35 = load ptr, ptr %34, align 8, !tbaa !5
  store ptr %35, ptr %4, align 8, !tbaa !5
  %36 = load ptr, ptr %29, align 8, !tbaa !15
  %37 = call i32 %36(ptr noundef nonnull %3, ptr noundef nonnull %4) #7
  %38 = icmp sgt i32 %37, -1
  br i1 %38, label %39, label %41

39:                                               ; preds = %31
  %40 = trunc nuw nsw i64 %indvars.iv to i32
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #7
  br label %.loopexit

41:                                               ; preds = %31
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = load ptr, ptr %0, align 8, !tbaa !12
  %44 = getelementptr inbounds ptr, ptr %43, i64 %indvars.iv
  store ptr %42, ptr %44, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #7
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %45 = icmp sgt i64 %indvars.iv, 1
  br i1 %45, label %31, label %.loopexit.loopexit, !llvm.loop !16

.loopexit.loopexit:                               ; preds = %41
  %46 = trunc nuw nsw i64 %indvars.iv.next to i32
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.loopexit, %26, %39
  %.037 = phi i32 [ %40, %39 ], [ %27, %26 ], [ %46, %.loopexit.loopexit ]
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  %48 = load ptr, ptr %0, align 8, !tbaa !12
  %49 = sext i32 %.037 to i64
  %50 = getelementptr inbounds ptr, ptr %48, i64 %49
  store ptr %47, ptr %50, align 8, !tbaa !5
  %51 = load i32, ptr %5, align 8, !tbaa !9
  %52 = add i32 %51, 1
  store i32 %52, ptr %5, align 8, !tbaa !9
  br label %53

53:                                               ; preds = %._crit_edge42, %.loopexit
  %.028 = phi ptr [ %47, %.loopexit ], [ %.028.pre, %._crit_edge42 ]
  ret ptr %.028
}

; Function Attrs: inlinehint nounwind uwtable
declare ptr @bsearch(ptr noundef nonnull, ptr noundef nonnull, i64 noundef, i64 noundef, ptr noundef nonnull) local_unnamed_addr #4

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { noreturn "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 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 #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 = { inlinehint 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 allocsize(1) }
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 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 8}
!10 = !{!"ordered_set", !6, i64 0, !11, i64 8, !11, i64 12, !6, i64 16, !6, i64 24, !6, i64 32}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 0}
!13 = !{!10, !6, i64 24}
!14 = !{!10, !11, i64 12}
!15 = !{!10, !6, i64 16}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


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