; LLVM IR from pingcap/tidb-bench :: tpcds/tools (checksum)

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

@stdin = external global ptr, align 8
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@stderr = external global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [80 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local zeroext i16 @GetCCITT(i16 noundef zeroext, i16 noundef zeroext) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @main(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  %14 = alloca i16, align 2
  %15 = alloca i32, align 4
  store i32 0, ptr %3, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  store i64 0, ptr %10, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  store i64 0, ptr %11, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  store i64 0, ptr %12, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #5
  store i64 0, ptr %13, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 2, ptr %14) #5
  store i16 0, ptr %14, align 2, !tbaa !13
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = icmp slt i32 %16, 2
  br i1 %17, label %18, label %20

18:                                               ; preds = %2
  %19 = load ptr, ptr @stdin, align 8, !tbaa !9
  store ptr %19, ptr %6, align 8, !tbaa !9
  br label %33

20:                                               ; preds = %2
  %21 = load ptr, ptr %5, align 8, !tbaa !9
  %22 = getelementptr inbounds ptr, ptr %21, i64 1
  %23 = load ptr, ptr %22, align 8, !tbaa !9
  %24 = call noalias ptr @fopen64(ptr noundef %23, ptr noundef @.str)
  store ptr %24, ptr %6, align 8, !tbaa !9
  %25 = icmp eq ptr %24, null
  br i1 %25, label %26, label %32

26:                                               ; preds = %20
  %27 = load ptr, ptr @stderr, align 8, !tbaa !9
  %28 = load ptr, ptr %5, align 8, !tbaa !9
  %29 = getelementptr inbounds ptr, ptr %28, i64 1
  %30 = load ptr, ptr %29, align 8, !tbaa !9
  %31 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %27, ptr noundef @.str.1, ptr noundef %30) #5
  store i32 1, ptr %3, align 4
  store i32 1, ptr %15, align 4
  br label %104

32:                                               ; preds = %20
  br label %33

33:                                               ; preds = %32, %18
  %34 = call noalias ptr @malloc(i64 noundef 32766) #6
  store ptr %34, ptr %7, align 8, !tbaa !9
  %35 = icmp eq ptr %34, null
  br i1 %35, label %36, label %39

36:                                               ; preds = %33
  %37 = load ptr, ptr @stderr, align 8, !tbaa !9
  %38 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %37, ptr noundef @.str.2) #5
  store i32 1, ptr %3, align 4
  store i32 1, ptr %15, align 4
  br label %104

39:                                               ; preds = %33
  br label %40

40:                                               ; preds = %103, %61, %39
  %41 = load ptr, ptr %7, align 8, !tbaa !9
  %42 = load ptr, ptr %6, align 8, !tbaa !9
  %43 = call i64 @fread(ptr noundef %41, i64 noundef 1, i64 noundef 32766, ptr noundef %42)
  store i64 %43, ptr %8, align 8, !tbaa !15
  %44 = load i64, ptr %8, align 8, !tbaa !15
  %45 = icmp eq i64 %44, 0
  br i1 %45, label %46, label %62

46:                                               ; preds = %40
  %47 = load ptr, ptr %6, align 8, !tbaa !9
  %48 = call i32 @feof(ptr noundef %47) #5
  %49 = icmp ne i32 %48, 0
  br i1 %49, label %50, label %61

50:                                               ; preds = %46
  %51 = load ptr, ptr %5, align 8, !tbaa !9
  %52 = getelementptr inbounds ptr, ptr %51, i64 1
  %53 = load ptr, ptr %52, align 8, !tbaa !9
  %54 = load i16, ptr %14, align 2, !tbaa !13
  %55 = zext i16 %54 to i32
  %56 = load i64, ptr %10, align 8, !tbaa !11
  %57 = load i64, ptr %11, align 8, !tbaa !11
  %58 = load i64, ptr %13, align 8, !tbaa !11
  %59 = load i64, ptr %12, align 8, !tbaa !11
  %60 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, ptr noundef %53, i32 noundef %55, i64 noundef %56, i64 noundef %57, i64 noundef %58, i64 noundef %59)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %15, align 4
  br label %104

61:                                               ; preds = %46
  br label %40

62:                                               ; preds = %40
  store i64 0, ptr %9, align 8, !tbaa !15
  br label %63

63:                                               ; preds = %100, %62
  %64 = load i64, ptr %9, align 8, !tbaa !15
  %65 = load i64, ptr %8, align 8, !tbaa !15
  %66 = icmp ult i64 %64, %65
  br i1 %66, label %67, label %103

67:                                               ; preds = %63
  %68 = load i64, ptr %12, align 8, !tbaa !11
  %69 = add nsw i64 %68, 1
  store i64 %69, ptr %12, align 8, !tbaa !11
  %70 = load ptr, ptr %7, align 8, !tbaa !9
  %71 = load i64, ptr %9, align 8, !tbaa !15
  %72 = getelementptr inbounds i8, ptr %70, i64 %71
  %73 = load i8, ptr %72, align 1, !tbaa !17
  %74 = sext i8 %73 to i32
  switch i32 %74, label %91 [
    i32 10, label %75
    i32 13, label %78
    i32 124, label %81
  ]

75:                                               ; preds = %67
  %76 = load i64, ptr %10, align 8, !tbaa !11
  %77 = add nsw i64 %76, 1
  store i64 %77, ptr %10, align 8, !tbaa !11
  br label %99

78:                                               ; preds = %67
  %79 = load i64, ptr %11, align 8, !tbaa !11
  %80 = add nsw i64 %79, 1
  store i64 %80, ptr %11, align 8, !tbaa !11
  br label %99

81:                                               ; preds = %67
  %82 = load i64, ptr %13, align 8, !tbaa !11
  %83 = add nsw i64 %82, 1
  store i64 %83, ptr %13, align 8, !tbaa !11
  %84 = load i16, ptr %14, align 2, !tbaa !13
  %85 = load ptr, ptr %7, align 8, !tbaa !9
  %86 = load i64, ptr %9, align 8, !tbaa !15
  %87 = getelementptr inbounds i8, ptr %85, i64 %86
  %88 = load i8, ptr %87, align 1, !tbaa !17
  %89 = sext i8 %88 to i16
  %90 = call zeroext i16 @GetCCITT(i16 noundef zeroext %84, i16 noundef zeroext %89)
  store i16 %90, ptr %14, align 2, !tbaa !13
  br label %99

91:                                               ; preds = %67
  %92 = load i16, ptr %14, align 2, !tbaa !13
  %93 = load ptr, ptr %7, align 8, !tbaa !9
  %94 = load i64, ptr %9, align 8, !tbaa !15
  %95 = getelementptr inbounds i8, ptr %93, i64 %94
  %96 = load i8, ptr %95, align 1, !tbaa !17
  %97 = sext i8 %96 to i16
  %98 = call zeroext i16 @GetCCITT(i16 noundef zeroext %92, i16 noundef zeroext %97)
  store i16 %98, ptr %14, align 2, !tbaa !13
  br label %99

99:                                               ; preds = %91, %81, %78, %75
  br label %100

100:                                              ; preds = %99
  %101 = load i64, ptr %9, align 8, !tbaa !15
  %102 = add i64 %101, 1
  store i64 %102, ptr %9, align 8, !tbaa !15
  br label %63, !llvm.loop !18

103:                                              ; preds = %63
  br label %40

104:                                              ; preds = %50, %36, %26
  call void @llvm.lifetime.end.p0(i64 2, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  %105 = load i32, ptr %3, align 4
  ret i32 %105
}

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

declare noalias ptr @fopen64(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #3

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #4

declare i64 @fread(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #2

; Function Attrs: nounwind
declare i32 @feof(ptr noundef) #3

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

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

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 = { 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 allocsize(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 #5 = { nounwind }
attributes #6 = { nounwind allocsize(0) }

!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, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"short", !7, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"long", !7, i64 0}
!17 = !{!7, !7, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


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

@stdin = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@stderr = external local_unnamed_addr global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [80 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local zeroext i16 @GetCCITT(i16 noundef zeroext, i16 noundef zeroext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @main(i32 noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = icmp slt i32 %0, 2
  br i1 %3, label %4, label %6

4:                                                ; preds = %2
  %5 = load ptr, ptr @stdin, align 8, !tbaa !5
  br label %15

6:                                                ; preds = %2
  %7 = getelementptr inbounds i8, ptr %1, i64 8
  %8 = load ptr, ptr %7, align 8, !tbaa !5
  %9 = tail call noalias ptr @fopen64(ptr noundef %8, ptr noundef nonnull @.str)
  %10 = icmp eq ptr %9, null
  br i1 %10, label %11, label %15

11:                                               ; preds = %6
  %12 = load ptr, ptr @stderr, align 8, !tbaa !5
  %13 = load ptr, ptr %7, align 8, !tbaa !5
  %14 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %12, ptr noundef nonnull @.str.1, ptr noundef %13) #3
  br label %46

15:                                               ; preds = %6, %4
  %.041 = phi ptr [ %5, %4 ], [ %9, %6 ]
  %16 = tail call noalias dereferenceable_or_null(32766) ptr @malloc(i64 noundef 32766) #4
  %17 = icmp eq ptr %16, null
  br i1 %17, label %18, label %.outer

18:                                               ; preds = %15
  %19 = load ptr, ptr @stderr, align 8, !tbaa !5
  %20 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %19, ptr noundef nonnull @.str.2) #3
  br label %46

.outer.loopexit:                                  ; preds = %44
  %21 = add i64 %.031.ph, %23
  br label %.outer, !llvm.loop !9

.outer:                                           ; preds = %15, %.outer.loopexit
  %.036.ph = phi i64 [ %.238, %.outer.loopexit ], [ 0, %15 ]
  %.033.ph = phi i64 [ %.235, %.outer.loopexit ], [ 0, %15 ]
  %.031.ph = phi i64 [ %21, %.outer.loopexit ], [ 0, %15 ]
  %.028.ph = phi i64 [ %.230, %.outer.loopexit ], [ 0, %15 ]
  %.0.ph = phi i16 [ %.2, %.outer.loopexit ], [ 0, %15 ]
  br label %22

22:                                               ; preds = %.outer, %25
  %23 = tail call i64 @fread(ptr noundef nonnull %16, i64 noundef 1, i64 noundef 32766, ptr noundef %.041)
  %24 = icmp eq i64 %23, 0
  br i1 %24, label %25, label %.preheader

25:                                               ; preds = %22
  %26 = tail call i32 @feof(ptr noundef %.041) #5
  %.not = icmp eq i32 %26, 0
  br i1 %.not, label %22, label %27

27:                                               ; preds = %25
  %28 = getelementptr inbounds i8, ptr %1, i64 8
  %29 = load ptr, ptr %28, align 8, !tbaa !5
  %30 = zext i16 %.0.ph to i32
  %31 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, ptr noundef %29, i32 noundef %30, i64 noundef %.036.ph, i64 noundef %.033.ph, i64 noundef %.028.ph, i64 noundef %.031.ph)
  br label %46

.preheader:                                       ; preds = %22, %44
  %.151 = phi i16 [ %.2, %44 ], [ %.0.ph, %22 ]
  %.12950 = phi i64 [ %.230, %44 ], [ %.028.ph, %22 ]
  %.13448 = phi i64 [ %.235, %44 ], [ %.033.ph, %22 ]
  %.13747 = phi i64 [ %.238, %44 ], [ %.036.ph, %22 ]
  %.03946 = phi i64 [ %45, %44 ], [ 0, %22 ]
  %32 = getelementptr inbounds i8, ptr %16, i64 %.03946
  %33 = load i8, ptr %32, align 1, !tbaa !11
  switch i8 %33, label %41 [
    i8 10, label %34
    i8 13, label %36
    i8 124, label %38
  ]

34:                                               ; preds = %.preheader
  %35 = add nsw i64 %.13747, 1
  br label %44

36:                                               ; preds = %.preheader
  %37 = add nsw i64 %.13448, 1
  br label %44

38:                                               ; preds = %.preheader
  %39 = add nsw i64 %.12950, 1
  %40 = tail call zeroext i16 @GetCCITT(i16 noundef zeroext %.151, i16 noundef zeroext 124)
  br label %44

41:                                               ; preds = %.preheader
  %42 = sext i8 %33 to i16
  %43 = tail call zeroext i16 @GetCCITT(i16 noundef zeroext %.151, i16 noundef zeroext %42)
  br label %44

44:                                               ; preds = %34, %36, %38, %41
  %.238 = phi i64 [ %.13747, %41 ], [ %.13747, %38 ], [ %.13747, %36 ], [ %35, %34 ]
  %.235 = phi i64 [ %.13448, %41 ], [ %.13448, %38 ], [ %37, %36 ], [ %.13448, %34 ]
  %.230 = phi i64 [ %.12950, %41 ], [ %39, %38 ], [ %.12950, %36 ], [ %.12950, %34 ]
  %.2 = phi i16 [ %43, %41 ], [ %40, %38 ], [ %.151, %36 ], [ %.151, %34 ]
  %45 = add nuw i64 %.03946, 1
  %exitcond.not = icmp eq i64 %45, %23
  br i1 %exitcond.not, label %.outer.loopexit, label %.preheader, !llvm.loop !9

46:                                               ; preds = %27, %18, %11
  %.040 = phi i32 [ 1, %18 ], [ 0, %27 ], [ 1, %11 ]
  ret i32 %.040
}

; Function Attrs: nofree nounwind
declare noalias noundef ptr @fopen64(ptr nocapture noundef readonly, ptr nocapture noundef readonly) local_unnamed_addr #1

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

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #2

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

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

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

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 = { 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 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { cold nounwind }
attributes #4 = { nounwind allocsize(0) }
attributes #5 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!7, !7, i64 0}


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