; LLVM IR from NOAA-PMEL/Ferret :: fer/ccr (binaryRead)

; 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.anon = type { i32, [256 x i8] }
%struct._FileInfo = type { %struct._MemInfo, ptr, i32, i32, ptr, i32, i32, [7 x i32], [7 x i32], [7 x i32], i32, i32, i32, i32 }
%struct._MemInfo = type { ptr, i32, i32, i32, i32 }

@FFileInfo = external hidden global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [71 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [15 x i8], align 1
@__PRETTY_FUNCTION__.br_add_var_ = external hidden unnamed_addr constant [32 x i8], align 1
@Types = external hidden global %struct.anon, align 4
@.str.3 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [58 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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

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

10:                                               ; preds = %2
  br label %12

11:                                               ; preds = %2
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 406, ptr noundef @__PRETTY_FUNCTION__.br_add_var_) #4
  unreachable

12:                                               ; preds = %10
  %13 = load i32, ptr @Types, align 4, !tbaa !9
  %14 = icmp sgt i32 %13, 0
  br i1 %14, label %15, label %16

15:                                               ; preds = %12
  br label %17

16:                                               ; preds = %12
  call void @__assert_fail(ptr noundef @.str.3, ptr noundef @.str.1, i32 noundef 407, ptr noundef @__PRETTY_FUNCTION__.br_add_var_) #4
  unreachable

17:                                               ; preds = %15
  %18 = load i32, ptr @Types, align 4, !tbaa !9
  %19 = icmp ne i32 %18, 1
  br i1 %19, label %20, label %27

20:                                               ; preds = %17
  %21 = load ptr, ptr @FFileInfo, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct._FileInfo, ptr %21, i32 0, i32 5
  %23 = load i32, ptr %22, align 8, !tbaa !12
  %24 = load i32, ptr @Types, align 4, !tbaa !9
  %25 = icmp sge i32 %23, %24
  br i1 %25, label %26, label %27

26:                                               ; preds = %20
  call void @setError(ptr noundef @.str.4, ptr noundef @.str.5)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %47

27:                                               ; preds = %20, %17
  %28 = load i32, ptr @Types, align 4, !tbaa !9
  %29 = icmp eq i32 %28, 1
  br i1 %29, label %30, label %32

30:                                               ; preds = %27
  %31 = load i8, ptr getelementptr inbounds (%struct.anon, ptr @Types, i32 0, i32 1), align 4, !tbaa !15
  store i8 %31, ptr %6, align 1, !tbaa !15
  br label %39

32:                                               ; preds = %27
  %33 = load ptr, ptr @FFileInfo, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct._FileInfo, ptr %33, i32 0, i32 5
  %35 = load i32, ptr %34, align 8, !tbaa !12
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [256 x i8], ptr getelementptr inbounds (%struct.anon, ptr @Types, i32 0, i32 1), i64 0, i64 %36
  %38 = load i8, ptr %37, align 1, !tbaa !15
  store i8 %38, ptr %6, align 1, !tbaa !15
  br label %39

39:                                               ; preds = %32, %30
  %40 = load ptr, ptr @FFileInfo, align 8, !tbaa !5
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = load i8, ptr %6, align 1, !tbaa !15
  %43 = sext i8 %42 to i32
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = load i32, ptr %44, align 4, !tbaa !16
  %46 = call i32 @addVar(ptr noundef %40, ptr noundef %41, i32 noundef %43, i32 noundef %45)
  store i32 %46, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %47

47:                                               ; preds = %39, %26
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #3
  %48 = load i32, ptr %3, align 4
  ret i32 %48
}

; Function Attrs: nounwind uwtable
declare hidden void @setError(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden i32 @addVar(ptr noundef, ptr noundef, i32 noundef, i32 noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { noreturn 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 }
attributes #4 = { noreturn 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 0}
!10 = !{!"", !11, i64 0, !7, i64 4}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !11, i64 48}
!13 = !{!"_FileInfo", !14, i64 0, !6, i64 24, !11, i64 32, !11, i64 36, !6, i64 40, !11, i64 48, !11, i64 52, !7, i64 56, !7, i64 84, !7, i64 112, !11, i64 140, !11, i64 144, !11, i64 148, !11, i64 152}
!14 = !{!"_MemInfo", !6, i64 0, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20}
!15 = !{!7, !7, i64 0}
!16 = !{!11, !11, i64 0}


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

@FFileInfo = external hidden local_unnamed_addr global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [71 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [15 x i8], align 1
@__PRETTY_FUNCTION__.br_add_var_ = external hidden unnamed_addr constant [32 x i8], align 1
@Types = external hidden local_unnamed_addr global %struct.anon, align 4
@.str.3 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [58 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @br_add_var_(ptr noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #1 {
  %3 = load ptr, ptr @FFileInfo, align 8, !tbaa !5
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %4, label %5

4:                                                ; preds = %2
  tail call void @__assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 406, ptr noundef nonnull @__PRETTY_FUNCTION__.br_add_var_) #2
  unreachable

5:                                                ; preds = %2
  %6 = load i32, ptr @Types, align 4, !tbaa !9
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %9, label %8

8:                                                ; preds = %5
  tail call void @__assert_fail(ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.1, i32 noundef 407, ptr noundef nonnull @__PRETTY_FUNCTION__.br_add_var_) #2
  unreachable

9:                                                ; preds = %5
  %.not6 = icmp eq i32 %6, 1
  br i1 %.not6, label %.thread, label %10

10:                                               ; preds = %9
  %11 = getelementptr inbounds i8, ptr %3, i64 48
  %12 = load i32, ptr %11, align 8, !tbaa !12
  %.not7 = icmp slt i32 %12, %6
  br i1 %.not7, label %14, label %13

13:                                               ; preds = %10
  tail call void @setError(ptr noundef nonnull @.str.4, ptr noundef nonnull @.str.5)
  br label %20

14:                                               ; preds = %10
  %15 = sext i32 %12 to i64
  %16 = getelementptr inbounds [256 x i8], ptr getelementptr inbounds (i8, ptr @Types, i64 4), i64 0, i64 %15
  br label %.thread

.thread:                                          ; preds = %9, %14
  %.0.in = phi ptr [ %16, %14 ], [ getelementptr inbounds (i8, ptr @Types, i64 4), %9 ]
  %.0 = load i8, ptr %.0.in, align 1, !tbaa !15
  %17 = sext i8 %.0 to i32
  %18 = load i32, ptr %1, align 4, !tbaa !16
  %19 = tail call i32 @addVar(ptr noundef nonnull %3, ptr noundef %0, i32 noundef %17, i32 noundef %18)
  br label %20

20:                                               ; preds = %.thread, %13
  %.03 = phi i32 [ 0, %13 ], [ %19, %.thread ]
  ret i32 %.03
}

; Function Attrs: nounwind uwtable
declare hidden void @setError(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden i32 @addVar(ptr noundef, ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

attributes #0 = { noreturn 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 = { 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 = { noreturn 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 0}
!10 = !{!"", !11, i64 0, !7, i64 4}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !11, i64 48}
!13 = !{!"_FileInfo", !14, i64 0, !6, i64 24, !11, i64 32, !11, i64 36, !6, i64 40, !11, i64 48, !11, i64 52, !7, i64 56, !7, i64 84, !7, i64 112, !11, i64 140, !11, i64 144, !11, i64 148, !11, i64 152}
!14 = !{!"_MemInfo", !6, i64 0, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20}
!15 = !{!7, !7, i64 0}
!16 = !{!11, !11, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass