; LLVM IR from recrsn/tinydb :: database (show_table_info)

; 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.table_info = type { [32 x i8], i32, [32 x %struct.field], i64 }
%struct.field = type { [32 x i8], i64, i32 }

@.str.33 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.34 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.35 = external hidden unnamed_addr constant [12 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 ptr @field_type_to_str(i32 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i64 @row_size(ptr noundef byval(%struct.table_info) align 8) #1

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

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @show_table_info(ptr noundef byval(%struct.table_info) align 8 %0) #1 {
  %2 = alloca i32, align 4
  %3 = getelementptr inbounds %struct.table_info, ptr %0, i32 0, i32 0
  %4 = getelementptr inbounds [32 x i8], ptr %3, i64 0, i64 0
  %5 = call i32 (ptr, ...) @printf(ptr noundef @.str.33, ptr noundef %4)
  %6 = call i64 @row_size(ptr noundef byval(%struct.table_info) align 8 %0)
  %7 = call i32 (ptr, ...) @printf(ptr noundef @.str.34, i64 noundef %6)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %8

8:                                                ; preds = %35, %1
  %9 = load i32, ptr %2, align 4, !tbaa !5
  %10 = getelementptr inbounds %struct.table_info, ptr %0, i32 0, i32 1
  %11 = load i32, ptr %10, align 8, !tbaa !9
  %12 = icmp slt i32 %9, %11
  br i1 %12, label %14, label %13

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

14:                                               ; preds = %8
  %15 = getelementptr inbounds %struct.table_info, ptr %0, i32 0, i32 2
  %16 = load i32, ptr %2, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [32 x %struct.field], ptr %15, i64 0, i64 %17
  %19 = getelementptr inbounds %struct.field, ptr %18, i32 0, i32 0
  %20 = getelementptr inbounds [32 x i8], ptr %19, i64 0, i64 0
  %21 = getelementptr inbounds %struct.table_info, ptr %0, i32 0, i32 2
  %22 = load i32, ptr %2, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [32 x %struct.field], ptr %21, i64 0, i64 %23
  %25 = getelementptr inbounds %struct.field, ptr %24, i32 0, i32 2
  %26 = load i32, ptr %25, align 8, !tbaa !12
  %27 = call ptr @field_type_to_str(i32 noundef %26)
  %28 = getelementptr inbounds %struct.table_info, ptr %0, i32 0, i32 2
  %29 = load i32, ptr %2, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [32 x %struct.field], ptr %28, i64 0, i64 %30
  %32 = getelementptr inbounds %struct.field, ptr %31, i32 0, i32 1
  %33 = load i64, ptr %32, align 8, !tbaa !14
  %34 = call i32 (ptr, ...) @printf(ptr noundef @.str.35, ptr noundef %20, ptr noundef %27, i64 noundef %33)
  br label %35

35:                                               ; preds = %14
  %36 = load i32, ptr %2, align 4, !tbaa !5
  %37 = add nsw i32 %36, 1
  store i32 %37, ptr %2, align 4, !tbaa !5
  br label %8, !llvm.loop !15

38:                                               ; preds = %13
  ret i1 true
}

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

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 32}
!10 = !{!"", !7, i64 0, !6, i64 32, !7, i64 40, !11, i64 1576}
!11 = !{!"long", !7, i64 0}
!12 = !{!13, !6, i64 40}
!13 = !{!"", !7, i64 0, !11, i64 32, !6, i64 40}
!14 = !{!13, !11, i64 32}
!15 = distinct !{!15, !16}
!16 = !{!"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"

%struct.table_info = type { [32 x i8], i32, [32 x %struct.field], i64 }
%struct.field = type { [32 x i8], i64, i32 }

@.str.33 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.34 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.35 = external hidden unnamed_addr constant [12 x i8], align 1

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

; Function Attrs: nounwind uwtable
declare dso_local i64 @row_size(ptr noundef byval(%struct.table_info) align 8) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local noundef zeroext i1 @show_table_info(ptr noundef byval(%struct.table_info) align 8 %0) local_unnamed_addr #0 {
  %2 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.33, ptr noundef nonnull %0)
  %3 = call i64 @row_size(ptr noundef nonnull byval(%struct.table_info) align 8 %0)
  %4 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.34, i64 noundef %3)
  %5 = getelementptr inbounds i8, ptr %0, i64 32
  %6 = load i32, ptr %5, align 8, !tbaa !5
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %1
  %8 = getelementptr inbounds i8, ptr %0, i64 40
  br label %9

._crit_edge:                                      ; preds = %9, %1
  ret i1 true

9:                                                ; preds = %.lr.ph, %9
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %9 ]
  %10 = getelementptr inbounds [32 x %struct.field], ptr %8, i64 0, i64 %indvars.iv
  %11 = getelementptr inbounds i8, ptr %10, i64 40
  %12 = load i32, ptr %11, align 8, !tbaa !11
  %13 = call ptr @field_type_to_str(i32 noundef %12)
  %14 = getelementptr inbounds i8, ptr %10, i64 32
  %15 = load i64, ptr %14, align 8, !tbaa !13
  %16 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.35, ptr noundef nonnull %10, ptr noundef %13, i64 noundef %15)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %17 = load i32, ptr %5, align 8, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = icmp slt i64 %indvars.iv.next, %18
  br i1 %19, label %9, label %._crit_edge, !llvm.loop !14
}

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

!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, !9, i64 32}
!6 = !{!"", !7, i64 0, !9, i64 32, !7, i64 40, !10, i64 1576}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !9, i64 40}
!12 = !{!"", !7, i64 0, !10, i64 32, !9, i64 40}
!13 = !{!12, !10, i64 32}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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