; LLVM IR from shellphish/how2heap :: glibc_2.27 (tcache_stashing_unlink_attack)

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

@stdout = external global ptr, align 8
@.str = external hidden unnamed_addr constant [63 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [62 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [220 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [97 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [160 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [57 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [249 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [48 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [55 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [212 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [123 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [81 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [114 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [101 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [186 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [164 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [77 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [96 x i8], align 1
@__PRETTY_FUNCTION__.main = external hidden unnamed_addr constant [11 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca [16 x i64], align 16
  %3 = alloca [16 x ptr], align 16
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 128, ptr %2) #8
  call void @llvm.memset.p0.i64(ptr align 16 %2, i8 0, i64 128, i1 false)
  call void @llvm.lifetime.start.p0(i64 128, ptr %3) #8
  call void @llvm.memset.p0.i64(ptr align 16 %3, i8 0, i64 128, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #8
  %7 = load ptr, ptr @stdout, align 8, !tbaa !5
  call void @setbuf(ptr noundef %7, ptr noundef null) #8
  %8 = call i32 (ptr, ...) @printf(ptr noundef @.str)
  %9 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  %10 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  %11 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  %12 = call i32 (ptr, ...) @printf(ptr noundef @.str.4)
  %13 = call i32 (ptr, ...) @printf(ptr noundef @.str.5)
  %14 = call i32 (ptr, ...) @printf(ptr noundef @.str.6)
  %15 = getelementptr inbounds [16 x i64], ptr %2, i64 0, i64 2
  %16 = ptrtoint ptr %15 to i64
  %17 = getelementptr inbounds [16 x i64], ptr %2, i64 0, i64 3
  store i64 %16, ptr %17, align 8, !tbaa !9
  %18 = getelementptr inbounds [16 x i64], ptr %2, i64 0, i64 3
  %19 = load i64, ptr %18, align 8, !tbaa !9
  %20 = inttoptr i64 %19 to ptr
  %21 = call i32 (ptr, ...) @printf(ptr noundef @.str.7, ptr noundef %20)
  %22 = getelementptr inbounds [16 x i64], ptr %2, i64 0, i64 4
  %23 = load i64, ptr %22, align 16, !tbaa !9
  %24 = inttoptr i64 %23 to ptr
  %25 = call i32 (ptr, ...) @printf(ptr noundef @.str.8, ptr noundef %24)
  %26 = call i32 (ptr, ...) @printf(ptr noundef @.str.9)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #8
  store i32 0, ptr %5, align 4, !tbaa !11
  br label %27

27:                                               ; preds = %36, %0
  %28 = load i32, ptr %5, align 4, !tbaa !11
  %29 = icmp slt i32 %28, 9
  br i1 %29, label %31, label %30

30:                                               ; preds = %27
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #8
  br label %39

31:                                               ; preds = %27
  %32 = call noalias ptr @malloc(i64 noundef 144) #9
  %33 = load i32, ptr %5, align 4, !tbaa !11
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [16 x ptr], ptr %3, i64 0, i64 %34
  store ptr %32, ptr %35, align 8, !tbaa !5
  br label %36

36:                                               ; preds = %31
  %37 = load i32, ptr %5, align 4, !tbaa !11
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr %5, align 4, !tbaa !11
  br label %27, !llvm.loop !13

39:                                               ; preds = %30
  %40 = call i32 (ptr, ...) @printf(ptr noundef @.str.10)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #8
  store i32 3, ptr %6, align 4, !tbaa !11
  br label %41

41:                                               ; preds = %50, %39
  %42 = load i32, ptr %6, align 4, !tbaa !11
  %43 = icmp slt i32 %42, 9
  br i1 %43, label %45, label %44

44:                                               ; preds = %41
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #8
  br label %53

45:                                               ; preds = %41
  %46 = load i32, ptr %6, align 4, !tbaa !11
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [16 x ptr], ptr %3, i64 0, i64 %47
  %49 = load ptr, ptr %48, align 8, !tbaa !5
  call void @free(ptr noundef %49) #8
  br label %50

50:                                               ; preds = %45
  %51 = load i32, ptr %6, align 4, !tbaa !11
  %52 = add nsw i32 %51, 1
  store i32 %52, ptr %6, align 4, !tbaa !11
  br label %41, !llvm.loop !15

53:                                               ; preds = %44
  %54 = call i32 (ptr, ...) @printf(ptr noundef @.str.11)
  %55 = getelementptr inbounds [16 x ptr], ptr %3, i64 0, i64 1
  %56 = load ptr, ptr %55, align 8, !tbaa !5
  call void @free(ptr noundef %56) #8
  %57 = getelementptr inbounds [16 x ptr], ptr %3, i64 0, i64 0
  %58 = load ptr, ptr %57, align 16, !tbaa !5
  call void @free(ptr noundef %58) #8
  %59 = getelementptr inbounds [16 x ptr], ptr %3, i64 0, i64 2
  %60 = load ptr, ptr %59, align 16, !tbaa !5
  call void @free(ptr noundef %60) #8
  %61 = call i32 (ptr, ...) @printf(ptr noundef @.str.12)
  %62 = call noalias ptr @malloc(i64 noundef 160) #9
  %63 = call i32 (ptr, ...) @printf(ptr noundef @.str.13)
  %64 = call noalias ptr @malloc(i64 noundef 144) #9
  %65 = call noalias ptr @malloc(i64 noundef 144) #9
  %66 = getelementptr inbounds [16 x i64], ptr %2, i64 0, i64 0
  %67 = call i32 (ptr, ...) @printf(ptr noundef @.str.14, ptr noundef %66)
  %68 = getelementptr inbounds [16 x i64], ptr %2, i64 0, i64 0
  %69 = ptrtoint ptr %68 to i64
  %70 = getelementptr inbounds [16 x ptr], ptr %3, i64 0, i64 2
  %71 = load ptr, ptr %70, align 16, !tbaa !5
  %72 = getelementptr inbounds i64, ptr %71, i64 1
  store i64 %69, ptr %72, align 8, !tbaa !9
  %73 = call i32 (ptr, ...) @printf(ptr noundef @.str.15)
  %74 = call noalias ptr @calloc(i64 noundef 1, i64 noundef 144) #10
  %75 = getelementptr inbounds [16 x i64], ptr %2, i64 0, i64 2
  %76 = load i64, ptr %75, align 16, !tbaa !9
  %77 = inttoptr i64 %76 to ptr
  %78 = getelementptr inbounds [16 x i64], ptr %2, i64 0, i64 4
  %79 = load i64, ptr %78, align 16, !tbaa !9
  %80 = inttoptr i64 %79 to ptr
  %81 = call i32 (ptr, ...) @printf(ptr noundef @.str.16, ptr noundef %77, ptr noundef %80)
  %82 = call noalias ptr @malloc(i64 noundef 144) #9
  store ptr %82, ptr %4, align 8, !tbaa !5
  %83 = load ptr, ptr %4, align 8, !tbaa !5
  %84 = call i32 (ptr, ...) @printf(ptr noundef @.str.17, ptr noundef %83)
  %85 = load ptr, ptr %4, align 8, !tbaa !5
  %86 = getelementptr inbounds [16 x i64], ptr %2, i64 0, i64 2
  %87 = icmp eq ptr %85, %86
  br i1 %87, label %88, label %89

88:                                               ; preds = %53
  br label %90

89:                                               ; preds = %53
  call void @__assert_fail(ptr noundef @.str.18, ptr noundef @.str.19, i32 noundef 78, ptr noundef @__PRETTY_FUNCTION__.main) #11
  unreachable

90:                                               ; preds = %88
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #8
  call void @llvm.lifetime.end.p0(i64 128, ptr %3) #8
  call void @llvm.lifetime.end.p0(i64 128, ptr %2) #8
  ret i32 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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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

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

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

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

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

; Function Attrs: nounwind allocsize(0,1)
declare noalias ptr @calloc(i64 noundef, i64 noundef) #6

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #7

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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = { "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 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 #6 = { nounwind allocsize(0,1) "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 = { 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 #8 = { nounwind }
attributes #9 = { nounwind allocsize(0) }
attributes #10 = { nounwind allocsize(0,1) }
attributes #11 = { 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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


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

@stdout = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [63 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [62 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [220 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [97 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [160 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [57 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [249 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [48 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [55 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [212 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [123 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [81 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [114 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [101 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [186 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [164 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [77 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [96 x i8], align 1
@__PRETTY_FUNCTION__.main = external hidden unnamed_addr constant [11 x i8], align 1

; Function Attrs: noreturn nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca [16 x i64], align 16
  call void @llvm.lifetime.start.p0(i64 128, ptr nonnull %1) #6
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(128) %1, i8 0, i64 128, i1 false)
  %2 = load ptr, ptr @stdout, align 8, !tbaa !5
  tail call void @setbuf(ptr noundef %2, ptr noundef null) #6
  %3 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str)
  %4 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1)
  %5 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  %6 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  %7 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4)
  %8 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5)
  %9 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6)
  %10 = getelementptr inbounds i8, ptr %1, i64 16
  %11 = ptrtoint ptr %10 to i64
  %12 = getelementptr inbounds i8, ptr %1, i64 24
  store i64 %11, ptr %12, align 8, !tbaa !9
  %13 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7, ptr noundef nonnull %10)
  %14 = getelementptr inbounds i8, ptr %1, i64 32
  %15 = load i64, ptr %14, align 16, !tbaa !9
  %16 = inttoptr i64 %15 to ptr
  %17 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.8, ptr noundef %16)
  %18 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.9)
  %19 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.10)
  %20 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.11)
  %21 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.12)
  %22 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.13)
  %23 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.14, ptr noundef nonnull %1)
  %24 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.15)
  %25 = load i64, ptr %10, align 16, !tbaa !9
  %26 = inttoptr i64 %25 to ptr
  %27 = load i64, ptr %14, align 16, !tbaa !9
  %28 = inttoptr i64 %27 to ptr
  %29 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.16, ptr noundef %26, ptr noundef %28)
  %30 = call noalias dereferenceable_or_null(144) ptr @malloc(i64 noundef 144) #7
  %31 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.17, ptr noundef %30)
  call void @__assert_fail(ptr noundef nonnull @.str.18, ptr noundef nonnull @.str.19, i32 noundef 78, ptr noundef nonnull @__PRETTY_FUNCTION__.main) #8
  unreachable
}

; 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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: nofree nounwind
declare void @setbuf(ptr nocapture noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) 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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #5

attributes #0 = { noreturn 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 nocallback nofree nounwind willreturn memory(argmem: write) }
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 = { 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 = { 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 = { nounwind }
attributes #7 = { nounwind allocsize(0) }
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, !10, i64 0}
!10 = !{!"long", !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass