; LLVM IR from OpenFAST/openfast :: modules/map/src (maperror)

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

@MAP_ERROR_STRING = external dso_local constant [132 x [256 x i8]], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [21 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @set_universal_error(ptr noundef %0, ptr noundef %1, i32 noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  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 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  store ptr null, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = call ptr (ptr, ...) @bformat(ptr noundef @.str, ptr noundef %11)
  store ptr %12, ptr %10, align 8, !tbaa !5
  %13 = load i32, ptr %6, align 4, !tbaa !9
  %14 = icmp uge i32 %13, 117
  br i1 %14, label %15, label %31

15:                                               ; preds = %3
  %16 = load i32, ptr %6, align 4, !tbaa !9
  %17 = sub i32 %16, 117
  %18 = add i32 %17, 1
  store i32 %18, ptr %7, align 4, !tbaa !9
  %19 = load i32, ptr %7, align 4, !tbaa !9
  %20 = load i32, ptr %6, align 4, !tbaa !9
  %21 = zext i32 %20 to i64
  %22 = getelementptr inbounds [132 x [256 x i8]], ptr @MAP_ERROR_STRING, i64 0, i64 %21
  %23 = getelementptr inbounds [256 x i8], ptr %22, i64 0, i64 0
  %24 = call ptr (ptr, ...) @bformat(ptr noundef @.str.1, i32 noundef %19, ptr noundef %23)
  store ptr %24, ptr %9, align 8, !tbaa !5
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = load i32, ptr %25, align 4, !tbaa !9
  %27 = icmp ule i32 %26, 1
  br i1 %27, label %28, label %30

28:                                               ; preds = %15
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  store i32 1, ptr %29, align 4, !tbaa !9
  br label %30

30:                                               ; preds = %28, %15
  br label %60

31:                                               ; preds = %3
  %32 = load i32, ptr %6, align 4, !tbaa !9
  %33 = icmp uge i32 %32, 99
  br i1 %33, label %34, label %50

34:                                               ; preds = %31
  %35 = load i32, ptr %6, align 4, !tbaa !9
  %36 = sub i32 %35, 99
  %37 = add i32 %36, 1
  store i32 %37, ptr %7, align 4, !tbaa !9
  %38 = load i32, ptr %7, align 4, !tbaa !9
  %39 = load i32, ptr %6, align 4, !tbaa !9
  %40 = zext i32 %39 to i64
  %41 = getelementptr inbounds [132 x [256 x i8]], ptr @MAP_ERROR_STRING, i64 0, i64 %40
  %42 = getelementptr inbounds [256 x i8], ptr %41, i64 0, i64 0
  %43 = call ptr (ptr, ...) @bformat(ptr noundef @.str.2, i32 noundef %38, ptr noundef %42)
  store ptr %43, ptr %9, align 8, !tbaa !5
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = load i32, ptr %44, align 4, !tbaa !9
  %46 = icmp ule i32 %45, 2
  br i1 %46, label %47, label %49

47:                                               ; preds = %34
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  store i32 2, ptr %48, align 4, !tbaa !9
  br label %49

49:                                               ; preds = %47, %34
  br label %59

50:                                               ; preds = %31
  %51 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %51, ptr %7, align 4, !tbaa !9
  %52 = load i32, ptr %7, align 4, !tbaa !9
  %53 = load i32, ptr %6, align 4, !tbaa !9
  %54 = zext i32 %53 to i64
  %55 = getelementptr inbounds [132 x [256 x i8]], ptr @MAP_ERROR_STRING, i64 0, i64 %54
  %56 = getelementptr inbounds [256 x i8], ptr %55, i64 0, i64 0
  %57 = call ptr (ptr, ...) @bformat(ptr noundef @.str.3, i32 noundef %52, ptr noundef %56)
  store ptr %57, ptr %9, align 8, !tbaa !5
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  store i32 3, ptr %58, align 4, !tbaa !9
  br label %59

59:                                               ; preds = %50, %49
  br label %60

60:                                               ; preds = %59, %30
  %61 = load ptr, ptr %10, align 8, !tbaa !5
  %62 = load ptr, ptr %9, align 8, !tbaa !5
  %63 = call i32 @bconcat(ptr noundef %61, ptr noundef %62)
  store i32 %63, ptr %8, align 4, !tbaa !9
  %64 = load ptr, ptr %10, align 8, !tbaa !5
  %65 = call i32 @btrunc(ptr noundef %64, i32 noundef 1023)
  store i32 %65, ptr %8, align 4, !tbaa !9
  %66 = load ptr, ptr %4, align 8, !tbaa !5
  %67 = load ptr, ptr %10, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.tagbstring, ptr %67, i32 0, i32 2
  %69 = load ptr, ptr %68, align 8, !tbaa !11
  call void @copy_target_string(ptr noundef %66, ptr noundef %69)
  %70 = load ptr, ptr %9, align 8, !tbaa !5
  %71 = call i32 @bdestroy(ptr noundef %70)
  store i32 %71, ptr %8, align 4, !tbaa !9
  %72 = load ptr, ptr %10, align 8, !tbaa !5
  %73 = call i32 @bdestroy(ptr noundef %72)
  store i32 %73, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

declare ptr @bformat(ptr noundef, ...) #2

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

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

declare void @copy_target_string(ptr noundef, ptr noundef) #2

declare i32 @bdestroy(ptr noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 }

!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 = !{!"tagbstring", !10, i64 0, !10, i64 4, !6, 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"

@MAP_ERROR_STRING = external dso_local constant [132 x [256 x i8]], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [21 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @set_universal_error(ptr noundef %0, ptr nocapture noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = tail call ptr (ptr, ...) @bformat(ptr noundef nonnull @.str, ptr noundef %0) #2
  %5 = icmp ugt i32 %2, 116
  br i1 %5, label %6, label %13

6:                                                ; preds = %3
  %7 = add i32 %2, -116
  %8 = zext i32 %2 to i64
  %9 = getelementptr inbounds [132 x [256 x i8]], ptr @MAP_ERROR_STRING, i64 0, i64 %8
  %10 = tail call ptr (ptr, ...) @bformat(ptr noundef nonnull @.str.1, i32 noundef %7, ptr noundef nonnull %9) #2
  %11 = load i32, ptr %1, align 4, !tbaa !5
  %12 = icmp ult i32 %11, 2
  br i1 %12, label %.sink.split, label %26

13:                                               ; preds = %3
  %14 = icmp ugt i32 %2, 98
  br i1 %14, label %15, label %22

15:                                               ; preds = %13
  %16 = add nsw i32 %2, -98
  %17 = zext nneg i32 %2 to i64
  %18 = getelementptr inbounds [132 x [256 x i8]], ptr @MAP_ERROR_STRING, i64 0, i64 %17
  %19 = tail call ptr (ptr, ...) @bformat(ptr noundef nonnull @.str.2, i32 noundef %16, ptr noundef nonnull %18) #2
  %20 = load i32, ptr %1, align 4, !tbaa !5
  %21 = icmp ult i32 %20, 3
  br i1 %21, label %.sink.split, label %26

22:                                               ; preds = %13
  %23 = zext nneg i32 %2 to i64
  %24 = getelementptr inbounds [132 x [256 x i8]], ptr @MAP_ERROR_STRING, i64 0, i64 %23
  %25 = tail call ptr (ptr, ...) @bformat(ptr noundef nonnull @.str.3, i32 noundef %2, ptr noundef nonnull %24) #2
  br label %.sink.split

.sink.split:                                      ; preds = %15, %6, %22
  %.sink = phi i32 [ 3, %22 ], [ 1, %6 ], [ 2, %15 ]
  %.0.ph = phi ptr [ %25, %22 ], [ %10, %6 ], [ %19, %15 ]
  store i32 %.sink, ptr %1, align 4, !tbaa !5
  br label %26

26:                                               ; preds = %.sink.split, %15, %6
  %.0 = phi ptr [ %10, %6 ], [ %19, %15 ], [ %.0.ph, %.sink.split ]
  %27 = tail call i32 @bconcat(ptr noundef %4, ptr noundef %.0) #2
  %28 = tail call i32 @btrunc(ptr noundef %4, i32 noundef 1023) #2
  %29 = getelementptr inbounds i8, ptr %4, i64 8
  %30 = load ptr, ptr %29, align 8, !tbaa !9
  tail call void @copy_target_string(ptr noundef %0, ptr noundef %30) #2
  %31 = tail call i32 @bdestroy(ptr noundef %.0) #2
  %32 = tail call i32 @bdestroy(ptr noundef %4) #2
  ret void
}

declare ptr @bformat(ptr noundef, ...) local_unnamed_addr #1

declare i32 @bconcat(ptr noundef, ptr noundef) local_unnamed_addr #1

declare i32 @btrunc(ptr noundef, i32 noundef) local_unnamed_addr #1

declare void @copy_target_string(ptr noundef, ptr noundef) local_unnamed_addr #1

declare i32 @bdestroy(ptr noundef) local_unnamed_addr #1

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" }
attributes #1 = { "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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 8}
!10 = !{!"tagbstring", !6, i64 0, !6, i64 4, !11, i64 8}
!11 = !{!"any pointer", !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass