; LLVM IR from musetronstar/tagd :: tagl/src (lemon)

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

@.str.129 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.130 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.131 = external hidden unnamed_addr constant [16 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
declare void @free(ptr noundef) #1

; Function Attrs: nounwind willreturn memory(read)
declare ptr @strchr(ptr noundef, i32 noundef) #2

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #2

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

; Function Attrs: nounwind willreturn memory(read)
declare ptr @strrchr(ptr noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
declare hidden void @lemon_strcpy(ptr noundef, ptr noundef) #4

; Function Attrs: nounwind uwtable
declare hidden i32 @lemon_sprintf(ptr noundef, ptr noundef, ...) #4

; Function Attrs: nounwind uwtable
define dso_local ptr @pathsearch(ptr noundef %0, ptr noundef %1, i32 noundef %2) #4 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i8, align 1
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  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
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.start.p0(i64 1, ptr %12) #5
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = call ptr @strrchr(ptr noundef %13, i32 noundef 47) #6
  store ptr %14, ptr %11, align 8, !tbaa !5
  %15 = load ptr, ptr %11, align 8, !tbaa !5
  %16 = icmp ne ptr %15, null
  br i1 %16, label %17, label %41

17:                                               ; preds = %3
  %18 = load ptr, ptr %11, align 8, !tbaa !5
  %19 = load i8, ptr %18, align 1, !tbaa !11
  store i8 %19, ptr %12, align 1, !tbaa !11
  %20 = load ptr, ptr %11, align 8, !tbaa !5
  store i8 0, ptr %20, align 1, !tbaa !11
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = call i64 @strlen(ptr noundef %21) #6
  %23 = trunc i64 %22 to i32
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = call i64 @strlen(ptr noundef %24) #6
  %26 = trunc i64 %25 to i32
  %27 = add nsw i32 %23, %26
  %28 = add nsw i32 %27, 2
  %29 = sext i32 %28 to i64
  %30 = call noalias ptr @malloc(i64 noundef %29) #7
  store ptr %30, ptr %10, align 8, !tbaa !5
  %31 = load ptr, ptr %10, align 8, !tbaa !5
  %32 = icmp ne ptr %31, null
  br i1 %32, label %33, label %38

33:                                               ; preds = %17
  %34 = load ptr, ptr %10, align 8, !tbaa !5
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = call i32 (ptr, ptr, ...) @lemon_sprintf(ptr noundef %34, ptr noundef @.str.129, ptr noundef %35, ptr noundef %36)
  br label %38

38:                                               ; preds = %33, %17
  %39 = load i8, ptr %12, align 1, !tbaa !11
  %40 = load ptr, ptr %11, align 8, !tbaa !5
  store i8 %39, ptr %40, align 1, !tbaa !11
  br label %117

41:                                               ; preds = %3
  %42 = call ptr @getenv(ptr noundef @.str.130) #5
  store ptr %42, ptr %7, align 8, !tbaa !5
  %43 = load ptr, ptr %7, align 8, !tbaa !5
  %44 = icmp eq ptr %43, null
  br i1 %44, label %45, label %46

45:                                               ; preds = %41
  store ptr @.str.131, ptr %7, align 8, !tbaa !5
  br label %46

46:                                               ; preds = %45, %41
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = call i64 @strlen(ptr noundef %47) #6
  %49 = trunc i64 %48 to i32
  %50 = add nsw i32 %49, 1
  %51 = sext i32 %50 to i64
  %52 = call noalias ptr @malloc(i64 noundef %51) #7
  store ptr %52, ptr %9, align 8, !tbaa !5
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  %54 = call i64 @strlen(ptr noundef %53) #6
  %55 = trunc i64 %54 to i32
  %56 = load ptr, ptr %5, align 8, !tbaa !5
  %57 = call i64 @strlen(ptr noundef %56) #6
  %58 = trunc i64 %57 to i32
  %59 = add nsw i32 %55, %58
  %60 = add nsw i32 %59, 2
  %61 = sext i32 %60 to i64
  %62 = call noalias ptr @malloc(i64 noundef %61) #7
  store ptr %62, ptr %10, align 8, !tbaa !5
  %63 = load ptr, ptr %9, align 8, !tbaa !5
  %64 = icmp ne ptr %63, null
  br i1 %64, label %65, label %116

65:                                               ; preds = %46
  %66 = load ptr, ptr %10, align 8, !tbaa !5
  %67 = icmp ne ptr %66, null
  br i1 %67, label %68, label %116

68:                                               ; preds = %65
  %69 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %69, ptr %8, align 8, !tbaa !5
  %70 = load ptr, ptr %9, align 8, !tbaa !5
  %71 = load ptr, ptr %7, align 8, !tbaa !5
  call void @lemon_strcpy(ptr noundef %70, ptr noundef %71)
  br label %72

72:                                               ; preds = %113, %68
  %73 = load ptr, ptr %9, align 8, !tbaa !5
  %74 = load i8, ptr %73, align 1, !tbaa !11
  %75 = icmp ne i8 %74, 0
  br i1 %75, label %76, label %114

76:                                               ; preds = %72
  %77 = load ptr, ptr %9, align 8, !tbaa !5
  %78 = call ptr @strchr(ptr noundef %77, i32 noundef 58) #6
  store ptr %78, ptr %11, align 8, !tbaa !5
  %79 = load ptr, ptr %11, align 8, !tbaa !5
  %80 = icmp eq ptr %79, null
  br i1 %80, label %81, label %88

81:                                               ; preds = %76
  %82 = load ptr, ptr %9, align 8, !tbaa !5
  %83 = load ptr, ptr %9, align 8, !tbaa !5
  %84 = call i64 @strlen(ptr noundef %83) #6
  %85 = trunc i64 %84 to i32
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds i8, ptr %82, i64 %86
  store ptr %87, ptr %11, align 8, !tbaa !5
  br label %88

88:                                               ; preds = %81, %76
  %89 = load ptr, ptr %11, align 8, !tbaa !5
  %90 = load i8, ptr %89, align 1, !tbaa !11
  store i8 %90, ptr %12, align 1, !tbaa !11
  %91 = load ptr, ptr %11, align 8, !tbaa !5
  store i8 0, ptr %91, align 1, !tbaa !11
  %92 = load ptr, ptr %10, align 8, !tbaa !5
  %93 = load ptr, ptr %9, align 8, !tbaa !5
  %94 = load ptr, ptr %5, align 8, !tbaa !5
  %95 = call i32 (ptr, ptr, ...) @lemon_sprintf(ptr noundef %92, ptr noundef @.str.129, ptr noundef %93, ptr noundef %94)
  %96 = load i8, ptr %12, align 1, !tbaa !11
  %97 = load ptr, ptr %11, align 8, !tbaa !5
  store i8 %96, ptr %97, align 1, !tbaa !11
  %98 = load i8, ptr %12, align 1, !tbaa !11
  %99 = sext i8 %98 to i32
  %100 = icmp eq i32 %99, 0
  br i1 %100, label %101, label %104

101:                                              ; preds = %88
  %102 = load ptr, ptr %9, align 8, !tbaa !5
  %103 = getelementptr inbounds i8, ptr %102, i64 0
  store i8 0, ptr %103, align 1, !tbaa !11
  br label %107

104:                                              ; preds = %88
  %105 = load ptr, ptr %11, align 8, !tbaa !5
  %106 = getelementptr inbounds i8, ptr %105, i64 1
  store ptr %106, ptr %9, align 8, !tbaa !5
  br label %107

107:                                              ; preds = %104, %101
  %108 = load ptr, ptr %10, align 8, !tbaa !5
  %109 = load i32, ptr %6, align 4, !tbaa !9
  %110 = call i32 @access(ptr noundef %108, i32 noundef %109) #5
  %111 = icmp eq i32 %110, 0
  br i1 %111, label %112, label %113

112:                                              ; preds = %107
  br label %114

113:                                              ; preds = %107
  br label %72, !llvm.loop !12

114:                                              ; preds = %112, %72
  %115 = load ptr, ptr %8, align 8, !tbaa !5
  call void @free(ptr noundef %115) #5
  br label %116

116:                                              ; preds = %114, %65, %46
  br label %117

117:                                              ; preds = %116, %38
  %118 = load ptr, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 1, 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
  ret ptr %118
}

; Function Attrs: nounwind
declare ptr @getenv(ptr noundef) #1

; Function Attrs: nounwind
declare i32 @access(ptr noundef, i32 noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { nounwind willreturn memory(read) "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 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 #4 = { 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 }
attributes #6 = { nounwind willreturn memory(read) }
attributes #7 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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"

@.str.129 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.130 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.131 = external hidden unnamed_addr constant [16 x i8], align 1

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare ptr @strchr(ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) 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: mustprogress nofree nounwind willreturn memory(argmem: read)
declare ptr @strrchr(ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden void @lemon_strcpy(ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare hidden i32 @lemon_sprintf(ptr noundef, ptr noundef, ...) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @pathsearch(ptr noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #3 {
  %4 = tail call ptr @strrchr(ptr noundef nonnull dereferenceable(1) %0, i32 noundef 47) #6
  %.not = icmp eq ptr %4, null
  br i1 %.not, label %16, label %5

5:                                                ; preds = %3
  %6 = load i8, ptr %4, align 1, !tbaa !5
  store i8 0, ptr %4, align 1, !tbaa !5
  %7 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #6
  %8 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %1) #6
  %9 = add i64 %8, %7
  %10 = shl i64 %9, 32
  %sext50 = add i64 %10, 8589934592
  %11 = ashr exact i64 %sext50, 32
  %12 = tail call noalias ptr @malloc(i64 noundef %11) #7
  %.not51 = icmp eq ptr %12, null
  br i1 %.not51, label %15, label %13

13:                                               ; preds = %5
  %14 = tail call i32 (ptr, ptr, ...) @lemon_sprintf(ptr noundef nonnull %12, ptr noundef nonnull @.str.129, ptr noundef %0, ptr noundef %1)
  br label %15

15:                                               ; preds = %13, %5
  store i8 %6, ptr %4, align 1, !tbaa !5
  br label %51

16:                                               ; preds = %3
  %17 = tail call ptr @getenv(ptr noundef nonnull @.str.130) #8
  %18 = icmp eq ptr %17, null
  %spec.store.select = select i1 %18, ptr @.str.131, ptr %17
  %19 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %spec.store.select) #6
  %20 = shl i64 %19, 32
  %sext = add i64 %20, 4294967296
  %21 = ashr exact i64 %sext, 32
  %22 = tail call noalias ptr @malloc(i64 noundef %21) #7
  %23 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %1) #6
  %24 = add i64 %23, %19
  %25 = shl i64 %24, 32
  %sext47 = add i64 %25, 8589934592
  %26 = ashr exact i64 %sext47, 32
  %27 = tail call noalias ptr @malloc(i64 noundef %26) #7
  %28 = icmp ne ptr %22, null
  %29 = icmp ne ptr %27, null
  %or.cond = and i1 %28, %29
  br i1 %or.cond, label %30, label %51

30:                                               ; preds = %16
  tail call void @lemon_strcpy(ptr noundef nonnull %22, ptr noundef nonnull %spec.store.select)
  br label %31

31:                                               ; preds = %47, %30
  %.041 = phi ptr [ %22, %30 ], [ %.1, %47 ]
  %32 = load i8, ptr %.041, align 1, !tbaa !5
  %.not48 = icmp eq i8 %32, 0
  br i1 %.not48, label %50, label %33

33:                                               ; preds = %31
  %34 = tail call ptr @strchr(ptr noundef nonnull dereferenceable(1) %.041, i32 noundef 58) #6
  %35 = icmp eq ptr %34, null
  br i1 %35, label %36, label %40

36:                                               ; preds = %33
  %37 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %.041) #6
  %sext49 = shl i64 %37, 32
  %38 = ashr exact i64 %sext49, 32
  %39 = getelementptr inbounds i8, ptr %.041, i64 %38
  br label %40

40:                                               ; preds = %36, %33
  %.0 = phi ptr [ %39, %36 ], [ %34, %33 ]
  %41 = load i8, ptr %.0, align 1, !tbaa !5
  store i8 0, ptr %.0, align 1, !tbaa !5
  %42 = tail call i32 (ptr, ptr, ...) @lemon_sprintf(ptr noundef nonnull %27, ptr noundef nonnull @.str.129, ptr noundef nonnull %.041, ptr noundef %1)
  store i8 %41, ptr %.0, align 1, !tbaa !5
  %43 = icmp eq i8 %41, 0
  br i1 %43, label %44, label %45

44:                                               ; preds = %40
  store i8 0, ptr %.041, align 1, !tbaa !5
  br label %47

45:                                               ; preds = %40
  %46 = getelementptr inbounds i8, ptr %.0, i64 1
  br label %47

47:                                               ; preds = %45, %44
  %.1 = phi ptr [ %.041, %44 ], [ %46, %45 ]
  %48 = tail call i32 @access(ptr noundef nonnull %27, i32 noundef %2) #8
  %49 = icmp eq i32 %48, 0
  br i1 %49, label %50, label %31, !llvm.loop !8

50:                                               ; preds = %47, %31
  tail call void @free(ptr noundef %22) #8
  br label %51

51:                                               ; preds = %16, %50, %15
  %.040 = phi ptr [ %12, %15 ], [ %27, %50 ], [ %27, %16 ]
  ret ptr %.040
}

; Function Attrs: nofree nounwind memory(read)
declare noundef ptr @getenv(ptr nocapture noundef) local_unnamed_addr #4

; Function Attrs: nofree nounwind
declare noundef i32 @access(ptr nocapture noundef readonly, i32 noundef) local_unnamed_addr #5

attributes #0 = { mustprogress nounwind willreturn allockind("free") 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 #1 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 = { 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 #4 = { nofree nounwind memory(read) "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 = { 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 #6 = { nounwind willreturn memory(read) }
attributes #7 = { nounwind allocsize(0) }
attributes #8 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


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