; LLVM IR from casensiom/fast-image-processing :: src (image)

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

; Function Attrs: nounwind uwtable
define dso_local void @create_image(ptr dead_on_unwind noalias writable sret(%struct.SImage) align 8 %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store i32 %1, ptr %5, align 4, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !5
  store i32 %3, ptr %7, align 4, !tbaa !5
  call void @reset_image(ptr noundef %0)
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %9 = load i32, ptr %5, align 4, !tbaa !5
  %10 = load i32, ptr %6, align 4, !tbaa !5
  %11 = mul i32 %9, %10
  %12 = load i32, ptr %7, align 4, !tbaa !5
  %13 = mul i32 %11, %12
  store i32 %13, ptr %8, align 4, !tbaa !5
  %14 = load i32, ptr %8, align 4, !tbaa !5
  %15 = icmp ugt i32 %14, 0
  br i1 %15, label %16, label %40

16:                                               ; preds = %4
  %17 = load i32, ptr %7, align 4, !tbaa !5
  %18 = icmp ne i32 %17, 0
  br i1 %18, label %19, label %40

19:                                               ; preds = %16
  %20 = load i32, ptr %8, align 4, !tbaa !5
  %21 = zext i32 %20 to i64
  %22 = call noalias ptr @malloc(i64 noundef %21) #5
  %23 = getelementptr inbounds %struct.SImage, ptr %0, i32 0, i32 4
  store ptr %22, ptr %23, align 8, !tbaa !9
  %24 = getelementptr inbounds %struct.SImage, ptr %0, i32 0, i32 4
  %25 = load ptr, ptr %24, align 8, !tbaa !9
  %26 = icmp ne ptr %25, null
  br i1 %26, label %27, label %39

27:                                               ; preds = %19
  %28 = load i32, ptr %5, align 4, !tbaa !5
  %29 = getelementptr inbounds %struct.SImage, ptr %0, i32 0, i32 0
  store i32 %28, ptr %29, align 8, !tbaa !12
  %30 = load i32, ptr %6, align 4, !tbaa !5
  %31 = getelementptr inbounds %struct.SImage, ptr %0, i32 0, i32 1
  store i32 %30, ptr %31, align 4, !tbaa !13
  %32 = getelementptr inbounds %struct.SImage, ptr %0, i32 0, i32 2
  store i32 0, ptr %32, align 8, !tbaa !14
  %33 = load i32, ptr %7, align 4, !tbaa !5
  %34 = getelementptr inbounds %struct.SImage, ptr %0, i32 0, i32 3
  store i32 %33, ptr %34, align 4, !tbaa !15
  %35 = getelementptr inbounds %struct.SImage, ptr %0, i32 0, i32 4
  %36 = load ptr, ptr %35, align 8, !tbaa !9
  %37 = load i32, ptr %8, align 4, !tbaa !5
  %38 = zext i32 %37 to i64
  call void @llvm.memset.p0.i64(ptr align 1 %36, i8 0, i64 %38, i1 false)
  br label %39

39:                                               ; preds = %27, %19
  br label %40

40:                                               ; preds = %39, %16, %4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  ret void
}

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

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

; 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 = { nounwind allocsize(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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { nounwind }
attributes #5 = { nounwind allocsize(0) }

!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 16}
!10 = !{!"SImage", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !11, i64 16}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!10, !6, i64 0}
!13 = !{!10, !6, i64 4}
!14 = !{!10, !6, i64 8}
!15 = !{!10, !6, i64 12}


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

; Function Attrs: nounwind uwtable
define dso_local void @create_image(ptr dead_on_unwind noalias writable sret(%struct.SImage) align 8 %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  tail call void @reset_image(ptr noundef %0)
  %5 = mul i32 %2, %1
  %6 = mul i32 %5, %3
  %.not = icmp eq i32 %6, 0
  br i1 %.not, label %14, label %7

7:                                                ; preds = %4
  %8 = zext i32 %6 to i64
  %calloc = tail call ptr @calloc(i64 1, i64 %8)
  %9 = getelementptr inbounds i8, ptr %0, i64 16
  store ptr %calloc, ptr %9, align 8, !tbaa !5
  %.not12 = icmp eq ptr %calloc, null
  br i1 %.not12, label %14, label %10

10:                                               ; preds = %7
  store i32 %1, ptr %0, align 8, !tbaa !11
  %11 = getelementptr inbounds i8, ptr %0, i64 4
  store i32 %2, ptr %11, align 4, !tbaa !12
  %12 = getelementptr inbounds i8, ptr %0, i64 8
  store i32 0, ptr %12, align 8, !tbaa !13
  %13 = getelementptr inbounds i8, ptr %0, i64 12
  store i32 %3, ptr %13, align 4, !tbaa !14
  br label %14

14:                                               ; preds = %7, %10, %4
  ret void
}

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

; Function Attrs: nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @calloc(i64 noundef, i64 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 = { nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" }

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


; Effective O3 passes: CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass