; LLVM IR from cruppstahl/upscaledb :: 3rdparty/json (main)

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

@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [30 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [38 x i8], align 1
@stdin = external global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [41 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [31 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 i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca %struct.JSON_config, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  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
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 32, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  store ptr null, ptr %9, align 8, !tbaa !9
  call void @init_JSON_config(ptr noundef %8)
  %12 = getelementptr inbounds %struct.JSON_config, ptr %8, i32 0, i32 2
  store i32 20, ptr %12, align 8, !tbaa !11
  %13 = getelementptr inbounds %struct.JSON_config, ptr %8, i32 0, i32 0
  store ptr @print, ptr %13, align 8, !tbaa !13
  %14 = getelementptr inbounds %struct.JSON_config, ptr %8, i32 0, i32 3
  store i32 1, ptr %14, align 4, !tbaa !14
  %15 = getelementptr inbounds %struct.JSON_config, ptr %8, i32 0, i32 4
  store i32 0, ptr %15, align 8, !tbaa !15
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = icmp sge i32 %16, 2
  br i1 %17, label %18, label %31

18:                                               ; preds = %2
  %19 = load ptr, ptr %5, align 8, !tbaa !9
  %20 = getelementptr inbounds ptr, ptr %19, i64 1
  %21 = load ptr, ptr %20, align 8, !tbaa !9
  %22 = call ptr @setlocale(i32 noundef 6, ptr noundef %21) #4
  %23 = icmp ne ptr %22, null
  br i1 %23, label %30, label %24

24:                                               ; preds = %18
  %25 = load ptr, ptr @stderr, align 8, !tbaa !9
  %26 = load ptr, ptr %5, align 8, !tbaa !9
  %27 = getelementptr inbounds ptr, ptr %26, i64 1
  %28 = load ptr, ptr %27, align 8, !tbaa !9
  %29 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %25, ptr noundef @.str, ptr noundef %28) #4
  br label %30

30:                                               ; preds = %24, %18
  br label %34

31:                                               ; preds = %2
  %32 = load ptr, ptr @stderr, align 8, !tbaa !9
  %33 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %32, ptr noundef @.str.1) #4
  br label %34

34:                                               ; preds = %31, %30
  %35 = call ptr @new_JSON_parser(ptr noundef %8)
  store ptr %35, ptr %9, align 8, !tbaa !9
  %36 = load ptr, ptr @stdin, align 8, !tbaa !9
  store ptr %36, ptr %7, align 8, !tbaa !9
  br label %37

37:                                               ; preds = %60, %34
  %38 = load ptr, ptr %7, align 8, !tbaa !9
  %39 = icmp ne ptr %38, null
  br i1 %39, label %40, label %63

40:                                               ; preds = %37
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %41 = load ptr, ptr %7, align 8, !tbaa !9
  %42 = call i32 @fgetc(ptr noundef %41)
  store i32 %42, ptr %10, align 4, !tbaa !5
  %43 = load i32, ptr %10, align 4, !tbaa !5
  %44 = icmp sle i32 %43, 0
  br i1 %44, label %45, label %46

45:                                               ; preds = %40
  store i32 2, ptr %11, align 4
  br label %57

46:                                               ; preds = %40
  %47 = load ptr, ptr %9, align 8, !tbaa !9
  %48 = load i32, ptr %10, align 4, !tbaa !5
  %49 = call i32 @JSON_parser_char(ptr noundef %47, i32 noundef %48)
  %50 = icmp ne i32 %49, 0
  br i1 %50, label %56, label %51

51:                                               ; preds = %46
  %52 = load ptr, ptr %9, align 8, !tbaa !9
  call void @delete_JSON_parser(ptr noundef %52)
  %53 = load ptr, ptr @stderr, align 8, !tbaa !9
  %54 = load i32, ptr %6, align 4, !tbaa !5
  %55 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %53, ptr noundef @.str.2, i32 noundef %54) #4
  store i32 1, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %57

56:                                               ; preds = %46
  store i32 0, ptr %11, align 4
  br label %57

57:                                               ; preds = %56, %51, %45
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  %58 = load i32, ptr %11, align 4
  switch i32 %58, label %72 [
    i32 0, label %59
    i32 2, label %63
  ]

59:                                               ; preds = %57
  br label %60

60:                                               ; preds = %59
  %61 = load i32, ptr %6, align 4, !tbaa !5
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %6, align 4, !tbaa !5
  br label %37, !llvm.loop !16

63:                                               ; preds = %57, %37
  %64 = load ptr, ptr %9, align 8, !tbaa !9
  %65 = call i32 @JSON_parser_done(ptr noundef %64)
  %66 = icmp ne i32 %65, 0
  br i1 %66, label %71, label %67

67:                                               ; preds = %63
  %68 = load ptr, ptr %9, align 8, !tbaa !9
  call void @delete_JSON_parser(ptr noundef %68)
  %69 = load ptr, ptr @stderr, align 8, !tbaa !9
  %70 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %69, ptr noundef @.str.3) #4
  store i32 1, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %72

71:                                               ; preds = %63
  store i32 0, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %72

72:                                               ; preds = %71, %67, %57
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  %73 = load i32, ptr %3, align 4
  ret i32 %73
}

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

declare void @init_JSON_config(ptr noundef) #2

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

; Function Attrs: nounwind
declare ptr @setlocale(i32 noundef, ptr noundef) #3

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #3

declare ptr @new_JSON_parser(ptr noundef) #2

declare i32 @fgetc(ptr noundef) #2

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

declare void @delete_JSON_parser(ptr noundef) #2

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

declare i32 @JSON_parser_done(ptr noundef) #2

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

@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [30 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [38 x i8], align 1
@stdin = external local_unnamed_addr global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [41 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [31 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @main(i32 noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = alloca %struct.JSON_config, align 8
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %3) #5
  call void @init_JSON_config(ptr noundef nonnull %3) #5
  %4 = getelementptr inbounds i8, ptr %3, i64 16
  store i32 20, ptr %4, align 8, !tbaa !5
  store ptr @print, ptr %3, align 8, !tbaa !11
  %5 = getelementptr inbounds i8, ptr %3, i64 20
  store i32 1, ptr %5, align 4, !tbaa !12
  %6 = getelementptr inbounds i8, ptr %3, i64 24
  store i32 0, ptr %6, align 8, !tbaa !13
  %7 = icmp sgt i32 %0, 1
  br i1 %7, label %8, label %16

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

12:                                               ; preds = %8
  %13 = load ptr, ptr @stderr, align 8, !tbaa !14
  %14 = load ptr, ptr %9, align 8, !tbaa !14
  %15 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %13, ptr noundef nonnull @.str, ptr noundef %14) #6
  br label %19

16:                                               ; preds = %2
  %17 = load ptr, ptr @stderr, align 8, !tbaa !14
  %18 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %17, ptr noundef nonnull @.str.1) #6
  br label %19

19:                                               ; preds = %8, %12, %16
  %20 = call ptr @new_JSON_parser(ptr noundef nonnull %3) #5
  %21 = load ptr, ptr @stdin, align 8, !tbaa !14
  %.not18 = icmp eq ptr %21, null
  br i1 %.not18, label %._crit_edge, label %.lr.ph.split

.lr.ph.split:                                     ; preds = %19
  %22 = call i32 @fgetc(ptr noundef nonnull %21)
  %23 = icmp slt i32 %22, 1
  br i1 %23, label %._crit_edge, label %.lr.ph31

.lr.ph31:                                         ; preds = %.lr.ph.split, %28
  %24 = phi i32 [ %30, %28 ], [ %22, %.lr.ph.split ]
  %.0152830 = phi i32 [ %29, %28 ], [ 0, %.lr.ph.split ]
  %25 = call i32 @JSON_parser_char(ptr noundef %20, i32 noundef %24) #5
  %.not19 = icmp eq i32 %25, 0
  br i1 %.not19, label %.thread, label %28

.thread:                                          ; preds = %.lr.ph31
  call void @delete_JSON_parser(ptr noundef %20) #5
  %26 = load ptr, ptr @stderr, align 8, !tbaa !14
  %27 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %26, ptr noundef nonnull @.str.2, i32 noundef %.0152830) #6
  br label %36

28:                                               ; preds = %.lr.ph31
  %29 = add nuw nsw i32 %.0152830, 1
  %30 = call i32 @fgetc(ptr noundef nonnull %21)
  %31 = icmp slt i32 %30, 1
  br i1 %31, label %._crit_edge, label %.lr.ph31

._crit_edge:                                      ; preds = %28, %.lr.ph.split, %19
  %32 = call i32 @JSON_parser_done(ptr noundef %20) #5
  %.not20 = icmp eq i32 %32, 0
  br i1 %.not20, label %33, label %36

33:                                               ; preds = %._crit_edge
  call void @delete_JSON_parser(ptr noundef %20) #5
  %34 = load ptr, ptr @stderr, align 8, !tbaa !14
  %35 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %34, ptr noundef nonnull @.str.3) #6
  br label %36

36:                                               ; preds = %.thread, %._crit_edge, %33
  %.2 = phi i32 [ 1, %33 ], [ 0, %._crit_edge ], [ 1, %.thread ]
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %3) #5
  ret i32 %.2
}

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

declare void @init_JSON_config(ptr noundef) local_unnamed_addr #2

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

; Function Attrs: nounwind
declare ptr @setlocale(i32 noundef, ptr noundef) local_unnamed_addr #3

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

declare ptr @new_JSON_parser(ptr noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @fgetc(ptr nocapture noundef) local_unnamed_addr #4

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

declare void @delete_JSON_parser(ptr noundef) local_unnamed_addr #2

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

declare i32 @JSON_parser_done(ptr noundef) local_unnamed_addr #2

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 = { "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 "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 = { 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 #5 = { nounwind }
attributes #6 = { cold 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, !10, i64 16}
!6 = !{!"", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!6, !10, i64 20}
!13 = !{!6, !10, i64 24}
!14 = !{!7, !7, i64 0}


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