; LLVM IR from ros2/rcutils :: src (env)

; 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 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [56 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [40 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [54 x i8], align 1
@stderr = external global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @rcutils_set_env_overwrite(ptr noundef %0, ptr noundef %1, i1 noundef zeroext %2) #0 {
  %4 = alloca i1, align 1
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i8, align 1
  %8 = alloca i32, align 4
  %9 = alloca [1024 x i8], align 16
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  %12 = zext i1 %2 to i8
  store i8 %12, ptr %7, align 1, !tbaa !9
  br label %13

13:                                               ; preds = %3
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = icmp eq ptr null, %14
  br i1 %15, label %16, label %19

16:                                               ; preds = %13
  br label %17

17:                                               ; preds = %16
  call void @rcutils_set_error_state(ptr noundef @.str, ptr noundef @.str.1, i64 noundef 39)
  br label %18

18:                                               ; preds = %17
  store i1 false, ptr %4, align 1
  br label %70

19:                                               ; preds = %13
  br label %20

20:                                               ; preds = %19
  %21 = load i8, ptr %7, align 1, !tbaa !9, !range !11, !noundef !12
  %22 = trunc i8 %21 to i1
  %23 = zext i1 %22 to i32
  %24 = icmp eq i32 %23, 0
  br i1 %24, label %25, label %30

25:                                               ; preds = %20
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = call ptr @getenv(ptr noundef %26) #5
  %28 = icmp ne ptr %27, null
  br i1 %28, label %29, label %30

29:                                               ; preds = %25
  store i1 true, ptr %4, align 1
  br label %70

30:                                               ; preds = %25, %20
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = icmp eq ptr null, %31
  br i1 %32, label %33, label %36

33:                                               ; preds = %30
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = call i32 @unsetenv(ptr noundef %34) #5
  store i32 %35, ptr %8, align 4, !tbaa !13
  br label %43

36:                                               ; preds = %30
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = load i8, ptr %7, align 1, !tbaa !9, !range !11, !noundef !12
  %40 = trunc i8 %39 to i1
  %41 = zext i1 %40 to i32
  %42 = call i32 @setenv(ptr noundef %37, ptr noundef %38, i32 noundef %41) #5
  store i32 %42, ptr %8, align 4, !tbaa !13
  br label %43

43:                                               ; preds = %36, %33
  %44 = load i32, ptr %8, align 4, !tbaa !13
  %45 = icmp ne i32 %44, 0
  br i1 %45, label %46, label %68

46:                                               ; preds = %43
  br label %47

47:                                               ; preds = %46
  call void @llvm.lifetime.start.p0(i64 1024, ptr %9) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  %48 = getelementptr inbounds [1024 x i8], ptr %9, i64 0, i64 0
  %49 = call ptr @__errno_location() #6
  %50 = load i32, ptr %49, align 4, !tbaa !13
  %51 = call i32 (ptr, i64, ptr, ...) @rcutils_snprintf(ptr noundef %48, i64 noundef 1024, ptr noundef @.str.2, i32 noundef %50)
  store i32 %51, ptr %10, align 4, !tbaa !13
  %52 = load i32, ptr %10, align 4, !tbaa !13
  %53 = icmp slt i32 %52, 0
  br i1 %53, label %54, label %60

54:                                               ; preds = %47
  br label %55

55:                                               ; preds = %54
  %56 = load ptr, ptr @stderr, align 8, !tbaa !5
  %57 = call i64 @fwrite(ptr noundef @.str.3, i64 noundef 1, i64 noundef 53, ptr noundef %56)
  br label %58

58:                                               ; preds = %55
  br label %59

59:                                               ; preds = %58
  br label %65

60:                                               ; preds = %47
  br label %61

61:                                               ; preds = %60
  %62 = getelementptr inbounds [1024 x i8], ptr %9, i64 0, i64 0
  call void @rcutils_set_error_state(ptr noundef %62, ptr noundef @.str.1, i64 noundef 60)
  br label %63

63:                                               ; preds = %61
  br label %64

64:                                               ; preds = %63
  br label %65

65:                                               ; preds = %64, %59
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 1024, ptr %9) #5
  br label %66

66:                                               ; preds = %65
  br label %67

67:                                               ; preds = %66
  store i1 false, ptr %4, align 1
  store i32 1, ptr %11, align 4
  br label %69

68:                                               ; preds = %43
  store i1 true, ptr %4, align 1
  store i32 1, ptr %11, align 4
  br label %69

69:                                               ; preds = %68, %67
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  br label %70

70:                                               ; preds = %69, %29, %18
  %71 = load i1, ptr %4, align 1
  ret i1 %71
}

