; LLVM IR from HRI-EU/Rcs :: src/RcsCore (Rcs_MatNd)

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

@stderr = external global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [68 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [2 x i8], align 1
@RCS_GLOBAL_RLOG_CB = external global ptr, align 8
@RcsLogLevel = external global i32, align 4
@.str.26 = external hidden unnamed_addr constant [16 x i8], align 1
@__func__.MatNd_condenseRows = external hidden unnamed_addr constant [19 x i8], align 1
@.str.121 = external hidden unnamed_addr constant [50 x i8], align 1

; Function Attrs: nounwind
declare i32 @fprintf(ptr 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: nounwind uwtable
declare dso_local void @MatNd_reshape(ptr noundef, i32 noundef, i32 noundef) #2

; 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
declare dso_local void @MatNd_fromPtr(ptr dead_on_unwind noalias writable sret(%struct._MatNd) align 8, i32 noundef, i32 noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local ptr @MatNd_getRowPtr(ptr noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local void @MatNd_appendRows(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @MatNd_condenseRows(ptr noundef %0, ptr noundef %1, double noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca double, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca %struct._MatNd, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store double %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %11 = load double, ptr %6, align 8, !tbaa !9
  %12 = fdiv double 1.000000e+00, %11
  %13 = call i64 @lround(double noundef %12) #3
  %14 = trunc i64 %13 to i32
  store i32 %14, ptr %8, align 4, !tbaa !11
  %15 = load double, ptr %6, align 8, !tbaa !9
  %16 = fcmp olt double %15, 0.000000e+00
  br i1 %16, label %20, label %17

17:                                               ; preds = %3
  %18 = load double, ptr %6, align 8, !tbaa !9
  %19 = fcmp ogt double %18, 1.000000e+00
  br i1 %19, label %20, label %41

20:                                               ; preds = %17, %3
  br label %21

21:                                               ; preds = %20
  %22 = load ptr, ptr @RCS_GLOBAL_RLOG_CB, align 8, !tbaa !5
  %23 = icmp ne ptr %22, null
  br i1 %23, label %24, label %27

24:                                               ; preds = %21
  %25 = load ptr, ptr @RCS_GLOBAL_RLOG_CB, align 8, !tbaa !5
  %26 = load double, ptr %6, align 8, !tbaa !9
  call void (i32, ptr, ptr, i32, ptr, ...) %25(i32 noundef 1, ptr noundef @.str.1, ptr noundef @__func__.MatNd_condenseRows, i32 noundef 1553, ptr noundef @.str.121, double noundef %26)
  br label %27

27:                                               ; preds = %24, %21
  %28 = load i32, ptr @RcsLogLevel, align 4, !tbaa !11
  %29 = icmp sle i32 1, %28
  br i1 %29, label %30, label %38

30:                                               ; preds = %27
  %31 = load ptr, ptr @stderr, align 8, !tbaa !5
  %32 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %31, ptr noundef @.str.26, ptr noundef @.str.1, ptr noundef @__func__.MatNd_condenseRows, i32 noundef 1553) #3
  %33 = load ptr, ptr @stderr, align 8, !tbaa !5
  %34 = load double, ptr %6, align 8, !tbaa !9
  %35 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %33, ptr noundef @.str.121, double noundef %34) #3
  %36 = load ptr, ptr @stderr, align 8, !tbaa !5
  %37 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %36, ptr noundef @.str.4) #3
  br label %38

38:                                               ; preds = %30, %27
  br label %39

39:                                               ; preds = %38
  br label %40

40:                                               ; preds = %39
  store i32 1, ptr %9, align 4
  br label %70

41:                                               ; preds = %17
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct._MatNd, ptr %43, i32 0, i32 2
  %45 = load i32, ptr %44, align 4, !tbaa !13
  call void @MatNd_reshape(ptr noundef %42, i32 noundef 0, i32 noundef %45)
  store i32 0, ptr %7, align 4, !tbaa !11
  br label %46

46:                                               ; preds = %66, %41
  %47 = load i32, ptr %7, align 4, !tbaa !11
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct._MatNd, ptr %48, i32 0, i32 1
  %50 = load i32, ptr %49, align 8, !tbaa !16
  %51 = icmp ult i32 %47, %50
  br i1 %51, label %52, label %69

52:                                               ; preds = %46
  %53 = load i32, ptr %7, align 4, !tbaa !11
  %54 = load i32, ptr %8, align 4, !tbaa !11
  %55 = urem i32 %53, %54
  %56 = icmp eq i32 %55, 0
  br i1 %56, label %57, label %65

57:                                               ; preds = %52
  call void @llvm.lifetime.start.p0(i64 24, ptr %10) #3
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct._MatNd, ptr %58, i32 0, i32 2
  %60 = load i32, ptr %59, align 4, !tbaa !13
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = load i32, ptr %7, align 4, !tbaa !11
  %63 = call ptr @MatNd_getRowPtr(ptr noundef %61, i32 noundef %62)
  call void @MatNd_fromPtr(ptr dead_on_unwind writable sret(%struct._MatNd) align 8 %10, i32 noundef 1, i32 noundef %60, ptr noundef %63)
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  call void @MatNd_appendRows(ptr noundef %64, ptr noundef %10)
  call void @llvm.lifetime.end.p0(i64 24, ptr %10) #3
  br label %65

65:                                               ; preds = %57, %52
  br label %66

66:                                               ; preds = %65
  %67 = load i32, ptr %7, align 4, !tbaa !11
  %68 = add i32 %67, 1
  store i32 %68, ptr %7, align 4, !tbaa !11
  br label %46, !llvm.loop !17

69:                                               ; preds = %46
  store i32 0, ptr %9, align 4
  br label %70

70:                                               ; preds = %69, %40
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  %71 = load i32, ptr %9, align 4
  switch i32 %71, label %73 [
    i32 0, label %72
    i32 1, label %72
  ]

72:                                               ; preds = %70, %70
  ret void

73:                                               ; preds = %70
  unreachable
}

; Function Attrs: nounwind
declare i64 @lround(double noundef) #0

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !12, i64 12}
!14 = !{!"_MatNd", !6, i64 0, !12, i64 8, !12, i64 12, !12, i64 16, !15, i64 20}
!15 = !{!"_Bool", !7, i64 0}
!16 = !{!14, !12, i64 8}
!17 = distinct !{!17, !18}
!18 = !{!"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"

%struct._MatNd = type { ptr, i32, i32, i32, i8 }

@stderr = external local_unnamed_addr global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [68 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [2 x i8], align 1
@RCS_GLOBAL_RLOG_CB = external local_unnamed_addr global ptr, align 8
@RcsLogLevel = external local_unnamed_addr global i32, align 4
@.str.26 = external hidden unnamed_addr constant [16 x i8], align 1
@__func__.MatNd_condenseRows = external hidden unnamed_addr constant [19 x i8], align 1
@.str.121 = external hidden unnamed_addr constant [50 x i8], align 1

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
declare dso_local void @MatNd_reshape(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #2

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

; Function Attrs: nounwind uwtable
declare dso_local void @MatNd_fromPtr(ptr dead_on_unwind noalias writable sret(%struct._MatNd) align 8, i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

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

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

; Function Attrs: nounwind uwtable
define dso_local void @MatNd_condenseRows(ptr noundef %0, ptr noundef %1, double noundef %2) local_unnamed_addr #2 {
  %4 = alloca %struct._MatNd, align 8
  %5 = fdiv double 1.000000e+00, %2
  %6 = tail call i64 @lround(double noundef %5) #4
  %7 = trunc i64 %6 to i32
  %8 = fcmp olt double %2, 0.000000e+00
  %9 = fcmp ogt double %2, 1.000000e+00
  %or.cond = or i1 %8, %9
  br i1 %or.cond, label %10, label %23

10:                                               ; preds = %3
  %11 = load ptr, ptr @RCS_GLOBAL_RLOG_CB, align 8, !tbaa !5
  %.not = icmp eq ptr %11, null
  br i1 %.not, label %13, label %12

12:                                               ; preds = %10
  tail call void (i32, ptr, ptr, i32, ptr, ...) %11(i32 noundef 1, ptr noundef nonnull @.str.1, ptr noundef nonnull @__func__.MatNd_condenseRows, i32 noundef 1553, ptr noundef nonnull @.str.121, double noundef %2) #4
  br label %13

13:                                               ; preds = %12, %10
  %14 = load i32, ptr @RcsLogLevel, align 4, !tbaa !9
  %15 = icmp sgt i32 %14, 0
  br i1 %15, label %16, label %.loopexit

16:                                               ; preds = %13
  %17 = load ptr, ptr @stderr, align 8, !tbaa !5
  %18 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %17, ptr noundef nonnull @.str.26, ptr noundef nonnull @.str.1, ptr noundef nonnull @__func__.MatNd_condenseRows, i32 noundef 1553) #5
  %19 = load ptr, ptr @stderr, align 8, !tbaa !5
  %20 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %19, ptr noundef nonnull @.str.121, double noundef %2) #5
  %21 = load ptr, ptr @stderr, align 8, !tbaa !5
  %22 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %21, ptr noundef nonnull @.str.4) #5
  br label %.loopexit

23:                                               ; preds = %3
  %24 = getelementptr inbounds i8, ptr %1, i64 12
  %25 = load i32, ptr %24, align 4, !tbaa !11
  tail call void @MatNd_reshape(ptr noundef %0, i32 noundef 0, i32 noundef %25)
  %26 = getelementptr inbounds i8, ptr %1, i64 8
  %27 = load i32, ptr %26, align 8, !tbaa !14
  %.not18 = icmp eq i32 %27, 0
  br i1 %.not18, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %23, %34
  %28 = phi i32 [ %35, %34 ], [ %27, %23 ]
  %.017 = phi i32 [ %36, %34 ], [ 0, %23 ]
  %29 = urem i32 %.017, %7
  %30 = icmp eq i32 %29, 0
  br i1 %30, label %31, label %34

31:                                               ; preds = %.lr.ph
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %4) #4
  %32 = load i32, ptr %24, align 4, !tbaa !11
  %33 = call ptr @MatNd_getRowPtr(ptr noundef nonnull %1, i32 noundef %.017)
  call void @MatNd_fromPtr(ptr dead_on_unwind nonnull writable sret(%struct._MatNd) align 8 %4, i32 noundef 1, i32 noundef %32, ptr noundef %33)
  call void @MatNd_appendRows(ptr noundef %0, ptr noundef nonnull %4)
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %4) #4
  %.pre = load i32, ptr %26, align 8, !tbaa !14
  br label %34

34:                                               ; preds = %.lr.ph, %31
  %35 = phi i32 [ %28, %.lr.ph ], [ %.pre, %31 ]
  %36 = add nuw i32 %.017, 1
  %37 = icmp ult i32 %36, %35
  br i1 %37, label %.lr.ph, label %.loopexit, !llvm.loop !15

.loopexit:                                        ; preds = %34, %23, %13, %16
  ret void
}

; Function Attrs: nounwind
declare i64 @lround(double noundef) local_unnamed_addr #3

attributes #0 = { nofree 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #4 = { nounwind }
attributes #5 = { cold 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 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 12}
!12 = !{!"_MatNd", !6, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !13, i64 20}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{!12, !10, i64 8}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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