; LLVM IR from PaulBatchelor/sndkit :: lil (lil)

; 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._lil_list_t = type { ptr, i64, i64 }
%struct._lil_value_t = type { i64, ptr }

@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [7 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @lil_append_char(ptr noundef, i8 noundef signext) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @lil_append_string(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @lil_append_val(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @lil_list_to_value(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %9 = call ptr @alloc_value(ptr noundef null)
  store ptr %9, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  store i64 0, ptr %6, align 8, !tbaa !11
  br label %10

10:                                               ; preds = %119, %2
  %11 = load i64, ptr %6, align 8, !tbaa !11
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct._lil_list_t, ptr %12, i32 0, i32 1
  %14 = load i64, ptr %13, align 8, !tbaa !13
  %15 = icmp ult i64 %11, %14
  br i1 %15, label %16, label %122

16:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %17 = load i32, ptr %4, align 4, !tbaa !9
  %18 = icmp ne i32 %17, 0
  br i1 %18, label %19, label %28

19:                                               ; preds = %16
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct._lil_list_t, ptr %20, i32 0, i32 0
  %22 = load ptr, ptr %21, align 8, !tbaa !15
  %23 = load i64, ptr %6, align 8, !tbaa !11
  %24 = getelementptr inbounds ptr, ptr %22, i64 %23
  %25 = load ptr, ptr %24, align 8, !tbaa !5
  %26 = call ptr @lil_to_string(ptr noundef %25)
  %27 = call i32 @needs_escape(ptr noundef %26)
  br label %29

28:                                               ; preds = %16
  br label %29

29:                                               ; preds = %28, %19
  %30 = phi i32 [ %27, %19 ], [ 0, %28 ]
  store i32 %30, ptr %8, align 4, !tbaa !9
  %31 = load i64, ptr %6, align 8, !tbaa !11
  %32 = icmp ne i64 %31, 0
  br i1 %32, label %33, label %36

33:                                               ; preds = %29
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = call i32 @lil_append_char(ptr noundef %34, i8 noundef signext 32)
  br label %36

36:                                               ; preds = %33, %29
  %37 = load i32, ptr %8, align 4, !tbaa !9
  %38 = icmp ne i32 %37, 0
  br i1 %38, label %39, label %109

39:                                               ; preds = %36
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = call i32 @lil_append_char(ptr noundef %40, i8 noundef signext 123)
  store i64 0, ptr %7, align 8, !tbaa !11
  br label %42

42:                                               ; preds = %103, %39
  %43 = load i64, ptr %7, align 8, !tbaa !11
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct._lil_list_t, ptr %44, i32 0, i32 0
  %46 = load ptr, ptr %45, align 8, !tbaa !15
  %47 = load i64, ptr %6, align 8, !tbaa !11
  %48 = getelementptr inbounds ptr, ptr %46, i64 %47
  %49 = load ptr, ptr %48, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct._lil_value_t, ptr %49, i32 0, i32 0
  %51 = load i64, ptr %50, align 8, !tbaa !16
  %52 = icmp ult i64 %43, %51
  br i1 %52, label %53, label %106

53:                                               ; preds = %42
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct._lil_list_t, ptr %54, i32 0, i32 0
  %56 = load ptr, ptr %55, align 8, !tbaa !15
  %57 = load i64, ptr %6, align 8, !tbaa !11
  %58 = getelementptr inbounds ptr, ptr %56, i64 %57
  %59 = load ptr, ptr %58, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct._lil_value_t, ptr %59, i32 0, i32 1
  %61 = load ptr, ptr %60, align 8, !tbaa !18
  %62 = load i64, ptr %7, align 8, !tbaa !11
  %63 = getelementptr inbounds i8, ptr %61, i64 %62
  %64 = load i8, ptr %63, align 1, !tbaa !19
  %65 = sext i8 %64 to i32
  %66 = icmp eq i32 %65, 123
  br i1 %66, label %67, label %70

67:                                               ; preds = %53
  %68 = load ptr, ptr %5, align 8, !tbaa !5
  %69 = call i32 @lil_append_string(ptr noundef %68, ptr noundef @.str)
  br label %102

70:                                               ; preds = %53
  %71 = load ptr, ptr %3, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct._lil_list_t, ptr %71, i32 0, i32 0
  %73 = load ptr, ptr %72, align 8, !tbaa !15
  %74 = load i64, ptr %6, align 8, !tbaa !11
  %75 = getelementptr inbounds ptr, ptr %73, i64 %74
  %76 = load ptr, ptr %75, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct._lil_value_t, ptr %76, i32 0, i32 1
  %78 = load ptr, ptr %77, align 8, !tbaa !18
  %79 = load i64, ptr %7, align 8, !tbaa !11
  %80 = getelementptr inbounds i8, ptr %78, i64 %79
  %81 = load i8, ptr %80, align 1, !tbaa !19
  %82 = sext i8 %81 to i32
  %83 = icmp eq i32 %82, 125
  br i1 %83, label %84, label %87

84:                                               ; preds = %70
  %85 = load ptr, ptr %5, align 8, !tbaa !5
  %86 = call i32 @lil_append_string(ptr noundef %85, ptr noundef @.str.1)
  br label %101

87:                                               ; preds = %70
  %88 = load ptr, ptr %5, align 8, !tbaa !5
  %89 = load ptr, ptr %3, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct._lil_list_t, ptr %89, i32 0, i32 0
  %91 = load ptr, ptr %90, align 8, !tbaa !15
  %92 = load i64, ptr %6, align 8, !tbaa !11
  %93 = getelementptr inbounds ptr, ptr %91, i64 %92
  %94 = load ptr, ptr %93, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct._lil_value_t, ptr %94, i32 0, i32 1
  %96 = load ptr, ptr %95, align 8, !tbaa !18
  %97 = load i64, ptr %7, align 8, !tbaa !11
  %98 = getelementptr inbounds i8, ptr %96, i64 %97
  %99 = load i8, ptr %98, align 1, !tbaa !19
  %100 = call i32 @lil_append_char(ptr noundef %88, i8 noundef signext %99)
  br label %101

101:                                              ; preds = %87, %84
  br label %102

102:                                              ; preds = %101, %67
  br label %103

103:                                              ; preds = %102
  %104 = load i64, ptr %7, align 8, !tbaa !11
  %105 = add i64 %104, 1
  store i64 %105, ptr %7, align 8, !tbaa !11
  br label %42, !llvm.loop !20

106:                                              ; preds = %42
  %107 = load ptr, ptr %5, align 8, !tbaa !5
  %108 = call i32 @lil_append_char(ptr noundef %107, i8 noundef signext 125)
  br label %118

109:                                              ; preds = %36
  %110 = load ptr, ptr %5, align 8, !tbaa !5
  %111 = load ptr, ptr %3, align 8, !tbaa !5
  %112 = getelementptr inbounds %struct._lil_list_t, ptr %111, i32 0, i32 0
  %113 = load ptr, ptr %112, align 8, !tbaa !15
  %114 = load i64, ptr %6, align 8, !tbaa !11
  %115 = getelementptr inbounds ptr, ptr %113, i64 %114
  %116 = load ptr, ptr %115, align 8, !tbaa !5
  %117 = call i32 @lil_append_val(ptr noundef %110, ptr noundef %116)
  br label %118

118:                                              ; preds = %109, %106
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  br label %119

119:                                              ; preds = %118
  %120 = load i64, ptr %6, align 8, !tbaa !11
  %121 = add i64 %120, 1
  store i64 %121, ptr %6, align 8, !tbaa !11
  br label %10, !llvm.loop !22

122:                                              ; preds = %10
  %123 = load ptr, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  ret ptr %123
}

; Function Attrs: nounwind uwtable
declare hidden ptr @alloc_value(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden i32 @needs_escape(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @lil_to_string(ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !12, i64 8}
!14 = !{!"_lil_list_t", !6, i64 0, !12, i64 8, !12, i64 16}
!15 = !{!14, !6, i64 0}
!16 = !{!17, !12, i64 0}
!17 = !{!"_lil_value_t", !12, i64 0, !6, i64 8}
!18 = !{!17, !6, i64 8}
!19 = !{!7, !7, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = distinct !{!22, !21}


; 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 [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [7 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @lil_append_char(ptr noundef, i8 noundef signext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @lil_append_string(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @lil_append_val(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local ptr @lil_list_to_value(ptr nocapture noundef readonly %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = tail call ptr @alloc_value(ptr noundef null)
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load i64, ptr %4, align 8, !tbaa !5
  %.not40 = icmp eq i64 %5, 0
  br i1 %.not40, label %._crit_edge39, label %.lr.ph38

.lr.ph38:                                         ; preds = %2
  %.not = icmp eq i32 %1, 0
  br label %6

6:                                                ; preds = %.lr.ph38, %48
  %.035 = phi i64 [ 0, %.lr.ph38 ], [ %49, %48 ]
  br i1 %.not, label %13, label %7

7:                                                ; preds = %6
  %8 = load ptr, ptr %0, align 8, !tbaa !11
  %9 = getelementptr inbounds ptr, ptr %8, i64 %.035
  %10 = load ptr, ptr %9, align 8, !tbaa !12
  %11 = tail call ptr @lil_to_string(ptr noundef %10)
  %12 = tail call i32 @needs_escape(ptr noundef %11)
  br label %13

13:                                               ; preds = %6, %7
  %14 = phi i32 [ %12, %7 ], [ 0, %6 ]
  %.not32 = icmp eq i64 %.035, 0
  br i1 %.not32, label %17, label %15

15:                                               ; preds = %13
  %16 = tail call i32 @lil_append_char(ptr noundef %3, i8 noundef signext 32)
  br label %17

17:                                               ; preds = %15, %13
  %.not33 = icmp eq i32 %14, 0
  br i1 %.not33, label %43, label %18

18:                                               ; preds = %17
  %19 = tail call i32 @lil_append_char(ptr noundef %3, i8 noundef signext 123)
  %20 = load ptr, ptr %0, align 8, !tbaa !11
  %21 = getelementptr inbounds ptr, ptr %20, i64 %.035
  %22 = load ptr, ptr %21, align 8, !tbaa !12
  %23 = load i64, ptr %22, align 8, !tbaa !13
  %.not41 = icmp eq i64 %23, 0
  br i1 %.not41, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %18, %35
  %24 = phi ptr [ %39, %35 ], [ %22, %18 ]
  %.03034 = phi i64 [ %36, %35 ], [ 0, %18 ]
  %25 = getelementptr inbounds i8, ptr %24, i64 8
  %26 = load ptr, ptr %25, align 8, !tbaa !15
  %27 = getelementptr inbounds i8, ptr %26, i64 %.03034
  %28 = load i8, ptr %27, align 1, !tbaa !16
  switch i8 %28, label %33 [
    i8 123, label %29
    i8 125, label %31
  ]

29:                                               ; preds = %.lr.ph
  %30 = tail call i32 @lil_append_string(ptr noundef %3, ptr noundef nonnull @.str)
  br label %35

31:                                               ; preds = %.lr.ph
  %32 = tail call i32 @lil_append_string(ptr noundef %3, ptr noundef nonnull @.str.1)
  br label %35

33:                                               ; preds = %.lr.ph
  %34 = tail call i32 @lil_append_char(ptr noundef %3, i8 noundef signext %28)
  br label %35

35:                                               ; preds = %29, %33, %31
  %36 = add nuw i64 %.03034, 1
  %37 = load ptr, ptr %0, align 8, !tbaa !11
  %38 = getelementptr inbounds ptr, ptr %37, i64 %.035
  %39 = load ptr, ptr %38, align 8, !tbaa !12
  %40 = load i64, ptr %39, align 8, !tbaa !13
  %41 = icmp ult i64 %36, %40
  br i1 %41, label %.lr.ph, label %._crit_edge, !llvm.loop !17

._crit_edge:                                      ; preds = %35, %18
  %42 = tail call i32 @lil_append_char(ptr noundef %3, i8 noundef signext 125)
  br label %48

43:                                               ; preds = %17
  %44 = load ptr, ptr %0, align 8, !tbaa !11
  %45 = getelementptr inbounds ptr, ptr %44, i64 %.035
  %46 = load ptr, ptr %45, align 8, !tbaa !12
  %47 = tail call i32 @lil_append_val(ptr noundef %3, ptr noundef %46)
  br label %48

48:                                               ; preds = %43, %._crit_edge
  %49 = add nuw i64 %.035, 1
  %50 = load i64, ptr %4, align 8, !tbaa !5
  %51 = icmp ult i64 %49, %50
  br i1 %51, label %6, label %._crit_edge39, !llvm.loop !19

._crit_edge39:                                    ; preds = %48, %2
  ret ptr %3
}

; Function Attrs: nounwind uwtable
declare hidden ptr @alloc_value(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden i32 @needs_escape(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @lil_to_string(ptr noundef) local_unnamed_addr #0

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

!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, !10, i64 8}
!6 = !{!"_lil_list_t", !7, i64 0, !10, i64 8, !10, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!7, !7, i64 0}
!13 = !{!14, !10, i64 0}
!14 = !{!"_lil_value_t", !10, i64 0, !7, i64 8}
!15 = !{!14, !7, i64 8}
!16 = !{!8, !8, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}


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