; LLVM IR from tangjz/acm-icpc :: buaa/oj3rd/948.ll (Z4dfs3c)

; 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.Node = type { i8, [3 x i8] }

@a = external dso_local global [30 x %struct.Node], align 16

; Function Attrs: inlinehint mustprogress uwtable
declare i32 @putchar(i32 noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z4dfs3c(i8 noundef signext %0) #1 {
  %2 = alloca i8, align 1
  store i8 %0, ptr %2, align 1, !tbaa !5
  %3 = load i8, ptr %2, align 1, !tbaa !5
  %4 = sext i8 %3 to i64
  %5 = getelementptr inbounds [30 x %struct.Node], ptr @a, i64 0, i64 %4
  %6 = getelementptr inbounds %struct.Node, ptr %5, i32 0, i32 1
  %7 = getelementptr inbounds [3 x i8], ptr %6, i64 0, i64 0
  %8 = load i8, ptr %7, align 1, !tbaa !5
  %9 = icmp ne i8 %8, 0
  br i1 %9, label %10, label %17

10:                                               ; preds = %1
  %11 = load i8, ptr %2, align 1, !tbaa !5
  %12 = sext i8 %11 to i64
  %13 = getelementptr inbounds [30 x %struct.Node], ptr @a, i64 0, i64 %12
  %14 = getelementptr inbounds %struct.Node, ptr %13, i32 0, i32 1
  %15 = getelementptr inbounds [3 x i8], ptr %14, i64 0, i64 0
  %16 = load i8, ptr %15, align 1, !tbaa !5
  call void @_Z4dfs3c(i8 noundef signext %16)
  br label %17

17:                                               ; preds = %10, %1
  %18 = load i8, ptr %2, align 1, !tbaa !5
  %19 = sext i8 %18 to i64
  %20 = getelementptr inbounds [30 x %struct.Node], ptr @a, i64 0, i64 %19
  %21 = getelementptr inbounds %struct.Node, ptr %20, i32 0, i32 1
  %22 = getelementptr inbounds [3 x i8], ptr %21, i64 0, i64 1
  %23 = load i8, ptr %22, align 1, !tbaa !5
  %24 = icmp ne i8 %23, 0
  br i1 %24, label %25, label %32

25:                                               ; preds = %17
  %26 = load i8, ptr %2, align 1, !tbaa !5
  %27 = sext i8 %26 to i64
  %28 = getelementptr inbounds [30 x %struct.Node], ptr @a, i64 0, i64 %27
  %29 = getelementptr inbounds %struct.Node, ptr %28, i32 0, i32 1
  %30 = getelementptr inbounds [3 x i8], ptr %29, i64 0, i64 1
  %31 = load i8, ptr %30, align 1, !tbaa !5
  call void @_Z4dfs3c(i8 noundef signext %31)
  br label %32

32:                                               ; preds = %25, %17
  %33 = load i8, ptr %2, align 1, !tbaa !5
  %34 = sext i8 %33 to i64
  %35 = getelementptr inbounds [30 x %struct.Node], ptr @a, i64 0, i64 %34
  %36 = getelementptr inbounds %struct.Node, ptr %35, i32 0, i32 0
  %37 = load i8, ptr %36, align 4, !tbaa !8
  %38 = sext i8 %37 to i32
  %39 = call i32 @putchar(i32 noundef %38)
  %40 = load i8, ptr %2, align 1, !tbaa !5
  %41 = sext i8 %40 to i64
  %42 = getelementptr inbounds [30 x %struct.Node], ptr @a, i64 0, i64 %41
  %43 = getelementptr inbounds %struct.Node, ptr %42, i32 0, i32 1
  %44 = getelementptr inbounds [3 x i8], ptr %43, i64 0, i64 2
  %45 = load i8, ptr %44, align 1, !tbaa !5
  %46 = icmp ne i8 %45, 0
  br i1 %46, label %47, label %54

47:                                               ; preds = %32
  %48 = load i8, ptr %2, align 1, !tbaa !5
  %49 = sext i8 %48 to i64
  %50 = getelementptr inbounds [30 x %struct.Node], ptr @a, i64 0, i64 %49
  %51 = getelementptr inbounds %struct.Node, ptr %50, i32 0, i32 1
  %52 = getelementptr inbounds [3 x i8], ptr %51, i64 0, i64 2
  %53 = load i8, ptr %52, align 1, !tbaa !5
  call void @_Z4dfs3c(i8 noundef signext %53)
  br label %54

54:                                               ; preds = %47, %32
  ret void
}

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

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !6, i64 0}
!9 = !{!"_ZTS4Node", !6, i64 0, !6, i64 1}


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

%struct.Node = type { i8, [3 x i8] }

@a = external dso_local local_unnamed_addr global [30 x %struct.Node], align 16

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

; Function Attrs: mustprogress nofree nounwind uwtable
define dso_local void @_Z4dfs3c(i8 noundef signext %0) local_unnamed_addr #1 {
  br label %tailrecurse

tailrecurse:                                      ; preds = %11, %1
  %.tr = phi i8 [ %0, %1 ], [ %16, %11 ]
  %2 = sext i8 %.tr to i64
  %3 = getelementptr inbounds [30 x %struct.Node], ptr @a, i64 0, i64 %2
  %4 = getelementptr inbounds i8, ptr %3, i64 1
  %5 = load i8, ptr %4, align 1, !tbaa !5
  %.not = icmp eq i8 %5, 0
  br i1 %.not, label %7, label %6

6:                                                ; preds = %tailrecurse
  tail call void @_Z4dfs3c(i8 noundef signext %5)
  br label %7

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

10:                                               ; preds = %7
  tail call void @_Z4dfs3c(i8 noundef signext %9)
  br label %11

11:                                               ; preds = %10, %7
  %12 = load i8, ptr %3, align 4, !tbaa !8
  %13 = sext i8 %12 to i32
  %14 = tail call i32 @putchar(i32 noundef %13)
  %15 = getelementptr inbounds i8, ptr %3, i64 3
  %16 = load i8, ptr %15, align 1, !tbaa !5
  %.not10 = icmp eq i8 %16, 0
  br i1 %.not10, label %17, label %tailrecurse

17:                                               ; preds = %11
  ret void
}

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

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !6, i64 0}
!9 = !{!"_ZTS4Node", !6, i64 0, !6, i64 1}


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