; LLVM IR from clibs/clib :: deps/tempdir (tempdir)

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

@env_vars = external hidden global [5 x ptr], align 16
@platform_dirs = external hidden global [4 x ptr], align 16

; Function Attrs: nounwind uwtable
define dso_local ptr @gettempdir() #0 {
  %1 = alloca ptr, align 8
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca [256 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %7

7:                                                ; preds = %33, %0
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [5 x ptr], ptr @env_vars, i64 0, i64 %9
  %11 = load ptr, ptr %10, align 8, !tbaa !9
  %12 = icmp ne ptr %11, null
  br i1 %12, label %14, label %13

13:                                               ; preds = %7
  store i32 2, ptr %3, align 4
  br label %36

14:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %15 = load i32, ptr %2, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [5 x ptr], ptr @env_vars, i64 0, i64 %16
  %18 = load ptr, ptr %17, align 8, !tbaa !9
  %19 = call ptr @getenv(ptr noundef %18) #3
  store ptr %19, ptr %4, align 8, !tbaa !9
  %20 = load ptr, ptr %4, align 8, !tbaa !9
  %21 = icmp ne ptr %20, null
  br i1 %21, label %22, label %29

22:                                               ; preds = %14
  %23 = load ptr, ptr %4, align 8, !tbaa !9
  %24 = call i32 @is_directory(ptr noundef %23)
  %25 = icmp eq i32 0, %24
  br i1 %25, label %26, label %29

26:                                               ; preds = %22
  %27 = load ptr, ptr %4, align 8, !tbaa !9
  %28 = call ptr @strdup(ptr noundef %27) #3
  store ptr %28, ptr %1, align 8
  store i32 1, ptr %3, align 4
  br label %30

29:                                               ; preds = %22, %14
  store i32 0, ptr %3, align 4
  br label %30

30:                                               ; preds = %29, %26
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %31 = load i32, ptr %3, align 4
  switch i32 %31, label %36 [
    i32 0, label %32
  ]

32:                                               ; preds = %30
  br label %33

33:                                               ; preds = %32
  %34 = load i32, ptr %2, align 4, !tbaa !5
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr %2, align 4, !tbaa !5
  br label %7, !llvm.loop !11

36:                                               ; preds = %30, %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  %37 = load i32, ptr %3, align 4
  switch i32 %37, label %76 [
    i32 2, label %38
    i32 1, label %74
  ]

38:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %39

39:                                               ; preds = %60, %38
  %40 = load i32, ptr %5, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [4 x ptr], ptr @platform_dirs, i64 0, i64 %41
  %43 = load ptr, ptr %42, align 8, !tbaa !9
  %44 = icmp ne ptr %43, null
  br i1 %44, label %46, label %45

45:                                               ; preds = %39
  store i32 5, ptr %3, align 4
  br label %63

46:                                               ; preds = %39
  %47 = load i32, ptr %5, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [4 x ptr], ptr @platform_dirs, i64 0, i64 %48
  %50 = load ptr, ptr %49, align 8, !tbaa !9
  %51 = call i32 @is_directory(ptr noundef %50)
  %52 = icmp eq i32 0, %51
  br i1 %52, label %53, label %59

53:                                               ; preds = %46
  %54 = load i32, ptr %5, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [4 x ptr], ptr @platform_dirs, i64 0, i64 %55
  %57 = load ptr, ptr %56, align 8, !tbaa !9
  %58 = call ptr @strdup(ptr noundef %57) #3
  store ptr %58, ptr %1, align 8
  store i32 1, ptr %3, align 4
  br label %63

59:                                               ; preds = %46
  br label %60

60:                                               ; preds = %59
  %61 = load i32, ptr %5, align 4, !tbaa !5
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %5, align 4, !tbaa !5
  br label %39, !llvm.loop !13

63:                                               ; preds = %53, %45
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  %64 = load i32, ptr %3, align 4
  switch i32 %64, label %76 [
    i32 5, label %65
    i32 1, label %74
  ]

65:                                               ; preds = %63
  call void @llvm.lifetime.start.p0(i64 256, ptr %6) #3
  %66 = getelementptr inbounds [256 x i8], ptr %6, i64 0, i64 0
  %67 = call ptr @getcwd(ptr noundef %66, i64 noundef 256) #3
  %68 = icmp ne ptr null, %67
  br i1 %68, label %69, label %72

69:                                               ; preds = %65
  %70 = getelementptr inbounds [256 x i8], ptr %6, i64 0, i64 0
  %71 = call ptr @strdup(ptr noundef %70) #3
  store ptr %71, ptr %1, align 8
  store i32 1, ptr %3, align 4
  br label %73

72:                                               ; preds = %65
  store ptr null, ptr %1, align 8
  store i32 1, ptr %3, align 4
  br label %73

73:                                               ; preds = %72, %69
  call void @llvm.lifetime.end.p0(i64 256, ptr %6) #3
  br label %74

74:                                               ; preds = %73, %63, %36
  %75 = load ptr, ptr %1, align 8
  ret ptr %75

76:                                               ; preds = %63, %36
  unreachable
}

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

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

; Function Attrs: nounwind uwtable
declare hidden i32 @is_directory(ptr noundef) #0

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

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

; Function Attrs: nounwind
declare ptr @getcwd(ptr noundef, i64 noundef) #2

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 = { 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 = { 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 = !{!"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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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

@env_vars = external hidden local_unnamed_addr global [5 x ptr], align 16
@platform_dirs = external hidden local_unnamed_addr global [4 x ptr], align 16

; Function Attrs: nounwind uwtable
define dso_local noalias ptr @gettempdir() local_unnamed_addr #0 {
  %1 = alloca [256 x i8], align 16
  %2 = load ptr, ptr @env_vars, align 16, !tbaa !5
  %.not40 = icmp eq ptr %2, null
  br i1 %.not40, label %.preheader, label %.lr.ph

.preheader:                                       ; preds = %10, %0
  %3 = load ptr, ptr @platform_dirs, align 16, !tbaa !5
  %.not2243 = icmp eq ptr %3, null
  br i1 %.not2243, label %._crit_edge, label %.lr.ph45

.lr.ph:                                           ; preds = %0, %10
  %indvars.iv = phi i64 [ %indvars.iv.next, %10 ], [ 0, %0 ]
  %4 = phi ptr [ %12, %10 ], [ %2, %0 ]
  %5 = tail call ptr @getenv(ptr noundef nonnull %4) #5
  %.not21 = icmp eq ptr %5, null
  br i1 %.not21, label %10, label %6

6:                                                ; preds = %.lr.ph
  %7 = tail call i32 @is_directory(ptr noundef nonnull %5)
  %8 = icmp eq i32 %7, 0
  br i1 %8, label %.thread29, label %10

.thread29:                                        ; preds = %6
  %9 = tail call ptr @strdup(ptr noundef nonnull %5) #5
  br label %27

10:                                               ; preds = %6, %.lr.ph
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %11 = getelementptr inbounds [5 x ptr], ptr @env_vars, i64 0, i64 %indvars.iv.next
  %12 = load ptr, ptr %11, align 8, !tbaa !5
  %.not = icmp eq ptr %12, null
  br i1 %.not, label %.preheader, label %.lr.ph, !llvm.loop !9

13:                                               ; preds = %.lr.ph45
  %indvars.iv.next51 = add nuw nsw i64 %indvars.iv50, 1
  %14 = getelementptr inbounds [4 x ptr], ptr @platform_dirs, i64 0, i64 %indvars.iv.next51
  %15 = load ptr, ptr %14, align 8, !tbaa !5
  %.not22 = icmp eq ptr %15, null
  br i1 %.not22, label %._crit_edge, label %.lr.ph45, !llvm.loop !11

.lr.ph45:                                         ; preds = %.preheader, %13
  %indvars.iv50 = phi i64 [ %indvars.iv.next51, %13 ], [ 0, %.preheader ]
  %16 = phi ptr [ %15, %13 ], [ %3, %.preheader ]
  %17 = tail call i32 @is_directory(ptr noundef nonnull %16)
  %18 = icmp eq i32 %17, 0
  br i1 %18, label %19, label %13

19:                                               ; preds = %.lr.ph45
  %20 = getelementptr inbounds [4 x ptr], ptr @platform_dirs, i64 0, i64 %indvars.iv50
  %21 = load ptr, ptr %20, align 8, !tbaa !5
  %22 = tail call ptr @strdup(ptr noundef %21) #5
  br label %27

._crit_edge:                                      ; preds = %13, %.preheader
  call void @llvm.lifetime.start.p0(i64 256, ptr nonnull %1) #5
  %23 = call ptr @getcwd(ptr noundef nonnull %1, i64 noundef 256) #5
  %.not23 = icmp eq ptr %23, null
  br i1 %.not23, label %26, label %24

24:                                               ; preds = %._crit_edge
  %25 = call ptr @strdup(ptr noundef nonnull %1) #5
  br label %26

26:                                               ; preds = %._crit_edge, %24
  %.4 = phi ptr [ %25, %24 ], [ null, %._crit_edge ]
  call void @llvm.lifetime.end.p0(i64 256, ptr nonnull %1) #5
  br label %27

27:                                               ; preds = %19, %.thread29, %26
  %.5 = phi ptr [ %22, %19 ], [ %.4, %26 ], [ %9, %.thread29 ]
  ret ptr %.5
}

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

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

; Function Attrs: nounwind uwtable
declare hidden i32 @is_directory(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias ptr @strdup(ptr nocapture noundef readonly) local_unnamed_addr #3

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

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

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 nofree nounwind willreturn 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 "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 }

!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 = distinct !{!11, !10}


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