; LLVM IR from InsightSoftwareConsortium/ITK :: Modules/ThirdParty/MINC/src/libminc/nifti (nifti1_io)

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

@nifti_type_list = external hidden global [43 x %struct.nifti_type_ele], align 16
@.str.415 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.416 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.417 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.418 = external hidden unnamed_addr constant [138 x i8], align 1
@.str.419 = external hidden unnamed_addr constant [30 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

declare i32 @printf(ptr noundef, ...) #1

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

9:                                                ; preds = %1
  store i32 1, ptr %5, align 4, !tbaa !5
  store ptr @.str.415, ptr %3, align 8, !tbaa !9
  br label %16

10:                                               ; preds = %1
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = icmp eq i32 %11, 2
  br i1 %12, label %13, label %14

13:                                               ; preds = %10
  store i32 2, ptr %5, align 4, !tbaa !5
  store ptr @.str.416, ptr %3, align 8, !tbaa !9
  br label %15

14:                                               ; preds = %10
  store i32 3, ptr %5, align 4, !tbaa !5
  store ptr @.str.417, ptr %3, align 8, !tbaa !9
  br label %15

15:                                               ; preds = %14, %13
  br label %16

16:                                               ; preds = %15, %9
  %17 = load ptr, ptr %3, align 8, !tbaa !9
  %18 = call i32 (ptr, ...) @printf(ptr noundef @.str.418, ptr noundef %17)
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %19

19:                                               ; preds = %74, %16
  %20 = load i32, ptr %6, align 4, !tbaa !5
  %21 = load i32, ptr %4, align 4, !tbaa !5
  %22 = icmp slt i32 %20, %21
  br i1 %22, label %23, label %77

23:                                               ; preds = %19
  %24 = load i32, ptr %5, align 4, !tbaa !5
  %25 = and i32 %24, 1
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %27, label %37

27:                                               ; preds = %23
  %28 = load i32, ptr %6, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [43 x %struct.nifti_type_ele], ptr @nifti_type_list, i64 0, i64 %29
  %31 = getelementptr inbounds %struct.nifti_type_ele, ptr %30, i32 0, i32 3
  %32 = load ptr, ptr %31, align 8, !tbaa !11
  %33 = getelementptr inbounds i8, ptr %32, i64 0
  %34 = load i8, ptr %33, align 1, !tbaa !13
  %35 = sext i8 %34 to i32
  %36 = icmp eq i32 %35, 68
  br i1 %36, label %51, label %37

37:                                               ; preds = %27, %23
  %38 = load i32, ptr %5, align 4, !tbaa !5
  %39 = and i32 %38, 2
  %40 = icmp ne i32 %39, 0
  br i1 %40, label %41, label %73

41:                                               ; preds = %37
  %42 = load i32, ptr %6, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [43 x %struct.nifti_type_ele], ptr @nifti_type_list, i64 0, i64 %43
  %45 = getelementptr inbounds %struct.nifti_type_ele, ptr %44, i32 0, i32 3
  %46 = load ptr, ptr %45, align 8, !tbaa !11
  %47 = getelementptr inbounds i8, ptr %46, i64 0
  %48 = load i8, ptr %47, align 1, !tbaa !13
  %49 = sext i8 %48 to i32
  %50 = icmp eq i32 %49, 78
  br i1 %50, label %51, label %73

51:                                               ; preds = %41, %27
  %52 = load i32, ptr %6, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [43 x %struct.nifti_type_ele], ptr @nifti_type_list, i64 0, i64 %53
  %55 = getelementptr inbounds %struct.nifti_type_ele, ptr %54, i32 0, i32 3
  %56 = load ptr, ptr %55, align 8, !tbaa !11
  %57 = load i32, ptr %6, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [43 x %struct.nifti_type_ele], ptr @nifti_type_list, i64 0, i64 %58
  %60 = getelementptr inbounds %struct.nifti_type_ele, ptr %59, i32 0, i32 0
  %61 = load i32, ptr %60, align 8, !tbaa !14
  %62 = load i32, ptr %6, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [43 x %struct.nifti_type_ele], ptr @nifti_type_list, i64 0, i64 %63
  %65 = getelementptr inbounds %struct.nifti_type_ele, ptr %64, i32 0, i32 1
  %66 = load i32, ptr %65, align 4, !tbaa !15
  %67 = load i32, ptr %6, align 4, !tbaa !5
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds [43 x %struct.nifti_type_ele], ptr @nifti_type_list, i64 0, i64 %68
  %70 = getelementptr inbounds %struct.nifti_type_ele, ptr %69, i32 0, i32 2
  %71 = load i32, ptr %70, align 8, !tbaa !16
  %72 = call i32 (ptr, ...) @printf(ptr noundef @.str.419, ptr noundef %56, i32 noundef %61, i32 noundef %66, i32 noundef %71)
  br label %73

73:                                               ; preds = %51, %41, %37
  br label %74

74:                                               ; preds = %73
  %75 = load i32, ptr %6, align 4, !tbaa !5
  %76 = add nsw i32 %75, 1
  store i32 %76, ptr %6, align 4, !tbaa !5
  br label %19, !llvm.loop !17

77:                                               ; preds = %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret i32 0
}

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 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 = !{!"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, !10, i64 16}
!12 = !{!"", !6, i64 0, !6, i64 4, !6, i64 8, !10, i64 16}
!13 = !{!7, !7, i64 0}
!14 = !{!12, !6, i64 0}
!15 = !{!12, !6, i64 4}
!16 = !{!12, !6, 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.nifti_type_ele = type { i32, i32, i32, ptr }

@nifti_type_list = external hidden local_unnamed_addr global [43 x %struct.nifti_type_ele], align 16
@.str.415 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.416 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.417 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.418 = external hidden unnamed_addr constant [138 x i8], align 1
@.str.419 = external hidden unnamed_addr constant [30 x i8], align 1

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

; Function Attrs: nofree nounwind uwtable
define dso_local noundef i32 @nifti_disp_type_list(i32 noundef %0) local_unnamed_addr #1 {
  %2 = icmp eq i32 %0, 1
  %3 = icmp eq i32 %0, 2
  %.str.416..str.417 = select i1 %3, ptr @.str.416, ptr @.str.417
  %.014 = select i1 %2, ptr @.str.415, ptr %.str.416..str.417
  %4 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.418, ptr noundef nonnull %.014)
  br i1 %3, label %.thread.us, label %.split

.thread.us:                                       ; preds = %1, %17
  %indvars.iv28 = phi i64 [ %indvars.iv.next29, %17 ], [ 0, %1 ]
  %5 = getelementptr inbounds [43 x %struct.nifti_type_ele], ptr @nifti_type_list, i64 0, i64 %indvars.iv28, i32 3
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %7 = load i8, ptr %6, align 1, !tbaa !11
  %8 = icmp eq i8 %7, 78
  br i1 %8, label %9, label %17

9:                                                ; preds = %.thread.us
  %10 = getelementptr inbounds [43 x %struct.nifti_type_ele], ptr @nifti_type_list, i64 0, i64 %indvars.iv28
  %11 = load i32, ptr %10, align 8, !tbaa !12
  %12 = getelementptr inbounds i8, ptr %10, i64 4
  %13 = load i32, ptr %12, align 4, !tbaa !13
  %14 = getelementptr inbounds i8, ptr %10, i64 8
  %15 = load i32, ptr %14, align 8, !tbaa !14
  %16 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.419, ptr noundef nonnull %6, i32 noundef %11, i32 noundef %13, i32 noundef %15)
  br label %17

17:                                               ; preds = %9, %.thread.us
  %indvars.iv.next29 = add nuw nsw i64 %indvars.iv28, 1
  %exitcond31.not = icmp eq i64 %indvars.iv.next29, 43
  br i1 %exitcond31.not, label %.split19.us, label %.thread.us, !llvm.loop !15

.split:                                           ; preds = %1
  br i1 %2, label %.split.split.us, label %.split.split

.split.split.us:                                  ; preds = %.split, %30
  %indvars.iv24 = phi i64 [ %indvars.iv.next25, %30 ], [ 0, %.split ]
  %18 = getelementptr inbounds [43 x %struct.nifti_type_ele], ptr @nifti_type_list, i64 0, i64 %indvars.iv24, i32 3
  %19 = load ptr, ptr %18, align 8, !tbaa !5
  %20 = load i8, ptr %19, align 1, !tbaa !11
  %21 = icmp eq i8 %20, 68
  br i1 %21, label %22, label %30

22:                                               ; preds = %.split.split.us
  %23 = getelementptr inbounds [43 x %struct.nifti_type_ele], ptr @nifti_type_list, i64 0, i64 %indvars.iv24
  %24 = load i32, ptr %23, align 8, !tbaa !12
  %25 = getelementptr inbounds i8, ptr %23, i64 4
  %26 = load i32, ptr %25, align 4, !tbaa !13
  %27 = getelementptr inbounds i8, ptr %23, i64 8
  %28 = load i32, ptr %27, align 8, !tbaa !14
  %29 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.419, ptr noundef nonnull %19, i32 noundef %24, i32 noundef %26, i32 noundef %28)
  br label %30

30:                                               ; preds = %.split.split.us, %22
  %indvars.iv.next25 = add nuw nsw i64 %indvars.iv24, 1
  %exitcond27.not = icmp eq i64 %indvars.iv.next25, 43
  br i1 %exitcond27.not, label %.split19.us, label %.split.split.us, !llvm.loop !15

.split.split:                                     ; preds = %.split, %42
  %indvars.iv = phi i64 [ %indvars.iv.next, %42 ], [ 0, %.split ]
  %31 = getelementptr inbounds [43 x %struct.nifti_type_ele], ptr @nifti_type_list, i64 0, i64 %indvars.iv, i32 3
  %32 = load ptr, ptr %31, align 8, !tbaa !5
  %33 = load i8, ptr %32, align 1, !tbaa !11
  switch i8 %33, label %42 [
    i8 68, label %34
    i8 78, label %34
  ]

34:                                               ; preds = %.split.split, %.split.split
  %35 = getelementptr inbounds [43 x %struct.nifti_type_ele], ptr @nifti_type_list, i64 0, i64 %indvars.iv
  %36 = load i32, ptr %35, align 8, !tbaa !12
  %37 = getelementptr inbounds i8, ptr %35, i64 4
  %38 = load i32, ptr %37, align 4, !tbaa !13
  %39 = getelementptr inbounds i8, ptr %35, i64 8
  %40 = load i32, ptr %39, align 8, !tbaa !14
  %41 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.419, ptr noundef nonnull %32, i32 noundef %36, i32 noundef %38, i32 noundef %40)
  br label %42

42:                                               ; preds = %.split.split, %34
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 43
  br i1 %exitcond.not, label %.split19.us, label %.split.split, !llvm.loop !15

.split19.us:                                      ; preds = %42, %30, %17
  ret i32 0
}

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 = { 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" }

!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, !10, i64 16}
!6 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !10, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!8, !8, i64 0}
!12 = !{!6, !7, i64 0}
!13 = !{!6, !7, i64 4}
!14 = !{!6, !7, i64 8}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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