; 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] }

@stderr = external global ptr, align 8
@g_debug = external hidden global i32, align 4
@.str.433 = external hidden unnamed_addr constant [57 x i8], align 1
@.str.434 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.435 = external hidden unnamed_addr constant [50 x i8], align 1
@.str.436 = external hidden unnamed_addr constant [10 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

declare i32 @fputs(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @check_total_size(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3) #3 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  store i32 0, ptr %12, align 4, !tbaa !9
  store i32 0, ptr %13, align 4, !tbaa !9
  store i32 0, ptr %11, align 4, !tbaa !9
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %15, ptr %10, align 8, !tbaa !5
  br label %16

16:                                               ; preds = %52, %4
  %17 = load i32, ptr %11, align 4, !tbaa !9
  %18 = load i32, ptr %8, align 4, !tbaa !9
  %19 = icmp slt i32 %17, %18
  br i1 %19, label %20, label %57

20:                                               ; preds = %16
  %21 = load ptr, ptr %10, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.field_s, ptr %21, i32 0, i32 1
  %23 = load i32, ptr %22, align 4, !tbaa !11
  %24 = load i32, ptr %12, align 4, !tbaa !9
  %25 = icmp ne i32 %23, %24
  br i1 %25, label %26, label %42

26:                                               ; preds = %20
  %27 = load i32, ptr @g_debug, align 4, !tbaa !9
  %28 = icmp sgt i32 %27, 2
  br i1 %28, label %29, label %39

29:                                               ; preds = %26
  %30 = load ptr, ptr @stderr, align 8, !tbaa !5
  %31 = load ptr, ptr %10, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.field_s, ptr %31, i32 0, i32 4
  %33 = getelementptr inbounds [20 x i8], ptr %32, i64 0, i64 0
  %34 = load ptr, ptr %10, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.field_s, ptr %34, i32 0, i32 1
  %36 = load i32, ptr %35, align 4, !tbaa !11
  %37 = load i32, ptr %12, align 4, !tbaa !9
  %38 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %30, ptr noundef @.str.433, ptr noundef %33, i32 noundef %36, i32 noundef %37) #4
  br label %39

39:                                               ; preds = %29, %26
  %40 = load i32, ptr %13, align 4, !tbaa !9
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr %13, align 4, !tbaa !9
  br label %42

42:                                               ; preds = %39, %20
  %43 = load ptr, ptr %10, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.field_s, ptr %43, i32 0, i32 2
  %45 = load i32, ptr %44, align 4, !tbaa !13
  %46 = load ptr, ptr %10, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.field_s, ptr %46, i32 0, i32 3
  %48 = load i32, ptr %47, align 4, !tbaa !14
  %49 = mul nsw i32 %45, %48
  %50 = load i32, ptr %12, align 4, !tbaa !9
  %51 = add nsw i32 %50, %49
  store i32 %51, ptr %12, align 4, !tbaa !9
  br label %52

52:                                               ; preds = %42
  %53 = load i32, ptr %11, align 4, !tbaa !9
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr %11, align 4, !tbaa !9
  %55 = load ptr, ptr %10, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.field_s, ptr %55, i32 1
  store ptr %56, ptr %10, align 8, !tbaa !5
  br label %16, !llvm.loop !15

57:                                               ; preds = %16
  %58 = load i32, ptr @g_debug, align 4, !tbaa !9
  %59 = icmp sgt i32 %58, 1
  br i1 %59, label %66, label %60

60:                                               ; preds = %57
  %61 = load i32, ptr @g_debug, align 4, !tbaa !9
  %62 = icmp sgt i32 %61, 0
  br i1 %62, label %63, label %96

63:                                               ; preds = %60
  %64 = load i32, ptr %13, align 4, !tbaa !9
  %65 = icmp sgt i32 %64, 0
  br i1 %65, label %66, label %96

66:                                               ; preds = %63, %57
  %67 = load ptr, ptr %6, align 8, !tbaa !5
  %68 = load ptr, ptr @stderr, align 8, !tbaa !5
  %69 = call i32 @fputs(ptr noundef %67, ptr noundef %68)
  store i32 0, ptr %11, align 4, !tbaa !9
  %70 = load i32, ptr %13, align 4, !tbaa !9
  %71 = icmp sgt i32 %70, 0
  br i1 %71, label %72, label %78

72:                                               ; preds = %66
  %73 = load ptr, ptr @stderr, align 8, !tbaa !5
  %74 = load i32, ptr %13, align 4, !tbaa !9
  %75 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %73, ptr noundef @.str.434, i32 noundef %74) #4
  %76 = load i32, ptr %11, align 4, !tbaa !9
  %77 = add nsw i32 %76, 1
  store i32 %77, ptr %11, align 4, !tbaa !9
  br label %78

78:                                               ; preds = %72, %66
  %79 = load i32, ptr %12, align 4, !tbaa !9
  %80 = load i32, ptr %9, align 4, !tbaa !9
  %81 = icmp ne i32 %79, %80
  br i1 %81, label %82, label %89

82:                                               ; preds = %78
  %83 = load ptr, ptr @stderr, align 8, !tbaa !5
  %84 = load i32, ptr %12, align 4, !tbaa !9
  %85 = load i32, ptr %9, align 4, !tbaa !9
  %86 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %83, ptr noundef @.str.435, i32 noundef %84, i32 noundef %85) #4
  %87 = load i32, ptr %11, align 4, !tbaa !9
  %88 = add nsw i32 %87, 1
  store i32 %88, ptr %11, align 4, !tbaa !9
  br label %89

89:                                               ; preds = %82, %78
  %90 = load i32, ptr %11, align 4, !tbaa !9
  %91 = icmp eq i32 %90, 0
  br i1 %91, label %92, label %95

92:                                               ; preds = %89
  %93 = load ptr, ptr @stderr, align 8, !tbaa !5
  %94 = call i32 @fputs(ptr noundef @.str.436, ptr noundef %93)
  br label %95

95:                                               ; preds = %92, %89
  br label %96

96:                                               ; preds = %95, %63, %60
  %97 = load i32, ptr %13, align 4, !tbaa !9
  %98 = icmp sgt i32 %97, 0
  br i1 %98, label %99, label %100

99:                                               ; preds = %96
  store i32 1, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %101

100:                                              ; preds = %96
  store i32 0, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %101

