; LLVM IR from Montimage/mmt-security :: src/lib (expression)

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

@.str.5 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [9 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: inlinehint nounwind uwtable
declare hidden ptr @mmt_mem_dup(ptr noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i64 @expr_stringify_constant(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca [10000 x i8], align 16
  %7 = alloca i32, align 4
  %8 = alloca double, align 8
  %9 = 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 10000, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = icmp eq ptr %10, null
  br i1 %11, label %12, label %13

12:                                               ; preds = %2
  store ptr null, ptr %4, align 8, !tbaa !5
  store i64 0, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %79

13:                                               ; preds = %2
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.constant_t, ptr %14, i32 0, i32 0
  %16 = load i32, ptr %15, align 8, !tbaa !9
  %17 = icmp eq i32 %16, 0
  br i1 %17, label %18, label %56

18:                                               ; preds = %13
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.constant_t, ptr %19, i32 0, i32 2
  %21 = load ptr, ptr %20, align 8, !tbaa !13
  %22 = load double, ptr %21, align 8, !tbaa !14
  store double %22, ptr %8, align 8, !tbaa !14
  %23 = getelementptr inbounds [10000 x i8], ptr %6, i64 0, i64 0
  %24 = load double, ptr %8, align 8, !tbaa !14
  %25 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef %23, i64 noundef 10000, ptr noundef @.str.5, double noundef %24) #4
  store i32 %25, ptr %7, align 4, !tbaa !16
  %26 = load i32, ptr %7, align 4, !tbaa !16
  %27 = add nsw i32 %26, -1
  store i32 %27, ptr %7, align 4, !tbaa !16
  br label %28

28:                                               ; preds = %41, %18
  %29 = load i32, ptr %7, align 4, !tbaa !16
  %30 = icmp sgt i32 %29, 1
  br i1 %30, label %31, label %39

31:                                               ; preds = %28
  %32 = load i32, ptr %7, align 4, !tbaa !16
  %33 = sub nsw i32 %32, 1
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [10000 x i8], ptr %6, i64 0, i64 %34
  %36 = load i8, ptr %35, align 1, !tbaa !17
  %37 = sext i8 %36 to i32
  %38 = icmp eq i32 %37, 48
  br label %39

39:                                               ; preds = %31, %28
  %40 = phi i1 [ false, %28 ], [ %38, %31 ]
  br i1 %40, label %41, label %44

41:                                               ; preds = %39
  %42 = load i32, ptr %7, align 4, !tbaa !16
  %43 = add nsw i32 %42, -1
  store i32 %43, ptr %7, align 4, !tbaa !16
  br label %28, !llvm.loop !18

44:                                               ; preds = %39
  %45 = load i32, ptr %7, align 4, !tbaa !16
  %46 = sub nsw i32 %45, 1
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [10000 x i8], ptr %6, i64 0, i64 %47
  %49 = load i8, ptr %48, align 1, !tbaa !17
  %50 = sext i8 %49 to i32
  %51 = icmp eq i32 %50, 46
  br i1 %51, label %52, label %55

52:                                               ; preds = %44
  %53 = load i32, ptr %7, align 4, !tbaa !16
  %54 = add nsw i32 %53, -1
  store i32 %54, ptr %7, align 4, !tbaa !16
  br label %55

55:                                               ; preds = %52, %44
  br label %71

56:                                               ; preds = %13
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.constant_t, ptr %57, i32 0, i32 0
  %59 = load i32, ptr %58, align 8, !tbaa !9
  %60 = icmp eq i32 %59, 1
  br i1 %60, label %61, label %67

61:                                               ; preds = %56
  %62 = getelementptr inbounds [10000 x i8], ptr %6, i64 0, i64 0
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.constant_t, ptr %63, i32 0, i32 2
  %65 = load ptr, ptr %64, align 8, !tbaa !13
  %66 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef %62, i64 noundef 10000, ptr noundef @.str.6, ptr noundef %65) #4
  store i32 %66, ptr %7, align 4, !tbaa !16
  br label %70

67:                                               ; preds = %56
  %68 = getelementptr inbounds [10000 x i8], ptr %6, i64 0, i64 0
  %69 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef %68, i64 noundef 10000, ptr noundef @.str.7) #4
  store i32 %69, ptr %7, align 4, !tbaa !16
  br label %70

70:                                               ; preds = %67, %61
  br label %71

71:                                               ; preds = %70, %55
  %72 = getelementptr inbounds [10000 x i8], ptr %6, i64 0, i64 0
  %73 = load i32, ptr %7, align 4, !tbaa !16
  %74 = sext i32 %73 to i64
  %75 = call ptr @mmt_mem_dup(ptr noundef %72, i64 noundef %74)
  %76 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %75, ptr %76, align 8, !tbaa !5
  %77 = load i32, ptr %7, align 4, !tbaa !16
  %78 = sext i32 %77 to i64
  store i64 %78, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %79

79:                                               ; preds = %71, %12
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 10000, ptr %6) #4
  %80 = load i64, ptr %3, align 8
  ret i64 %80
}

; Function Attrs: nounwind
declare i32 @snprintf(ptr noundef, i64 noundef, ptr noundef, ...) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 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 "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, !11, i64 0}
!10 = !{!"", !11, i64 0, !12, i64 8, !6, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!10, !6, i64 16}
!14 = !{!15, !15, i64 0}
!15 = !{!"double", !7, i64 0}
!16 = !{!11, !11, i64 0}
!17 = !{!7, !7, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"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"

@.str.5 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [9 x i8], align 1

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

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @mmt_mem_dup(ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local range(i64 -2147483648, 2147483648) i64 @expr_stringify_constant(ptr nocapture noundef writeonly %0, ptr noundef readonly %1) local_unnamed_addr #2 {
  %3 = alloca [10000 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 10000, ptr nonnull %3) #5
  %4 = icmp eq ptr %1, null
  br i1 %4, label %36, label %5

5:                                                ; preds = %2
  %6 = load i32, ptr %1, align 8, !tbaa !5
  switch i32 %6, label %31 [
    i32 0, label %7
    i32 1, label %27
  ]

7:                                                ; preds = %5
  %8 = getelementptr inbounds i8, ptr %1, i64 16
  %9 = load ptr, ptr %8, align 8, !tbaa !12
  %10 = load double, ptr %9, align 8, !tbaa !13
  %11 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef nonnull dereferenceable(1) %3, i64 noundef 10000, ptr noundef nonnull @.str.5, double noundef %10) #5
  %12 = zext i32 %11 to i64
  %smin = tail call i32 @llvm.smin.i32(i32 %11, i32 2)
  %13 = add i32 %smin, -1
  br label %14

14:                                               ; preds = %17, %7
  %indvars.iv = phi i64 [ %indvars.iv.next, %17 ], [ %12, %7 ]
  %15 = trunc nuw i64 %indvars.iv to i32
  %16 = icmp sgt i32 %15, 2
  br i1 %16, label %17, label %.critedge

17:                                               ; preds = %14
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %18 = add nsw i64 %indvars.iv, -2
  %19 = getelementptr inbounds [10000 x i8], ptr %3, i64 0, i64 %18
  %20 = load i8, ptr %19, align 1, !tbaa !15
  %21 = icmp eq i8 %20, 48
  br i1 %21, label %14, label %.critedge.split.loop.exit19, !llvm.loop !16

.critedge.split.loop.exit19:                      ; preds = %17
  %indvars.le = trunc i64 %indvars.iv.next to i32
  br label %.critedge

.critedge:                                        ; preds = %14, %.critedge.split.loop.exit19
  %.015.in.lcssa = phi i32 [ %15, %.critedge.split.loop.exit19 ], [ %smin, %14 ]
  %.015.lcssa = phi i32 [ %indvars.le, %.critedge.split.loop.exit19 ], [ %13, %14 ]
  %22 = add nsw i32 %.015.in.lcssa, -2
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [10000 x i8], ptr %3, i64 0, i64 %23
  %25 = load i8, ptr %24, align 1, !tbaa !15
  %26 = icmp eq i8 %25, 46
  %spec.select = select i1 %26, i32 %22, i32 %.015.lcssa
  br label %33

27:                                               ; preds = %5
  %28 = getelementptr inbounds i8, ptr %1, i64 16
  %29 = load ptr, ptr %28, align 8, !tbaa !12
  %30 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef nonnull dereferenceable(1) %3, i64 noundef 10000, ptr noundef nonnull @.str.6, ptr noundef %29) #5
  br label %33

31:                                               ; preds = %5
  %32 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef nonnull dereferenceable(1) %3, i64 noundef 10000, ptr noundef nonnull @.str.7) #5
  br label %33

33:                                               ; preds = %.critedge, %27, %31
  %.1 = phi i32 [ %30, %27 ], [ %32, %31 ], [ %spec.select, %.critedge ]
  %34 = sext i32 %.1 to i64
  %35 = call ptr @mmt_mem_dup(ptr noundef nonnull %3, i64 noundef %34)
  store ptr %35, ptr %0, align 8, !tbaa !18
  br label %36

36:                                               ; preds = %2, %33
  %.0 = phi i64 [ %34, %33 ], [ 0, %2 ]
  call void @llvm.lifetime.end.p0(i64 10000, ptr nonnull %3) #5
  ret i64 %.0
}

; Function Attrs: nofree nounwind
declare noundef i32 @snprintf(ptr noalias nocapture noundef writeonly, i64 noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.i32(i32, i32) #4

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 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 = { 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 #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { 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, !7, i64 0}
!6 = !{!"", !7, i64 0, !10, i64 8, !11, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!6, !11, i64 16}
!13 = !{!14, !14, i64 0}
!14 = !{!"double", !8, i64 0}
!15 = !{!8, !8, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!11, !11, i64 0}


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