; LLVM IR from holzschu/ios_system :: shell_cmds/locate/bigram/locate.bigram (main)

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

@buf1 = external dso_local global [4096 x i8], align 16
@buf2 = external dso_local global [4096 x i8], align 16
@stdin = external global ptr, align 8
@bigram = external dso_local global [256 x [256 x i32]], align 16
@.str = external hidden unnamed_addr constant [10 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %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 8, ptr %2) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  store ptr @buf1, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  store ptr @buf2, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  br label %7

7:                                                ; preds = %67, %0
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = load ptr, ptr @stdin, align 8, !tbaa !5
  %10 = call ptr @fgets(ptr noundef %8, i32 noundef 4096, ptr noundef %9)
  %11 = icmp ne ptr %10, null
  br i1 %11, label %12, label %68

12:                                               ; preds = %7
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %13, ptr %2, align 8, !tbaa !5
  br label %14

14:                                               ; preds = %29, %12
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = load i8, ptr %15, align 1, !tbaa !9
  %17 = zext i8 %16 to i32
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = load i8, ptr %18, align 1, !tbaa !9
  %20 = zext i8 %19 to i32
  %21 = icmp eq i32 %17, %20
  br i1 %21, label %22, label %34

22:                                               ; preds = %14
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  %24 = load i8, ptr %23, align 1, !tbaa !9
  %25 = zext i8 %24 to i32
  %26 = icmp eq i32 %25, 0
  br i1 %26, label %27, label %28

27:                                               ; preds = %22
  br label %34

28:                                               ; preds = %22
  br label %29

29:                                               ; preds = %28
  %30 = load ptr, ptr %2, align 8, !tbaa !5
  %31 = getelementptr inbounds i8, ptr %30, i32 1
  store ptr %31, ptr %2, align 8, !tbaa !5
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = getelementptr inbounds i8, ptr %32, i32 1
  store ptr %33, ptr %3, align 8, !tbaa !5
  br label %14, !llvm.loop !10

34:                                               ; preds = %27, %14
  br label %35

35:                                               ; preds = %48, %34
  %36 = load ptr, ptr %2, align 8, !tbaa !5
  %37 = load i8, ptr %36, align 1, !tbaa !9
  %38 = zext i8 %37 to i32
  %39 = icmp ne i32 %38, 0
  br i1 %39, label %40, label %46

40:                                               ; preds = %35
  %41 = load ptr, ptr %2, align 8, !tbaa !5
  %42 = getelementptr inbounds i8, ptr %41, i64 1
  %43 = load i8, ptr %42, align 1, !tbaa !9
  %44 = zext i8 %43 to i32
  %45 = icmp ne i32 %44, 0
  br label %46

46:                                               ; preds = %40, %35
  %47 = phi i1 [ false, %35 ], [ %45, %40 ]
  br i1 %47, label %48, label %62

48:                                               ; preds = %46
  %49 = load ptr, ptr %2, align 8, !tbaa !5
  %50 = load i8, ptr %49, align 1, !tbaa !9
  %51 = zext i8 %50 to i64
  %52 = getelementptr inbounds [256 x [256 x i32]], ptr @bigram, i64 0, i64 %51
  %53 = load ptr, ptr %2, align 8, !tbaa !5
  %54 = getelementptr inbounds i8, ptr %53, i64 1
  %55 = load i8, ptr %54, align 1, !tbaa !9
  %56 = zext i8 %55 to i64
  %57 = getelementptr inbounds [256 x i32], ptr %52, i64 0, i64 %56
  %58 = load i32, ptr %57, align 4, !tbaa !12
  %59 = add i32 %58, 1
  store i32 %59, ptr %57, align 4, !tbaa !12
  %60 = load ptr, ptr %2, align 8, !tbaa !5
  %61 = getelementptr inbounds i8, ptr %60, i64 2
  store ptr %61, ptr %2, align 8, !tbaa !5
  br label %35, !llvm.loop !14

62:                                               ; preds = %46
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = icmp eq ptr %63, @buf1
  br i1 %64, label %65, label %66

65:                                               ; preds = %62
  store ptr @buf2, ptr %4, align 8, !tbaa !5
  store ptr @buf1, ptr %3, align 8, !tbaa !5
  br label %67

66:                                               ; preds = %62
  store ptr @buf1, ptr %4, align 8, !tbaa !5
  store ptr @buf2, ptr %3, align 8, !tbaa !5
  br label %67

67:                                               ; preds = %66, %65
  br label %7, !llvm.loop !15

68:                                               ; preds = %7
  store i32 32, ptr %5, align 4, !tbaa !12
  br label %69

