; LLVM IR from KamilSJaron/smudgeplot :: src_ploidyplot (libfastk)

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

@.str.19 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [11 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local ptr @Malloc(i64 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

; 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 @PathTo(ptr noundef) #0

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

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #2

; Function Attrs: nounwind
declare void @free(ptr noundef) #3

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

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #4

declare i32 @open(ptr noundef, i32 noundef, ...) #5

declare i32 @close(i32 noundef) #5

; Function Attrs: nounwind uwtable
declare hidden void @toggle_histogram(ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @Write_Histogram(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = 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 8, ptr %6) #6
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.Histogram, ptr %14, i32 0, i32 4
  %16 = load ptr, ptr %15, align 8, !tbaa !9
  store ptr %16, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #6
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.Histogram, ptr %17, i32 0, i32 2
  %19 = load i32, ptr %18, align 8, !tbaa !12
  store i32 %19, ptr %7, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.Histogram, ptr %20, i32 0, i32 3
  %22 = load i32, ptr %21, align 4, !tbaa !14
  store i32 %22, ptr %8, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #6
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.Histogram, ptr %23, i32 0, i32 1
  %25 = load i32, ptr %24, align 4, !tbaa !15
  %26 = icmp eq i32 %25, 0
  br i1 %26, label %27, label %29

27:                                               ; preds = %2
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  call void @toggle_histogram(ptr noundef %28)
  br label %29

29:                                               ; preds = %27, %2
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = call ptr @PathTo(ptr noundef %30)
  store ptr %31, ptr %9, align 8, !tbaa !5
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = call ptr @Root(ptr noundef %32, ptr noundef @.str.19)
  store ptr %33, ptr %10, align 8, !tbaa !5
  %34 = load ptr, ptr %9, align 8, !tbaa !5
  %35 = call i64 @strlen(ptr noundef %34) #7
  %36 = load ptr, ptr %10, align 8, !tbaa !5
  %37 = call i64 @strlen(ptr noundef %36) #7
  %38 = add i64 %35, %37
  %39 = add i64 %38, 10
  %40 = call ptr @Malloc(i64 noundef %39, ptr noundef @.str.20)
  store ptr %40, ptr %11, align 8, !tbaa !5
  %41 = load ptr, ptr %11, align 8, !tbaa !5
  %42 = icmp eq ptr %41, null
  br i1 %42, label %43, label %44

43:                                               ; preds = %29
  call void @exit(i32 noundef 1) #8
  unreachable

44:                                               ; preds = %29
  %45 = load ptr, ptr %11, align 8, !tbaa !5
  %46 = load ptr, ptr %9, align 8, !tbaa !5
  %47 = load ptr, ptr %10, align 8, !tbaa !5
  %48 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef %45, ptr noundef @.str.21, ptr noundef %46, ptr noundef %47) #6
  %49 = load ptr, ptr %11, align 8, !tbaa !5
  %50 = call i32 (ptr, i32, ...) @open(ptr noundef %49, i32 noundef 577, i32 noundef 448)
  store i32 %50, ptr %12, align 4, !tbaa !13
  %51 = load i32, ptr %12, align 4, !tbaa !13
  %52 = icmp slt i32 %51, 0
  br i1 %52, label %53, label %54

53:                                               ; preds = %44
  store i32 1, ptr %3, align 4
  store i32 1, ptr %13, align 4
  br label %101

54:                                               ; preds = %44
  %55 = load ptr, ptr %11, align 8, !tbaa !5
  call void @free(ptr noundef %55) #6
  %56 = load ptr, ptr %10, align 8, !tbaa !5
  call void @free(ptr noundef %56) #6
  %57 = load ptr, ptr %9, align 8, !tbaa !5
  call void @free(ptr noundef %57) #6
  %58 = load i32, ptr %12, align 4, !tbaa !13
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.Histogram, ptr %59, i32 0, i32 0
  %61 = call i64 @write(i32 noundef %58, ptr noundef %60, i64 noundef 4)
  %62 = load i32, ptr %12, align 4, !tbaa !13
  %63 = call i64 @write(i32 noundef %62, ptr noundef %7, i64 noundef 4)
  %64 = load i32, ptr %12, align 4, !tbaa !13
  %65 = call i64 @write(i32 noundef %64, ptr noundef %8, i64 noundef 4)
  %66 = load i32, ptr %12, align 4, !tbaa !13
  %67 = load ptr, ptr %6, align 8, !tbaa !5
  %68 = load i32, ptr %8, align 4, !tbaa !13
  %69 = add nsw i32 %68, 1
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds i64, ptr %67, i64 %70
  %72 = call i64 @write(i32 noundef %66, ptr noundef %71, i64 noundef 8)
  %73 = load i32, ptr %12, align 4, !tbaa !13
  %74 = load ptr, ptr %6, align 8, !tbaa !5
  %75 = load i32, ptr %8, align 4, !tbaa !13
  %76 = add nsw i32 %75, 2
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds i64, ptr %74, i64 %77
  %79 = call i64 @write(i32 noundef %73, ptr noundef %78, i64 noundef 8)
  %80 = load i32, ptr %12, align 4, !tbaa !13
  %81 = load ptr, ptr %6, align 8, !tbaa !5
  %82 = load i32, ptr %7, align 4, !tbaa !13
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds i64, ptr %81, i64 %83
  %85 = load i32, ptr %8, align 4, !tbaa !13
  %86 = load i32, ptr %7, align 4, !tbaa !13
  %87 = sub nsw i32 %85, %86
  %88 = add nsw i32 %87, 1
  %89 = sext i32 %88 to i64
  %90 = mul i64 8, %89
  %91 = call i64 @write(i32 noundef %80, ptr noundef %84, i64 noundef %90)
  %92 = load i32, ptr %12, align 4, !tbaa !13
  %93 = call i32 @close(i32 noundef %92)
  %94 = load ptr, ptr %5, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.Histogram, ptr %94, i32 0, i32 1
  %96 = load i32, ptr %95, align 4, !tbaa !15
  %97 = icmp eq i32 %96, 0
  br i1 %97, label %98, label %100

98:                                               ; preds = %54
  %99 = load ptr, ptr %5, align 8, !tbaa !5
  call void @toggle_histogram(ptr noundef %99)
  br label %100

100:                                              ; preds = %98, %54
  store i32 0, ptr %3, align 4
  store i32 1, ptr %13, align 4
  br label %101

101:                                              ; preds = %100, %53
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  %102 = load i32, ptr %3, align 4
  ret i32 %102
}

declare i64 @write(i32 noundef, ptr noundef, i64 noundef) #5

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 willreturn memory(read) "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 = { noreturn 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 #5 = { "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 #6 = { nounwind }
attributes #7 = { nounwind willreturn memory(read) }
attributes #8 = { noreturn 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, !6, i64 16}
!10 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !6, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 8}
!13 = !{!11, !11, i64 0}
!14 = !{!10, !11, i64 12}
!15 = !{!10, !11, i64 4}


; 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.19 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [11 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local ptr @Malloc(i64 noundef, ptr 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 @PathTo(ptr noundef) local_unnamed_addr #0

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #2

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

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

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #5

; Function Attrs: nofree
declare noundef i32 @open(ptr nocapture noundef readonly, i32 noundef, ...) local_unnamed_addr #6

declare i32 @close(i32 noundef) local_unnamed_addr #7

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @Write_Histogram(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = getelementptr inbounds i8, ptr %1, i64 16
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #8
  %7 = getelementptr inbounds i8, ptr %1, i64 8
  %8 = load i32, ptr %7, align 8, !tbaa !11
  store i32 %8, ptr %3, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #8
  %9 = getelementptr inbounds i8, ptr %1, i64 12
  %10 = load i32, ptr %9, align 4, !tbaa !13
  store i32 %10, ptr %4, align 4, !tbaa !12
  %11 = getelementptr inbounds i8, ptr %1, i64 4
  %12 = load i32, ptr %11, align 4, !tbaa !14
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %14, label %15

14:                                               ; preds = %2
  tail call void @toggle_histogram(ptr noundef nonnull %1)
  br label %15

15:                                               ; preds = %14, %2
  %16 = tail call ptr @PathTo(ptr noundef %0)
  %17 = tail call ptr @Root(ptr noundef %0, ptr noundef nonnull @.str.19)
  %18 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %16) #9
  %19 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %17) #9
  %20 = add i64 %18, 10
  %21 = add i64 %20, %19
  %22 = tail call ptr @Malloc(i64 noundef %21, ptr noundef nonnull @.str.20)
  %23 = icmp eq ptr %22, null
  br i1 %23, label %24, label %25

24:                                               ; preds = %15
  tail call void @exit(i32 noundef 1) #10
  unreachable

25:                                               ; preds = %15
  %26 = tail call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) %22, ptr noundef nonnull dereferenceable(1) @.str.21, ptr noundef %16, ptr noundef %17) #8
  %27 = tail call i32 (ptr, i32, ...) @open(ptr noundef nonnull %22, i32 noundef 577, i32 noundef 448) #8
  %28 = icmp slt i32 %27, 0
  br i1 %28, label %49, label %29

29:                                               ; preds = %25
  tail call void @free(ptr noundef nonnull %22) #8
  tail call void @free(ptr noundef %17) #8
  tail call void @free(ptr noundef %16) #8
  %30 = tail call i64 @write(i32 noundef %27, ptr noundef nonnull %1, i64 noundef 4) #8
  %31 = call i64 @write(i32 noundef %27, ptr noundef nonnull %3, i64 noundef 4) #8
  %32 = call i64 @write(i32 noundef %27, ptr noundef nonnull %4, i64 noundef 4) #8
  %33 = sext i32 %10 to i64
  %34 = getelementptr i64, ptr %6, i64 %33
  %35 = getelementptr i8, ptr %34, i64 8
  %36 = tail call i64 @write(i32 noundef %27, ptr noundef %35, i64 noundef 8) #8
  %37 = getelementptr i8, ptr %34, i64 16
  %38 = tail call i64 @write(i32 noundef %27, ptr noundef %37, i64 noundef 8) #8
  %39 = sext i32 %8 to i64
  %40 = getelementptr inbounds i64, ptr %6, i64 %39
  %reass.sub = sub i32 %10, %8
  %41 = add i32 %reass.sub, 1
  %42 = sext i32 %41 to i64
  %43 = shl nsw i64 %42, 3
  %44 = tail call i64 @write(i32 noundef %27, ptr noundef %40, i64 noundef %43) #8
  %45 = tail call i32 @close(i32 noundef %27) #8
  %46 = load i32, ptr %11, align 4, !tbaa !14
  %47 = icmp eq i32 %46, 0
  br i1 %47, label %48, label %49

48:                                               ; preds = %29
  tail call void @toggle_histogram(ptr noundef nonnull %1)
  br label %49

49:                                               ; preds = %29, %48, %25
  %.0 = phi i32 [ 1, %25 ], [ 0, %48 ], [ 0, %29 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #8
  ret i32 %.0
}

; Function Attrs: nofree
declare noundef i64 @write(i32 noundef, ptr nocapture noundef readonly, i64 noundef) local_unnamed_addr #6

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 = { 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 #4 = { 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 #5 = { noreturn 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 #6 = { nofree "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 #7 = { "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 #8 = { nounwind }
attributes #9 = { nounwind willreturn memory(read) }
attributes #10 = { noreturn 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, !10, i64 16}
!6 = !{!"", !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 8}
!12 = !{!7, !7, i64 0}
!13 = !{!6, !7, i64 12}
!14 = !{!6, !7, i64 4}


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