; LLVM IR from InsightSoftwareConsortium/ITK :: Modules/ThirdParty/NIFTI/src/nifti/niftilib (nifti1_tool)

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

; 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 uwtable
define dso_local i32 @diff_hdrs_list(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  store i32 %3, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  store i32 0, ptr %12, align 4, !tbaa !9
  %13 = load ptr, ptr %7, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.str_list, ptr %13, i32 0, i32 1
  %15 = load ptr, ptr %14, align 8, !tbaa !11
  store ptr %15, ptr %10, align 8, !tbaa !5
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %16

16:                                               ; preds = %53, %4
  %17 = load i32, ptr %11, align 4, !tbaa !9
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.str_list, ptr %18, i32 0, i32 0
  %20 = load i32, ptr %19, align 8, !tbaa !13
  %21 = icmp slt i32 %17, %20
  br i1 %21, label %22, label %56

22:                                               ; preds = %16
  %23 = load ptr, ptr %10, align 8, !tbaa !5
  %24 = load ptr, ptr %23, align 8, !tbaa !5
  %25 = call ptr @get_hdr_field(ptr noundef %24, i32 noundef 1)
  store ptr %25, ptr %9, align 8, !tbaa !5
  %26 = load ptr, ptr %9, align 8, !tbaa !5
  %27 = icmp ne ptr %26, null
  br i1 %27, label %28, label %50

28:                                               ; preds = %22
  %29 = load ptr, ptr %9, align 8, !tbaa !5
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = call i32 @diff_field(ptr noundef %29, ptr noundef %30, ptr noundef %31, i32 noundef 1)
  %33 = icmp ne i32 %32, 0
  br i1 %33, label %34, label %50

34:                                               ; preds = %28
  %35 = load i32, ptr %8, align 4, !tbaa !9
  %36 = icmp ne i32 %35, 0
  br i1 %36, label %37, label %47

37:                                               ; preds = %34
  %38 = load ptr, ptr %9, align 8, !tbaa !5
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = load i32, ptr %12, align 4, !tbaa !9
  %41 = icmp eq i32 %40, 0
  %42 = zext i1 %41 to i32
  %43 = call i32 @disp_field(ptr noundef null, ptr noundef %38, ptr noundef %39, i32 noundef 1, i32 noundef %42)
  %44 = load ptr, ptr %9, align 8, !tbaa !5
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  %46 = call i32 @disp_field(ptr noundef null, ptr noundef %44, ptr noundef %45, i32 noundef 1, i32 noundef 0)
  br label %47

47:                                               ; preds = %37, %34
  %48 = load i32, ptr %12, align 4, !tbaa !9
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr %12, align 4, !tbaa !9
  br label %50

50:                                               ; preds = %47, %28, %22
  %51 = load ptr, ptr %10, align 8, !tbaa !5
  %52 = getelementptr inbounds ptr, ptr %51, i32 1
  store ptr %52, ptr %10, align 8, !tbaa !5
  br label %53

53:                                               ; preds = %50
  %54 = load i32, ptr %11, align 4, !tbaa !9
  %55 = add nsw i32 %54, 1
  store i32 %55, ptr %11, align 4, !tbaa !9
  br label %16, !llvm.loop !14

56:                                               ; preds = %16
  %57 = load i32, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  ret i32 %57
}

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

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

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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, !6, i64 8}
!12 = !{!"", !10, i64 0, !6, i64 8}
!13 = !{!12, !10, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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: nounwind uwtable
define dso_local i32 @diff_hdrs_list(ptr noundef %0, ptr noundef %1, ptr nocapture noundef readonly %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = load i32, ptr %2, align 8, !tbaa !5
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %4
  %7 = getelementptr inbounds i8, ptr %2, i64 8
  %8 = load ptr, ptr %7, align 8, !tbaa !11
  %.not21 = icmp eq i32 %3, 0
  br i1 %.not21, label %.lr.ph.split.us, label %.lr.ph.split

.lr.ph.split.us:                                  ; preds = %.lr.ph, %14
  %.024.us = phi i32 [ %.1.us, %14 ], [ 0, %.lr.ph ]
  %.01723.us = phi i32 [ %16, %14 ], [ 0, %.lr.ph ]
  %.01822.us = phi ptr [ %15, %14 ], [ %8, %.lr.ph ]
  %9 = load ptr, ptr %.01822.us, align 8, !tbaa !12
  %10 = tail call ptr @get_hdr_field(ptr noundef %9, i32 noundef 1)
  %.not.us = icmp eq ptr %10, null
  br i1 %.not.us, label %14, label %11

11:                                               ; preds = %.lr.ph.split.us
  %12 = tail call i32 @diff_field(ptr noundef nonnull %10, ptr noundef %0, ptr noundef %1, i32 noundef 1)
  %.not20.us = icmp ne i32 %12, 0
  %13 = zext i1 %.not20.us to i32
  %spec.select = add nsw i32 %.024.us, %13
  br label %14

14:                                               ; preds = %11, %.lr.ph.split.us
  %.1.us = phi i32 [ %.024.us, %.lr.ph.split.us ], [ %spec.select, %11 ]
  %15 = getelementptr inbounds i8, ptr %.01822.us, i64 8
  %16 = add nuw nsw i32 %.01723.us, 1
  %17 = load i32, ptr %2, align 8, !tbaa !5
  %18 = icmp slt i32 %16, %17
  br i1 %18, label %.lr.ph.split.us, label %._crit_edge, !llvm.loop !13

.lr.ph.split:                                     ; preds = %.lr.ph, %29
  %.024 = phi i32 [ %.1, %29 ], [ 0, %.lr.ph ]
  %.01723 = phi i32 [ %31, %29 ], [ 0, %.lr.ph ]
  %.01822 = phi ptr [ %30, %29 ], [ %8, %.lr.ph ]
  %19 = load ptr, ptr %.01822, align 8, !tbaa !12
  %20 = tail call ptr @get_hdr_field(ptr noundef %19, i32 noundef 1)
  %.not = icmp eq ptr %20, null
  br i1 %.not, label %29, label %21

21:                                               ; preds = %.lr.ph.split
  %22 = tail call i32 @diff_field(ptr noundef nonnull %20, ptr noundef %0, ptr noundef %1, i32 noundef 1)
  %.not20 = icmp eq i32 %22, 0
  br i1 %.not20, label %29, label %23

23:                                               ; preds = %21
  %24 = icmp eq i32 %.024, 0
  %25 = zext i1 %24 to i32
  %26 = tail call i32 @disp_field(ptr noundef null, ptr noundef nonnull %20, ptr noundef %0, i32 noundef 1, i32 noundef %25)
  %27 = tail call i32 @disp_field(ptr noundef null, ptr noundef nonnull %20, ptr noundef %1, i32 noundef 1, i32 noundef 0)
  %28 = add nsw i32 %.024, 1
  br label %29

29:                                               ; preds = %23, %21, %.lr.ph.split
  %.1 = phi i32 [ %28, %23 ], [ %.024, %21 ], [ %.024, %.lr.ph.split ]
  %30 = getelementptr inbounds i8, ptr %.01822, i64 8
  %31 = add nuw nsw i32 %.01723, 1
  %32 = load i32, ptr %2, align 8, !tbaa !5
  %33 = icmp slt i32 %31, %32
  br i1 %33, label %.lr.ph.split, label %._crit_edge, !llvm.loop !13

._crit_edge:                                      ; preds = %29, %14, %4
  %.0.lcssa = phi i32 [ 0, %4 ], [ %.1.us, %14 ], [ %.1, %29 ]
  ret i32 %.0.lcssa
}

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

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

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

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


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