; LLVM IR from kala13x/libxutils :: tools (xpass)

; 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.xpass_ctx_t = type { [256 x i8], [256 x i8], [256 x i8], [2048 x i8], [2048 x i8], [256 x i8], [2048 x i8], [2048 x i8], [2048 x i8], [256 x i8], i64, i64, i64, %struct.xjson_, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8 }
%struct.xjson_ = type { %struct.xjson_token_, i32, ptr, ptr, ptr, i64, i64 }
%struct.xjson_token_ = type { i32, ptr, i64 }
%struct.passwd = type { ptr, ptr, i32, i32, ptr, ptr, ptr }

@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @XPass_InitCtx(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 8 %4, i8 0, i64 11632, i1 false)
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct.xpass_ctx_t, ptr %5, i32 0, i32 13
  %7 = getelementptr inbounds %struct.xjson_, ptr %6, i32 0, i32 2
  store ptr null, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  %8 = call ptr @getenv(ptr noundef @.str) #5
  store ptr %8, ptr %3, align 8, !tbaa !5
  %9 = icmp eq ptr %8, null
  br i1 %9, label %10, label %15

10:                                               ; preds = %1
  %11 = call i32 @getuid() #5
  %12 = call ptr @getpwuid(i32 noundef %11)
  %13 = getelementptr inbounds %struct.passwd, ptr %12, i32 0, i32 5
  %14 = load ptr, ptr %13, align 8, !tbaa !15
  store ptr %14, ptr %3, align 8, !tbaa !5
  br label %15

15:                                               ; preds = %10, %1
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.xpass_ctx_t, ptr %16, i32 0, i32 8
  %18 = getelementptr inbounds [2048 x i8], ptr %17, i64 0, i64 0
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = call i64 (ptr, i64, ptr, ...) @xstrncpyf(ptr noundef %18, i64 noundef 2048, ptr noundef @.str.1, ptr noundef %19, ptr noundef @.str.2)
  %21 = load i8, ptr @.str.3, align 1, !tbaa !17
  %22 = load ptr, ptr %2, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.xpass_ctx_t, ptr %22, i32 0, i32 21
  store i8 %21, ptr %23, align 1, !tbaa !18
  %24 = load i8, ptr @.str.4, align 1, !tbaa !17
  %25 = load ptr, ptr %2, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.xpass_ctx_t, ptr %25, i32 0, i32 22
  store i8 %24, ptr %26, align 8, !tbaa !19
  %27 = load i8, ptr @.str.5, align 1, !tbaa !17
  %28 = load ptr, ptr %2, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.xpass_ctx_t, ptr %28, i32 0, i32 23
  store i8 %27, ptr %29, align 1, !tbaa !20
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

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

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

declare ptr @getpwuid(i32 noundef) #4

; Function Attrs: nounwind
declare i32 @getuid() #3

declare i64 @xstrncpyf(ptr noundef, i64 noundef, ptr noundef, ...) #4

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 nounwind willreturn memory(argmem: write) }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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 = !{!10, !6, i64 11576}
!10 = !{!"", !7, i64 0, !7, i64 256, !7, i64 512, !7, i64 768, !7, i64 2816, !7, i64 4864, !7, i64 5120, !7, i64 7168, !7, i64 9216, !7, i64 11264, !11, i64 11520, !11, i64 11528, !11, i64 11536, !12, i64 11544, !7, i64 11616, !7, i64 11617, !7, i64 11618, !7, i64 11619, !7, i64 11620, !7, i64 11621, !7, i64 11622, !7, i64 11623, !7, i64 11624, !7, i64 11625}
!11 = !{!"long", !7, i64 0}
!12 = !{!"xjson_", !13, i64 0, !14, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !11, i64 56, !11, i64 64}
!13 = !{!"xjson_token_", !14, i64 0, !6, i64 8, !11, i64 16}
!14 = !{!"int", !7, i64 0}
!15 = !{!16, !6, i64 32}
!16 = !{!"passwd", !6, i64 0, !6, i64 8, !14, i64 16, !14, i64 20, !6, i64 24, !6, i64 32, !6, i64 40}
!17 = !{!7, !7, i64 0}
!18 = !{!10, !7, i64 11623}
!19 = !{!10, !7, i64 11624}
!20 = !{!10, !7, i64 11625}


; 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 [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @XPass_InitCtx(ptr noundef %0) local_unnamed_addr #0 {
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(11632) %0, i8 0, i64 11632, i1 false)
  %2 = tail call ptr @getenv(ptr noundef nonnull @.str) #5
  %3 = icmp eq ptr %2, null
  br i1 %3, label %4, label %9

4:                                                ; preds = %1
  %5 = tail call i32 @getuid() #5
  %6 = tail call ptr @getpwuid(i32 noundef %5) #5
  %7 = getelementptr inbounds i8, ptr %6, i64 32
  %8 = load ptr, ptr %7, align 8, !tbaa !5
  br label %9

9:                                                ; preds = %4, %1
  %.0 = phi ptr [ %8, %4 ], [ %2, %1 ]
  %10 = getelementptr inbounds i8, ptr %0, i64 9216
  %11 = tail call i64 (ptr, i64, ptr, ...) @xstrncpyf(ptr noundef nonnull %10, i64 noundef 2048, ptr noundef nonnull @.str.1, ptr noundef %.0, ptr noundef nonnull @.str.2) #5
  %12 = load i8, ptr @.str.3, align 1, !tbaa !11
  %13 = getelementptr inbounds i8, ptr %0, i64 11623
  store i8 %12, ptr %13, align 1, !tbaa !12
  %14 = load i8, ptr @.str.4, align 1, !tbaa !11
  %15 = getelementptr inbounds i8, ptr %0, i64 11624
  store i8 %14, ptr %15, align 8, !tbaa !17
  %16 = load i8, ptr @.str.5, align 1, !tbaa !11
  %17 = getelementptr inbounds i8, ptr %0, i64 11625
  store i8 %16, ptr %17, align 1, !tbaa !18
  ret void
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

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

declare ptr @getpwuid(i32 noundef) local_unnamed_addr #3

; Function Attrs: nounwind
declare i32 @getuid() local_unnamed_addr #4

declare i64 @xstrncpyf(ptr noundef, i64 noundef, ptr noundef, ...) local_unnamed_addr #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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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 = { "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, !7, i64 32}
!6 = !{!"passwd", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 20, !7, i64 24, !7, i64 32, !7, i64 40}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!8, !8, i64 0}
!12 = !{!13, !8, i64 11623}
!13 = !{!"", !8, i64 0, !8, i64 256, !8, i64 512, !8, i64 768, !8, i64 2816, !8, i64 4864, !8, i64 5120, !8, i64 7168, !8, i64 9216, !8, i64 11264, !14, i64 11520, !14, i64 11528, !14, i64 11536, !15, i64 11544, !8, i64 11616, !8, i64 11617, !8, i64 11618, !8, i64 11619, !8, i64 11620, !8, i64 11621, !8, i64 11622, !8, i64 11623, !8, i64 11624, !8, i64 11625}
!14 = !{!"long", !8, i64 0}
!15 = !{!"xjson_", !16, i64 0, !10, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !14, i64 56, !14, i64 64}
!16 = !{!"xjson_token_", !10, i64 0, !7, i64 8, !14, i64 16}
!17 = !{!13, !8, i64 11624}
!18 = !{!13, !8, i64 11625}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,MemCpyOptPass,SROAPass,TailCallElimPass