; LLVM IR from cruppstahl/upscaledb :: tools (config)

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

@.str = external hidden unnamed_addr constant [30 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @config_parse_string(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca %struct.JSON_config, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  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 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 32, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  store ptr null, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %11 = call noalias ptr @calloc(i64 noundef 72, i64 noundef 1) #5
  store ptr %11, ptr %9, align 8, !tbaa !5
  %12 = load ptr, ptr %9, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %15, label %14

14:                                               ; preds = %2
  store i32 -6, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %55

15:                                               ; preds = %2
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr null, ptr %16, align 8, !tbaa !5
  call void @init_JSON_config(ptr noundef %7)
  %17 = getelementptr inbounds %struct.JSON_config, ptr %7, i32 0, i32 2
  store i32 20, ptr %17, align 8, !tbaa !11
  %18 = getelementptr inbounds %struct.JSON_config, ptr %7, i32 0, i32 0
  store ptr @__parser_cb, ptr %18, align 8, !tbaa !13
  %19 = load ptr, ptr %9, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.JSON_config, ptr %7, i32 0, i32 1
  store ptr %19, ptr %20, align 8, !tbaa !14
  %21 = getelementptr inbounds %struct.JSON_config, ptr %7, i32 0, i32 3
  store i32 1, ptr %21, align 4, !tbaa !15
  %22 = getelementptr inbounds %struct.JSON_config, ptr %7, i32 0, i32 4
  store i32 1, ptr %22, align 8, !tbaa !16
  %23 = call ptr @new_JSON_parser(ptr noundef %7)
  store ptr %23, ptr %8, align 8, !tbaa !5
  br label %24

24:                                               ; preds = %39, %15
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = load i8, ptr %25, align 1, !tbaa !17
  %27 = icmp ne i8 %26, 0
  br i1 %27, label %28, label %44

28:                                               ; preds = %24
  %29 = load ptr, ptr %8, align 8, !tbaa !5
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = load i8, ptr %30, align 1, !tbaa !17
  %32 = sext i8 %31 to i32
  %33 = call i32 @JSON_parser_char(ptr noundef %29, i32 noundef %32)
  %34 = icmp ne i32 %33, 0
  br i1 %34, label %39, label %35

35:                                               ; preds = %28
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  call void @delete_JSON_parser(ptr noundef %36)
  %37 = load i32, ptr %6, align 4, !tbaa !9
  call void (i32, ptr, ...) @hlog(i32 noundef 3, ptr noundef @.str, i32 noundef %37)
  %38 = load ptr, ptr %9, align 8, !tbaa !5
  call void @config_clear_table(ptr noundef %38)
  store i32 -8, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %55

39:                                               ; preds = %28
  %40 = load i32, ptr %6, align 4, !tbaa !9
  %41 = add i32 %40, 1
  store i32 %41, ptr %6, align 4, !tbaa !9
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = getelementptr inbounds i8, ptr %42, i32 1
  store ptr %43, ptr %4, align 8, !tbaa !5
  br label %24, !llvm.loop !18

44:                                               ; preds = %24
  %45 = load ptr, ptr %8, align 8, !tbaa !5
  %46 = call i32 @JSON_parser_done(ptr noundef %45)
  %47 = icmp ne i32 %46, 0
  br i1 %47, label %51, label %48

48:                                               ; preds = %44
  %49 = load ptr, ptr %8, align 8, !tbaa !5
  call void @delete_JSON_parser(ptr noundef %49)
  %50 = load ptr, ptr %9, align 8, !tbaa !5
  call void @config_clear_table(ptr noundef %50)
  store i32 -8, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %55

51:                                               ; preds = %44
  %52 = load ptr, ptr %9, align 8, !tbaa !5
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %52, ptr %53, align 8, !tbaa !5
  %54 = load ptr, ptr %8, align 8, !tbaa !5
  call void @delete_JSON_parser(ptr noundef %54)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %55

55:                                               ; preds = %51, %48, %35, %14
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  %56 = load i32, ptr %3, align 4
  ret i32 %56
}

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

; Function Attrs: nounwind allocsize(0,1)
declare noalias ptr @calloc(i64 noundef, i64 noundef) #2

declare void @init_JSON_config(ptr noundef) #3

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

declare ptr @new_JSON_parser(ptr noundef) #3

declare i32 @JSON_parser_char(ptr noundef, i32 noundef) #3

declare void @delete_JSON_parser(ptr noundef) #3

declare void @hlog(i32 noundef, ptr noundef, ...) #3

; Function Attrs: nounwind uwtable
declare dso_local void @config_clear_table(ptr noundef) #0

declare i32 @JSON_parser_done(ptr noundef) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nounwind allocsize(0,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 = { "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 = { nounwind allocsize(0,1) }

!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, !10, i64 16}
!12 = !{!"", !6, i64 0, !6, i64 8, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28}
!13 = !{!12, !6, i64 0}
!14 = !{!12, !6, i64 8}
!15 = !{!12, !10, i64 20}
!16 = !{!12, !10, i64 24}
!17 = !{!7, !7, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"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.JSON_config = type { ptr, ptr, i32, i32, i32, i32 }

@.str = external hidden unnamed_addr constant [30 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local range(i32 -8, 1) i32 @config_parse_string(ptr nocapture noundef readonly %0, ptr nocapture noundef writeonly %1) local_unnamed_addr #0 {
  %3 = alloca %struct.JSON_config, align 8
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %3) #4
  %4 = tail call noalias dereferenceable_or_null(72) ptr @calloc(i64 noundef 72, i64 noundef 1) #5
  %.not = icmp eq ptr %4, null
  br i1 %.not, label %23, label %5

5:                                                ; preds = %2
  store ptr null, ptr %1, align 8, !tbaa !5
  call void @init_JSON_config(ptr noundef nonnull %3) #4
  %6 = getelementptr inbounds i8, ptr %3, i64 16
  store i32 20, ptr %6, align 8, !tbaa !9
  store ptr @__parser_cb, ptr %3, align 8, !tbaa !12
  %7 = getelementptr inbounds i8, ptr %3, i64 8
  store ptr %4, ptr %7, align 8, !tbaa !13
  %8 = getelementptr inbounds i8, ptr %3, i64 20
  store i32 1, ptr %8, align 4, !tbaa !14
  %9 = getelementptr inbounds i8, ptr %3, i64 24
  store i32 1, ptr %9, align 8, !tbaa !15
  %10 = call ptr @new_JSON_parser(ptr noundef nonnull %3) #4
  %11 = load i8, ptr %0, align 1, !tbaa !16
  %.not2125 = icmp eq i8 %11, 0
  br i1 %.not2125, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %5, %16
  %12 = phi i8 [ %19, %16 ], [ %11, %5 ]
  %.01727 = phi i32 [ %17, %16 ], [ 0, %5 ]
  %.01826 = phi ptr [ %18, %16 ], [ %0, %5 ]
  %13 = sext i8 %12 to i32
  %14 = call i32 @JSON_parser_char(ptr noundef %10, i32 noundef %13) #4
  %.not23 = icmp eq i32 %14, 0
  br i1 %.not23, label %15, label %16

15:                                               ; preds = %.lr.ph
  call void @delete_JSON_parser(ptr noundef %10) #4
  call void (i32, ptr, ...) @hlog(i32 noundef 3, ptr noundef nonnull @.str, i32 noundef %.01727) #4
  call void @config_clear_table(ptr noundef nonnull %4)
  br label %23

16:                                               ; preds = %.lr.ph
  %17 = add i32 %.01727, 1
  %18 = getelementptr inbounds i8, ptr %.01826, i64 1
  %19 = load i8, ptr %18, align 1, !tbaa !16
  %.not21 = icmp eq i8 %19, 0
  br i1 %.not21, label %._crit_edge, label %.lr.ph, !llvm.loop !17

._crit_edge:                                      ; preds = %16, %5
  %20 = call i32 @JSON_parser_done(ptr noundef %10) #4
  %.not22 = icmp eq i32 %20, 0
  br i1 %.not22, label %21, label %22

21:                                               ; preds = %._crit_edge
  call void @delete_JSON_parser(ptr noundef %10) #4
  call void @config_clear_table(ptr noundef nonnull %4)
  br label %23

22:                                               ; preds = %._crit_edge
  store ptr %4, ptr %1, align 8, !tbaa !5
  call void @delete_JSON_parser(ptr noundef %10) #4
  br label %23

23:                                               ; preds = %2, %22, %21, %15
  %.0 = phi i32 [ -8, %15 ], [ 0, %22 ], [ -8, %21 ], [ -6, %2 ]
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %3) #4
  ret i32 %.0
}

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

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @calloc(i64 noundef, i64 noundef) local_unnamed_addr #2

declare void @init_JSON_config(ptr noundef) local_unnamed_addr #3

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

declare ptr @new_JSON_parser(ptr noundef) local_unnamed_addr #3

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

declare void @delete_JSON_parser(ptr noundef) local_unnamed_addr #3

declare void @hlog(i32 noundef, ptr noundef, ...) local_unnamed_addr #3

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

declare i32 @JSON_parser_done(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

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 = { mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(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 = { "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 = { nounwind allocsize(0,1) }

!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 16}
!10 = !{!"", !6, i64 0, !6, i64 8, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 0}
!13 = !{!10, !6, i64 8}
!14 = !{!10, !11, i64 20}
!15 = !{!10, !11, i64 24}
!16 = !{!7, !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


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