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

@.str.4 = external hidden unnamed_addr constant [75 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [31 x i8], align 1
@__FUNCTION__.mCSVRowAppend = external hidden unnamed_addr constant [14 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: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

declare void @m_ArrayAppend(ptr noundef, ptr noundef, i32 noundef) #2

declare void @m_Exception(i32 noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef, ...) #2

; Function Attrs: nounwind uwtable
declare dso_local ptr @CSVHandle(ptr noundef) #3

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memmove.p0.p0.i64(ptr nocapture writeonly, ptr nocapture readonly, i64, i1 immarg) #4

; Function Attrs: nounwind uwtable
define dso_local void @mCSVRowAppend(ptr noundef %0, i64 noundef %1) #3 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = call ptr @CSVHandle(ptr noundef %9)
  store ptr %10, ptr %5, align 8, !tbaa !5
  br label %11

11:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  %12 = load i8, ptr @.str.12, align 1, !tbaa !11
  %13 = sext i8 %12 to i32
  %14 = icmp ne i32 %13, 0
  %15 = zext i1 %14 to i32
  store i32 %15, ptr %6, align 4, !tbaa !12
  %16 = load i32, ptr %6, align 4, !tbaa !12
  %17 = icmp eq i32 %16, 1
  br i1 %17, label %18, label %34

18:                                               ; preds = %11
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.HandleCSV, ptr %19, i32 0, i32 0
  %21 = load ptr, ptr %20, align 8, !tbaa !14
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.HandleCSV, ptr %22, i32 0, i32 0
  %24 = load ptr, ptr %23, align 8, !tbaa !14
  %25 = getelementptr inbounds %struct.MArray, ptr %24, i32 0, i32 0
  %26 = load i32, ptr %25, align 8, !tbaa !16
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.HandleCSV, ptr %27, i32 0, i32 3
  %29 = load i32, ptr %28, align 8, !tbaa !19
  %30 = add nsw i32 %26, %29
  %31 = add nsw i32 %30, 0
  %32 = sext i32 %31 to i64
  %33 = trunc i64 %32 to i32
  call void @m_ArrayAppend(ptr noundef %21, ptr noundef null, i32 noundef %33)
  br label %63

34:                                               ; preds = %11
  %35 = load i32, ptr %6, align 4, !tbaa !12
  %36 = icmp eq i32 %35, 2
  br i1 %36, label %37, label %53

37:                                               ; preds = %34
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.HandleCSV, ptr %38, i32 0, i32 0
  %40 = load ptr, ptr %39, align 8, !tbaa !14
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.HandleCSV, ptr %41, i32 0, i32 0
  %43 = load ptr, ptr %42, align 8, !tbaa !14
  %44 = getelementptr inbounds %struct.MArray, ptr %43, i32 0, i32 0
  %45 = load i32, ptr %44, align 8, !tbaa !16
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.HandleCSV, ptr %46, i32 0, i32 3
  %48 = load i32, ptr %47, align 8, !tbaa !19
  %49 = add nsw i32 %45, %48
  %50 = add nsw i32 %49, 0
  %51 = sext i32 %50 to i64
  %52 = inttoptr i64 %51 to ptr
  call void @m_ArrayAppend(ptr noundef %40, ptr noundef %52, i32 noundef -1)
  br label %62

53:                                               ; preds = %34
  br label %54

54:                                               ; preds = %53
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  store i32 1, ptr %7, align 4, !tbaa !12
  %55 = load i32, ptr %7, align 4, !tbaa !12
  %56 = icmp ne i32 %55, 0
  br i1 %56, label %57, label %59

57:                                               ; preds = %54
  %58 = load i32, ptr %7, align 4, !tbaa !12
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef %58, i32 noundef -1, ptr noundef @.str.4, i32 noundef 356, ptr noundef @__FUNCTION__.mCSVRowAppend, ptr noundef @.str.5)
  br label %59

59:                                               ; preds = %57, %54
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  br label %60

60:                                               ; preds = %59
  br label %61

61:                                               ; preds = %60
  br label %62

62:                                               ; preds = %61, %37
  br label %63

63:                                               ; preds = %62, %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  br label %64

64:                                               ; preds = %63
  br label %65

65:                                               ; preds = %64
  %66 = load i64, ptr %4, align 8, !tbaa !9
  %67 = icmp slt i64 %66, 0
  br i1 %67, label %68, label %73

68:                                               ; preds = %65
  %69 = load ptr, ptr %5, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.HandleCSV, ptr %69, i32 0, i32 4
  %71 = load i32, ptr %70, align 4, !tbaa !20
  %72 = sext i32 %71 to i64
  store i64 %72, ptr %4, align 8, !tbaa !9
  br label %73

73:                                               ; preds = %68, %65
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %74 = load ptr, ptr %5, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.HandleCSV, ptr %74, i32 0, i32 0
  %76 = load ptr, ptr %75, align 8, !tbaa !14
  %77 = getelementptr inbounds %struct.MArray, ptr %76, i32 0, i32 2
  %78 = load ptr, ptr %77, align 8, !tbaa !11
  store ptr %78, ptr %8, align 8, !tbaa !5
  %79 = load i64, ptr %4, align 8, !tbaa !9
  %80 = load ptr, ptr %5, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.HandleCSV, ptr %80, i32 0, i32 4
  %82 = load i32, ptr %81, align 4, !tbaa !20
  %83 = sext i32 %82 to i64
  %84 = icmp slt i64 %79, %83
  br i1 %84, label %85, label %115

85:                                               ; preds = %73
  %86 = load ptr, ptr %8, align 8, !tbaa !5
  %87 = load i64, ptr %4, align 8, !tbaa !9
  %88 = add nsw i64 %87, 1
  %89 = load ptr, ptr %5, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.HandleCSV, ptr %89, i32 0, i32 3
  %91 = load i32, ptr %90, align 8, !tbaa !19
  %92 = sext i32 %91 to i64
  %93 = mul nsw i64 %88, %92
  %94 = getelementptr inbounds i32, ptr %86, i64 %93
  %95 = load ptr, ptr %8, align 8, !tbaa !5
  %96 = load i64, ptr %4, align 8, !tbaa !9
  %97 = load ptr, ptr %5, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.HandleCSV, ptr %97, i32 0, i32 3
  %99 = load i32, ptr %98, align 8, !tbaa !19
  %100 = sext i32 %99 to i64
  %101 = mul nsw i64 %96, %100
  %102 = getelementptr inbounds i32, ptr %95, i64 %101
  %103 = load ptr, ptr %5, align 8, !tbaa !5
  %104 = getelementptr inbounds %struct.HandleCSV, ptr %103, i32 0, i32 4
  %105 = load i32, ptr %104, align 4, !tbaa !20
  %106 = sext i32 %105 to i64
  %107 = load i64, ptr %4, align 8, !tbaa !9
  %108 = sub nsw i64 %106, %107
  %109 = load ptr, ptr %5, align 8, !tbaa !5
  %110 = getelementptr inbounds %struct.HandleCSV, ptr %109, i32 0, i32 3
  %111 = load i32, ptr %110, align 8, !tbaa !19
  %112 = sext i32 %111 to i64
  %113 = mul nsw i64 %108, %112
  %114 = mul i64 %113, 4
  call void @llvm.memmove.p0.p0.i64(ptr align 4 %94, ptr align 4 %102, i64 %114, i1 false)
  br label %115

115:                                              ; preds = %85, %73
  %116 = load ptr, ptr %8, align 8, !tbaa !5
  %117 = load i64, ptr %4, align 8, !tbaa !9
  %118 = load ptr, ptr %5, align 8, !tbaa !5
  %119 = getelementptr inbounds %struct.HandleCSV, ptr %118, i32 0, i32 3
  %120 = load i32, ptr %119, align 8, !tbaa !19
  %121 = sext i32 %120 to i64
  %122 = mul nsw i64 %117, %121
  %123 = getelementptr inbounds i32, ptr %116, i64 %122
  %124 = load ptr, ptr %5, align 8, !tbaa !5
  %125 = getelementptr inbounds %struct.HandleCSV, ptr %124, i32 0, i32 3
  %126 = load i32, ptr %125, align 8, !tbaa !19
  %127 = sext i32 %126 to i64
  %128 = mul i64 %127, 4
  call void @llvm.memset.p0.i64(ptr align 4 %123, i8 0, i64 %128, i1 false)
  %129 = load ptr, ptr %5, align 8, !tbaa !5
  %130 = getelementptr inbounds %struct.HandleCSV, ptr %129, i32 0, i32 4
  %131 = load i32, ptr %130, align 4, !tbaa !20
  %132 = add nsw i32 %131, 1
  store i32 %132, ptr %130, align 4, !tbaa !20
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 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 #4 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { 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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !6, i64 0}
!15 = !{!"HandleCSV", !6, i64 0, !6, i64 8, !6, i64 16, !13, i64 24, !13, i64 28, !7, i64 32, !13, i64 288, !13, i64 292, !6, i64 296, !6, i64 304, !6, i64 312}
!16 = !{!17, !13, i64 0}
!17 = !{!"MArray", !13, i64 0, !18, i64 4, !7, i64 8}
!18 = !{!"short", !7, i64 0}
!19 = !{!15, !13, i64 24}
!20 = !{!15, !13, i64 28}


; 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 [75 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [31 x i8], align 1
@__FUNCTION__.mCSVRowAppend = external hidden unnamed_addr constant [14 x i8], align 1

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

declare void @m_ArrayAppend(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

declare void @m_Exception(i32 noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef, ...) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @CSVHandle(ptr noundef) local_unnamed_addr #2

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

; Function Attrs: nounwind uwtable
define dso_local void @mCSVRowAppend(ptr noundef %0, i64 noundef %1) local_unnamed_addr #2 {
  %3 = tail call ptr @CSVHandle(ptr noundef %0)
  %4 = load i8, ptr @.str.12, align 1, !tbaa !5
  %.not = icmp eq i8 %4, 0
  br i1 %.not, label %11, label %5

5:                                                ; preds = %2
  %6 = load ptr, ptr %3, align 8, !tbaa !8
  %7 = load i32, ptr %6, align 8, !tbaa !12
  %8 = getelementptr inbounds i8, ptr %3, i64 24
  %9 = load i32, ptr %8, align 8, !tbaa !15
  %10 = add nsw i32 %9, %7
  tail call void @m_ArrayAppend(ptr noundef nonnull %6, ptr noundef null, i32 noundef %10) #4
  br label %12

11:                                               ; preds = %2
  tail call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef 1, i32 noundef -1, ptr noundef nonnull @.str.4, i32 noundef 356, ptr noundef nonnull @__FUNCTION__.mCSVRowAppend, ptr noundef nonnull @.str.5) #4
  br label %12

12:                                               ; preds = %11, %5
  %13 = icmp slt i64 %1, 0
  %14 = getelementptr inbounds i8, ptr %3, i64 28
  %15 = load i32, ptr %14, align 4, !tbaa !16
  %16 = sext i32 %15 to i64
  %17 = load ptr, ptr %3, align 8, !tbaa !8
  %18 = getelementptr inbounds i8, ptr %17, i64 8
  %19 = load ptr, ptr %18, align 8, !tbaa !5
  br i1 %13, label %.thread, label %20

20:                                               ; preds = %12
  %21 = icmp sgt i64 %16, %1
  br i1 %21, label %22, label %.thread

22:                                               ; preds = %20
  %23 = add nuw nsw i64 %1, 1
  %24 = getelementptr inbounds i8, ptr %3, i64 24
  %25 = load i32, ptr %24, align 8, !tbaa !15
  %26 = sext i32 %25 to i64
  %27 = mul nsw i64 %23, %26
  %28 = getelementptr inbounds i32, ptr %19, i64 %27
  %29 = mul nsw i64 %26, %1
  %30 = getelementptr inbounds i32, ptr %19, i64 %29
  %31 = sub nsw i64 %16, %1
  %32 = shl nsw i64 %31, 2
  %33 = mul i64 %32, %26
  tail call void @llvm.memmove.p0.p0.i64(ptr align 4 %28, ptr align 4 %30, i64 %33, i1 false)
  br label %.thread

.thread:                                          ; preds = %12, %22, %20
  %.034 = phi i64 [ %1, %22 ], [ %1, %20 ], [ %16, %12 ]
  %34 = getelementptr inbounds i8, ptr %3, i64 28
  %35 = getelementptr inbounds i8, ptr %3, i64 24
  %36 = load i32, ptr %35, align 8, !tbaa !15
  %37 = sext i32 %36 to i64
  %38 = mul nsw i64 %.034, %37
  %39 = getelementptr inbounds i32, ptr %19, i64 %38
  %40 = shl nsw i64 %37, 2
  tail call void @llvm.memset.p0.i64(ptr align 4 %39, i8 0, i64 %40, i1 false)
  %41 = load i32, ptr %34, align 4, !tbaa !16
  %42 = add nsw i32 %41, 1
  store i32 %42, ptr %34, align 4, !tbaa !16
  ret void
}

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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 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 #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !10, i64 0}
!9 = !{!"HandleCSV", !10, i64 0, !10, i64 8, !10, i64 16, !11, i64 24, !11, i64 28, !6, i64 32, !11, i64 288, !11, i64 292, !10, i64 296, !10, i64 304, !10, i64 312}
!10 = !{!"any pointer", !6, i64 0}
!11 = !{!"int", !6, i64 0}
!12 = !{!13, !11, i64 0}
!13 = !{!"MArray", !11, i64 0, !14, i64 4, !6, i64 8}
!14 = !{!"short", !6, i64 0}
!15 = !{!9, !11, i64 24}
!16 = !{!9, !11, i64 28}


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass