; LLVM IR from attractivechaos/klib :: test (krmq_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, i32, %struct.anon }
%struct.anon = type { [2 x ptr], ptr, i8, i32 }

@.str.6 = external hidden unnamed_addr constant [9 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 @print_tree(ptr noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 1, ptr %4, align 4, !tbaa !9
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = icmp eq ptr %6, null
  br i1 %7, label %8, label %9

8:                                                ; preds = %1
  store i32 0, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %78

9:                                                ; preds = %1
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.my_node, ptr %10, i32 0, i32 2
  %12 = getelementptr inbounds %struct.anon, ptr %11, i32 0, i32 0
  %13 = getelementptr inbounds [2 x ptr], ptr %12, i64 0, i64 0
  %14 = load ptr, ptr %13, align 8, !tbaa !5
  %15 = icmp ne ptr %14, null
  br i1 %15, label %23, label %16

16:                                               ; preds = %9
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.my_node, ptr %17, i32 0, i32 2
  %19 = getelementptr inbounds %struct.anon, ptr %18, i32 0, i32 0
  %20 = getelementptr inbounds [2 x ptr], ptr %19, i64 0, i64 1
  %21 = load ptr, ptr %20, align 8, !tbaa !5
  %22 = icmp ne ptr %21, null
  br i1 %22, label %23, label %63

23:                                               ; preds = %16, %9
  %24 = call i32 @putchar(i32 noundef 40)
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.my_node, ptr %25, i32 0, i32 2
  %27 = getelementptr inbounds %struct.anon, ptr %26, i32 0, i32 0
  %28 = getelementptr inbounds [2 x ptr], ptr %27, i64 0, i64 0
  %29 = load ptr, ptr %28, align 8, !tbaa !5
  %30 = icmp ne ptr %29, null
  br i1 %30, label %31, label %40

31:                                               ; preds = %23
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.my_node, ptr %32, i32 0, i32 2
  %34 = getelementptr inbounds %struct.anon, ptr %33, i32 0, i32 0
  %35 = getelementptr inbounds [2 x ptr], ptr %34, i64 0, i64 0
  %36 = load ptr, ptr %35, align 8, !tbaa !5
  %37 = call i32 @print_tree(ptr noundef %36)
  %38 = load i32, ptr %4, align 4, !tbaa !9
  %39 = add nsw i32 %38, %37
  store i32 %39, ptr %4, align 4, !tbaa !9
  br label %42

40:                                               ; preds = %23
  %41 = call i32 @putchar(i32 noundef 46)
  br label %42

42:                                               ; preds = %40, %31
  %43 = call i32 @putchar(i32 noundef 44)
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.my_node, ptr %44, i32 0, i32 2
  %46 = getelementptr inbounds %struct.anon, ptr %45, i32 0, i32 0
  %47 = getelementptr inbounds [2 x ptr], ptr %46, i64 0, i64 1
  %48 = load ptr, ptr %47, align 8, !tbaa !5
  %49 = icmp ne ptr %48, null
  br i1 %49, label %50, label %59

50:                                               ; preds = %42
  %51 = load ptr, ptr %3, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.my_node, ptr %51, i32 0, i32 2
  %53 = getelementptr inbounds %struct.anon, ptr %52, i32 0, i32 0
  %54 = getelementptr inbounds [2 x ptr], ptr %53, i64 0, i64 1
  %55 = load ptr, ptr %54, align 8, !tbaa !5
  %56 = call i32 @print_tree(ptr noundef %55)
  %57 = load i32, ptr %4, align 4, !tbaa !9
  %58 = add nsw i32 %57, %56
  store i32 %58, ptr %4, align 4, !tbaa !9
  br label %61

59:                                               ; preds = %42
  %60 = call i32 @putchar(i32 noundef 46)
  br label %61

61:                                               ; preds = %59, %50
  %62 = call i32 @putchar(i32 noundef 41)
  br label %63

63:                                               ; preds = %61, %16
  %64 = load ptr, ptr %3, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.my_node, ptr %64, i32 0, i32 0
  %66 = load i32, ptr %65, align 8, !tbaa !11
  %67 = load ptr, ptr %3, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.my_node, ptr %67, i32 0, i32 1
  %69 = load i32, ptr %68, align 4, !tbaa !14
  %70 = load ptr, ptr %3, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.my_node, ptr %70, i32 0, i32 2
  %72 = getelementptr inbounds %struct.anon, ptr %71, i32 0, i32 1
  %73 = load ptr, ptr %72, align 8, !tbaa !15
  %74 = getelementptr inbounds %struct.my_node, ptr %73, i32 0, i32 1
  %75 = load i32, ptr %74, align 4, !tbaa !14
  %76 = call i32 (ptr, ...) @printf(ptr noundef @.str.6, i32 noundef %66, i32 noundef %69, i32 noundef %75)
  %77 = load i32, ptr %4, align 4, !tbaa !9
  store i32 %77, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %78

78:                                               ; preds = %63, %8
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  %79 = load i32, ptr %2, align 4
  ret i32 %79
}

; Function Attrs: inlinehint nounwind uwtable
declare i32 @putchar(i32 noundef) #2

declare i32 @printf(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 = { inlinehint 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 = { "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, !10, i64 0}
!12 = !{!"my_node", !10, i64 0, !10, i64 4, !13, i64 8}
!13 = !{!"", !7, i64 0, !6, i64 16, !7, i64 24, !10, i64 28}
!14 = !{!12, !10, i64 4}
!15 = !{!12, !6, i64 24}


; 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.6 = external hidden unnamed_addr constant [9 x i8], align 1

; Function Attrs: nofree nounwind uwtable
define dso_local i32 @print_tree(ptr noundef readonly %0) local_unnamed_addr #0 {
  %2 = icmp eq ptr %0, null
  br i1 %2, label %37, label %3

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

6:                                                ; preds = %3
  %7 = getelementptr inbounds i8, ptr %0, i64 16
  %8 = load ptr, ptr %7, align 8, !tbaa !5
  %.not17 = icmp eq ptr %8, null
  br i1 %.not17, label %28, label %9

9:                                                ; preds = %6, %3
  %10 = tail call i32 @putchar(i32 noundef 40)
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %.not18 = icmp eq ptr %11, null
  br i1 %.not18, label %15, label %12

12:                                               ; preds = %9
  %13 = tail call i32 @print_tree(ptr noundef nonnull %11)
  %14 = add nsw i32 %13, 1
  br label %17

15:                                               ; preds = %9
  %16 = tail call i32 @putchar(i32 noundef 46)
  br label %17

17:                                               ; preds = %15, %12
  %.0 = phi i32 [ %14, %12 ], [ 1, %15 ]
  %18 = tail call i32 @putchar(i32 noundef 44)
  %19 = getelementptr inbounds i8, ptr %0, i64 16
  %20 = load ptr, ptr %19, align 8, !tbaa !5
  %.not19 = icmp eq ptr %20, null
  br i1 %.not19, label %24, label %21

21:                                               ; preds = %17
  %22 = tail call i32 @print_tree(ptr noundef nonnull %20)
  %23 = add nsw i32 %22, %.0
  br label %26

24:                                               ; preds = %17
  %25 = tail call i32 @putchar(i32 noundef 46)
  br label %26

26:                                               ; preds = %24, %21
  %.1 = phi i32 [ %23, %21 ], [ %.0, %24 ]
  %27 = tail call i32 @putchar(i32 noundef 41)
  br label %28

28:                                               ; preds = %26, %6
  %.2 = phi i32 [ %.1, %26 ], [ 1, %6 ]
  %29 = load i32, ptr %0, align 8, !tbaa !9
  %30 = getelementptr inbounds i8, ptr %0, i64 4
  %31 = load i32, ptr %30, align 4, !tbaa !13
  %32 = getelementptr inbounds i8, ptr %0, i64 24
  %33 = load ptr, ptr %32, align 8, !tbaa !14
  %34 = getelementptr inbounds i8, ptr %33, i64 4
  %35 = load i32, ptr %34, align 4, !tbaa !13
  %36 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6, i32 noundef %29, i32 noundef %31, i32 noundef %35)
  br label %37

37:                                               ; preds = %1, %28
  %.013 = phi i32 [ %.2, %28 ], [ 0, %1 ]
  ret i32 %.013
}

; Function Attrs: inlinehint nofree nounwind uwtable
declare noundef i32 @putchar(i32 noundef) local_unnamed_addr #1

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

attributes #0 = { 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 #1 = { inlinehint 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" }

!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, !11, i64 0}
!10 = !{!"my_node", !11, i64 0, !11, i64 4, !12, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!"", !7, i64 0, !6, i64 16, !7, i64 24, !11, i64 28}
!13 = !{!10, !11, i64 4}
!14 = !{!10, !6, i64 24}


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