; 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.field_s = type { i32, i32, i32, i32, [20 x i8] }

@g_hdr_fields = external hidden global [43 x %struct.field_s], align 16

; 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(ptr noundef %0, ptr noundef %1, i32 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  store ptr @g_hdr_fields, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  store i32 0, ptr %9, align 4, !tbaa !9
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %10

10:                                               ; preds = %36, %3
  %11 = load i32, ptr %8, align 4, !tbaa !9
  %12 = icmp slt i32 %11, 43
  br i1 %12, label %13, label %41

13:                                               ; preds = %10
  %14 = load ptr, ptr %7, align 8, !tbaa !5
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = call i32 @diff_field(ptr noundef %14, ptr noundef %15, ptr noundef %16, i32 noundef 1)
  %18 = icmp ne i32 %17, 0
  br i1 %18, label %19, label %35

19:                                               ; preds = %13
  %20 = load i32, ptr %6, align 4, !tbaa !9
  %21 = icmp ne i32 %20, 0
  br i1 %21, label %22, label %32

22:                                               ; preds = %19
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = load i32, ptr %9, align 4, !tbaa !9
  %26 = icmp eq i32 %25, 0
  %27 = zext i1 %26 to i32
  %28 = call i32 @disp_field(ptr noundef null, ptr noundef %23, ptr noundef %24, i32 noundef 1, i32 noundef %27)
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = call i32 @disp_field(ptr noundef null, ptr noundef %29, ptr noundef %30, i32 noundef 1, i32 noundef 0)
  br label %32

32:                                               ; preds = %22, %19
  %33 = load i32, ptr %9, align 4, !tbaa !9
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr %9, align 4, !tbaa !9
  br label %35

35:                                               ; preds = %32, %13
  br label %36

36:                                               ; preds = %35
  %37 = load i32, ptr %8, align 4, !tbaa !9
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr %8, align 4, !tbaa !9
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.field_s, ptr %39, i32 1
  store ptr %40, ptr %7, align 8, !tbaa !5
  br label %10, !llvm.loop !11

41:                                               ; preds = %10
  %42 = load i32, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  ret i32 %42
}

; 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 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 = distinct !{!11, !12}
!12 = !{!"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.field_s = type { i32, i32, i32, i32, [20 x i8] }

@g_hdr_fields = external hidden global [43 x %struct.field_s], align 16

; Function Attrs: nounwind uwtable
define dso_local i32 @diff_hdrs(ptr noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %.not15 = icmp eq i32 %2, 0
  br i1 %.not15, label %.split.us, label %.split

.split.us:                                        ; preds = %3, %.split.us
  %.018.us = phi i32 [ %spec.select, %.split.us ], [ 0, %3 ]
  %.01317.us = phi i32 [ %6, %.split.us ], [ 0, %3 ]
  %.01416.us = phi ptr [ %7, %.split.us ], [ @g_hdr_fields, %3 ]
  %4 = tail call i32 @diff_field(ptr noundef nonnull %.01416.us, ptr noundef %0, ptr noundef %1, i32 noundef 1)
  %.not.us = icmp ne i32 %4, 0
  %5 = zext i1 %.not.us to i32
  %spec.select = add nuw nsw i32 %.018.us, %5
  %6 = add nuw nsw i32 %.01317.us, 1
  %7 = getelementptr inbounds i8, ptr %.01416.us, i64 36
  %exitcond22.not = icmp eq i32 %6, 43
  br i1 %exitcond22.not, label %.split20.us, label %.split.us, !llvm.loop !5

.split:                                           ; preds = %3, %15
  %.018 = phi i32 [ %.1, %15 ], [ 0, %3 ]
  %.01317 = phi i32 [ %16, %15 ], [ 0, %3 ]
  %.01416 = phi ptr [ %17, %15 ], [ @g_hdr_fields, %3 ]
  %8 = tail call i32 @diff_field(ptr noundef nonnull %.01416, ptr noundef %0, ptr noundef %1, i32 noundef 1)
  %.not = icmp eq i32 %8, 0
  br i1 %.not, label %15, label %9

9:                                                ; preds = %.split
  %10 = icmp eq i32 %.018, 0
  %11 = zext i1 %10 to i32
  %12 = tail call i32 @disp_field(ptr noundef null, ptr noundef nonnull %.01416, ptr noundef %0, i32 noundef 1, i32 noundef %11)
  %13 = tail call i32 @disp_field(ptr noundef null, ptr noundef nonnull %.01416, ptr noundef %1, i32 noundef 1, i32 noundef 0)
  %14 = add nsw i32 %.018, 1
  br label %15

15:                                               ; preds = %.split, %9
  %.1 = phi i32 [ %14, %9 ], [ %.018, %.split ]
  %16 = add nuw nsw i32 %.01317, 1
  %17 = getelementptr inbounds i8, ptr %.01416, i64 36
  %exitcond.not = icmp eq i32 %16, 43
  br i1 %exitcond.not, label %.split20.us, label %.split, !llvm.loop !5

.split20.us:                                      ; preds = %15, %.split.us
  %.us-phi = phi i32 [ %spec.select, %.split.us ], [ %.1, %15 ]
  ret i32 %.us-phi
}

; 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 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


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