declare void @rcutils_set_error_state(ptr noundef, ptr noundef, i64 noundef) #1

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

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

; Function Attrs: nounwind
declare i32 @unsetenv(ptr noundef) #2

; Function Attrs: nounwind
declare i32 @setenv(ptr noundef, ptr noundef, i32 noundef) #2

declare i32 @rcutils_snprintf(ptr noundef, i64 noundef, ptr noundef, ...) #1

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__errno_location() #4

declare i64 @fwrite(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { "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 "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { nounwind willreturn memory(none) "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(none) }

!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 = !{!"_Bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}


; 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 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [56 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [40 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [54 x i8], align 1
@stderr = external local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local noundef zeroext i1 @rcutils_set_env_overwrite(ptr noundef %0, ptr noundef %1, i1 noundef zeroext %2) local_unnamed_addr #0 {
  %4 = alloca [1024 x i8], align 16
  %5 = icmp eq ptr %0, null
  br i1 %5, label %6, label %7

6:                                                ; preds = %3
  tail call void @rcutils_set_error_state(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i64 noundef 39) #7
  br label %28

7:                                                ; preds = %3
  %8 = zext i1 %2 to i32
  br i1 %2, label %11, label %9

9:                                                ; preds = %7
  %10 = tail call ptr @getenv(ptr noundef nonnull %0) #7
  %.not = icmp eq ptr %10, null
  br i1 %.not, label %11, label %28

11:                                               ; preds = %9, %7
  %12 = icmp eq ptr %1, null
  br i1 %12, label %13, label %15

13:                                               ; preds = %11
  %14 = tail call i32 @unsetenv(ptr noundef nonnull %0) #7
  br label %17

15:                                               ; preds = %11
  %16 = tail call i32 @setenv(ptr noundef nonnull %0, ptr noundef nonnull %1, i32 noundef %8) #7
  br label %17

17:                                               ; preds = %15, %13
  %.010 = phi i32 [ %14, %13 ], [ %16, %15 ]
  %.not13 = icmp eq i32 %.010, 0
  br i1 %.not13, label %28, label %18

18:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 1024, ptr nonnull %4) #7
  %19 = tail call ptr @__errno_location() #8
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %21 = call i32 (ptr, i64, ptr, ...) @rcutils_snprintf(ptr noundef nonnull %4, i64 noundef 1024, ptr noundef nonnull @.str.2, i32 noundef %20) #7
  %22 = icmp slt i32 %21, 0
  br i1 %22, label %23, label %26

23:                                               ; preds = %18
  %24 = load ptr, ptr @stderr, align 8, !tbaa !9
  %25 = call i64 @fwrite(ptr noundef nonnull @.str.3, i64 noundef 1, i64 noundef 53, ptr noundef %24) #9
  br label %27

26:                                               ; preds = %18
  call void @rcutils_set_error_state(ptr noundef nonnull %4, ptr noundef nonnull @.str.1, i64 noundef 60) #7
  br label %27

27:                                               ; preds = %26, %23
  call void @llvm.lifetime.end.p0(i64 1024, ptr nonnull %4) #7
  br label %28

28:                                               ; preds = %27, %17, %9, %6
  %.1 = phi i1 [ false, %6 ], [ true, %9 ], [ true, %17 ], [ false, %27 ]
  ret i1 %.1
}

declare void @rcutils_set_error_state(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

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

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

; Function Attrs: nofree nounwind
declare noundef i32 @unsetenv(ptr nocapture noundef readonly) local_unnamed_addr #4

; Function Attrs: nounwind
declare i32 @setenv(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #5

declare i32 @rcutils_snprintf(ptr noundef, i64 noundef, ptr noundef, ...) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__errno_location() local_unnamed_addr #6

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { "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 = { 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 #3 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 #5 = { 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 = { mustprogress nofree nosync nounwind willreturn memory(none) "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 #7 = { nounwind }
attributes #8 = { nounwind willreturn memory(none) }
attributes #9 = { cold }

!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}


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