; LLVM IR from zchrissirhcz/pixel :: src (px_mnist)

; 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.px_mnist_label_array_t = type { i32, ptr, ptr }
%struct.px_array_t = type { ptr, i32 }

@.str = external hidden unnamed_addr constant [3 x i8], align 1
@stderr = external global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [41 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [67 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 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

declare noalias ptr @fopen(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #2

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #3

; Function Attrs: nounwind uwtable
declare hidden i32 @get_mnist_magic_number(ptr noundef) #4

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

declare i32 @fclose(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @px_read_mnist_label(ptr noundef %0) #4 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i8, align 1
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #6
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = call noalias ptr @fopen(ptr noundef %10, ptr noundef @.str)
  store ptr %11, ptr %3, align 8, !tbaa !5
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = icmp eq ptr %12, null
  br i1 %13, label %14, label %23

14:                                               ; preds = %1
  br label %15

15:                                               ; preds = %14
  %16 = load ptr, ptr @stderr, align 8, !tbaa !5
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %16, ptr noundef @.str.1, ptr noundef %17, ptr noundef @.str.2, i32 noundef 110) #6
  %19 = load ptr, ptr @stderr, align 8, !tbaa !5
  %20 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %19, ptr noundef @.str.3) #6
  br label %21

21:                                               ; preds = %15
  br label %22

22:                                               ; preds = %21
  call void @exit(i32 noundef 1) #7
  unreachable

23:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #6
  store i32 10, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #6
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = call i32 @get_mnist_magic_number(ptr noundef %24)
  store i32 %25, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = call i32 @get_mnist_number_of_labels(ptr noundef %26)
  store i32 %27, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #6
  %28 = load i32, ptr %6, align 4, !tbaa !9
  %29 = call ptr @create_px_mnist_label_array_t(i32 noundef %28)
  store ptr %29, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %30

30:                                               ; preds = %66, %23
  %31 = load i32, ptr %8, align 4, !tbaa !9
  %32 = load i32, ptr %6, align 4, !tbaa !9
  %33 = icmp slt i32 %31, %32
  br i1 %33, label %35, label %34

34:                                               ; preds = %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  br label %69

35:                                               ; preds = %30
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.px_mnist_label_array_t, ptr %36, i32 0, i32 2
  %38 = load ptr, ptr %37, align 8, !tbaa !11
  %39 = load i32, ptr %8, align 4, !tbaa !9
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds %struct.px_array_t, ptr %38, i64 %40
  %42 = getelementptr inbounds %struct.px_array_t, ptr %41, i32 0, i32 1
  store i32 10, ptr %42, align 8, !tbaa !13
  %43 = load i32, ptr %4, align 4, !tbaa !9
  %44 = sext i32 %43 to i64
  %45 = call noalias ptr @calloc(i64 noundef %44, i64 noundef 4) #8
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.px_mnist_label_array_t, ptr %46, i32 0, i32 2
  %48 = load ptr, ptr %47, align 8, !tbaa !11
  %49 = load i32, ptr %8, align 4, !tbaa !9
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds %struct.px_array_t, ptr %48, i64 %50
  %52 = getelementptr inbounds %struct.px_array_t, ptr %51, i32 0, i32 0
  store ptr %45, ptr %52, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #6
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = call zeroext i8 @read_mnist_single_label(ptr noundef %53)
  store i8 %54, ptr %9, align 1, !tbaa !16
  %55 = load ptr, ptr %7, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.px_mnist_label_array_t, ptr %55, i32 0, i32 2
  %57 = load ptr, ptr %56, align 8, !tbaa !11
  %58 = load i32, ptr %8, align 4, !tbaa !9
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds %struct.px_array_t, ptr %57, i64 %59
  %61 = getelementptr inbounds %struct.px_array_t, ptr %60, i32 0, i32 0
  %62 = load ptr, ptr %61, align 8, !tbaa !15
  %63 = load i8, ptr %9, align 1, !tbaa !16
  %64 = zext i8 %63 to i64
  %65 = getelementptr inbounds float, ptr %62, i64 %64
  store float 1.000000e+00, ptr %65, align 4, !tbaa !17
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #6
  br label %66

66:                                               ; preds = %35
  %67 = load i32, ptr %8, align 4, !tbaa !9
  %68 = add nsw i32 %67, 1
  store i32 %68, ptr %8, align 4, !tbaa !9
  br label %30, !llvm.loop !19

69:                                               ; preds = %34
  %70 = load ptr, ptr %3, align 8, !tbaa !5
  %71 = call i32 @fclose(ptr noundef %70)
  %72 = load ptr, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #6
  ret ptr %72
}

; Function Attrs: nounwind uwtable
declare hidden i32 @get_mnist_number_of_labels(ptr noundef) #4

; Function Attrs: nounwind uwtable
declare hidden ptr @create_px_mnist_label_array_t(i32 noundef) #4

; Function Attrs: nounwind allocsize(0,1)
declare noalias ptr @calloc(i64 noundef, i64 noundef) #5

; Function Attrs: nounwind uwtable
declare hidden zeroext i8 @read_mnist_single_label(ptr noundef) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 "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 = { 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 #4 = { 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 #5 = { nounwind allocsize(0,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 #6 = { nounwind }
attributes #7 = { noreturn nounwind }
attributes #8 = { nounwind allocsize(0,1) }

!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, !6, i64 16}
!12 = !{!"px_mnist_label_array_t", !10, i64 0, !6, i64 8, !6, i64 16}
!13 = !{!14, !10, i64 8}
!14 = !{!"px_array_t", !6, i64 0, !10, i64 8}
!15 = !{!14, !6, i64 0}
!16 = !{!7, !7, i64 0}
!17 = !{!18, !18, i64 0}
!18 = !{!"float", !7, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"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.px_array_t = type { ptr, i32 }

@.str = external hidden unnamed_addr constant [3 x i8], align 1
@stderr = external local_unnamed_addr global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [41 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [67 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nofree nounwind
declare noalias noundef ptr @fopen(ptr nocapture noundef readonly, ptr nocapture noundef readonly) local_unnamed_addr #0

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

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden i32 @get_mnist_magic_number(ptr noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @fclose(ptr nocapture noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local ptr @px_read_mnist_label(ptr noundef %0) local_unnamed_addr #2 {
  %2 = tail call noalias ptr @fopen(ptr noundef %0, ptr noundef nonnull @.str)
  %3 = icmp eq ptr %2, null
  br i1 %3, label %4, label %9

4:                                                ; preds = %1
  %5 = load ptr, ptr @stderr, align 8, !tbaa !5
  %6 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %5, ptr noundef nonnull @.str.1, ptr noundef %0, ptr noundef nonnull @.str.2, i32 noundef 110) #4
  %7 = load ptr, ptr @stderr, align 8, !tbaa !5
  %8 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %7, ptr noundef nonnull @.str.3) #4
  tail call void @exit(i32 noundef 1) #5
  unreachable

9:                                                ; preds = %1
  %10 = tail call i32 @get_mnist_magic_number(ptr noundef nonnull %2)
  %11 = tail call i32 @get_mnist_number_of_labels(ptr noundef nonnull %2)
  %12 = tail call ptr @create_px_mnist_label_array_t(i32 noundef %11)
  %13 = icmp sgt i32 %11, 0
  br i1 %13, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %9
  %14 = getelementptr inbounds i8, ptr %12, i64 16
  %wide.trip.count = zext nneg i32 %11 to i64
  %.pre = load ptr, ptr %14, align 8, !tbaa !9
  br label %16

._crit_edge:                                      ; preds = %16, %9
  %15 = tail call i32 @fclose(ptr noundef nonnull %2)
  ret ptr %12

16:                                               ; preds = %.lr.ph, %16
  %17 = phi ptr [ %.pre, %.lr.ph ], [ %22, %16 ]
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %16 ]
  %18 = getelementptr inbounds %struct.px_array_t, ptr %17, i64 %indvars.iv, i32 1
  store i32 10, ptr %18, align 8, !tbaa !12
  %19 = tail call noalias dereferenceable_or_null(40) ptr @calloc(i64 noundef 10, i64 noundef 4) #6
  %20 = getelementptr inbounds %struct.px_array_t, ptr %17, i64 %indvars.iv
  store ptr %19, ptr %20, align 8, !tbaa !14
  %21 = tail call zeroext i8 @read_mnist_single_label(ptr noundef nonnull %2)
  %22 = load ptr, ptr %14, align 8, !tbaa !9
  %23 = getelementptr inbounds %struct.px_array_t, ptr %22, i64 %indvars.iv
  %24 = load ptr, ptr %23, align 8, !tbaa !14
  %25 = zext i8 %21 to i64
  %26 = getelementptr inbounds float, ptr %24, i64 %25
  store float 1.000000e+00, ptr %26, align 4, !tbaa !15
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %16, !llvm.loop !17
}

; Function Attrs: nounwind uwtable
declare hidden i32 @get_mnist_number_of_labels(ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden ptr @create_px_mnist_label_array_t(i32 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @calloc(i64 noundef, i64 noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare hidden zeroext i8 @read_mnist_single_label(ptr noundef) local_unnamed_addr #2

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 = { 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 #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 nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { cold nounwind }
attributes #5 = { noreturn nounwind }
attributes #6 = { nounwind allocsize(0,1) }

!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 = !{!"px_mnist_label_array_t", !11, i64 0, !6, i64 8, !6, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !11, i64 8}
!13 = !{!"px_array_t", !6, i64 0, !11, i64 8}
!14 = !{!13, !6, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"float", !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


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