; LLVM IR from avik-das/seam-carver :: seam-carver (run_iteration)

; 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"

@.str.14 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [21 x i8], align 1

; Function Attrs: nounwind
declare void @free(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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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

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

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @run_iteration(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) #2 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca [1024 x i8], align 16
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !9
  store i32 %4, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  store ptr null, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  store ptr null, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  store ptr null, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  store ptr null, ptr %14, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1024, ptr %15) #3
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = load i32, ptr %8, align 4, !tbaa !9
  %18 = load i32, ptr %9, align 4, !tbaa !9
  %19 = call ptr @compute_energy(ptr noundef %16, i32 noundef %17, i32 noundef %18)
  store ptr %19, ptr %11, align 8, !tbaa !5
  %20 = load ptr, ptr %11, align 8, !tbaa !5
  %21 = icmp ne ptr %20, null
  br i1 %21, label %23, label %22

22:                                               ; preds = %5
  br label %69

23:                                               ; preds = %5
  %24 = load i32, ptr %10, align 4, !tbaa !9
  %25 = icmp eq i32 %24, 0
  br i1 %25, label %26, label %38

26:                                               ; preds = %23
  %27 = getelementptr inbounds [1024 x i8], ptr %15, i64 0, i64 0
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef %27, i64 noundef 1024, ptr noundef @.str.14, ptr noundef %28) #3
  %30 = load ptr, ptr %11, align 8, !tbaa !5
  %31 = load i32, ptr %8, align 4, !tbaa !9
  %32 = load i32, ptr %9, align 4, !tbaa !9
  %33 = getelementptr inbounds [1024 x i8], ptr %15, i64 0, i64 0
  %34 = call i32 @write_energy(ptr noundef %30, i32 noundef %31, i32 noundef %32, ptr noundef %33)
  %35 = icmp ne i32 %34, 0
  br i1 %35, label %36, label %37

36:                                               ; preds = %26
  br label %69

37:                                               ; preds = %26
  br label %38

38:                                               ; preds = %37, %23
  %39 = load ptr, ptr %11, align 8, !tbaa !5
  %40 = load i32, ptr %8, align 4, !tbaa !9
  %41 = load i32, ptr %9, align 4, !tbaa !9
  %42 = call ptr @compute_vertical_seam_links(ptr noundef %39, i32 noundef %40, i32 noundef %41)
  store ptr %42, ptr %12, align 8, !tbaa !5
  %43 = load ptr, ptr %12, align 8, !tbaa !5
  %44 = icmp ne ptr %43, null
  br i1 %44, label %46, label %45

45:                                               ; preds = %38
  br label %69

46:                                               ; preds = %38
  %47 = load ptr, ptr %12, align 8, !tbaa !5
  %48 = load i32, ptr %8, align 4, !tbaa !9
  %49 = load i32, ptr %9, align 4, !tbaa !9
  %50 = call ptr @get_minimal_seam(ptr noundef %47, i32 noundef %48, i32 noundef %49)
  store ptr %50, ptr %13, align 8, !tbaa !5
  %51 = getelementptr inbounds [1024 x i8], ptr %15, i64 0, i64 0
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  %53 = load i32, ptr %10, align 4, !tbaa !9
  %54 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef %51, i64 noundef 1024, ptr noundef @.str.15, ptr noundef %52, i32 noundef %53) #3
  %55 = load ptr, ptr %7, align 8, !tbaa !5
  %56 = load ptr, ptr %13, align 8, !tbaa !5
  %57 = load i32, ptr %8, align 4, !tbaa !9
  %58 = load i32, ptr %9, align 4, !tbaa !9
  %59 = getelementptr inbounds [1024 x i8], ptr %15, i64 0, i64 0
  %60 = call i32 @draw_vertical_seam(ptr noundef %55, ptr noundef %56, i32 noundef %57, i32 noundef %58, ptr noundef %59)
  %61 = icmp ne i32 %60, 0
  br i1 %61, label %62, label %63

62:                                               ; preds = %46
  br label %69

63:                                               ; preds = %46
  %64 = load ptr, ptr %7, align 8, !tbaa !5
  %65 = load ptr, ptr %13, align 8, !tbaa !5
  %66 = load i32, ptr %8, align 4, !tbaa !9
  %67 = load i32, ptr %9, align 4, !tbaa !9
  %68 = call ptr @image_after_vertical_seam_removal(ptr noundef %64, ptr noundef %65, i32 noundef %66, i32 noundef %67)
  store ptr %68, ptr %14, align 8, !tbaa !5
  br label %69

69:                                               ; preds = %63, %62, %45, %36, %22
  %70 = load ptr, ptr %11, align 8, !tbaa !5
  %71 = icmp ne ptr %70, null
  br i1 %71, label %72, label %74

72:                                               ; preds = %69
  %73 = load ptr, ptr %11, align 8, !tbaa !5
  call void @free(ptr noundef %73) #3
  br label %74

74:                                               ; preds = %72, %69
  %75 = load ptr, ptr %12, align 8, !tbaa !5
  %76 = icmp ne ptr %75, null
  br i1 %76, label %77, label %79

77:                                               ; preds = %74
  %78 = load ptr, ptr %12, align 8, !tbaa !5
  call void @free(ptr noundef %78) #3
  br label %79

79:                                               ; preds = %77, %74
  %80 = load ptr, ptr %13, align 8, !tbaa !5
  %81 = icmp ne ptr %80, null
  br i1 %81, label %82, label %84

82:                                               ; preds = %79
  %83 = load ptr, ptr %13, align 8, !tbaa !5
  call void @free(ptr noundef %83) #3
  br label %84

84:                                               ; preds = %82, %79
  %85 = load ptr, ptr %14, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 1024, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  ret ptr %85
}

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

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

!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}


; 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.14 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [21 x i8], align 1

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #0

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

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @compute_energy(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local ptr @compute_vertical_seam_links(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local ptr @get_minimal_seam(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local ptr @image_after_vertical_seam_removal(ptr noundef, ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local i32 @write_energy(ptr noundef, i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local i32 @draw_vertical_seam(ptr noundef, ptr noundef, i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local ptr @run_iteration(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #2 {
  %6 = alloca [1024 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 1024, ptr nonnull %6) #4
  %7 = tail call ptr @compute_energy(ptr noundef %1, i32 noundef %2, i32 noundef %3)
  %.not = icmp eq ptr %7, null
  br i1 %.not, label %.thread65, label %8

8:                                                ; preds = %5
  %9 = icmp eq i32 %4, 0
  br i1 %9, label %10, label %13

10:                                               ; preds = %8
  %11 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef nonnull dereferenceable(1) %6, i64 noundef 1024, ptr noundef nonnull @.str.14, ptr noundef %0) #4
  %12 = call i32 @write_energy(ptr noundef nonnull %7, i32 noundef %2, i32 noundef %3, ptr noundef nonnull %6)
  %.not37 = icmp eq i32 %12, 0
  br i1 %.not37, label %13, label %.thread65.sink.split

13:                                               ; preds = %10, %8
  %14 = call ptr @compute_vertical_seam_links(ptr noundef nonnull %7, i32 noundef %2, i32 noundef %3)
  %.not38 = icmp eq ptr %14, null
  br i1 %.not38, label %.thread65.sink.split, label %15

15:                                               ; preds = %13
  %16 = call ptr @get_minimal_seam(ptr noundef nonnull %14, i32 noundef %2, i32 noundef %3)
  %17 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef nonnull dereferenceable(1) %6, i64 noundef 1024, ptr noundef nonnull @.str.15, ptr noundef %0, i32 noundef %4) #4
  %18 = call i32 @draw_vertical_seam(ptr noundef %1, ptr noundef %16, i32 noundef %2, i32 noundef %3, ptr noundef nonnull %6)
  %.not39 = icmp eq i32 %18, 0
  br i1 %.not39, label %19, label %21

19:                                               ; preds = %15
  %20 = call ptr @image_after_vertical_seam_removal(ptr noundef %1, ptr noundef %16, i32 noundef %2, i32 noundef %3)
  br label %21

21:                                               ; preds = %19, %15
  %.0.ph = phi ptr [ %20, %19 ], [ null, %15 ]
  call void @free(ptr noundef nonnull %7) #4
  call void @free(ptr noundef nonnull %14) #4
  %.not41 = icmp eq ptr %16, null
  br i1 %.not41, label %.thread65, label %.thread65.sink.split

.thread65.sink.split:                             ; preds = %21, %10, %13
  %.sink = phi ptr [ %7, %13 ], [ %7, %10 ], [ %16, %21 ]
  %.0505669.ph = phi ptr [ null, %13 ], [ null, %10 ], [ %.0.ph, %21 ]
  call void @free(ptr noundef nonnull %.sink) #4
  br label %.thread65

.thread65:                                        ; preds = %.thread65.sink.split, %5, %21
  %.0505669 = phi ptr [ %.0.ph, %21 ], [ null, %5 ], [ %.0505669.ph, %.thread65.sink.split ]
  call void @llvm.lifetime.end.p0(i64 1024, ptr nonnull %6) #4
  ret ptr %.0505669
}

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

attributes #0 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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)"}


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