69:                                               ; preds = %101, %68
  %70 = load i32, ptr %5, align 4, !tbaa !12
  %71 = icmp ule i32 %70, 127
  br i1 %71, label %72, label %104

72:                                               ; preds = %69
  store i32 32, ptr %6, align 4, !tbaa !12
  br label %73

73:                                               ; preds = %97, %72
  %74 = load i32, ptr %6, align 4, !tbaa !12
  %75 = icmp ule i32 %74, 127
  br i1 %75, label %76, label %100

76:                                               ; preds = %73
  %77 = load i32, ptr %5, align 4, !tbaa !12
  %78 = zext i32 %77 to i64
  %79 = getelementptr inbounds [256 x [256 x i32]], ptr @bigram, i64 0, i64 %78
  %80 = load i32, ptr %6, align 4, !tbaa !12
  %81 = zext i32 %80 to i64
  %82 = getelementptr inbounds [256 x i32], ptr %79, i64 0, i64 %81
  %83 = load i32, ptr %82, align 4, !tbaa !12
  %84 = icmp ne i32 %83, 0
  br i1 %84, label %85, label %96

85:                                               ; preds = %76
  %86 = load i32, ptr %5, align 4, !tbaa !12
  %87 = zext i32 %86 to i64
  %88 = getelementptr inbounds [256 x [256 x i32]], ptr @bigram, i64 0, i64 %87
  %89 = load i32, ptr %6, align 4, !tbaa !12
  %90 = zext i32 %89 to i64
  %91 = getelementptr inbounds [256 x i32], ptr %88, i64 0, i64 %90
  %92 = load i32, ptr %91, align 4, !tbaa !12
  %93 = load i32, ptr %5, align 4, !tbaa !12
  %94 = load i32, ptr %6, align 4, !tbaa !12
  %95 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %92, i32 noundef %93, i32 noundef %94)
  br label %96

96:                                               ; preds = %85, %76
  br label %97

97:                                               ; preds = %96
  %98 = load i32, ptr %6, align 4, !tbaa !12
  %99 = add i32 %98, 1
  store i32 %99, ptr %6, align 4, !tbaa !12
  br label %73, !llvm.loop !16

100:                                              ; preds = %73
  br label %101

101:                                              ; preds = %100
  %102 = load i32, ptr %5, align 4, !tbaa !12
  %103 = add i32 %102, 1
  store i32 %103, ptr %5, align 4, !tbaa !12
  br label %69, !llvm.loop !17

104:                                              ; preds = %69
  call void @exit(i32 noundef 0) #5
  unreachable
}

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

declare ptr @fgets(ptr noundef, i32 noundef, ptr noundef) #2

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

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #3

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 = { "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 = { 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 #4 = { nounwind }
attributes #5 = { 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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = distinct !{!14, !11}
!15 = distinct !{!15, !11}
!16 = distinct !{!16, !11}
!17 = distinct !{!17, !11}


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

@buf1 = external dso_local global [4096 x i8], align 16
@buf2 = external dso_local global [4096 x i8], align 16
@stdin = external local_unnamed_addr global ptr, align 8
@bigram = external dso_local local_unnamed_addr global [256 x [256 x i32]], align 16
@.str = external hidden unnamed_addr constant [10 x i8], align 1

; Function Attrs: noreturn nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = load ptr, ptr @stdin, align 8, !tbaa !5
  %2 = tail call ptr @fgets(ptr noundef nonnull @buf2, i32 noundef 4096, ptr noundef %1)
  %.not44 = icmp eq ptr %2, null
  br i1 %.not44, label %.preheader.preheader, label %.preheader35

.preheader35:                                     ; preds = %0, %.critedge
  %.02346 = phi ptr [ %buf2.buf1, %.critedge ], [ @buf2, %0 ]
  %.02445 = phi ptr [ %buf1.buf2, %.critedge ], [ @buf1, %0 ]
  %3 = load i8, ptr %.02346, align 1, !tbaa !9
  %4 = load i8, ptr %.02445, align 1, !tbaa !9
  %5 = icmp ne i8 %3, %4
  %6 = icmp eq i8 %3, 0
  %or.cond36 = or i1 %6, %5
  br i1 %or.cond36, label %.preheader34, label %.lr.ph

.preheader34:                                     ; preds = %.lr.ph, %.preheader35
  %.026.lcssa = phi ptr [ %.02346, %.preheader35 ], [ %7, %.lr.ph ]
  %.lcssa = phi i8 [ %3, %.preheader35 ], [ %9, %.lr.ph ]
  %.not3140 = icmp eq i8 %.lcssa, 0
  br i1 %.not3140, label %.critedge, label %.lr.ph42

.lr.ph:                                           ; preds = %.preheader35, %.lr.ph
  %.12538 = phi ptr [ %8, %.lr.ph ], [ %.02445, %.preheader35 ]
  %.02637 = phi ptr [ %7, %.lr.ph ], [ %.02346, %.preheader35 ]
  %7 = getelementptr inbounds i8, ptr %.02637, i64 1
  %8 = getelementptr inbounds i8, ptr %.12538, i64 1
  %9 = load i8, ptr %7, align 1, !tbaa !9
  %10 = load i8, ptr %8, align 1, !tbaa !9
  %11 = icmp ne i8 %9, %10
  %12 = icmp eq i8 %9, 0
  %or.cond = or i1 %12, %11
  br i1 %or.cond, label %.preheader34, label %.lr.ph, !llvm.loop !10

.lr.ph42:                                         ; preds = %.preheader34, %16
  %.12741 = phi ptr [ %22, %16 ], [ %.026.lcssa, %.preheader34 ]
  %13 = phi i8 [ %.pr, %16 ], [ %.lcssa, %.preheader34 ]
  %14 = getelementptr inbounds i8, ptr %.12741, i64 1
  %15 = load i8, ptr %14, align 1, !tbaa !9
  %.not32 = icmp eq i8 %15, 0
  br i1 %.not32, label %.critedge, label %16

16:                                               ; preds = %.lr.ph42
  %17 = zext i8 %13 to i64
  %18 = zext i8 %15 to i64
  %19 = getelementptr inbounds [256 x [256 x i32]], ptr @bigram, i64 0, i64 %17, i64 %18
  %20 = load i32, ptr %19, align 4, !tbaa !12
  %21 = add i32 %20, 1
  store i32 %21, ptr %19, align 4, !tbaa !12
  %22 = getelementptr inbounds i8, ptr %.12741, i64 2
  %.pr = load i8, ptr %22, align 1, !tbaa !9
  %.not31 = icmp eq i8 %.pr, 0
  br i1 %.not31, label %.critedge, label %.lr.ph42, !llvm.loop !14

.critedge:                                        ; preds = %.lr.ph42, %16, %.preheader34
  %23 = icmp eq ptr %.02346, @buf1
  %buf1.buf2 = select i1 %23, ptr @buf1, ptr @buf2
  %buf2.buf1 = select i1 %23, ptr @buf2, ptr @buf1
  %24 = load ptr, ptr @stdin, align 8, !tbaa !5
  %25 = tail call ptr @fgets(ptr noundef nonnull %buf2.buf1, i32 noundef 4096, ptr noundef %24)
  %.not = icmp eq ptr %25, null
  br i1 %.not, label %.preheader.preheader, label %.preheader35, !llvm.loop !15

.preheader.preheader:                             ; preds = %.critedge, %0
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %34
  %indvars.iv52 = phi i64 [ %indvars.iv.next53, %34 ], [ 32, %.preheader.preheader ]
  %26 = trunc nuw nsw i64 %indvars.iv52 to i32
  br label %27

27:                                               ; preds = %.preheader, %33
  %indvars.iv = phi i64 [ 32, %.preheader ], [ %indvars.iv.next, %33 ]
  %28 = getelementptr inbounds [256 x [256 x i32]], ptr @bigram, i64 0, i64 %indvars.iv52, i64 %indvars.iv
  %29 = load i32, ptr %28, align 4, !tbaa !12
  %.not30 = icmp eq i32 %29, 0
  br i1 %.not30, label %33, label %30

30:                                               ; preds = %27
  %31 = trunc nuw nsw i64 %indvars.iv to i32
  %32 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %29, i32 noundef %26, i32 noundef %31)
  br label %33

33:                                               ; preds = %27, %30
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 128
  br i1 %exitcond.not, label %34, label %27, !llvm.loop !16

34:                                               ; preds = %33
  %indvars.iv.next53 = add nuw nsw i64 %indvars.iv52, 1
  %exitcond55.not = icmp eq i64 %indvars.iv.next53, 128
  br i1 %exitcond55.not, label %35, label %.preheader, !llvm.loop !17

35:                                               ; preds = %34
  tail call void @exit(i32 noundef 0) #3
  unreachable
}

; Function Attrs: nofree nounwind
declare noundef ptr @fgets(ptr noundef, i32 noundef, ptr nocapture noundef) local_unnamed_addr #1

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

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #2

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 = { 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 #2 = { 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 #3 = { 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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = distinct !{!14, !11}
!15 = distinct !{!15, !11}
!16 = distinct !{!16, !11}
!17 = distinct !{!17, !11}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass