; LLVM IR from bkaradzic/bgfx :: 3rdparty/fcpp (cpp6)

; 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.Global = type { i32, i32, ptr, ptr, i32, i32, i32, ptr, i32, i32, i32, i32, [513 x i8], ptr, i8, i8, i8, i8, i8, [32 x i8], ptr, [20 x ptr], ptr, [20 x ptr], [20 x i8], i32, [5 x ptr], [5 x ptr], i8, ptr, [1025 x i8], ptr, [31 x ptr], i32, ptr, [64 x ptr], i32, ptr, ptr, ptr, ptr, ptr, ptr, i8, i8, i8, i8, i8, i8, i8, i8, ptr, i64, i8, i8, i8, i8, i8, i8, ptr, [20 x ptr], i32, i8, i8, i8, ptr }

@type = external dso_local global <{ [127 x i8], [129 x i8] }>, align 16

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

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

; 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
define dso_local void @fpp_scanid(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = 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 4, ptr %5) #3
  %6 = load i32, ptr %4, align 4, !tbaa !9
  %7 = icmp eq i32 %6, 29
  br i1 %7, label %8, label %11

8:                                                ; preds = %2
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = call i32 @fpp_get(ptr noundef %9)
  store i32 %10, ptr %4, align 4, !tbaa !9
  br label %11

11:                                               ; preds = %8, %2
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %12

12:                                               ; preds = %57, %11
  %13 = load i32, ptr %5, align 4, !tbaa !9
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.Global, ptr %14, i32 0, i32 5
  %16 = load i32, ptr %15, align 4, !tbaa !11
  %17 = icmp eq i32 %13, %16
  br i1 %17, label %18, label %31

18:                                               ; preds = %12
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.Global, ptr %19, i32 0, i32 2
  %21 = load ptr, ptr %20, align 8, !tbaa !14
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.Global, ptr %22, i32 0, i32 5
  %24 = load i32, ptr %23, align 4, !tbaa !11
  %25 = mul nsw i32 %24, 2
  store i32 %25, ptr %23, align 4, !tbaa !11
  %26 = add nsw i32 1, %25
  %27 = sext i32 %26 to i64
  %28 = call ptr @realloc(ptr noundef %21, i64 noundef %27) #4
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.Global, ptr %29, i32 0, i32 2
  store ptr %28, ptr %30, align 8, !tbaa !14
  br label %31

31:                                               ; preds = %18, %12
  %32 = load i32, ptr %4, align 4, !tbaa !9
  %33 = trunc i32 %32 to i8
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.Global, ptr %34, i32 0, i32 2
  %36 = load ptr, ptr %35, align 8, !tbaa !14
  %37 = load i32, ptr %5, align 4, !tbaa !9
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr %5, align 4, !tbaa !9
  %39 = sext i32 %37 to i64
  %40 = getelementptr inbounds i8, ptr %36, i64 %39
  store i8 %33, ptr %40, align 1, !tbaa !15
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = call i32 @fpp_get(ptr noundef %41)
  store i32 %42, ptr %4, align 4, !tbaa !9
  br label %43

43:                                               ; preds = %31
  %44 = load i32, ptr %4, align 4, !tbaa !9
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [256 x i8], ptr @type, i64 0, i64 %45
  %47 = load i8, ptr %46, align 1, !tbaa !15
  %48 = sext i8 %47 to i32
  %49 = icmp eq i32 %48, 2
  br i1 %49, label %57, label %50

50:                                               ; preds = %43
  %51 = load i32, ptr %4, align 4, !tbaa !9
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [256 x i8], ptr @type, i64 0, i64 %52
  %54 = load i8, ptr %53, align 1, !tbaa !15
  %55 = sext i8 %54 to i32
  %56 = icmp eq i32 %55, 1
  br label %57

57:                                               ; preds = %50, %43
  %58 = phi i1 [ true, %43 ], [ %56, %50 ]
  br i1 %58, label %12, label %59, !llvm.loop !16

59:                                               ; preds = %57
  %60 = load ptr, ptr %3, align 8, !tbaa !5
  call void @fpp_unget(ptr noundef %60)
  %61 = load ptr, ptr %3, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.Global, ptr %61, i32 0, i32 2
  %63 = load ptr, ptr %62, align 8, !tbaa !14
  %64 = load i32, ptr %5, align 4, !tbaa !9
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds i8, ptr %63, i64 %65
  store i8 0, ptr %66, align 1, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret void
}

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

