; LLVM IR from delthas/libpaulstretch :: example (simple)

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

@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [36 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [22 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @main(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i32, align 4
  store i32 0, ptr %3, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = icmp ne i32 %16, 3
  br i1 %17, label %18, label %24

18:                                               ; preds = %2
  %19 = load ptr, ptr @stderr, align 8, !tbaa !9
  %20 = load ptr, ptr %5, align 8, !tbaa !9
  %21 = getelementptr inbounds ptr, ptr %20, i64 0
  %22 = load ptr, ptr %21, align 8, !tbaa !9
  %23 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %19, ptr noundef @.str, ptr noundef %22) #5
  store i32 1, ptr %3, align 4
  br label %90

24:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  store i32 0, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  store double 1.000000e+01, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  store double 2.500000e-01, ptr %8, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %25 = load double, ptr %8, align 8, !tbaa !11
  %26 = fmul double %25, 4.410000e+04
  %27 = fptoui double %26 to i64
  store i64 %27, ptr %9, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %28 = load double, ptr %7, align 8, !tbaa !11
  %29 = load i64, ptr %9, align 8, !tbaa !13
  %30 = call ptr @paulstretch_create(double noundef %28, i64 noundef %29)
  store ptr %30, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %31 = load i64, ptr %9, align 8, !tbaa !13
  %32 = mul i64 %31, 4
  %33 = call noalias ptr @malloc(i64 noundef %32) #6
  store ptr %33, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %34 = load ptr, ptr %5, align 8, !tbaa !9
  %35 = getelementptr inbounds ptr, ptr %34, i64 1
  %36 = load ptr, ptr %35, align 8, !tbaa !9
  %37 = call noalias ptr @fopen(ptr noundef %36, ptr noundef @.str.1)
  store ptr %37, ptr %12, align 8, !tbaa !9
  %38 = load ptr, ptr %12, align 8, !tbaa !9
  %39 = icmp ne ptr %38, null
  br i1 %39, label %41, label %40

40:                                               ; preds = %24
  store i32 1, ptr %6, align 4, !tbaa !5
  call void @perror(ptr noundef @.str.2)
  br label %85

41:                                               ; preds = %24
  %42 = load ptr, ptr %5, align 8, !tbaa !9
  %43 = getelementptr inbounds ptr, ptr %42, i64 2
  %44 = load ptr, ptr %43, align 8, !tbaa !9
  %45 = call noalias ptr @fopen(ptr noundef %44, ptr noundef @.str.3)
  store ptr %45, ptr %13, align 8, !tbaa !9
  %46 = load ptr, ptr %13, align 8, !tbaa !9
  %47 = icmp ne ptr %46, null
  br i1 %47, label %49, label %48

48:                                               ; preds = %41
  store i32 1, ptr %6, align 4, !tbaa !5
  call void @perror(ptr noundef @.str.4)
  br label %82

49:                                               ; preds = %41
  br label %50

50:                                               ; preds = %77, %49
  br label %51

51:                                               ; preds = %50
  %52 = load ptr, ptr %11, align 8, !tbaa !9
  %53 = load i64, ptr %9, align 8, !tbaa !13
  %54 = load ptr, ptr %12, align 8, !tbaa !9
  %55 = call i64 @fread(ptr noundef %52, i64 noundef 4, i64 noundef %53, ptr noundef %54)
  %56 = load i64, ptr %9, align 8, !tbaa !13
  %57 = icmp ne i64 %55, %56
  br i1 %57, label %58, label %59

58:                                               ; preds = %51
  br label %78

59:                                               ; preds = %51
  %60 = load ptr, ptr %10, align 8, !tbaa !9
  %61 = load ptr, ptr %11, align 8, !tbaa !9
  call void @paulstretch_write(ptr noundef %60, ptr noundef %61)
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #5
  br label %62

62:                                               ; preds = %73, %59
  %63 = load ptr, ptr %10, align 8, !tbaa !9
  %64 = call zeroext i1 @paulstretch_read(ptr noundef %63, ptr noundef %14)
  br i1 %64, label %65, label %74

65:                                               ; preds = %62
  %66 = load ptr, ptr %14, align 8, !tbaa !9
  %67 = load i64, ptr %9, align 8, !tbaa !13
  %68 = load ptr, ptr %13, align 8, !tbaa !9
  %69 = call i64 @fwrite(ptr noundef %66, i64 noundef 4, i64 noundef %67, ptr noundef %68)
  %70 = load i64, ptr %9, align 8, !tbaa !13
  %71 = icmp ne i64 %69, %70
  br i1 %71, label %72, label %73

72:                                               ; preds = %65
  store i32 1, ptr %6, align 4, !tbaa !5
  call void @perror(ptr noundef @.str.5)
  store i32 8, ptr %15, align 4
  br label %75

73:                                               ; preds = %65
  br label %62, !llvm.loop !15

74:                                               ; preds = %62
  store i32 0, ptr %15, align 4
  br label %75

75:                                               ; preds = %74, %72
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #5
  %76 = load i32, ptr %15, align 4
  switch i32 %76, label %89 [
    i32 0, label %77
    i32 8, label %79
  ]

77:                                               ; preds = %75
  br label %50

78:                                               ; preds = %58
  br label %79

79:                                               ; preds = %78, %75
  %80 = load ptr, ptr %13, align 8, !tbaa !9
  %81 = call i32 @fclose(ptr noundef %80)
  br label %82

82:                                               ; preds = %79, %48
  %83 = load ptr, ptr %12, align 8, !tbaa !9
  %84 = call i32 @fclose(ptr noundef %83)
  br label %85

85:                                               ; preds = %82, %40
  %86 = load ptr, ptr %11, align 8, !tbaa !9
  call void @free(ptr noundef %86) #5
  %87 = load ptr, ptr %10, align 8, !tbaa !9
  call void @paulstretch_destroy(ptr noundef %87)
  %88 = load i32, ptr %6, align 4, !tbaa !5
  store i32 %88, ptr %3, align 4
  store i32 1, ptr %15, align 4
  br label %89

89:                                               ; preds = %85, %75
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  br label %90

90:                                               ; preds = %89, %18
  %91 = load i32, ptr %3, align 4
  ret i32 %91
}

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #1

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

declare ptr @paulstretch_create(double noundef, i64 noundef) #3

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

declare noalias ptr @fopen(ptr noundef, ptr noundef) #3

declare void @perror(ptr noundef) #3

declare i64 @fread(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #3

declare void @paulstretch_write(ptr noundef, ptr noundef) #3

declare zeroext i1 @paulstretch_read(ptr noundef, ptr noundef) #3

declare i64 @fwrite(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #3

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

declare i32 @fclose(ptr noundef) #3

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

declare void @paulstretch_destroy(ptr noundef) #3

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 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { "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 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 #5 = { nounwind }
attributes #6 = { 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, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"long", !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"

@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [36 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [22 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @main(i32 noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = alloca ptr, align 8
  %.not = icmp eq i32 %0, 3
  br i1 %.not, label %8, label %4

4:                                                ; preds = %2
  %5 = load ptr, ptr @stderr, align 8, !tbaa !5
  %6 = load ptr, ptr %1, align 8, !tbaa !5
  %7 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %5, ptr noundef nonnull @.str, ptr noundef %6) #6
  br label %32

8:                                                ; preds = %2
  %9 = tail call ptr @paulstretch_create(double noundef 1.000000e+01, i64 noundef 11025) #7
  %10 = tail call noalias dereferenceable_or_null(44100) ptr @malloc(i64 noundef 44100) #8
  %11 = getelementptr inbounds i8, ptr %1, i64 8
  %12 = load ptr, ptr %11, align 8, !tbaa !5
  %13 = tail call noalias ptr @fopen(ptr noundef %12, ptr noundef nonnull @.str.1)
  %.not30 = icmp eq ptr %13, null
  br i1 %.not30, label %14, label %15

14:                                               ; preds = %8
  tail call void @perror(ptr noundef nonnull @.str.2) #9
  br label %31

15:                                               ; preds = %8
  %16 = getelementptr inbounds i8, ptr %1, i64 16
  %17 = load ptr, ptr %16, align 8, !tbaa !5
  %18 = tail call noalias ptr @fopen(ptr noundef %17, ptr noundef nonnull @.str.3)
  %.not31 = icmp eq ptr %18, null
  br i1 %.not31, label %20, label %.preheader

.preheader:                                       ; preds = %15
  %19 = tail call i64 @fread(ptr noundef %10, i64 noundef 4, i64 noundef 11025, ptr noundef nonnull %13)
  %.not3238 = icmp eq i64 %19, 11025
  br i1 %.not3238, label %.lr.ph, label %.loopexit

20:                                               ; preds = %15
  tail call void @perror(ptr noundef nonnull @.str.4) #9
  br label %29

.lr.ph:                                           ; preds = %.preheader, %26
  call void @paulstretch_write(ptr noundef %9, ptr noundef %10) #7
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #7
  br label %21

21:                                               ; preds = %23, %.lr.ph
  %22 = call zeroext i1 @paulstretch_read(ptr noundef %9, ptr noundef nonnull %3) #7
  br i1 %22, label %23, label %26

23:                                               ; preds = %21
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = call i64 @fwrite(ptr noundef %24, i64 noundef 4, i64 noundef 11025, ptr noundef nonnull %18)
  %.not33 = icmp eq i64 %25, 11025
  br i1 %.not33, label %21, label %.thread, !llvm.loop !9

.thread:                                          ; preds = %23
  call void @perror(ptr noundef nonnull @.str.5) #9
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #7
  br label %.loopexit

26:                                               ; preds = %21
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #7
  %27 = call i64 @fread(ptr noundef %10, i64 noundef 4, i64 noundef 11025, ptr noundef nonnull %13)
  %.not32 = icmp eq i64 %27, 11025
  br i1 %.not32, label %.lr.ph, label %.loopexit

.loopexit:                                        ; preds = %26, %.preheader, %.thread
  %.2 = phi i32 [ 1, %.thread ], [ 0, %.preheader ], [ 0, %26 ]
  %28 = call i32 @fclose(ptr noundef nonnull %18)
  br label %29

29:                                               ; preds = %.loopexit, %20
  %.3 = phi i32 [ %.2, %.loopexit ], [ 1, %20 ]
  %30 = call i32 @fclose(ptr noundef nonnull %13)
  br label %31

31:                                               ; preds = %29, %14
  %.4 = phi i32 [ %.3, %29 ], [ 1, %14 ]
  call void @free(ptr noundef %10) #7
  call void @paulstretch_destroy(ptr noundef %9) #7
  br label %32

32:                                               ; preds = %31, %4
  %.1 = phi i32 [ 1, %4 ], [ %.4, %31 ]
  ret i32 %.1
}

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

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

declare ptr @paulstretch_create(double noundef, i64 noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #4

; Function Attrs: nofree nounwind
declare noalias noundef ptr @fopen(ptr nocapture noundef readonly, ptr nocapture noundef readonly) local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare void @perror(ptr nocapture noundef readonly) local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare noundef i64 @fread(ptr nocapture noundef, i64 noundef, i64 noundef, ptr nocapture noundef) local_unnamed_addr #1

declare void @paulstretch_write(ptr noundef, ptr noundef) local_unnamed_addr #3

declare zeroext i1 @paulstretch_read(ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: nofree nounwind
declare noundef i64 @fwrite(ptr nocapture noundef, i64 noundef, i64 noundef, ptr nocapture noundef) local_unnamed_addr #1

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

; Function Attrs: nofree nounwind
declare noundef i32 @fclose(ptr nocapture noundef) local_unnamed_addr #1

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

declare void @paulstretch_destroy(ptr noundef) local_unnamed_addr #3

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { "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 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(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 #5 = { 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 #6 = { cold nounwind }
attributes #7 = { nounwind }
attributes #8 = { nounwind allocsize(0) }
attributes #9 = { cold }

!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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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