; LLVM IR from bytecodealliance/sightglass :: benchmarks/shootout/src (minicsv)

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

@__const.main.buf = external hidden unnamed_addr constant [121 x i8], align 16
@black_box = external hidden global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca [10 x ptr], align 16
  %3 = alloca i64, align 8
  %4 = alloca i32, align 4
  %5 = alloca [121 x i8], align 16
  %6 = alloca ptr, align 8
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 80, ptr %2) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  call void (...) @bench_start()
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %7

7:                                                ; preds = %34, %0
  %8 = load i32, ptr %4, align 4, !tbaa !5
  %9 = icmp slt i32 %8, 1000000
  br i1 %9, label %10, label %37

10:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 121, ptr %5) #5
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %5, ptr align 16 @__const.main.buf, i64 121, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %11 = getelementptr inbounds [121 x i8], ptr %5, i64 0, i64 0
  store ptr %11, ptr %6, align 8, !tbaa !9
  %12 = load volatile ptr, ptr @black_box, align 8, !tbaa !9
  call void %12(ptr noundef %5)
  %13 = load ptr, ptr %6, align 8, !tbaa !9
  %14 = getelementptr inbounds [10 x ptr], ptr %2, i64 0, i64 0
  %15 = call ptr @minicsv_parse_line(ptr noundef %13, ptr noundef %14, ptr noundef %3, i64 noundef 10)
  store ptr %15, ptr %6, align 8, !tbaa !9
  %16 = load i64, ptr %3, align 8, !tbaa !11
  %17 = icmp ugt i64 %16, 10
  br i1 %17, label %18, label %19

18:                                               ; preds = %10
  call void @abort() #6
  unreachable

19:                                               ; preds = %10
  %20 = getelementptr inbounds [10 x ptr], ptr %2, i64 0, i64 0
  %21 = load i64, ptr %3, align 8, !tbaa !11
  call void @minicsv_trim_cols(ptr noundef %20, i64 noundef %21)
  %22 = load volatile ptr, ptr @black_box, align 8, !tbaa !9
  call void %22(ptr noundef %2)
  %23 = load ptr, ptr %6, align 8, !tbaa !9
  %24 = getelementptr inbounds [10 x ptr], ptr %2, i64 0, i64 0
  %25 = call ptr @minicsv_parse_line(ptr noundef %23, ptr noundef %24, ptr noundef %3, i64 noundef 10)
  store ptr %25, ptr %6, align 8, !tbaa !9
  %26 = load i64, ptr %3, align 8, !tbaa !11
  %27 = icmp ugt i64 %26, 10
  br i1 %27, label %28, label %29

28:                                               ; preds = %19
  call void @abort() #6
  unreachable

29:                                               ; preds = %19
  %30 = getelementptr inbounds [10 x ptr], ptr %2, i64 0, i64 0
  %31 = load i64, ptr %3, align 8, !tbaa !11
  call void @minicsv_trim_cols(ptr noundef %30, i64 noundef %31)
  %32 = load volatile ptr, ptr @black_box, align 8, !tbaa !9
  call void %32(ptr noundef %3)
  %33 = load volatile ptr, ptr @black_box, align 8, !tbaa !9
  call void %33(ptr noundef %6)
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 121, ptr %5) #5
  br label %34

34:                                               ; preds = %29
  %35 = load i32, ptr %4, align 4, !tbaa !5
  %36 = add nsw i32 %35, 1
  store i32 %36, ptr %4, align 4, !tbaa !5
  br label %7, !llvm.loop !13

37:                                               ; preds = %7
  call void (...) @bench_end()
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 80, ptr %2) #5
  %38 = load i32, ptr %1, align 4
  ret i32 %38
}

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

declare void @bench_start(...) #2

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

; Function Attrs: nounwind uwtable
declare hidden ptr @minicsv_parse_line(ptr noundef, ptr noundef, ptr noundef, i64 noundef) #0

