; LLVM IR from NervanaSystems/ngraph :: doc/examples/mnist_mlp/mnist_loader.ll (ZN11MNistLoader4readIjEEvPT_m)

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

%class.MNistLoader = type { ptr, %"class.std::__cxx11::basic_string", ptr, i32, i32, %struct._G_fpos_t }
%"class.std::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon = type { i64, [8 x i8] }
%struct._G_fpos_t = type { i64, %struct.__mbstate_t }
%struct.__mbstate_t = type { i32, %union.anon.0 }
%union.anon.0 = type { i32 }

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

11:                                               ; preds = %43, %3
  %12 = load i64, ptr %8, align 8, !tbaa !9
  %13 = load i64, ptr %6, align 8, !tbaa !9
  %14 = icmp ult i64 %12, %13
  br i1 %14, label %16, label %15

15:                                               ; preds = %11
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %46

16:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %17 = getelementptr inbounds %class.MNistLoader, ptr %10, i32 0, i32 2
  %18 = load ptr, ptr %17, align 8, !tbaa !11
  %19 = call i32 @fgetc(ptr noundef %18)
  store i32 %19, ptr %9, align 4, !tbaa !18
  %20 = load i32, ptr %9, align 4, !tbaa !18
  %21 = shl i32 %20, 24
  store i32 %21, ptr %7, align 4, !tbaa !18
  %22 = getelementptr inbounds %class.MNistLoader, ptr %10, i32 0, i32 2
  %23 = load ptr, ptr %22, align 8, !tbaa !11
  %24 = call i32 @fgetc(ptr noundef %23)
  %25 = shl i32 %24, 16
  %26 = load i32, ptr %7, align 4, !tbaa !18
  %27 = or i32 %26, %25
  store i32 %27, ptr %7, align 4, !tbaa !18
  %28 = getelementptr inbounds %class.MNistLoader, ptr %10, i32 0, i32 2
  %29 = load ptr, ptr %28, align 8, !tbaa !11
  %30 = call i32 @fgetc(ptr noundef %29)
  %31 = shl i32 %30, 8
  %32 = load i32, ptr %7, align 4, !tbaa !18
  %33 = or i32 %32, %31
  store i32 %33, ptr %7, align 4, !tbaa !18
  %34 = getelementptr inbounds %class.MNistLoader, ptr %10, i32 0, i32 2
  %35 = load ptr, ptr %34, align 8, !tbaa !11
  %36 = call i32 @fgetc(ptr noundef %35)
  %37 = load i32, ptr %7, align 4, !tbaa !18
  %38 = or i32 %37, %36
  store i32 %38, ptr %7, align 4, !tbaa !18
  %39 = load i32, ptr %7, align 4, !tbaa !18
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = load i64, ptr %8, align 8, !tbaa !9
  %42 = getelementptr inbounds i32, ptr %40, i64 %41
  store i32 %39, ptr %42, align 4, !tbaa !18
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %43

43:                                               ; preds = %16
  %44 = load i64, ptr %8, align 8, !tbaa !9
  %45 = add i64 %44, 1
  store i64 %45, ptr %8, align 8, !tbaa !9
  br label %11, !llvm.loop !19

46:                                               ; preds = %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  ret void
}

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

declare i32 @fgetc(ptr noundef) #2

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

attributes #0 = { mustprogress 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 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !6, i64 40}
!12 = !{!"_ZTS11MNistLoader", !13, i64 8, !6, i64 40, !15, i64 48, !15, i64 52, !16, i64 56}
!13 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !14, i64 0, !10, i64 8, !7, i64 16}
!14 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !6, i64 0}
!15 = !{!"int", !7, i64 0}
!16 = !{!"_ZTS9_G_fpos_t", !10, i64 0, !17, i64 8}
!17 = !{!"_ZTS11__mbstate_t", !15, i64 0, !7, i64 4}
!18 = !{!15, !15, 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"

; Function Attrs: mustprogress nofree nounwind uwtable
define dso_local void @_ZN11MNistLoader4readIjEEvPT_m(ptr nocapture noundef nonnull readonly align 8 dereferenceable(72) %0, ptr nocapture noundef writeonly %1, i64 noundef %2) local_unnamed_addr #0 align 2 {
  %.not = icmp eq i64 %2, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %3
  %4 = getelementptr inbounds i8, ptr %0, i64 40
  br label %5

._crit_edge:                                      ; preds = %5, %3
  ret void

5:                                                ; preds = %.lr.ph, %5
  %.010 = phi i64 [ 0, %.lr.ph ], [ %21, %5 ]
  %6 = load ptr, ptr %4, align 8, !tbaa !5
  %7 = tail call i32 @fgetc(ptr noundef %6)
  %8 = shl i32 %7, 24
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = tail call i32 @fgetc(ptr noundef %9)
  %11 = shl i32 %10, 16
  %12 = or i32 %11, %8
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = tail call i32 @fgetc(ptr noundef %13)
  %15 = shl i32 %14, 8
  %16 = or i32 %12, %15
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = tail call i32 @fgetc(ptr noundef %17)
  %19 = or i32 %16, %18
  %20 = getelementptr inbounds i32, ptr %1, i64 %.010
  store i32 %19, ptr %20, align 4, !tbaa !16
  %21 = add nuw i64 %.010, 1
  %exitcond.not = icmp eq i64 %21, %2
  br i1 %exitcond.not, label %._crit_edge, label %5, !llvm.loop !17
}

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

attributes #0 = { mustprogress nofree 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 = { 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" }

!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, !9, i64 40}
!6 = !{!"_ZTS11MNistLoader", !7, i64 8, !9, i64 40, !13, i64 48, !13, i64 52, !14, i64 56}
!7 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !8, i64 0, !12, i64 8, !10, i64 16}
!8 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !9, i64 0}
!9 = !{!"any pointer", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C++ TBAA"}
!12 = !{!"long", !10, i64 0}
!13 = !{!"int", !10, i64 0}
!14 = !{!"_ZTS9_G_fpos_t", !12, i64 0, !15, i64 8}
!15 = !{!"_ZTS11__mbstate_t", !13, i64 0, !10, i64 4}
!16 = !{!13, !13, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


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