101:                                              ; preds = %100, %99
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  %102 = load i32, ptr %5, align 4
  ret i32 %102
}

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 = { "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 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 #4 = { 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, !10, i64 4}
!12 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !7, i64 16}
!13 = !{!12, !10, i64 8}
!14 = !{!12, !10, i64 12}
!15 = distinct !{!15, !16}
!16 = !{!"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"

@stderr = external local_unnamed_addr global ptr, align 8
@g_debug = external hidden local_unnamed_addr global i32, align 4
@.str.433 = external hidden unnamed_addr constant [57 x i8], align 1
@.str.434 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.435 = external hidden unnamed_addr constant [50 x i8], align 1
@.str.436 = external hidden unnamed_addr constant [10 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: nofree nounwind
declare noundef i32 @fputs(ptr nocapture noundef readonly, ptr nocapture noundef) local_unnamed_addr #0

; Function Attrs: nofree nounwind uwtable
define dso_local range(i32 0, 2) i32 @check_total_size(ptr nocapture noundef readonly %0, ptr noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #1 {
  %5 = icmp sgt i32 %2, 0
  br i1 %5, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %4, %17
  %.042 = phi i32 [ %.1, %17 ], [ 0, %4 ]
  %.02740 = phi i32 [ %23, %17 ], [ 0, %4 ]
  %.02839 = phi i32 [ %24, %17 ], [ 0, %4 ]
  %.03038 = phi ptr [ %25, %17 ], [ %1, %4 ]
  %6 = getelementptr inbounds i8, ptr %.03038, i64 4
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %.not35 = icmp eq i32 %7, %.02740
  br i1 %.not35, label %17, label %8

8:                                                ; preds = %.lr.ph
  %9 = load i32, ptr @g_debug, align 4, !tbaa !10
  %10 = icmp sgt i32 %9, 2
  br i1 %10, label %11, label %15

11:                                               ; preds = %8
  %12 = load ptr, ptr @stderr, align 8, !tbaa !11
  %13 = getelementptr inbounds i8, ptr %.03038, i64 16
  %14 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %12, ptr noundef nonnull @.str.433, ptr noundef nonnull %13, i32 noundef %7, i32 noundef %.02740) #2
  br label %15

15:                                               ; preds = %11, %8
  %16 = add nsw i32 %.042, 1
  br label %17

17:                                               ; preds = %15, %.lr.ph
  %.1 = phi i32 [ %16, %15 ], [ %.042, %.lr.ph ]
  %18 = getelementptr inbounds i8, ptr %.03038, i64 8
  %19 = load i32, ptr %18, align 4, !tbaa !13
  %20 = getelementptr inbounds i8, ptr %.03038, i64 12
  %21 = load i32, ptr %20, align 4, !tbaa !14
  %22 = mul nsw i32 %21, %19
  %23 = add nsw i32 %22, %.02740
  %24 = add nuw nsw i32 %.02839, 1
  %25 = getelementptr inbounds i8, ptr %.03038, i64 36
  %exitcond.not = icmp eq i32 %24, %2
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !15

._crit_edge:                                      ; preds = %17, %4
  %.027.lcssa = phi i32 [ 0, %4 ], [ %23, %17 ]
  %.0.lcssa = phi i32 [ 0, %4 ], [ %.1, %17 ]
  %26 = load i32, ptr @g_debug, align 4, !tbaa !10
  %27 = icmp sgt i32 %26, 1
  br i1 %27, label %33, label %28

28:                                               ; preds = %._crit_edge
  %29 = icmp eq i32 %26, 1
  %30 = icmp sgt i32 %.0.lcssa, 0
  %or.cond = select i1 %29, i1 %30, i1 false
  br i1 %or.cond, label %.thread, label %.thread46

.thread:                                          ; preds = %28
  %31 = load ptr, ptr @stderr, align 8, !tbaa !11
  %32 = tail call i32 @fputs(ptr noundef %0, ptr noundef %31) #3
  br label %.thread44

33:                                               ; preds = %._crit_edge
  %34 = load ptr, ptr @stderr, align 8, !tbaa !11
  %35 = tail call i32 @fputs(ptr noundef %0, ptr noundef %34) #3
  %36 = icmp sgt i32 %.0.lcssa, 0
  br i1 %36, label %.thread44, label %37

37:                                               ; preds = %33
  %.not = icmp eq i32 %.027.lcssa, %3
  br i1 %.not, label %42, label %.thread36

.thread44:                                        ; preds = %33, %.thread
  %38 = load ptr, ptr @stderr, align 8, !tbaa !11
  %39 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %38, ptr noundef nonnull @.str.434, i32 noundef %.0.lcssa) #2
  %.not45 = icmp eq i32 %.027.lcssa, %3
  br i1 %.not45, label %.thread46, label %.thread36

.thread36:                                        ; preds = %.thread44, %37
  %40 = load ptr, ptr @stderr, align 8, !tbaa !11
  %41 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %40, ptr noundef nonnull @.str.435, i32 noundef %.027.lcssa, i32 noundef %3) #2
  br label %.thread46

42:                                               ; preds = %37
  %43 = load ptr, ptr @stderr, align 8, !tbaa !11
  %44 = tail call i32 @fputs(ptr noundef nonnull @.str.436, ptr noundef %43) #3
  br label %.thread46

.thread46:                                        ; preds = %.thread44, %.thread36, %42, %28
  %45 = icmp sgt i32 %.0.lcssa, 0
  %. = zext i1 %45 to i32
  ret i32 %.
}

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" }
attributes #2 = { cold nounwind }
attributes #3 = { cold }

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


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