; LLVM IR from aagdev/mlimgsynth :: src (demo_mlimgsynth)

; 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.MLIS_Tensor = type { ptr, [4 x i32], i32 }

@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [13 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @img_save(ptr noundef, ptr noundef) #0

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

declare i32 @printf(ptr noundef, ...) #2

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

declare i32 @mlis_option_set(ptr noundef, i32 noundef, ...) #2

declare i32 @mlis_generate(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @demo_inpaint(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  br label %16

16:                                               ; preds = %1
  %17 = call i32 (ptr, ...) @printf(ptr noundef @.str.12)
  %18 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  br label %19

19:                                               ; preds = %16
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  %21 = call i32 (ptr, i32, ...) @mlis_option_set(ptr noundef %20, i32 noundef 7, ptr noundef @.str.13)
  %22 = load ptr, ptr %2, align 8, !tbaa !5
  %23 = call i32 (ptr, i32, ...) @mlis_option_set(ptr noundef %22, i32 noundef 22, i32 noundef 1)
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  %25 = call i32 @mlis_generate(ptr noundef %24)
  %26 = load ptr, ptr %2, align 8, !tbaa !5
  %27 = call i32 (ptr, i32, ...) @mlis_option_set(ptr noundef %26, i32 noundef 22, i32 noundef 0)
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %28 = load ptr, ptr %2, align 8, !tbaa !5
  %29 = call ptr @mlis_tensor_get(ptr noundef %28, i32 noundef 3)
  store ptr %29, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %30 = load ptr, ptr %2, align 8, !tbaa !5
  %31 = call ptr @mlis_tensor_get(ptr noundef %30, i32 noundef 4)
  store ptr %31, ptr %4, align 8, !tbaa !5
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  call void @mlis_tensor_resize_like(ptr noundef %32, ptr noundef %33)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.MLIS_Tensor, ptr %34, i32 0, i32 1
  %36 = getelementptr inbounds [4 x i32], ptr %35, i64 0, i64 0
  %37 = load i32, ptr %36, align 8, !tbaa !9
  %38 = sdiv i32 %37, 2
  store i32 %38, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.MLIS_Tensor, ptr %39, i32 0, i32 1
  %41 = getelementptr inbounds [4 x i32], ptr %40, i64 0, i64 1
  %42 = load i32, ptr %41, align 4, !tbaa !9
  %43 = sdiv i32 %42, 2
  store i32 %43, 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 4, ptr %9) #3
  store i32 0, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 0, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store i32 0, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.MLIS_Tensor, ptr %44, i32 0, i32 1
  %46 = getelementptr inbounds [4 x i32], ptr %45, i64 0, i64 0
  %47 = load i32, ptr %46, align 8, !tbaa !9
  store i32 %47, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.MLIS_Tensor, ptr %48, i32 0, i32 1
  %50 = getelementptr inbounds [4 x i32], ptr %49, i64 0, i64 1
  %51 = load i32, ptr %50, align 4, !tbaa !9
  store i32 %51, ptr %13, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.MLIS_Tensor, ptr %52, i32 0, i32 1
  %54 = getelementptr inbounds [4 x i32], ptr %53, i64 0, i64 2
  %55 = load i32, ptr %54, align 8, !tbaa !9
  store i32 %55, ptr %14, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.MLIS_Tensor, ptr %56, i32 0, i32 1
  %58 = getelementptr inbounds [4 x i32], ptr %57, i64 0, i64 3
  %59 = load i32, ptr %58, align 4, !tbaa !9
  store i32 %59, ptr %15, align 4, !tbaa !9
  br label %60

60:                                               ; preds = %113, %19
  %61 = load i32, ptr %8, align 4, !tbaa !9
  %62 = load i32, ptr %12, align 4, !tbaa !9
  %63 = icmp slt i32 %61, %62
  br i1 %63, label %82, label %64

64:                                               ; preds = %60
  store i32 0, ptr %8, align 4, !tbaa !9
  %65 = load i32, ptr %9, align 4, !tbaa !9
  %66 = add nsw i32 %65, 1
  store i32 %66, ptr %9, align 4, !tbaa !9
  %67 = load i32, ptr %9, align 4, !tbaa !9
  %68 = load i32, ptr %13, align 4, !tbaa !9
  %69 = icmp slt i32 %67, %68
  br i1 %69, label %82, label %70

70:                                               ; preds = %64
  store i32 0, ptr %9, align 4, !tbaa !9
  %71 = load i32, ptr %10, align 4, !tbaa !9
  %72 = add nsw i32 %71, 1
  store i32 %72, ptr %10, align 4, !tbaa !9
  %73 = load i32, ptr %10, align 4, !tbaa !9
  %74 = load i32, ptr %14, align 4, !tbaa !9
  %75 = icmp slt i32 %73, %74
  br i1 %75, label %82, label %76

76:                                               ; preds = %70
  store i32 0, ptr %10, align 4, !tbaa !9
  %77 = load i32, ptr %11, align 4, !tbaa !9
  %78 = add nsw i32 %77, 1
  store i32 %78, ptr %11, align 4, !tbaa !9
  %79 = load i32, ptr %11, align 4, !tbaa !9
  %80 = load i32, ptr %15, align 4, !tbaa !9
  %81 = icmp slt i32 %79, %80
  br label %82

82:                                               ; preds = %76, %70, %64, %60
  %83 = phi i1 [ true, %70 ], [ true, %64 ], [ true, %60 ], [ %81, %76 ]
  br i1 %83, label %85, label %84

84:                                               ; preds = %82
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, 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
  br label %118

85:                                               ; preds = %82
  %86 = load i32, ptr %8, align 4, !tbaa !9
  %87 = load i32, ptr %5, align 4, !tbaa !9
  %88 = sub nsw i32 %86, %87
  %89 = load i32, ptr %8, align 4, !tbaa !9
  %90 = load i32, ptr %5, align 4, !tbaa !9
  %91 = sub nsw i32 %89, %90
  %92 = mul nsw i32 %88, %91
  %93 = load i32, ptr %9, align 4, !tbaa !9
  %94 = load i32, ptr %6, align 4, !tbaa !9
  %95 = sub nsw i32 %93, %94
  %96 = load i32, ptr %9, align 4, !tbaa !9
  %97 = load i32, ptr %6, align 4, !tbaa !9
  %98 = sub nsw i32 %96, %97
  %99 = mul nsw i32 %95, %98
  %100 = add nsw i32 %92, %99
  %101 = load i32, ptr %6, align 4, !tbaa !9
  %102 = load i32, ptr %6, align 4, !tbaa !9
  %103 = mul nsw i32 %101, %102
  %104 = icmp sgt i32 %100, %103
  %105 = zext i1 %104 to i32
  %106 = sitofp i32 %105 to float
  %107 = load ptr, ptr %4, align 8, !tbaa !5
  %108 = getelementptr inbounds %struct.MLIS_Tensor, ptr %107, i32 0, i32 0
  %109 = load ptr, ptr %108, align 8, !tbaa !11
  %110 = load i32, ptr %7, align 4, !tbaa !9
  %111 = sext i32 %110 to i64
  %112 = getelementptr inbounds float, ptr %109, i64 %111
  store float %106, ptr %112, align 4, !tbaa !13
  br label %113

113:                                              ; preds = %85
  %114 = load i32, ptr %8, align 4, !tbaa !9
  %115 = add nsw i32 %114, 1
  store i32 %115, ptr %8, align 4, !tbaa !9
  %116 = load i32, ptr %7, align 4, !tbaa !9
  %117 = add nsw i32 %116, 1
  store i32 %117, ptr %7, align 4, !tbaa !9
  br label %60, !llvm.loop !15

118:                                              ; preds = %84
  %119 = load ptr, ptr %2, align 8, !tbaa !5
  %120 = call i32 (ptr, i32, ...) @mlis_option_set(ptr noundef %119, i32 noundef 7, ptr noundef @.str.14)
  %121 = load ptr, ptr %2, align 8, !tbaa !5
  %122 = call i32 (ptr, i32, ...) @mlis_option_set(ptr noundef %121, i32 noundef 16, double noundef 0x3FE6666666666666)
  %123 = load ptr, ptr %2, align 8, !tbaa !5
  %124 = call i32 (ptr, i32, ...) @mlis_option_set(ptr noundef %123, i32 noundef 23, i32 noundef 12)
  %125 = load ptr, ptr %2, align 8, !tbaa !5
  %126 = call i32 @mlis_generate(ptr noundef %125)
  %127 = load ptr, ptr %2, align 8, !tbaa !5
  call void @img_save(ptr noundef %127, ptr noundef @.str.15)
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret void
}

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

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

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 0}
!12 = !{!"MLIS_Tensor", !6, i64 0, !7, i64 8, !10, i64 24}
!13 = !{!14, !14, i64 0}
!14 = !{!"float", !7, i64 0}
!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"

@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [13 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @img_save(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

declare i32 @mlis_option_set(ptr noundef, i32 noundef, ...) local_unnamed_addr #2

declare i32 @mlis_generate(ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local void @demo_inpaint(ptr noundef %0) local_unnamed_addr #0 {
  %2 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.12)
  %3 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1)
  %4 = tail call i32 (ptr, i32, ...) @mlis_option_set(ptr noundef %0, i32 noundef 7, ptr noundef nonnull @.str.13) #3
  %5 = tail call i32 (ptr, i32, ...) @mlis_option_set(ptr noundef %0, i32 noundef 22, i32 noundef 1) #3
  %6 = tail call i32 @mlis_generate(ptr noundef %0) #3
  %7 = tail call i32 (ptr, i32, ...) @mlis_option_set(ptr noundef %0, i32 noundef 22, i32 noundef 0) #3
  %8 = tail call ptr @mlis_tensor_get(ptr noundef %0, i32 noundef 3) #3
  %9 = tail call ptr @mlis_tensor_get(ptr noundef %0, i32 noundef 4) #3
  tail call void @mlis_tensor_resize_like(ptr noundef %9, ptr noundef %8) #3
  %10 = getelementptr inbounds i8, ptr %9, i64 8
  %11 = load i32, ptr %10, align 8, !tbaa !5
  %.neg = sdiv i32 %11, -2
  %12 = getelementptr inbounds i8, ptr %9, i64 12
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %14 = sdiv i32 %13, 2
  %15 = getelementptr inbounds i8, ptr %9, i64 16
  %16 = load i32, ptr %15, align 8, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %9, i64 20
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %19 = mul nsw i32 %14, %14
  br label %20

20:                                               ; preds = %.critedge, %1
  %indvars.iv = phi i64 [ %indvars.iv.next, %.critedge ], [ 0, %1 ]
  %.048 = phi i32 [ %.149, %.critedge ], [ 0, %1 ]
  %.046 = phi i32 [ %.147, %.critedge ], [ 0, %1 ]
  %.044 = phi i32 [ %.145, %.critedge ], [ 0, %1 ]
  %.043 = phi i32 [ %45, %.critedge ], [ 0, %1 ]
  %21 = icmp slt i32 %.043, %11
  br i1 %21, label %.critedge, label %22

22:                                               ; preds = %20
  %23 = add nsw i32 %.044, 1
  %24 = icmp slt i32 %23, %13
  br i1 %24, label %.critedge, label %25

25:                                               ; preds = %22
  %26 = add nsw i32 %.046, 1
  %27 = icmp slt i32 %26, %16
  br i1 %27, label %.critedge, label %28

28:                                               ; preds = %25
  %29 = add nsw i32 %.048, 1
  %30 = icmp slt i32 %29, %18
  br i1 %30, label %.critedge, label %31

31:                                               ; preds = %28
  %32 = tail call i32 (ptr, i32, ...) @mlis_option_set(ptr noundef %0, i32 noundef 7, ptr noundef nonnull @.str.14) #3
  %33 = tail call i32 (ptr, i32, ...) @mlis_option_set(ptr noundef %0, i32 noundef 16, double noundef 0x3FE6666666666666) #3
  %34 = tail call i32 (ptr, i32, ...) @mlis_option_set(ptr noundef %0, i32 noundef 23, i32 noundef 12) #3
  %35 = tail call i32 @mlis_generate(ptr noundef %0) #3
  tail call void @img_save(ptr noundef %0, ptr noundef nonnull @.str.15)
  ret void

.critedge:                                        ; preds = %25, %22, %20, %28
  %.149 = phi i32 [ %.048, %20 ], [ %.048, %22 ], [ %.048, %25 ], [ %29, %28 ]
  %.147 = phi i32 [ %.046, %20 ], [ %.046, %22 ], [ %26, %25 ], [ 0, %28 ]
  %.145 = phi i32 [ %.044, %20 ], [ %23, %22 ], [ 0, %25 ], [ 0, %28 ]
  %.1 = phi i32 [ %.043, %20 ], [ 0, %22 ], [ 0, %25 ], [ 0, %28 ]
  %36 = add i32 %.1, %.neg
  %37 = mul nsw i32 %36, %36
  %38 = sub nsw i32 %.145, %14
  %39 = mul nsw i32 %38, %38
  %40 = add nuw nsw i32 %37, %39
  %41 = icmp ugt i32 %40, %19
  %42 = uitofp i1 %41 to float
  %43 = load ptr, ptr %9, align 8, !tbaa !9
  %44 = getelementptr inbounds float, ptr %43, i64 %indvars.iv
  store float %42, ptr %44, align 4, !tbaa !12
  %45 = add nsw i32 %.1, 1
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  br label %20, !llvm.loop !14
}

declare ptr @mlis_tensor_get(ptr noundef, i32 noundef) local_unnamed_addr #2

declare void @mlis_tensor_resize_like(ptr noundef, ptr noundef) local_unnamed_addr #2

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


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass