; LLVM IR from davidesantangelo/krep :: krep (match_result_add)

; 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.match_result_t = type { ptr, i64, i64 }
%struct.match_position_t = type { i64, i64 }

@stderr = external global ptr, align 8
@.str.3 = external hidden unnamed_addr constant [47 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [66 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [41 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 allocsize(0)
declare noalias ptr @malloc(i64 noundef) #1

declare void @perror(ptr noundef) #2

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

; Function Attrs: inlinehint nounwind uwtable
define dso_local zeroext i1 @match_result_add(ptr noundef %0, i64 noundef %1, i64 noundef %2) #4 {
  %4 = alloca i1, align 1
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca i64, align 8
  %11 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store i64 %2, ptr %7, align 8, !tbaa !9
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %15, label %14

14:                                               ; preds = %3
  store i1 false, ptr %4, align 1
  br label %114

15:                                               ; preds = %3
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.match_result_t, ptr %16, i32 0, i32 1
  %18 = load i64, ptr %17, align 8, !tbaa !11
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.match_result_t, ptr %19, i32 0, i32 2
  %21 = load i64, ptr %20, align 8, !tbaa !13
  %22 = icmp uge i64 %18, %21
  br i1 %22, label %23, label %91

23:                                               ; preds = %15
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.match_result_t, ptr %24, i32 0, i32 2
  %26 = load i64, ptr %25, align 8, !tbaa !13
  %27 = icmp eq i64 %26, 0
  br i1 %27, label %28, label %46

28:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #6
  store i64 16, ptr %8, align 8, !tbaa !9
  %29 = load i64, ptr %8, align 8, !tbaa !9
  %30 = mul i64 %29, 16
  %31 = call noalias ptr @malloc(i64 noundef %30) #7
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.match_result_t, ptr %32, i32 0, i32 0
  store ptr %31, ptr %33, align 8, !tbaa !14
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.match_result_t, ptr %34, i32 0, i32 0
  %36 = load ptr, ptr %35, align 8, !tbaa !14
  %37 = icmp ne ptr %36, null
  br i1 %37, label %39, label %38

38:                                               ; preds = %28
  call void @perror(ptr noundef @.str.3)
  store i1 false, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %43

39:                                               ; preds = %28
  %40 = load i64, ptr %8, align 8, !tbaa !9
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.match_result_t, ptr %41, i32 0, i32 2
  store i64 %40, ptr %42, align 8, !tbaa !13
  store i32 0, ptr %9, align 4
  br label %43

43:                                               ; preds = %39, %38
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #6
  %44 = load i32, ptr %9, align 4
  switch i32 %44, label %116 [
    i32 0, label %45
    i32 1, label %114
  ]

45:                                               ; preds = %43
  br label %90

46:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #6
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.match_result_t, ptr %47, i32 0, i32 2
  %49 = load i64, ptr %48, align 8, !tbaa !13
  %50 = icmp ugt i64 %49, 576460752303423487
  br i1 %50, label %51, label %64

51:                                               ; preds = %46
  store i64 1152921504606846975, ptr %10, align 8, !tbaa !9
  %52 = load i64, ptr %10, align 8, !tbaa !9
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.match_result_t, ptr %53, i32 0, i32 2
  %55 = load i64, ptr %54, align 8, !tbaa !13
  %56 = icmp ule i64 %52, %55
  br i1 %56, label %57, label %63

57:                                               ; preds = %51
  %58 = load ptr, ptr @stderr, align 8, !tbaa !5
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.match_result_t, ptr %59, i32 0, i32 2
  %61 = load i64, ptr %60, align 8, !tbaa !13
  %62 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %58, ptr noundef @.str.4, i64 noundef %61) #6
  store i1 false, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %87

63:                                               ; preds = %51
  br label %69

64:                                               ; preds = %46
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.match_result_t, ptr %65, i32 0, i32 2
  %67 = load i64, ptr %66, align 8, !tbaa !13
  %68 = mul i64 %67, 2
  store i64 %68, ptr %10, align 8, !tbaa !9
  br label %69

69:                                               ; preds = %64, %63
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #6
  %70 = load ptr, ptr %5, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.match_result_t, ptr %70, i32 0, i32 0
  %72 = load ptr, ptr %71, align 8, !tbaa !14
  %73 = load i64, ptr %10, align 8, !tbaa !9
  %74 = mul i64 %73, 16
  %75 = call ptr @realloc(ptr noundef %72, i64 noundef %74) #8
  store ptr %75, ptr %11, align 8, !tbaa !5
  %76 = load ptr, ptr %11, align 8, !tbaa !5
  %77 = icmp ne ptr %76, null
  br i1 %77, label %79, label %78

78:                                               ; preds = %69
  call void @perror(ptr noundef @.str.5)
  store i1 false, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %86

79:                                               ; preds = %69
  %80 = load ptr, ptr %11, align 8, !tbaa !5
  %81 = load ptr, ptr %5, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.match_result_t, ptr %81, i32 0, i32 0
  store ptr %80, ptr %82, align 8, !tbaa !14
  %83 = load i64, ptr %10, align 8, !tbaa !9
  %84 = load ptr, ptr %5, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.match_result_t, ptr %84, i32 0, i32 2
  store i64 %83, ptr %85, align 8, !tbaa !13
  store i32 0, ptr %9, align 4
  br label %86

86:                                               ; preds = %79, %78
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #6
  br label %87

87:                                               ; preds = %86, %57
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #6
  %88 = load i32, ptr %9, align 4
  switch i32 %88, label %116 [
    i32 0, label %89
    i32 1, label %114
  ]

89:                                               ; preds = %87
  br label %90

90:                                               ; preds = %89, %45
  br label %91

91:                                               ; preds = %90, %15
  %92 = load i64, ptr %6, align 8, !tbaa !9
  %93 = load ptr, ptr %5, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.match_result_t, ptr %93, i32 0, i32 0
  %95 = load ptr, ptr %94, align 8, !tbaa !14
  %96 = load ptr, ptr %5, align 8, !tbaa !5
  %97 = getelementptr inbounds %struct.match_result_t, ptr %96, i32 0, i32 1
  %98 = load i64, ptr %97, align 8, !tbaa !11
  %99 = getelementptr inbounds %struct.match_position_t, ptr %95, i64 %98
  %100 = getelementptr inbounds %struct.match_position_t, ptr %99, i32 0, i32 0
  store i64 %92, ptr %100, align 8, !tbaa !15
  %101 = load i64, ptr %7, align 8, !tbaa !9
  %102 = load ptr, ptr %5, align 8, !tbaa !5
  %103 = getelementptr inbounds %struct.match_result_t, ptr %102, i32 0, i32 0
  %104 = load ptr, ptr %103, align 8, !tbaa !14
  %105 = load ptr, ptr %5, align 8, !tbaa !5
  %106 = getelementptr inbounds %struct.match_result_t, ptr %105, i32 0, i32 1
  %107 = load i64, ptr %106, align 8, !tbaa !11
  %108 = getelementptr inbounds %struct.match_position_t, ptr %104, i64 %107
  %109 = getelementptr inbounds %struct.match_position_t, ptr %108, i32 0, i32 1
  store i64 %101, ptr %109, align 8, !tbaa !17
  %110 = load ptr, ptr %5, align 8, !tbaa !5
  %111 = getelementptr inbounds %struct.match_result_t, ptr %110, i32 0, i32 1
  %112 = load i64, ptr %111, align 8, !tbaa !11
  %113 = add i64 %112, 1
  store i64 %113, ptr %111, align 8, !tbaa !11
  store i1 true, ptr %4, align 1
  br label %114

114:                                              ; preds = %91, %87, %43, %14
  %115 = load i1, ptr %4, align 1
  ret i1 %115

116:                                              ; preds = %87, %43
  unreachable
}

; Function Attrs: nounwind allocsize(1)
declare ptr @realloc(ptr noundef, i64 noundef) #5

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { 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 #5 = { nounwind allocsize(1) "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 #6 = { nounwind }
attributes #7 = { nounwind allocsize(0) }
attributes #8 = { nounwind allocsize(1) }

!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 = !{!"long", !7, i64 0}
!11 = !{!12, !10, i64 8}
!12 = !{!"match_result_t", !6, i64 0, !10, i64 8, !10, i64 16}
!13 = !{!12, !10, i64 16}
!14 = !{!12, !6, i64 0}
!15 = !{!16, !10, i64 0}
!16 = !{!"", !10, i64 0, !10, i64 8}
!17 = !{!16, !10, i64 8}


; 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.match_position_t = type { i64, i64 }

@stderr = external local_unnamed_addr global ptr, align 8
@.str.3 = external hidden unnamed_addr constant [47 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [66 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [41 x i8], align 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 #0

; Function Attrs: nofree nounwind
declare void @perror(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: inlinehint nounwind uwtable
define dso_local noundef zeroext i1 @match_result_add(ptr noundef %0, i64 noundef %1, i64 noundef %2) local_unnamed_addr #2 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %.thread42, label %4

4:                                                ; preds = %3
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load i64, ptr %5, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 16
  %8 = load i64, ptr %7, align 8, !tbaa !11
  %.not36 = icmp ult i64 %6, %8
  br i1 %.not36, label %._crit_edge, label %9

._crit_edge:                                      ; preds = %4
  %.pre = load ptr, ptr %0, align 8, !tbaa !12
  br label %29

9:                                                ; preds = %4
  %10 = icmp eq i64 %8, 0
  br i1 %10, label %11, label %14

11:                                               ; preds = %9
  %12 = tail call noalias dereferenceable_or_null(256) ptr @malloc(i64 noundef 256) #4
  store ptr %12, ptr %0, align 8, !tbaa !12
  %.not38 = icmp eq ptr %12, null
  br i1 %.not38, label %13, label %.thread

.thread:                                          ; preds = %11
  store i64 16, ptr %7, align 8, !tbaa !11
  br label %29

13:                                               ; preds = %11
  tail call void @perror(ptr noundef nonnull @.str.3) #5
  br label %.thread42

14:                                               ; preds = %9
  %15 = icmp ugt i64 %8, 576460752303423487
  br i1 %15, label %16, label %21

16:                                               ; preds = %14
  %17 = icmp ugt i64 %8, 1152921504606846974
  br i1 %17, label %18, label %23

18:                                               ; preds = %16
  %19 = load ptr, ptr @stderr, align 8, !tbaa !13
  %20 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %19, ptr noundef nonnull @.str.4, i64 noundef %8) #6
  br label %.thread42

21:                                               ; preds = %14
  %22 = shl nuw nsw i64 %8, 1
  br label %23

23:                                               ; preds = %16, %21
  %.030 = phi i64 [ 1152921504606846975, %16 ], [ %22, %21 ]
  %24 = load ptr, ptr %0, align 8, !tbaa !12
  %25 = shl nuw i64 %.030, 4
  %26 = tail call ptr @realloc(ptr noundef %24, i64 noundef %25) #7
  %.not37 = icmp eq ptr %26, null
  br i1 %.not37, label %27, label %28

27:                                               ; preds = %23
  tail call void @perror(ptr noundef nonnull @.str.5) #5
  br label %.thread42

28:                                               ; preds = %23
  store ptr %26, ptr %0, align 8, !tbaa !12
  store i64 %.030, ptr %7, align 8, !tbaa !11
  %.pre45 = load i64, ptr %5, align 8, !tbaa !5
  br label %29

29:                                               ; preds = %._crit_edge, %28, %.thread
  %30 = phi i64 [ %6, %._crit_edge ], [ %.pre45, %28 ], [ %6, %.thread ]
  %31 = phi ptr [ %.pre, %._crit_edge ], [ %26, %28 ], [ %12, %.thread ]
  %32 = getelementptr inbounds %struct.match_position_t, ptr %31, i64 %30
  store i64 %1, ptr %32, align 8, !tbaa !14
  %33 = getelementptr inbounds %struct.match_position_t, ptr %31, i64 %30, i32 1
  store i64 %2, ptr %33, align 8, !tbaa !16
  %34 = add i64 %30, 1
  store i64 %34, ptr %5, align 8, !tbaa !5
  br label %.thread42

.thread42:                                        ; preds = %27, %18, %13, %3, %29
  %.3 = phi i1 [ false, %13 ], [ true, %29 ], [ false, %3 ], [ false, %18 ], [ false, %27 ]
  ret i1 %.3
}

; Function Attrs: mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias noundef ptr @realloc(ptr allocptr nocapture noundef, i64 noundef) local_unnamed_addr #3

attributes #0 = { 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 #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 = { 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 = { mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, 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 #4 = { nounwind allocsize(0) }
attributes #5 = { cold }
attributes #6 = { cold nounwind }
attributes #7 = { nounwind allocsize(1) }

!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, !10, i64 8}
!6 = !{!"match_result_t", !7, i64 0, !10, i64 8, !10, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!6, !10, i64 16}
!12 = !{!6, !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!15, !10, i64 0}
!15 = !{!"", !10, i64 0, !10, i64 8}
!16 = !{!15, !10, i64 8}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass