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

; 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 @_Z4dfs2c(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 @_Z4dfs2c(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 0
  %22 = load i8, ptr %21, align 4, !tbaa !8
  %23 = sext i8 %22 to i32
  %24 = call i32 @putchar(i32 noundef %23)
  %25 = load i8, ptr %2, align 1, !tbaa !5
  %26 = sext i8 %25 to i64
  %27 = getelementptr inbounds [30 x %struct.Node], ptr @a, i64 0, i64 %26
  %28 = getelementptr inbounds %struct.Node, ptr %27, i32 0, i32 1
  %29 = getelementptr inbounds [3 x i8], ptr %28, i64 0, i64 1
  %30 = load i8, ptr %29, align 1, !tbaa !5
  %31 = icmp ne i8 %30, 0
  br i1 %31, label %32, label %39

32:                                               ; preds = %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 1
  %37 = getelementptr inbounds [3 x i8], ptr %36, i64 0, i64 1
  %38 = load i8, ptr %37, align 1, !tbaa !5
  call void @_Z4dfs2c(i8 noundef signext %38)
  br label %39

39:                                               ; preds = %32, %17
  %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 = %39
  %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 @_Z4dfs2c(i8 noundef signext %53)
  br label %54

54:                                               ; preds = %47, %39
  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 @_Z4dfs2c(i8 noundef signext %0) local_unnamed_addr #1 {
  br label %tailrecurse

tailrecurse:                                      ; preds = %14, %1
  %.tr = phi i8 [ %0, %1 ], [ %16, %14 ]
  %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 @_Z4dfs2c(i8 noundef signext %5)
  br label %7

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

13:                                               ; preds = %7
  tail call void @_Z4dfs2c(i8 noundef signext %12)
  br label %14

14:                                               ; preds = %13, %7
  %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 = %14
  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