; LLVM IR from jingweizhanghuai/Morn :: src/util (morn_csv)

; 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.HandleCSV = type { ptr, ptr, ptr, i32, i32, [256 x i8], i32, i32, ptr, ptr, ptr }
%struct.MArray = type { i32, i16, %union.anon }
%union.anon = type { ptr }
%struct.MList = type { i32, ptr }

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

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

; 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 @CSVKey(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.HandleCSV, ptr %12, i32 0, i32 2
  %14 = load ptr, ptr %13, align 8, !tbaa !9
  %15 = icmp eq ptr %14, null
  br i1 %15, label %16, label %17

16:                                               ; preds = %2
  br label %100

17:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !12
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.HandleCSV, ptr %18, i32 0, i32 2
  %20 = load ptr, ptr %19, align 8, !tbaa !9
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = call ptr @mornMapRead(ptr noundef %20, ptr noundef %21, i32 noundef -1, ptr noundef %5, ptr noundef null)
  %23 = load i32, ptr %5, align 4, !tbaa !12
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.HandleCSV, ptr %24, i32 0, i32 6
  store i32 %23, ptr %25, align 8, !tbaa !13
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.HandleCSV, ptr %26, i32 0, i32 1
  %28 = load ptr, ptr %27, align 8, !tbaa !14
  %29 = load i32, ptr %5, align 4, !tbaa !12
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds ptr, ptr %28, i64 %30
  %32 = load ptr, ptr %31, align 8, !tbaa !5
  %33 = icmp ne ptr %32, null
  br i1 %33, label %34, label %35

34:                                               ; preds = %17
  store i32 1, ptr %6, align 4
  br label %98

35:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %36 = call ptr (...) @mMapCreate()
  store ptr %36, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !12
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = call ptr @m_PropertyWrite(ptr noundef %37, ptr noundef @.str, ptr noundef %8, i32 noundef 4)
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 0, ptr %9, align 4, !tbaa !12
  br label %39

39:                                               ; preds = %87, %35
  %40 = load i32, ptr %9, align 4, !tbaa !12
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.HandleCSV, ptr %41, i32 0, i32 4
  %43 = load i32, ptr %42, align 4, !tbaa !15
  %44 = icmp slt i32 %40, %43
  br i1 %44, label %46, label %45

45:                                               ; preds = %39
  store i32 2, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %90

46:                                               ; preds = %39
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.HandleCSV, ptr %47, i32 0, i32 0
  %49 = load ptr, ptr %48, align 8, !tbaa !16
  %50 = getelementptr inbounds %struct.MArray, ptr %49, i32 0, i32 2
  %51 = load ptr, ptr %50, align 8, !tbaa !17
  %52 = load i32, ptr %9, align 4, !tbaa !12
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.HandleCSV, ptr %53, i32 0, i32 3
  %55 = load i32, ptr %54, align 8, !tbaa !18
  %56 = mul nsw i32 %52, %55
  %57 = load i32, ptr %5, align 4, !tbaa !12
  %58 = add nsw i32 %56, %57
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds i32, ptr %51, i64 %59
  %61 = load i32, ptr %60, align 4, !tbaa !12
  store i32 %61, ptr %10, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %62 = load i32, ptr %10, align 4, !tbaa !12
  %63 = icmp sge i32 %62, 0
  br i1 %63, label %64, label %71

64:                                               ; preds = %46
  %65 = load ptr, ptr %4, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.HandleCSV, ptr %65, i32 0, i32 10
  %67 = load ptr, ptr %66, align 8, !tbaa !19
  %68 = load i32, ptr %10, align 4, !tbaa !12
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds i8, ptr %67, i64 %69
  store ptr %70, ptr %11, align 8, !tbaa !5
  br label %83

71:                                               ; preds = %46
  %72 = load ptr, ptr %4, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.HandleCSV, ptr %72, i32 0, i32 9
  %74 = load ptr, ptr %73, align 8, !tbaa !20
  %75 = getelementptr inbounds %struct.MList, ptr %74, i32 0, i32 1
  %76 = load ptr, ptr %75, align 8, !tbaa !21
  %77 = load i32, ptr %10, align 4, !tbaa !12
  %78 = sub nsw i32 -2, %77
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds ptr, ptr %76, i64 %79
  %81 = load ptr, ptr %80, align 8, !tbaa !5
  %82 = getelementptr inbounds i8, ptr %81, i64 1
  store ptr %82, ptr %11, align 8, !tbaa !5
  br label %83

83:                                               ; preds = %71, %64
  %84 = load ptr, ptr %7, align 8, !tbaa !5
  %85 = load ptr, ptr %11, align 8, !tbaa !5
  %86 = call ptr @m_MapWrite(ptr noundef %84, ptr noundef %85, i32 noundef -1, ptr noundef %9, i32 noundef 4)
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %87

87:                                               ; preds = %83
  %88 = load i32, ptr %9, align 4, !tbaa !12
  %89 = add nsw i32 %88, 1
  store i32 %89, ptr %9, align 4, !tbaa !12
  br label %39, !llvm.loop !23

90:                                               ; preds = %45
  %91 = load ptr, ptr %7, align 8, !tbaa !5
  %92 = load ptr, ptr %4, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.HandleCSV, ptr %92, i32 0, i32 1
  %94 = load ptr, ptr %93, align 8, !tbaa !14
  %95 = load i32, ptr %5, align 4, !tbaa !12
  %96 = sext i32 %95 to i64
  %97 = getelementptr inbounds ptr, ptr %94, i64 %96
  store ptr %91, ptr %97, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  store i32 0, ptr %6, align 4
  br label %98

98:                                               ; preds = %90, %34
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  %99 = load i32, ptr %6, align 4
  switch i32 %99, label %101 [
    i32 0, label %100
    i32 1, label %100
  ]

100:                                              ; preds = %98, %98, %16
  ret void

101:                                              ; preds = %98
  unreachable
}

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

declare ptr @mMapCreate(...) #2

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

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

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 = { "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, !6, i64 16}
!10 = !{!"HandleCSV", !6, i64 0, !6, i64 8, !6, i64 16, !11, i64 24, !11, i64 28, !7, i64 32, !11, i64 288, !11, i64 292, !6, i64 296, !6, i64 304, !6, i64 312}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !11, i64 288}
!14 = !{!10, !6, i64 8}
!15 = !{!10, !11, i64 28}
!16 = !{!10, !6, i64 0}
!17 = !{!7, !7, i64 0}
!18 = !{!10, !11, i64 24}
!19 = !{!10, !6, i64 312}
!20 = !{!10, !6, i64 304}
!21 = !{!22, !6, i64 8}
!22 = !{!"MList", !11, i64 0, !6, i64 8}
!23 = distinct !{!23, !24}
!24 = !{!"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 [10 x i8], align 1

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

; Function Attrs: mustprogress 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 @CSVKey(ptr noundef %0, ptr nocapture noundef %1) local_unnamed_addr #1 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = getelementptr inbounds i8, ptr %1, i64 16
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  %8 = icmp eq ptr %7, null
  br i1 %8, label %63, label %9

9:                                                ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #3
  store i32 0, ptr %3, align 4, !tbaa !11
  %10 = call ptr @mornMapRead(ptr noundef nonnull %7, ptr noundef %0, i32 noundef -1, ptr noundef nonnull %3, ptr noundef null) #3
  %11 = load i32, ptr %3, align 4, !tbaa !11
  %12 = getelementptr inbounds i8, ptr %1, i64 288
  store i32 %11, ptr %12, align 8, !tbaa !12
  %13 = getelementptr inbounds i8, ptr %1, i64 8
  %14 = load ptr, ptr %13, align 8, !tbaa !13
  %15 = sext i32 %11 to i64
  %16 = getelementptr inbounds ptr, ptr %14, i64 %15
  %17 = load ptr, ptr %16, align 8, !tbaa !14
  %.not = icmp eq ptr %17, null
  br i1 %.not, label %18, label %62

18:                                               ; preds = %9
  %19 = call ptr (...) @mMapCreate() #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #3
  store i32 0, ptr %4, align 4, !tbaa !11
  %20 = call ptr @m_PropertyWrite(ptr noundef %19, ptr noundef nonnull @.str, ptr noundef nonnull %4, i32 noundef 4) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #3
  %21 = getelementptr inbounds i8, ptr %1, i64 28
  store i32 0, ptr %5, align 4, !tbaa !11
  %22 = load i32, ptr %21, align 4, !tbaa !15
  %23 = icmp sgt i32 %22, 0
  br i1 %23, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %18
  %24 = getelementptr inbounds i8, ptr %1, i64 24
  %25 = getelementptr inbounds i8, ptr %1, i64 304
  %26 = getelementptr inbounds i8, ptr %1, i64 312
  br label %31

._crit_edge:                                      ; preds = %56, %18
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #3
  %27 = load ptr, ptr %13, align 8, !tbaa !13
  %28 = load i32, ptr %3, align 4, !tbaa !11
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds ptr, ptr %27, i64 %29
  store ptr %19, ptr %30, align 8, !tbaa !14
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #3
  br label %62

31:                                               ; preds = %.lr.ph, %56
  %storemerge19 = phi i32 [ 0, %.lr.ph ], [ %59, %56 ]
  %32 = load ptr, ptr %1, align 8, !tbaa !16
  %33 = getelementptr inbounds i8, ptr %32, i64 8
  %34 = load ptr, ptr %33, align 8, !tbaa !17
  %35 = load i32, ptr %24, align 8, !tbaa !18
  %36 = mul nsw i32 %35, %storemerge19
  %37 = load i32, ptr %3, align 4, !tbaa !11
  %38 = add nsw i32 %36, %37
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds i32, ptr %34, i64 %39
  %41 = load i32, ptr %40, align 4, !tbaa !11
  %42 = icmp sgt i32 %41, -1
  br i1 %42, label %43, label %47

43:                                               ; preds = %31
  %44 = load ptr, ptr %26, align 8, !tbaa !19
  %45 = zext nneg i32 %41 to i64
  %46 = getelementptr inbounds i8, ptr %44, i64 %45
  br label %56

47:                                               ; preds = %31
  %48 = load ptr, ptr %25, align 8, !tbaa !20
  %49 = getelementptr inbounds i8, ptr %48, i64 8
  %50 = load ptr, ptr %49, align 8, !tbaa !21
  %51 = sub nsw i32 -2, %41
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds ptr, ptr %50, i64 %52
  %54 = load ptr, ptr %53, align 8, !tbaa !14
  %55 = getelementptr inbounds i8, ptr %54, i64 1
  br label %56

56:                                               ; preds = %47, %43
  %.0 = phi ptr [ %46, %43 ], [ %55, %47 ]
  %57 = call ptr @m_MapWrite(ptr noundef %19, ptr noundef %.0, i32 noundef -1, ptr noundef nonnull %5, i32 noundef 4) #3
  %58 = load i32, ptr %5, align 4, !tbaa !11
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %5, align 4, !tbaa !11
  %60 = load i32, ptr %21, align 4, !tbaa !15
  %61 = icmp slt i32 %59, %60
  br i1 %61, label %31, label %._crit_edge, !llvm.loop !23

62:                                               ; preds = %9, %._crit_edge
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #3
  br label %63

63:                                               ; preds = %2, %62
  ret void
}

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

declare ptr @mMapCreate(...) local_unnamed_addr #2

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

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

attributes #0 = { mustprogress 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 = { "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, !7, i64 16}
!6 = !{!"HandleCSV", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24, !10, i64 28, !8, i64 32, !10, i64 288, !10, i64 292, !7, i64 296, !7, i64 304, !7, i64 312}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!10, !10, i64 0}
!12 = !{!6, !10, i64 288}
!13 = !{!6, !7, i64 8}
!14 = !{!7, !7, i64 0}
!15 = !{!6, !10, i64 28}
!16 = !{!6, !7, i64 0}
!17 = !{!8, !8, i64 0}
!18 = !{!6, !10, i64 24}
!19 = !{!6, !7, i64 312}
!20 = !{!6, !7, i64 304}
!21 = !{!22, !7, i64 8}
!22 = !{!"MList", !10, i64 0, !7, i64 8}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}


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