; Function Attrs: nounwind uwtable
declare dso_local void @fpp_unget(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 allocsize(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 = { nounwind }
attributes #4 = { nounwind allocsize(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 28}
!12 = !{!"Global", !10, i64 0, !10, i64 4, !6, i64 8, !6, i64 16, !10, i64 24, !10, i64 28, !10, i64 32, !6, i64 40, !10, i64 48, !10, i64 52, !10, i64 56, !10, i64 60, !7, i64 64, !6, i64 584, !7, i64 592, !7, i64 593, !7, i64 594, !7, i64 595, !7, i64 596, !7, i64 597, !6, i64 632, !7, i64 640, !6, i64 800, !7, i64 808, !7, i64 968, !10, i64 988, !7, i64 992, !7, i64 1032, !7, i64 1072, !6, i64 1080, !7, i64 1088, !6, i64 2120, !7, i64 2128, !10, i64 2376, !6, i64 2384, !7, i64 2392, !10, i64 2904, !6, i64 2912, !6, i64 2920, !6, i64 2928, !6, i64 2936, !6, i64 2944, !6, i64 2952, !7, i64 2960, !7, i64 2961, !7, i64 2962, !7, i64 2963, !7, i64 2964, !7, i64 2965, !7, i64 2966, !7, i64 2967, !6, i64 2968, !13, i64 2976, !7, i64 2984, !7, i64 2985, !7, i64 2986, !7, i64 2987, !7, i64 2988, !7, i64 2989, !6, i64 2992, !7, i64 3000, !10, i64 3160, !7, i64 3164, !7, i64 3165, !7, i64 3166, !6, i64 3168}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !6, i64 8}
!15 = !{!7, !7, i64 0}
!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"

@type = external dso_local local_unnamed_addr global <{ [127 x i8], [129 x i8] }>, align 16

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

; Function Attrs: nounwind uwtable
define dso_local void @fpp_scanid(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = icmp eq i32 %1, 29
  br i1 %3, label %4, label %6

4:                                                ; preds = %2
  %5 = tail call i32 @fpp_get(ptr noundef %0)
  br label %6

6:                                                ; preds = %4, %2
  %.015 = phi i32 [ %5, %4 ], [ %1, %2 ]
  %7 = getelementptr inbounds i8, ptr %0, i64 28
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  br label %.critedge

.critedge:                                        ; preds = %17, %6
  %indvars.iv = phi i64 [ %indvars.iv.next, %17 ], [ 0, %6 ]
  %.1 = phi i32 [ %21, %17 ], [ %.015, %6 ]
  %9 = load i32, ptr %7, align 4, !tbaa !5
  %10 = zext i32 %9 to i64
  %11 = icmp eq i64 %indvars.iv, %10
  %.pre = load ptr, ptr %8, align 8, !tbaa !12
  br i1 %11, label %12, label %17

12:                                               ; preds = %.critedge
  %13 = shl nsw i32 %9, 1
  store i32 %13, ptr %7, align 4, !tbaa !5
  %14 = or disjoint i32 %13, 1
  %15 = sext i32 %14 to i64
  %16 = tail call ptr @realloc(ptr noundef %.pre, i64 noundef %15) #2
  store ptr %16, ptr %8, align 8, !tbaa !12
  br label %17

17:                                               ; preds = %12, %.critedge
  %18 = phi ptr [ %16, %12 ], [ %.pre, %.critedge ]
  %19 = trunc i32 %.1 to i8
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %20 = getelementptr inbounds i8, ptr %18, i64 %indvars.iv
  store i8 %19, ptr %20, align 1, !tbaa !13
  %21 = tail call i32 @fpp_get(ptr noundef nonnull %0)
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [256 x i8], ptr @type, i64 0, i64 %22
  %24 = load i8, ptr %23, align 1, !tbaa !13
  %.off = add i8 %24, -1
  %switch = icmp ult i8 %.off, 2
  br i1 %switch, label %.critedge, label %25

25:                                               ; preds = %17
  tail call void @fpp_unget(ptr noundef nonnull %0)
  %26 = load ptr, ptr %8, align 8, !tbaa !12
  %27 = and i64 %indvars.iv.next, 4294967295
  %28 = getelementptr inbounds i8, ptr %26, i64 %27
  store i8 0, ptr %28, align 1, !tbaa !13
  ret void
}

; Function Attrs: mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias noundef ptr @realloc(ptr allocptr nocapture noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @fpp_unget(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" }
attributes #1 = { mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, 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 #2 = { nounwind allocsize(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, !7, i64 28}
!6 = !{!"Global", !7, i64 0, !7, i64 4, !10, i64 8, !10, i64 16, !7, i64 24, !7, i64 28, !7, i64 32, !10, i64 40, !7, i64 48, !7, i64 52, !7, i64 56, !7, i64 60, !8, i64 64, !10, i64 584, !8, i64 592, !8, i64 593, !8, i64 594, !8, i64 595, !8, i64 596, !8, i64 597, !10, i64 632, !8, i64 640, !10, i64 800, !8, i64 808, !8, i64 968, !7, i64 988, !8, i64 992, !8, i64 1032, !8, i64 1072, !10, i64 1080, !8, i64 1088, !10, i64 2120, !8, i64 2128, !7, i64 2376, !10, i64 2384, !8, i64 2392, !7, i64 2904, !10, i64 2912, !10, i64 2920, !10, i64 2928, !10, i64 2936, !10, i64 2944, !10, i64 2952, !8, i64 2960, !8, i64 2961, !8, i64 2962, !8, i64 2963, !8, i64 2964, !8, i64 2965, !8, i64 2966, !8, i64 2967, !10, i64 2968, !11, i64 2976, !8, i64 2984, !8, i64 2985, !8, i64 2986, !8, i64 2987, !8, i64 2988, !8, i64 2989, !10, i64 2992, !8, i64 3000, !7, i64 3160, !8, i64 3164, !8, i64 3165, !8, i64 3166, !10, i64 3168}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!6, !10, i64 8}
!13 = !{!8, !8, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass