; 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.xhttp_ = type { ptr, i16, ptr, i32, %struct.XByteBuffer, i32, %struct.XMap, i16, i16, i64, i64, i64, i64, i64, i8, i8, i8, [256 x i8], [128 x i8], [2048 x i8] }
%struct.XByteBuffer = type { ptr, i64, i64, i16, i16, i32 }
%struct.XMap = type { ptr, ptr, ptr, i64, i64, i32 }
%struct.covid_cases_t = type { i32, i32, i32, i32, i32 }

@.str.4 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [68 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [78 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [53 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [56 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [60 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @COVID_ParseCase(ptr noundef, i64 noundef, ptr noundef) #0

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @COVID_ParseResponse(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.xhttp_, ptr %8, i32 0, i32 8
  %10 = load i16, ptr %9, align 2, !tbaa !9
  %11 = zext i16 %10 to i32
  %12 = icmp ne i32 %11, 200
  br i1 %12, label %13, label %27

13:                                               ; preds = %2
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.xhttp_, ptr %14, i32 0, i32 4
  %16 = getelementptr inbounds %struct.XByteBuffer, ptr %15, i32 0, i32 0
  %17 = load ptr, ptr %16, align 8, !tbaa !16
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.xhttp_, ptr %18, i32 0, i32 10
  %20 = load i64, ptr %19, align 8, !tbaa !17
  %21 = sub i64 %20, 1
  %22 = getelementptr inbounds i8, ptr %17, i64 %21
  store i8 0, ptr %22, align 1, !tbaa !18
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.xhttp_, ptr %23, i32 0, i32 4
  %25 = getelementptr inbounds %struct.XByteBuffer, ptr %24, i32 0, i32 0
  %26 = load ptr, ptr %25, align 8, !tbaa !16
  call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 4, i8 noundef zeroext 1, ptr noundef @.str.4, ptr noundef %26)
  store i32 0, ptr %3, align 4
  br label %60

27:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = call ptr @XHTTP_GetBody(ptr noundef %28)
  store ptr %29, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = call i64 @XHTTP_GetBodySize(ptr noundef %30)
  store i64 %31, ptr %7, align 8, !tbaa !19
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = load i64, ptr %7, align 8, !tbaa !19
  %34 = call i32 @COVID_ParseCase(ptr noundef %32, i64 noundef %33, ptr noundef @.str.5)
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.covid_cases_t, ptr %35, i32 0, i32 2
  store i32 %34, ptr %36, align 4, !tbaa !20
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = load i64, ptr %7, align 8, !tbaa !19
  %39 = call i32 @COVID_ParseCase(ptr noundef %37, i64 noundef %38, ptr noundef @.str.6)
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.covid_cases_t, ptr %40, i32 0, i32 3
  store i32 %39, ptr %41, align 4, !tbaa !22
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = load i64, ptr %7, align 8, !tbaa !19
  %44 = call i32 @COVID_ParseCase(ptr noundef %42, i64 noundef %43, ptr noundef @.str.7)
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.covid_cases_t, ptr %45, i32 0, i32 0
  store i32 %44, ptr %46, align 4, !tbaa !23
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = load i64, ptr %7, align 8, !tbaa !19
  %49 = call i32 @COVID_ParseCase(ptr noundef %47, i64 noundef %48, ptr noundef @.str.8)
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.covid_cases_t, ptr %50, i32 0, i32 1
  store i32 %49, ptr %51, align 4, !tbaa !24
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  %53 = load i64, ptr %7, align 8, !tbaa !19
  %54 = call i32 @COVID_ParseCase(ptr noundef %52, i64 noundef %53, ptr noundef @.str.9)
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.covid_cases_t, ptr %55, i32 0, i32 4
  store i32 %54, ptr %56, align 4, !tbaa !25
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.covid_cases_t, ptr %57, i32 0, i32 2
  %59 = load i32, ptr %58, align 4, !tbaa !20
  store i32 %59, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %60

60:                                               ; preds = %27, %13
  %61 = load i32, ptr %3, align 4
  ret i32 %61
}

declare void @XLog_Display(i32 noundef, i8 noundef zeroext, ptr noundef, ...) #2

declare ptr @XHTTP_GetBody(ptr noundef) #2

declare i64 @XHTTP_GetBodySize(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 }

!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 122}
!10 = !{!"xhttp_", !6, i64 0, !11, i64 8, !6, i64 16, !12, i64 24, !13, i64 32, !12, i64 64, !15, i64 72, !11, i64 120, !11, i64 122, !14, i64 128, !14, i64 136, !14, i64 144, !14, i64 152, !14, i64 160, !7, i64 168, !7, i64 169, !7, i64 170, !7, i64 171, !7, i64 427, !7, i64 555}
!11 = !{!"short", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!"XByteBuffer", !6, i64 0, !14, i64 8, !14, i64 16, !11, i64 24, !11, i64 26, !12, i64 28}
!14 = !{!"long", !7, i64 0}
!15 = !{!"XMap", !6, i64 0, !6, i64 8, !6, i64 16, !14, i64 24, !14, i64 32, !12, i64 40}
!16 = !{!10, !6, i64 32}
!17 = !{!10, !14, i64 136}
!18 = !{!7, !7, i64 0}
!19 = !{!14, !14, i64 0}
!20 = !{!21, !12, i64 8}
!21 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16}
!22 = !{!21, !12, i64 12}
!23 = !{!21, !12, i64 0}
!24 = !{!21, !12, i64 4}
!25 = !{!21, !12, i64 16}


; 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.4 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [68 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [78 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [53 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [56 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [60 x i8], align 1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @COVID_ParseResponse(ptr noundef %0, ptr nocapture noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 122
  %4 = load i16, ptr %3, align 2, !tbaa !5
  %.not = icmp eq i16 %4, 200
  br i1 %.not, label %13, label %5

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 32
  %7 = load ptr, ptr %6, align 8, !tbaa !15
  %8 = getelementptr inbounds i8, ptr %0, i64 136
  %9 = load i64, ptr %8, align 8, !tbaa !16
  %10 = getelementptr i8, ptr %7, i64 %9
  %11 = getelementptr i8, ptr %10, i64 -1
  store i8 0, ptr %11, align 1, !tbaa !17
  %12 = load ptr, ptr %6, align 8, !tbaa !15
  tail call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 4, i8 noundef zeroext 1, ptr noundef nonnull @.str.4, ptr noundef %12) #2
  br label %26

13:                                               ; preds = %2
  %14 = tail call ptr @XHTTP_GetBody(ptr noundef nonnull %0) #2
  %15 = tail call i64 @XHTTP_GetBodySize(ptr noundef nonnull %0) #2
  %16 = tail call i32 @COVID_ParseCase(ptr noundef %14, i64 noundef %15, ptr noundef nonnull @.str.5)
  %17 = getelementptr inbounds i8, ptr %1, i64 8
  store i32 %16, ptr %17, align 4, !tbaa !18
  %18 = tail call i32 @COVID_ParseCase(ptr noundef %14, i64 noundef %15, ptr noundef nonnull @.str.6)
  %19 = getelementptr inbounds i8, ptr %1, i64 12
  store i32 %18, ptr %19, align 4, !tbaa !20
  %20 = tail call i32 @COVID_ParseCase(ptr noundef %14, i64 noundef %15, ptr noundef nonnull @.str.7)
  store i32 %20, ptr %1, align 4, !tbaa !21
  %21 = tail call i32 @COVID_ParseCase(ptr noundef %14, i64 noundef %15, ptr noundef nonnull @.str.8)
  %22 = getelementptr inbounds i8, ptr %1, i64 4
  store i32 %21, ptr %22, align 4, !tbaa !22
  %23 = tail call i32 @COVID_ParseCase(ptr noundef %14, i64 noundef %15, ptr noundef nonnull @.str.9)
  %24 = getelementptr inbounds i8, ptr %1, i64 16
  store i32 %23, ptr %24, align 4, !tbaa !23
  %25 = load i32, ptr %17, align 4, !tbaa !18
  br label %26

26:                                               ; preds = %13, %5
  %.0 = phi i32 [ 0, %5 ], [ %25, %13 ]
  ret i32 %.0
}

declare void @XLog_Display(i32 noundef, i8 noundef zeroext, ptr noundef, ...) local_unnamed_addr #1

declare ptr @XHTTP_GetBody(ptr noundef) local_unnamed_addr #1

declare i64 @XHTTP_GetBodySize(ptr noundef) local_unnamed_addr #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 }

!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 122}
!6 = !{!"xhttp_", !7, i64 0, !10, i64 8, !7, i64 16, !11, i64 24, !12, i64 32, !11, i64 64, !14, i64 72, !10, i64 120, !10, i64 122, !13, i64 128, !13, i64 136, !13, i64 144, !13, i64 152, !13, i64 160, !8, i64 168, !8, i64 169, !8, i64 170, !8, i64 171, !8, i64 427, !8, i64 555}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"short", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!"XByteBuffer", !7, i64 0, !13, i64 8, !13, i64 16, !10, i64 24, !10, i64 26, !11, i64 28}
!13 = !{!"long", !8, i64 0}
!14 = !{!"XMap", !7, i64 0, !7, i64 8, !7, i64 16, !13, i64 24, !13, i64 32, !11, i64 40}
!15 = !{!6, !7, i64 32}
!16 = !{!6, !13, i64 136}
!17 = !{!8, !8, i64 0}
!18 = !{!19, !11, i64 8}
!19 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16}
!20 = !{!19, !11, i64 12}
!21 = !{!19, !11, i64 0}
!22 = !{!19, !11, i64 4}
!23 = !{!19, !11, i64 16}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,TailCallElimPass