; Function Attrs: noreturn nounwind
declare void @abort() #4

; Function Attrs: nounwind uwtable
declare hidden void @minicsv_trim_cols(ptr noundef, i64 noundef) #0

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

declare void @bench_end(...) #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: readwrite) }
attributes #4 = { noreturn nounwind "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 }
attributes #6 = { noreturn 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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"

@__const.main.buf = external hidden unnamed_addr constant [121 x i8], align 16
@black_box = external hidden global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca [10 x ptr], align 16
  %2 = alloca i64, align 8
  %3 = alloca [121 x i8], align 16
  %4 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 80, ptr nonnull %1) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  tail call void (...) @bench_start() #5
  br label %5

5:                                                ; preds = %0, %19
  %.05 = phi i32 [ 0, %0 ], [ %22, %19 ]
  call void @llvm.lifetime.start.p0(i64 121, ptr nonnull %3) #5
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(121) %3, ptr noundef nonnull align 16 dereferenceable(121) @__const.main.buf, i64 121, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #5
  store ptr %3, ptr %4, align 8, !tbaa !5
  %6 = load volatile ptr, ptr @black_box, align 8, !tbaa !5
  call void %6(ptr noundef nonnull %3) #5
  %7 = load ptr, ptr %4, align 8, !tbaa !5
  %8 = call ptr @minicsv_parse_line(ptr noundef %7, ptr noundef nonnull %1, ptr noundef nonnull %2, i64 noundef 10)
  store ptr %8, ptr %4, align 8, !tbaa !5
  %9 = load i64, ptr %2, align 8, !tbaa !9
  %10 = icmp ugt i64 %9, 10
  br i1 %10, label %11, label %12

11:                                               ; preds = %5
  call void @abort() #6
  unreachable

12:                                               ; preds = %5
  call void @minicsv_trim_cols(ptr noundef nonnull %1, i64 noundef %9)
  %13 = load volatile ptr, ptr @black_box, align 8, !tbaa !5
  call void %13(ptr noundef nonnull %1) #5
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = call ptr @minicsv_parse_line(ptr noundef %14, ptr noundef nonnull %1, ptr noundef nonnull %2, i64 noundef 10)
  store ptr %15, ptr %4, align 8, !tbaa !5
  %16 = load i64, ptr %2, align 8, !tbaa !9
  %17 = icmp ugt i64 %16, 10
  br i1 %17, label %18, label %19

18:                                               ; preds = %12
  call void @abort() #6
  unreachable

19:                                               ; preds = %12
  call void @minicsv_trim_cols(ptr noundef nonnull %1, i64 noundef %16)
  %20 = load volatile ptr, ptr @black_box, align 8, !tbaa !5
  call void %20(ptr noundef nonnull %2) #5
  %21 = load volatile ptr, ptr @black_box, align 8, !tbaa !5
  call void %21(ptr noundef nonnull %4) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #5
  call void @llvm.lifetime.end.p0(i64 121, ptr nonnull %3) #5
  %22 = add nuw nsw i32 %.05, 1
  %exitcond.not = icmp eq i32 %22, 1000000
  br i1 %exitcond.not, label %23, label %5, !llvm.loop !11

23:                                               ; preds = %19
  call void (...) @bench_end() #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  call void @llvm.lifetime.end.p0(i64 80, ptr nonnull %1) #5
  ret i32 0
}

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

declare void @bench_start(...) local_unnamed_addr #2

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

; Function Attrs: nounwind uwtable
declare hidden ptr @minicsv_parse_line(ptr noundef, ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: noreturn nounwind
declare void @abort() local_unnamed_addr #4

; Function Attrs: nounwind uwtable
declare hidden void @minicsv_trim_cols(ptr noundef, i64 noundef) local_unnamed_addr #0

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

declare void @bench_end(...) 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: readwrite) }
attributes #4 = { noreturn nounwind "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 }
attributes #6 = { noreturn 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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass