; 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_global_options = type { i32, i32, i32 }
%struct.nifti_image = type { i32, i32, i32, i32, i32, i32, i32, i32, [8 x i32], i64, i32, i32, float, float, float, float, float, float, float, [8 x float], float, float, float, float, i32, i32, i32, i32, i32, i32, i32, i32, float, float, float, float, float, float, float, float, %struct.mat44, %struct.mat44, %struct.mat44, %struct.mat44, float, i32, i32, i32, i32, float, float, float, [16 x i8], [80 x i8], [24 x i8], ptr, ptr, i32, i32, i32, ptr, i32, ptr, i32 }
%struct.mat44 = type { [4 x [4 x float]] }
%struct.nifti1_extension = type { i32, i32, ptr }

@stderr = external global ptr, align 8
@g_opts = external hidden global %struct.nifti_global_options, align 4
@.str.210 = external hidden unnamed_addr constant [54 x i8], align 1
@.str.211 = external hidden unnamed_addr constant [27 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

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

; Function Attrs: nounwind
declare void @free(ptr noundef) #1

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

8:                                                ; preds = %1
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %90

9:                                                ; preds = %1
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.nifti_image, ptr %10, i32 0, i32 61
  %12 = load i32, ptr %11, align 8, !tbaa !9
  %13 = icmp sgt i32 %12, 0
  br i1 %13, label %14, label %53

14:                                               ; preds = %9
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.nifti_image, ptr %15, i32 0, i32 62
  %17 = load ptr, ptr %16, align 8, !tbaa !15
  %18 = icmp ne ptr %17, null
  br i1 %18, label %19, label %53

19:                                               ; preds = %14
  store i32 0, ptr %4, align 4, !tbaa !16
  br label %20

20:                                               ; preds = %46, %19
  %21 = load i32, ptr %4, align 4, !tbaa !16
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.nifti_image, ptr %22, i32 0, i32 61
  %24 = load i32, ptr %23, align 8, !tbaa !9
  %25 = icmp slt i32 %21, %24
  br i1 %25, label %26, label %49

26:                                               ; preds = %20
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.nifti_image, ptr %27, i32 0, i32 62
  %29 = load ptr, ptr %28, align 8, !tbaa !15
  %30 = load i32, ptr %4, align 4, !tbaa !16
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds %struct.nifti1_extension, ptr %29, i64 %31
  %33 = getelementptr inbounds %struct.nifti1_extension, ptr %32, i32 0, i32 2
  %34 = load ptr, ptr %33, align 8, !tbaa !17
  %35 = icmp ne ptr %34, null
  br i1 %35, label %36, label %45

36:                                               ; preds = %26
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.nifti_image, ptr %37, i32 0, i32 62
  %39 = load ptr, ptr %38, align 8, !tbaa !15
  %40 = load i32, ptr %4, align 4, !tbaa !16
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds %struct.nifti1_extension, ptr %39, i64 %41
  %43 = getelementptr inbounds %struct.nifti1_extension, ptr %42, i32 0, i32 2
  %44 = load ptr, ptr %43, align 8, !tbaa !17
  call void @free(ptr noundef %44) #3
  br label %45

45:                                               ; preds = %36, %26
  br label %46

46:                                               ; preds = %45
  %47 = load i32, ptr %4, align 4, !tbaa !16
  %48 = add nsw i32 %47, 1
  store i32 %48, ptr %4, align 4, !tbaa !16
  br label %20, !llvm.loop !19

49:                                               ; preds = %20
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.nifti_image, ptr %50, i32 0, i32 62
  %52 = load ptr, ptr %51, align 8, !tbaa !15
  call void @free(ptr noundef %52) #3
  br label %76

53:                                               ; preds = %14, %9
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.nifti_image, ptr %54, i32 0, i32 61
  %56 = load i32, ptr %55, align 8, !tbaa !9
  %57 = icmp sgt i32 %56, 0
  br i1 %57, label %63, label %58

58:                                               ; preds = %53
  %59 = load ptr, ptr %3, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.nifti_image, ptr %59, i32 0, i32 62
  %61 = load ptr, ptr %60, align 8, !tbaa !15
  %62 = icmp ne ptr %61, null
  br i1 %62, label %63, label %75

63:                                               ; preds = %58, %53
  %64 = load i32, ptr @g_opts, align 4, !tbaa !21
  %65 = icmp sgt i32 %64, 0
  br i1 %65, label %66, label %75

66:                                               ; preds = %63
  %67 = load ptr, ptr @stderr, align 8, !tbaa !5
  %68 = load ptr, ptr %3, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.nifti_image, ptr %68, i32 0, i32 61
  %70 = load i32, ptr %69, align 8, !tbaa !9
  %71 = load ptr, ptr %3, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.nifti_image, ptr %71, i32 0, i32 62
  %73 = load ptr, ptr %72, align 8, !tbaa !15
  %74 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %67, ptr noundef @.str.210, i32 noundef %70, ptr noundef %73) #3
  br label %75

75:                                               ; preds = %66, %63, %58
  br label %76

76:                                               ; preds = %75, %49
  %77 = load i32, ptr @g_opts, align 4, !tbaa !21
  %78 = icmp sgt i32 %77, 2
  br i1 %78, label %79, label %85

79:                                               ; preds = %76
  %80 = load ptr, ptr @stderr, align 8, !tbaa !5
  %81 = load ptr, ptr %3, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.nifti_image, ptr %81, i32 0, i32 61
  %83 = load i32, ptr %82, align 8, !tbaa !9
  %84 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %80, ptr noundef @.str.211, i32 noundef %83) #3
  br label %85

85:                                               ; preds = %79, %76
  %86 = load ptr, ptr %3, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.nifti_image, ptr %86, i32 0, i32 61
  store i32 0, ptr %87, align 8, !tbaa !9
  %88 = load ptr, ptr %3, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.nifti_image, ptr %88, i32 0, i32 62
  store ptr null, ptr %89, align 8, !tbaa !15
  store i32 0, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %90

90:                                               ; preds = %85, %8
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  %91 = load i32, ptr %2, align 4
  ret i32 %91
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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, !11, i64 672}
!10 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !7, i64 32, !12, i64 64, !11, i64 72, !11, i64 76, !13, i64 80, !13, i64 84, !13, i64 88, !13, i64 92, !13, i64 96, !13, i64 100, !13, i64 104, !7, i64 108, !13, i64 140, !13, i64 144, !13, i64 148, !13, i64 152, !11, i64 156, !11, i64 160, !11, i64 164, !11, i64 168, !11, i64 172, !11, i64 176, !11, i64 180, !11, i64 184, !13, i64 188, !13, i64 192, !13, i64 196, !13, i64 200, !13, i64 204, !13, i64 208, !13, i64 212, !13, i64 216, !14, i64 220, !14, i64 284, !14, i64 348, !14, i64 412, !13, i64 476, !11, i64 480, !11, i64 484, !11, i64 488, !11, i64 492, !13, i64 496, !13, i64 500, !13, i64 504, !7, i64 508, !7, i64 524, !7, i64 604, !6, i64 632, !6, i64 640, !11, i64 648, !11, i64 652, !11, i64 656, !6, i64 664, !11, i64 672, !6, i64 680, !11, i64 688}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!"float", !7, i64 0}
!14 = !{!"", !7, i64 0}
!15 = !{!10, !6, i64 680}
!16 = !{!11, !11, i64 0}
!17 = !{!18, !6, i64 8}
!18 = !{!"nifti1_extension", !11, i64 0, !11, i64 4, !6, i64 8}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!22, !11, i64 0}
!22 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8}


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

@stderr = external local_unnamed_addr global ptr, align 8
@g_opts = external hidden local_unnamed_addr global %struct.nifti_global_options, align 4
@.str.210 = external hidden unnamed_addr constant [54 x i8], align 1
@.str.211 = external hidden unnamed_addr constant [27 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 nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @nifti_free_extensions(ptr noundef %0) local_unnamed_addr #2 {
  %2 = icmp eq ptr %0, null
  br i1 %2, label %36, label %3

3:                                                ; preds = %1
  %4 = getelementptr inbounds i8, ptr %0, i64 672
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %6 = icmp sgt i32 %5, 0
  %7 = getelementptr inbounds i8, ptr %0, i64 680
  %8 = load ptr, ptr %7, align 8, !tbaa !14
  br i1 %6, label %9, label %19

9:                                                ; preds = %3
  %.not = icmp eq ptr %8, null
  br i1 %.not, label %23, label %.lr.ph

.lr.ph:                                           ; preds = %9, %15
  %10 = phi i32 [ %16, %15 ], [ %5, %9 ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %15 ], [ 0, %9 ]
  %11 = load ptr, ptr %7, align 8, !tbaa !14
  %12 = getelementptr inbounds %struct.nifti1_extension, ptr %11, i64 %indvars.iv, i32 2
  %13 = load ptr, ptr %12, align 8, !tbaa !15
  %.not22 = icmp eq ptr %13, null
  br i1 %.not22, label %15, label %14

14:                                               ; preds = %.lr.ph
  tail call void @free(ptr noundef nonnull %13) #3
  %.pre = load i32, ptr %4, align 8, !tbaa !5
  br label %15

15:                                               ; preds = %.lr.ph, %14
  %16 = phi i32 [ %10, %.lr.ph ], [ %.pre, %14 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %17 = sext i32 %16 to i64
  %18 = icmp slt i64 %indvars.iv.next, %17
  br i1 %18, label %.lr.ph, label %._crit_edge, !llvm.loop !17

._crit_edge:                                      ; preds = %15
  %.pre26 = load ptr, ptr %7, align 8, !tbaa !14
  tail call void @free(ptr noundef %.pre26) #3
  br label %thread-pre-split

19:                                               ; preds = %3
  %20 = icmp ne ptr %8, null
  %21 = load i32, ptr @g_opts, align 4
  %22 = icmp sgt i32 %21, 0
  %or.cond = select i1 %20, i1 %22, i1 false
  br i1 %or.cond, label %24, label %28

23:                                               ; preds = %9
  %.old = load i32, ptr @g_opts, align 4, !tbaa !19
  %.old1 = icmp sgt i32 %.old, 0
  br i1 %.old1, label %24, label %.thread23

24:                                               ; preds = %19, %23
  %25 = phi ptr [ %8, %19 ], [ null, %23 ]
  %26 = load ptr, ptr @stderr, align 8, !tbaa !21
  %27 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %26, ptr noundef nonnull @.str.210, i32 noundef %5, ptr noundef %25) #4
  br label %thread-pre-split

thread-pre-split:                                 ; preds = %._crit_edge, %24
  %.pr = load i32, ptr @g_opts, align 4, !tbaa !19
  br label %28

28:                                               ; preds = %thread-pre-split, %19
  %29 = phi i32 [ %.pr, %thread-pre-split ], [ %21, %19 ]
  %30 = icmp sgt i32 %29, 2
  br i1 %30, label %31, label %.thread23

31:                                               ; preds = %28
  %32 = load ptr, ptr @stderr, align 8, !tbaa !21
  %33 = load i32, ptr %4, align 8, !tbaa !5
  %34 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %32, ptr noundef nonnull @.str.211, i32 noundef %33) #4
  br label %.thread23

.thread23:                                        ; preds = %23, %31, %28
  store i32 0, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds i8, ptr %0, i64 680
  store ptr null, ptr %35, align 8, !tbaa !14
  br label %36

36:                                               ; preds = %1, %.thread23
  %.019 = phi i32 [ 0, %.thread23 ], [ -1, %1 ]
  ret i32 %.019
}

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 nounwind willreturn allockind("free") memory(argmem: readwrite, 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 #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 }
attributes #4 = { 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, !7, i64 672}
!6 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24, !7, i64 28, !8, i64 32, !10, i64 64, !7, i64 72, !7, i64 76, !11, i64 80, !11, i64 84, !11, i64 88, !11, i64 92, !11, i64 96, !11, i64 100, !11, i64 104, !8, i64 108, !11, i64 140, !11, i64 144, !11, i64 148, !11, i64 152, !7, i64 156, !7, i64 160, !7, i64 164, !7, i64 168, !7, i64 172, !7, i64 176, !7, i64 180, !7, i64 184, !11, i64 188, !11, i64 192, !11, i64 196, !11, i64 200, !11, i64 204, !11, i64 208, !11, i64 212, !11, i64 216, !12, i64 220, !12, i64 284, !12, i64 348, !12, i64 412, !11, i64 476, !7, i64 480, !7, i64 484, !7, i64 488, !7, i64 492, !11, i64 496, !11, i64 500, !11, i64 504, !8, i64 508, !8, i64 524, !8, i64 604, !13, i64 632, !13, i64 640, !7, i64 648, !7, i64 652, !7, i64 656, !13, i64 664, !7, i64 672, !13, i64 680, !7, i64 688}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"float", !8, i64 0}
!12 = !{!"", !8, i64 0}
!13 = !{!"any pointer", !8, i64 0}
!14 = !{!6, !13, i64 680}
!15 = !{!16, !13, i64 8}
!16 = !{!"nifti1_extension", !7, i64 0, !7, i64 4, !13, i64 8}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!20, !7, i64 0}
!20 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8}
!21 = !{!13, !13, i64 0}


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