; LLVM IR from kala13x/libxutils :: examples (statcov)

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

@.str = external hidden unnamed_addr constant [9 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @COVID_ParseCase(ptr noundef %0, i64 noundef %1, ptr noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca [2048 x i8], align 16
  %12 = alloca [2048 x i8], align 16
  %13 = alloca i64, align 8
  %14 = alloca i64, align 8
  %15 = alloca ptr, align 8
  %16 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = load i64, ptr %6, align 8, !tbaa !9
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = call i32 @xstrnsrc(ptr noundef %17, i64 noundef %18, ptr noundef %19, i64 noundef 0)
  store i32 %20, ptr %8, align 4, !tbaa !11
  %21 = load i32, ptr %8, align 4, !tbaa !11
  %22 = icmp slt i32 %21, 0
  br i1 %22, label %23, label %24

23:                                               ; preds = %3
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %75

24:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #6
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = load i32, ptr %8, align 4, !tbaa !11
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds i8, ptr %25, i64 %27
  store ptr %28, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 2048, ptr %11) #6
  call void @llvm.memset.p0.i64(ptr align 16 %11, i8 0, i64 2048, i1 false)
  call void @llvm.lifetime.start.p0(i64 2048, ptr %12) #6
  call void @llvm.memset.p0.i64(ptr align 16 %12, i8 0, i64 2048, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #6
  %29 = getelementptr inbounds [2048 x i8], ptr %12, i64 0, i64 0
  %30 = load ptr, ptr %10, align 8, !tbaa !5
  %31 = call i64 @xstrncuts(ptr noundef %29, i64 noundef 2048, ptr noundef %30, ptr noundef @.str, ptr noundef @.str.1)
  store i64 %31, ptr %14, align 8, !tbaa !9
  %32 = load i64, ptr %14, align 8, !tbaa !9
  %33 = icmp ne i64 %32, 0
  br i1 %33, label %35, label %34

34:                                               ; preds = %24
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %74

35:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #6
  %36 = getelementptr inbounds [2048 x i8], ptr %12, i64 0, i64 0
  %37 = call ptr @xstrsplit(ptr noundef %36, ptr noundef @.str.2)
  store ptr %37, ptr %15, align 8, !tbaa !5
  %38 = load ptr, ptr %15, align 8, !tbaa !5
  %39 = icmp eq ptr %38, null
  br i1 %39, label %40, label %43

40:                                               ; preds = %35
  %41 = getelementptr inbounds [2048 x i8], ptr %12, i64 0, i64 0
  %42 = call i32 @atoi(ptr noundef %41) #7
  store i32 %42, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %73

43:                                               ; preds = %35
  store i64 0, ptr %13, align 8, !tbaa !9
  br label %44

44:                                               ; preds = %66, %43
  %45 = load i64, ptr %13, align 8, !tbaa !9
  %46 = load ptr, ptr %15, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.XArray_, ptr %46, i32 0, i32 8
  %48 = load i64, ptr %47, align 8, !tbaa !13
  %49 = icmp ult i64 %45, %48
  br i1 %49, label %50, label %69

50:                                               ; preds = %44
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #6
  %51 = load ptr, ptr %15, align 8, !tbaa !5
  %52 = load i64, ptr %13, align 8, !tbaa !9
  %53 = call ptr @XArray_GetData(ptr noundef %51, i64 noundef %52)
  store ptr %53, ptr %16, align 8, !tbaa !5
  %54 = load ptr, ptr %16, align 8, !tbaa !5
  %55 = icmp ne ptr %54, null
  br i1 %55, label %56, label %65

56:                                               ; preds = %50
  %57 = getelementptr inbounds [2048 x i8], ptr %11, i64 0, i64 0
  %58 = getelementptr inbounds [2048 x i8], ptr %11, i64 0, i64 0
  %59 = call i64 @strlen(ptr noundef %58) #7
  %60 = trunc i64 %59 to i32
  %61 = sub nsw i32 2048, %60
  %62 = sext i32 %61 to i64
  %63 = load ptr, ptr %16, align 8, !tbaa !5
  %64 = call i64 (ptr, i64, ptr, ...) @xstrncatf(ptr noundef %57, i64 noundef %62, ptr noundef @.str.3, ptr noundef %63)
  br label %65

65:                                               ; preds = %56, %50
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #6
  br label %66

66:                                               ; preds = %65
  %67 = load i64, ptr %13, align 8, !tbaa !9
  %68 = add i64 %67, 1
  store i64 %68, ptr %13, align 8, !tbaa !9
  br label %44, !llvm.loop !15

69:                                               ; preds = %44
  %70 = load ptr, ptr %15, align 8, !tbaa !5
  call void @XArray_Destroy(ptr noundef %70)
  %71 = getelementptr inbounds [2048 x i8], ptr %11, i64 0, i64 0
  %72 = call i32 @atoi(ptr noundef %71) #7
  store i32 %72, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %73

73:                                               ; preds = %69, %40
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #6
  br label %74

74:                                               ; preds = %73, %34
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #6
  call void @llvm.lifetime.end.p0(i64 2048, ptr %12) #6
  call void @llvm.lifetime.end.p0(i64 2048, ptr %11) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #6
  br label %75

75:                                               ; preds = %74, %23
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  %76 = load i32, ptr %4, align 4
  ret i32 %76
}

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

declare i32 @xstrnsrc(ptr noundef, i64 noundef, ptr noundef, i64 noundef) #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

declare i64 @xstrncuts(ptr noundef, i64 noundef, ptr noundef, ptr noundef, ptr noundef) #2

declare ptr @xstrsplit(ptr noundef, ptr noundef) #2

; Function Attrs: inlinehint nounwind willreturn memory(read) uwtable
declare i32 @atoi(ptr noundef nonnull) #4

declare ptr @XArray_GetData(ptr noundef, i64 noundef) #2

declare i64 @xstrncatf(ptr noundef, i64 noundef, ptr noundef, ...) #2

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #5

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

declare void @XArray_Destroy(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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { inlinehint nounwind willreturn memory(read) 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 #5 = { nounwind willreturn memory(read) "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 #6 = { nounwind }
attributes #7 = { nounwind willreturn memory(read) }

!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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !10, i64 48}
!14 = !{!"XArray_", !6, i64 0, !6, i64 8, !12, i64 16, !6, i64 24, !7, i64 32, !7, i64 33, !7, i64 34, !10, i64 40, !10, i64 48}
!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"

@.str = external hidden unnamed_addr constant [9 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @COVID_ParseCase(ptr noundef %0, i64 noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = alloca [2048 x i8], align 16
  %5 = alloca [2048 x i8], align 16
  %6 = tail call i32 @xstrnsrc(ptr noundef %0, i64 noundef %1, ptr noundef %2, i64 noundef 0) #6
  %7 = icmp slt i32 %6, 0
  br i1 %7, label %29, label %8

8:                                                ; preds = %3
  %9 = zext nneg i32 %6 to i64
  %10 = getelementptr inbounds i8, ptr %0, i64 %9
  call void @llvm.lifetime.start.p0(i64 2048, ptr nonnull %4) #6
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(2048) %4, i8 0, i64 2048, i1 false)
  call void @llvm.lifetime.start.p0(i64 2048, ptr nonnull %5) #6
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(2048) %5, i8 0, i64 2048, i1 false)
  %11 = call i64 @xstrncuts(ptr noundef nonnull %5, i64 noundef 2048, ptr noundef %10, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1) #6
  %.not = icmp eq i64 %11, 0
  br i1 %.not, label %28, label %12

12:                                               ; preds = %8
  %13 = call ptr @xstrsplit(ptr noundef nonnull %5, ptr noundef nonnull @.str.2) #6
  %14 = icmp eq ptr %13, null
  br i1 %14, label %.sink.split, label %.preheader

.preheader:                                       ; preds = %12
  %15 = getelementptr inbounds i8, ptr %13, i64 48
  %16 = load i64, ptr %15, align 8, !tbaa !5
  %.not23 = icmp eq i64 %16, 0
  br i1 %.not23, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %23
  %.01722 = phi i64 [ %24, %23 ], [ 0, %.preheader ]
  %17 = call ptr @XArray_GetData(ptr noundef nonnull %13, i64 noundef %.01722) #6
  %.not21 = icmp eq ptr %17, null
  br i1 %.not21, label %23, label %18

18:                                               ; preds = %.lr.ph
  %19 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %4) #7
  %20 = shl i64 %19, 32
  %sext = sub i64 8796093022208, %20
  %21 = ashr exact i64 %sext, 32
  %22 = call i64 (ptr, i64, ptr, ...) @xstrncatf(ptr noundef nonnull %4, i64 noundef %21, ptr noundef nonnull @.str.3, ptr noundef nonnull %17) #6
  br label %23

23:                                               ; preds = %18, %.lr.ph
  %24 = add nuw i64 %.01722, 1
  %25 = load i64, ptr %15, align 8, !tbaa !5
  %26 = icmp ult i64 %24, %25
  br i1 %26, label %.lr.ph, label %._crit_edge, !llvm.loop !12

._crit_edge:                                      ; preds = %23, %.preheader
  call void @XArray_Destroy(ptr noundef nonnull %13) #6
  br label %.sink.split

.sink.split:                                      ; preds = %12, %._crit_edge
  %.sink = phi ptr [ %4, %._crit_edge ], [ %5, %12 ]
  %27 = call i32 @atoi(ptr nocapture noundef %.sink) #7
  br label %28

28:                                               ; preds = %.sink.split, %8
  %.1 = phi i32 [ -1, %8 ], [ %27, %.sink.split ]
  call void @llvm.lifetime.end.p0(i64 2048, ptr nonnull %5) #6
  call void @llvm.lifetime.end.p0(i64 2048, ptr nonnull %4) #6
  br label %29

29:                                               ; preds = %3, %28
  %.2 = phi i32 [ %.1, %28 ], [ 0, %3 ]
  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 i32 @xstrnsrc(ptr noundef, i64 noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

declare i64 @xstrncuts(ptr noundef, i64 noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

declare ptr @xstrsplit(ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress nofree nounwind willreturn memory(read) uwtable
declare i32 @atoi(ptr nocapture noundef nonnull) local_unnamed_addr #4

declare ptr @XArray_GetData(ptr noundef, i64 noundef) local_unnamed_addr #2

declare i64 @xstrncatf(ptr noundef, i64 noundef, ptr noundef, ...) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #5

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

declare void @XArray_Destroy(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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { inlinehint mustprogress nofree nounwind willreturn memory(read) 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 #5 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 #6 = { nounwind }
attributes #7 = { nounwind willreturn memory(read) }

!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, !11, i64 48}
!6 = !{!"XArray_", !7, i64 0, !7, i64 8, !10, i64 16, !7, i64 24, !8, i64 32, !8, i64 33, !8, i64 34, !11, i64 40, !11, i64 48}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


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