; LLVM IR from attractivechaos/klib :: test (kavl_test)

; 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.my_node = type { i32, %struct.anon }
%struct.anon = type { [2 x ptr], i8, i32 }

@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [21 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [16 x i8], align 1

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @check(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca [2 x i32], align 4
  %8 = 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 4, ptr %6) #4
  store i32 1, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  call void @llvm.memset.p0.i64(ptr align 4 %7, i8 0, i64 8, i1 false)
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  store i32 0, ptr %9, align 4, !tbaa !9
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = icmp ne ptr %10, null
  br i1 %11, label %12, label %108

12:                                               ; preds = %2
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.my_node, ptr %13, i32 0, i32 1
  %15 = getelementptr inbounds %struct.anon, ptr %14, i32 0, i32 0
  %16 = getelementptr inbounds [2 x ptr], ptr %15, i64 0, i64 0
  %17 = load ptr, ptr %16, align 8, !tbaa !5
  %18 = icmp ne ptr %17, null
  br i1 %18, label %19, label %29

19:                                               ; preds = %12
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.my_node, ptr %20, i32 0, i32 1
  %22 = getelementptr inbounds %struct.anon, ptr %21, i32 0, i32 0
  %23 = getelementptr inbounds [2 x ptr], ptr %22, i64 0, i64 0
  %24 = load ptr, ptr %23, align 8, !tbaa !5
  %25 = getelementptr inbounds [2 x i32], ptr %7, i64 0, i64 0
  %26 = call i32 @check(ptr noundef %24, ptr noundef %25)
  %27 = load i32, ptr %6, align 4, !tbaa !9
  %28 = add nsw i32 %27, %26
  store i32 %28, ptr %6, align 4, !tbaa !9
  br label %29

29:                                               ; preds = %19, %12
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.my_node, ptr %30, i32 0, i32 1
  %32 = getelementptr inbounds %struct.anon, ptr %31, i32 0, i32 0
  %33 = getelementptr inbounds [2 x ptr], ptr %32, i64 0, i64 1
  %34 = load ptr, ptr %33, align 8, !tbaa !5
  %35 = icmp ne ptr %34, null
  br i1 %35, label %36, label %46

36:                                               ; preds = %29
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.my_node, ptr %37, i32 0, i32 1
  %39 = getelementptr inbounds %struct.anon, ptr %38, i32 0, i32 0
  %40 = getelementptr inbounds [2 x ptr], ptr %39, i64 0, i64 1
  %41 = load ptr, ptr %40, align 8, !tbaa !5
  %42 = getelementptr inbounds [2 x i32], ptr %7, i64 0, i64 1
  %43 = call i32 @check(ptr noundef %41, ptr noundef %42)
  %44 = load i32, ptr %6, align 4, !tbaa !9
  %45 = add nsw i32 %44, %43
  store i32 %45, ptr %6, align 4, !tbaa !9
  br label %46

46:                                               ; preds = %36, %29
  %47 = getelementptr inbounds [2 x i32], ptr %7, i64 0, i64 0
  %48 = load i32, ptr %47, align 4, !tbaa !9
  %49 = getelementptr inbounds [2 x i32], ptr %7, i64 0, i64 1
  %50 = load i32, ptr %49, align 4, !tbaa !9
  %51 = icmp sgt i32 %48, %50
  br i1 %51, label %52, label %55

52:                                               ; preds = %46
  %53 = getelementptr inbounds [2 x i32], ptr %7, i64 0, i64 0
  %54 = load i32, ptr %53, align 4, !tbaa !9
  br label %58

55:                                               ; preds = %46
  %56 = getelementptr inbounds [2 x i32], ptr %7, i64 0, i64 1
  %57 = load i32, ptr %56, align 4, !tbaa !9
  br label %58

58:                                               ; preds = %55, %52
  %59 = phi i32 [ %54, %52 ], [ %57, %55 ]
  %60 = add nsw i32 %59, 1
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  store i32 %60, ptr %61, align 4, !tbaa !9
  %62 = getelementptr inbounds [2 x i32], ptr %7, i64 0, i64 1
  %63 = load i32, ptr %62, align 4, !tbaa !9
  %64 = getelementptr inbounds [2 x i32], ptr %7, i64 0, i64 0
  %65 = load i32, ptr %64, align 4, !tbaa !9
  %66 = sub nsw i32 %63, %65
  %67 = load ptr, ptr %4, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.my_node, ptr %67, i32 0, i32 1
  %69 = getelementptr inbounds %struct.anon, ptr %68, i32 0, i32 1
  %70 = load i8, ptr %69, align 8, !tbaa !11
  %71 = sext i8 %70 to i32
  %72 = icmp ne i32 %66, %71
  br i1 %72, label %73, label %88

73:                                               ; preds = %58
  %74 = load ptr, ptr @stderr, align 8, !tbaa !5
  %75 = getelementptr inbounds [2 x i32], ptr %7, i64 0, i64 1
  %76 = load i32, ptr %75, align 4, !tbaa !9
  %77 = getelementptr inbounds [2 x i32], ptr %7, i64 0, i64 0
  %78 = load i32, ptr %77, align 4, !tbaa !9
  %79 = load ptr, ptr %4, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.my_node, ptr %79, i32 0, i32 1
  %81 = getelementptr inbounds %struct.anon, ptr %80, i32 0, i32 1
  %82 = load i8, ptr %81, align 8, !tbaa !11
  %83 = sext i8 %82 to i32
  %84 = load ptr, ptr %4, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.my_node, ptr %84, i32 0, i32 0
  %86 = load i32, ptr %85, align 8, !tbaa !14
  %87 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %74, ptr noundef @.str, i32 noundef %76, i32 noundef %78, i32 noundef %83, i32 noundef %86) #4
  br label %88

88:                                               ; preds = %73, %58
  %89 = load i32, ptr %6, align 4, !tbaa !9
  %90 = load ptr, ptr %4, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.my_node, ptr %90, i32 0, i32 1
  %92 = getelementptr inbounds %struct.anon, ptr %91, i32 0, i32 2
  %93 = load i32, ptr %92, align 4, !tbaa !15
  %94 = icmp ne i32 %89, %93
  br i1 %94, label %95, label %106

95:                                               ; preds = %88
  %96 = load ptr, ptr @stderr, align 8, !tbaa !5
  %97 = load ptr, ptr %4, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.my_node, ptr %97, i32 0, i32 1
  %99 = getelementptr inbounds %struct.anon, ptr %98, i32 0, i32 2
  %100 = load i32, ptr %99, align 4, !tbaa !15
  %101 = load i32, ptr %6, align 4, !tbaa !9
  %102 = load ptr, ptr %4, align 8, !tbaa !5
  %103 = getelementptr inbounds %struct.my_node, ptr %102, i32 0, i32 0
  %104 = load i32, ptr %103, align 8, !tbaa !14
  %105 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %96, ptr noundef @.str.1, i32 noundef %100, i32 noundef %101, i32 noundef %104) #4
  br label %106

106:                                              ; preds = %95, %88
  %107 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %107, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %109

108:                                              ; preds = %2
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %109

109:                                              ; preds = %108, %106
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  %110 = load i32, ptr %3, align 4
  ret i32 %110
}

; 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 i32 @fprintf(ptr noundef, ptr noundef, ...) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { 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}
!11 = !{!12, !7, i64 24}
!12 = !{!"my_node", !10, i64 0, !13, i64 8}
!13 = !{!"", !7, i64 0, !7, i64 16, !10, i64 20}
!14 = !{!12, !10, i64 0}
!15 = !{!12, !10, i64 28}


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

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

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

; Function Attrs: nofree nounwind uwtable
define dso_local i32 @check(ptr noundef readonly %0, ptr nocapture noundef writeonly %1) local_unnamed_addr #1 {
  %3 = alloca [2 x i32], align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #4
  store i64 0, ptr %3, align 8
  store i32 0, ptr %1, align 4, !tbaa !5
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %38, label %4

4:                                                ; preds = %2
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load ptr, ptr %5, align 8, !tbaa !9
  %.not24 = icmp eq ptr %6, null
  br i1 %.not24, label %10, label %7

7:                                                ; preds = %4
  %8 = call i32 @check(ptr noundef nonnull %6, ptr noundef nonnull %3)
  %9 = add nsw i32 %8, 1
  br label %10

10:                                               ; preds = %7, %4
  %.0 = phi i32 [ %9, %7 ], [ 1, %4 ]
  %11 = getelementptr inbounds i8, ptr %0, i64 16
  %12 = load ptr, ptr %11, align 8, !tbaa !9
  %.not25 = icmp eq ptr %12, null
  br i1 %.not25, label %17, label %13

13:                                               ; preds = %10
  %14 = getelementptr inbounds i8, ptr %3, i64 4
  %15 = call i32 @check(ptr noundef nonnull %12, ptr noundef nonnull %14)
  %16 = add nsw i32 %15, %.0
  br label %17

17:                                               ; preds = %13, %10
  %.1 = phi i32 [ %16, %13 ], [ %.0, %10 ]
  %18 = load i32, ptr %3, align 8
  %19 = getelementptr inbounds i8, ptr %3, i64 4
  %20 = load i32, ptr %19, align 4
  %21 = tail call i32 @llvm.smax.i32(i32 %18, i32 %20)
  %22 = add nsw i32 %21, 1
  store i32 %22, ptr %1, align 4, !tbaa !5
  %23 = sub nsw i32 %20, %18
  %24 = getelementptr inbounds i8, ptr %0, i64 24
  %25 = load i8, ptr %24, align 8, !tbaa !11
  %26 = sext i8 %25 to i32
  %.not26 = icmp eq i32 %23, %26
  br i1 %.not26, label %31, label %27

27:                                               ; preds = %17
  %28 = load ptr, ptr @stderr, align 8, !tbaa !9
  %29 = load i32, ptr %0, align 8, !tbaa !14
  %30 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %28, ptr noundef nonnull @.str, i32 noundef %20, i32 noundef %18, i32 noundef %26, i32 noundef %29) #5
  br label %31

31:                                               ; preds = %27, %17
  %32 = getelementptr inbounds i8, ptr %0, i64 28
  %33 = load i32, ptr %32, align 4, !tbaa !15
  %.not27 = icmp eq i32 %.1, %33
  br i1 %.not27, label %38, label %34

34:                                               ; preds = %31
  %35 = load ptr, ptr @stderr, align 8, !tbaa !9
  %36 = load i32, ptr %0, align 8, !tbaa !14
  %37 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %35, ptr noundef nonnull @.str.1, i32 noundef %33, i32 noundef %.1, i32 noundef %36) #5
  br label %38

38:                                               ; preds = %2, %31, %34
  %.018 = phi i32 [ %.1, %34 ], [ %.1, %31 ], [ 0, %2 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #4
  ret i32 %.018
}

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nofree 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 #2 = { 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 #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { nounwind }
attributes #5 = { cold 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 = !{!"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, !7, i64 24}
!12 = !{!"my_node", !6, i64 0, !13, i64 8}
!13 = !{!"", !7, i64 0, !7, i64 16, !6, i64 20}
!14 = !{!12, !6, i64 0}
!15 = !{!12, !6, i64 28}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass