; LLVM IR from chkn/logdb :: stress (dump)

; 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 [27 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [42 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [59 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [10 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @main(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  store i32 0, ptr %3, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  %13 = load i32, ptr %4, align 4, !tbaa !5
  %14 = icmp ne i32 %13, 2
  br i1 %14, label %15, label %22

15:                                               ; preds = %2
  %16 = load ptr, ptr %5, align 8, !tbaa !9
  %17 = getelementptr inbounds ptr, ptr %16, i64 0
  %18 = load ptr, ptr %17, align 8, !tbaa !9
  %19 = call ptr @__xpg_basename(ptr noundef %18) #4
  %20 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef %19)
  %21 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  store i32 1, ptr %3, align 4
  br label %82

22:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %23 = load ptr, ptr %5, align 8, !tbaa !9
  %24 = getelementptr inbounds ptr, ptr %23, i64 1
  %25 = load ptr, ptr %24, align 8, !tbaa !9
  %26 = call ptr @logdb_open(ptr noundef %25, i32 noundef 0)
  store ptr %26, ptr %6, align 8, !tbaa !9
  %27 = load ptr, ptr %6, align 8, !tbaa !9
  %28 = icmp ne ptr %27, null
  br i1 %28, label %31, label %29

29:                                               ; preds = %22
  %30 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  store i32 2, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %81

31:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %32 = load ptr, ptr %6, align 8, !tbaa !9
  %33 = call ptr @logdb_iter_all(ptr noundef %32)
  store ptr %33, ptr %8, align 8, !tbaa !9
  %34 = load ptr, ptr %8, align 8, !tbaa !9
  %35 = icmp ne ptr %34, null
  br i1 %35, label %38, label %36

36:                                               ; preds = %31
  %37 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  store i32 8, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %80

38:                                               ; preds = %31
  br label %39

39:                                               ; preds = %75, %38
  %40 = load ptr, ptr %8, align 8, !tbaa !9
  %41 = call i32 @logdb_iter_next(ptr noundef %40)
  %42 = icmp ne i32 %41, 0
  br i1 %42, label %43, label %76

43:                                               ; preds = %39
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %44 = load ptr, ptr %8, align 8, !tbaa !9
  %45 = call ptr @logdb_iter_current_key(ptr noundef %44)
  store ptr %45, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %46 = load ptr, ptr %8, align 8, !tbaa !9
  %47 = call ptr @logdb_iter_current_value(ptr noundef %46)
  store ptr %47, ptr %10, align 8, !tbaa !9
  %48 = load ptr, ptr %9, align 8, !tbaa !9
  %49 = icmp ne ptr %48, null
  br i1 %49, label %50, label %53

50:                                               ; preds = %43
  %51 = load ptr, ptr %10, align 8, !tbaa !9
  %52 = icmp ne ptr %51, null
  br i1 %52, label %55, label %53

53:                                               ; preds = %50, %43
  %54 = call i32 (ptr, ...) @printf(ptr noundef @.str.4)
  store i32 9, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %73

55:                                               ; preds = %50
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %56 = load ptr, ptr %9, align 8, !tbaa !9
  %57 = call ptr @logdb_buffer_data(ptr noundef %56)
  store ptr %57, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %58 = load ptr, ptr %10, align 8, !tbaa !9
  %59 = call ptr @logdb_buffer_data(ptr noundef %58)
  store ptr %59, ptr %12, align 8, !tbaa !9
  %60 = load ptr, ptr %11, align 8, !tbaa !9
  %61 = icmp ne ptr %60, null
  br i1 %61, label %62, label %65

62:                                               ; preds = %55
  %63 = load ptr, ptr %12, align 8, !tbaa !9
  %64 = icmp ne ptr %63, null
  br i1 %64, label %67, label %65

65:                                               ; preds = %62, %55
  %66 = call i32 (ptr, ...) @printf(ptr noundef @.str.5)
  store i32 10, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %72

67:                                               ; preds = %62
  %68 = load ptr, ptr %11, align 8, !tbaa !9
  %69 = load ptr, ptr %12, align 8, !tbaa !9
  %70 = load i32, ptr %69, align 4, !tbaa !5
  %71 = call i32 (ptr, ...) @printf(ptr noundef @.str.6, ptr noundef %68, i32 noundef %70)
  store i32 0, ptr %7, align 4
  br label %72

72:                                               ; preds = %67, %65
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  br label %73

73:                                               ; preds = %72, %53
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  %74 = load i32, ptr %7, align 4
  switch i32 %74, label %80 [
    i32 0, label %75
  ]

75:                                               ; preds = %73
  br label %39, !llvm.loop !11

76:                                               ; preds = %39
  %77 = load ptr, ptr %8, align 8, !tbaa !9
  call void @logdb_iter_free(ptr noundef %77)
  %78 = load ptr, ptr %6, align 8, !tbaa !9
  %79 = call i32 @logdb_close(ptr noundef %78)
  store i32 %79, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %80

80:                                               ; preds = %76, %73, %36
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %81

81:                                               ; preds = %80, %29
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %82

82:                                               ; preds = %81, %15
  %83 = load i32, ptr %3, align 4
  ret i32 %83
}

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

; Function Attrs: nounwind
declare ptr @__xpg_basename(ptr noundef) #2

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

declare ptr @logdb_open(ptr noundef, i32 noundef) #1

declare ptr @logdb_iter_all(ptr noundef) #1

declare i32 @logdb_iter_next(ptr noundef) #1

declare ptr @logdb_iter_current_key(ptr noundef) #1

declare ptr @logdb_iter_current_value(ptr noundef) #1

declare ptr @logdb_buffer_data(ptr noundef) #1

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

declare void @logdb_iter_free(ptr noundef) #1

declare i32 @logdb_close(ptr noundef) #1

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 = { "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 "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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, !10, i64 0}
!10 = !{!"any pointer", !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 [27 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [42 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [59 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [10 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @main(i32 noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %.not = icmp eq i32 %0, 2
  br i1 %.not, label %8, label %3

3:                                                ; preds = %2
  %4 = load ptr, ptr %1, align 8, !tbaa !5
  %5 = tail call ptr @__xpg_basename(ptr noundef %4) #4
  %6 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, ptr noundef %5)
  %7 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1)
  br label %.thread

8:                                                ; preds = %2
  %9 = getelementptr inbounds i8, ptr %1, i64 8
  %10 = load ptr, ptr %9, align 8, !tbaa !5
  %11 = tail call ptr @logdb_open(ptr noundef %10, i32 noundef 0) #4
  %.not30 = icmp eq ptr %11, null
  br i1 %.not30, label %12, label %14

12:                                               ; preds = %8
  %13 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  br label %.thread

14:                                               ; preds = %8
  %15 = tail call ptr @logdb_iter_all(ptr noundef nonnull %11) #4
  %.not31 = icmp eq ptr %15, null
  br i1 %.not31, label %17, label %.preheader

.preheader:                                       ; preds = %14
  %16 = tail call i32 @logdb_iter_next(ptr noundef nonnull %15) #4
  %.not3236 = icmp eq i32 %16, 0
  br i1 %.not3236, label %._crit_edge, label %.lr.ph

17:                                               ; preds = %14
  %18 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  br label %.thread

.lr.ph:                                           ; preds = %.preheader, %32
  %19 = tail call ptr @logdb_iter_current_key(ptr noundef nonnull %15) #4
  %20 = tail call ptr @logdb_iter_current_value(ptr noundef nonnull %15) #4
  %21 = icmp ne ptr %19, null
  %22 = icmp ne ptr %20, null
  %or.cond = select i1 %21, i1 %22, i1 false
  br i1 %or.cond, label %25, label %23

23:                                               ; preds = %.lr.ph
  %24 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4)
  br label %.thread

25:                                               ; preds = %.lr.ph
  %26 = tail call ptr @logdb_buffer_data(ptr noundef nonnull %19) #4
  %27 = tail call ptr @logdb_buffer_data(ptr noundef nonnull %20) #4
  %28 = icmp ne ptr %26, null
  %29 = icmp ne ptr %27, null
  %or.cond3 = select i1 %28, i1 %29, i1 false
  br i1 %or.cond3, label %32, label %30

30:                                               ; preds = %25
  %31 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5)
  br label %.thread

32:                                               ; preds = %25
  %33 = load i32, ptr %27, align 4, !tbaa !9
  %34 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6, ptr noundef nonnull %26, i32 noundef %33)
  %35 = tail call i32 @logdb_iter_next(ptr noundef nonnull %15) #4
  %.not32 = icmp eq i32 %35, 0
  br i1 %.not32, label %._crit_edge, label %.lr.ph, !llvm.loop !11

._crit_edge:                                      ; preds = %32, %.preheader
  tail call void @logdb_iter_free(ptr noundef nonnull %15) #4
  %36 = tail call i32 @logdb_close(ptr noundef nonnull %11) #4
  br label %.thread

.thread:                                          ; preds = %30, %23, %12, %._crit_edge, %17, %3
  %.5 = phi i32 [ 1, %3 ], [ 2, %12 ], [ %36, %._crit_edge ], [ 8, %17 ], [ 10, %30 ], [ 9, %23 ]
  ret i32 %.5
}

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

; Function Attrs: nounwind
declare ptr @__xpg_basename(ptr noundef) local_unnamed_addr #2

declare ptr @logdb_open(ptr noundef, i32 noundef) local_unnamed_addr #3

declare ptr @logdb_iter_all(ptr noundef) local_unnamed_addr #3

declare i32 @logdb_iter_next(ptr noundef) local_unnamed_addr #3

declare ptr @logdb_iter_current_key(ptr noundef) local_unnamed_addr #3

declare ptr @logdb_iter_current_value(ptr noundef) local_unnamed_addr #3

declare ptr @logdb_buffer_data(ptr noundef) local_unnamed_addr #3

declare void @logdb_iter_free(ptr noundef) local_unnamed_addr #3

declare i32 @logdb_close(ptr noundef) local_unnamed_addr #3

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

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


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