; LLVM IR from unitreerobotics/kinect_teleoperate :: src/mujoco-3.1.5/sample/compile.ll (Z8filetypePKc)

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

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

8:                                                ; preds = %18, %1
  %9 = load i64, ptr %5, align 8, !tbaa !9
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = call i64 @strlen(ptr noundef %10) #4
  %12 = icmp ult i64 %9, %11
  br i1 %12, label %13, label %16

13:                                               ; preds = %8
  %14 = load i64, ptr %5, align 8, !tbaa !9
  %15 = icmp ult i64 %14, 999
  br label %16

16:                                               ; preds = %13, %8
  %17 = phi i1 [ false, %8 ], [ %15, %13 ]
  br i1 %17, label %18, label %30

18:                                               ; preds = %16
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = load i64, ptr %5, align 8, !tbaa !9
  %21 = getelementptr inbounds i8, ptr %19, i64 %20
  %22 = load i8, ptr %21, align 1, !tbaa !11
  %23 = sext i8 %22 to i32
  %24 = call i32 @tolower(i32 noundef %23) #4
  %25 = trunc i32 %24 to i8
  %26 = load i64, ptr %5, align 8, !tbaa !9
  %27 = getelementptr inbounds [1000 x i8], ptr %4, i64 0, i64 %26
  store i8 %25, ptr %27, align 1, !tbaa !11
  %28 = load i64, ptr %5, align 8, !tbaa !9
  %29 = add i64 %28, 1
  store i64 %29, ptr %5, align 8, !tbaa !9
  br label %8, !llvm.loop !12

30:                                               ; preds = %16
  %31 = load i64, ptr %5, align 8, !tbaa !9
  %32 = getelementptr inbounds [1000 x i8], ptr %4, i64 0, i64 %31
  store i8 0, ptr %32, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %33 = getelementptr inbounds [1000 x i8], ptr %4, i64 0, i64 0
  %34 = call i64 @strlen(ptr noundef %33) #4
  %35 = trunc i64 %34 to i32
  store i32 %35, ptr %6, align 4, !tbaa !14
  br label %36

36:                                               ; preds = %48, %30
  %37 = load i32, ptr %6, align 4, !tbaa !14
  %38 = icmp sge i32 %37, 0
  br i1 %38, label %39, label %46

39:                                               ; preds = %36
  %40 = load i32, ptr %6, align 4, !tbaa !14
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [1000 x i8], ptr %4, i64 0, i64 %41
  %43 = load i8, ptr %42, align 1, !tbaa !11
  %44 = sext i8 %43 to i32
  %45 = icmp ne i32 %44, 46
  br label %46

46:                                               ; preds = %39, %36
  %47 = phi i1 [ false, %36 ], [ %45, %39 ]
  br i1 %47, label %48, label %51

48:                                               ; preds = %46
  %49 = load i32, ptr %6, align 4, !tbaa !14
  %50 = add nsw i32 %49, -1
  store i32 %50, ptr %6, align 4, !tbaa !14
  br label %36, !llvm.loop !16

51:                                               ; preds = %46
  %52 = load i32, ptr %6, align 4, !tbaa !14
  %53 = icmp slt i32 %52, 0
  br i1 %53, label %54, label %55

54:                                               ; preds = %51
  store i32 0, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %87

55:                                               ; preds = %51
  %56 = getelementptr inbounds [1000 x i8], ptr %4, i64 0, i64 0
  %57 = load i32, ptr %6, align 4, !tbaa !14
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds i8, ptr %56, i64 %58
  %60 = call i32 @strcmp(ptr noundef %59, ptr noundef @.str) #4
  %61 = icmp ne i32 %60, 0
  br i1 %61, label %62, label %69

62:                                               ; preds = %55
  %63 = getelementptr inbounds [1000 x i8], ptr %4, i64 0, i64 0
  %64 = load i32, ptr %6, align 4, !tbaa !14
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds i8, ptr %63, i64 %65
  %67 = call i32 @strcmp(ptr noundef %66, ptr noundef @.str.1) #4
  %68 = icmp ne i32 %67, 0
  br i1 %68, label %70, label %69

69:                                               ; preds = %62, %55
  store i32 1, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %87

70:                                               ; preds = %62
  %71 = getelementptr inbounds [1000 x i8], ptr %4, i64 0, i64 0
  %72 = load i32, ptr %6, align 4, !tbaa !14
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds i8, ptr %71, i64 %73
  %75 = call i32 @strcmp(ptr noundef %74, ptr noundef @.str.2) #4
  %76 = icmp ne i32 %75, 0
  br i1 %76, label %78, label %77

77:                                               ; preds = %70
  store i32 2, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %87

78:                                               ; preds = %70
  %79 = getelementptr inbounds [1000 x i8], ptr %4, i64 0, i64 0
  %80 = load i32, ptr %6, align 4, !tbaa !14
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds i8, ptr %79, i64 %81
  %83 = call i32 @strcmp(ptr noundef %82, ptr noundef @.str.3) #4
  %84 = icmp ne i32 %83, 0
  br i1 %84, label %86, label %85

85:                                               ; preds = %78
  store i32 3, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %87

86:                                               ; preds = %78
  store i32 0, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %87

87:                                               ; preds = %86, %85, %77, %69, %54
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 1000, ptr %4) #3
  %88 = load i32, ptr %2, align 4
  ret i32 %88
}

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

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

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

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

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

attributes #0 = { mustprogress 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 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 }
attributes #4 = { nounwind willreturn memory(read) }

!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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!15, !15, i64 0}
!15 = !{!"int", !7, i64 0}
!16 = distinct !{!16, !13}


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

; Function Attrs: mustprogress nofree nounwind willreturn memory(read) uwtable
define dso_local noundef range(i32 0, 4) i32 @_Z8filetypePKc(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = alloca [1000 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 1000, ptr nonnull %2) #5
  %3 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #6
  %invariant.umin = tail call i64 @llvm.umin.i64(i64 %3, i64 999)
  %.not27 = icmp eq i64 %3, 0
  br i1 %.not27, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1, %.lr.ph
  %.01623 = phi i64 [ %10, %.lr.ph ], [ 0, %1 ]
  %4 = getelementptr inbounds i8, ptr %0, i64 %.01623
  %5 = load i8, ptr %4, align 1, !tbaa !5
  %6 = sext i8 %5 to i32
  %7 = tail call i32 @tolower(i32 noundef %6) #6
  %8 = trunc i32 %7 to i8
  %9 = getelementptr inbounds [1000 x i8], ptr %2, i64 0, i64 %.01623
  store i8 %8, ptr %9, align 1, !tbaa !5
  %10 = add nuw nsw i64 %.01623, 1
  %exitcond.not = icmp eq i64 %10, %invariant.umin
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !8

._crit_edge:                                      ; preds = %.lr.ph, %1
  %.016.lcssa = phi i64 [ 0, %1 ], [ %invariant.umin, %.lr.ph ]
  %11 = getelementptr inbounds [1000 x i8], ptr %2, i64 0, i64 %.016.lcssa
  store i8 0, ptr %11, align 1, !tbaa !5
  %12 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %2) #6
  %13 = trunc i64 %12 to i32
  %14 = icmp sgt i32 %13, -1
  br i1 %14, label %.lr.ph26, label %.critedge.thread

.lr.ph26:                                         ; preds = %._crit_edge, %18
  %.024 = phi i32 [ %19, %18 ], [ %13, %._crit_edge ]
  %15 = zext nneg i32 %.024 to i64
  %16 = getelementptr inbounds [1000 x i8], ptr %2, i64 0, i64 %15
  %17 = load i8, ptr %16, align 1, !tbaa !5
  %.not = icmp eq i8 %17, 46
  br i1 %.not, label %.critedge, label %18

18:                                               ; preds = %.lr.ph26
  %19 = add nsw i32 %.024, -1
  %20 = icmp sgt i32 %.024, 0
  br i1 %20, label %.lr.ph26, label %.critedge.thread, !llvm.loop !10

.critedge:                                        ; preds = %.lr.ph26
  %21 = getelementptr inbounds [1000 x i8], ptr %2, i64 0, i64 %15
  %22 = call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %21, ptr noundef nonnull dereferenceable(1) @.str) #6
  %.not18 = icmp eq i32 %22, 0
  br i1 %.not18, label %.critedge.thread, label %23

23:                                               ; preds = %.critedge
  %24 = call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %21, ptr noundef nonnull dereferenceable(1) @.str.1) #6
  %.not19 = icmp eq i32 %24, 0
  br i1 %.not19, label %.critedge.thread, label %25

25:                                               ; preds = %23
  %26 = call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %21, ptr noundef nonnull dereferenceable(1) @.str.2) #6
  %.not20 = icmp eq i32 %26, 0
  br i1 %.not20, label %.critedge.thread, label %27

27:                                               ; preds = %25
  %28 = call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %21, ptr noundef nonnull dereferenceable(1) @.str.3) #6
  %.not21 = icmp eq i32 %28, 0
  %. = select i1 %.not21, i32 3, i32 0
  br label %.critedge.thread

.critedge.thread:                                 ; preds = %18, %._crit_edge, %27, %25, %.critedge, %23
  %.017 = phi i32 [ 1, %23 ], [ 1, %.critedge ], [ 2, %25 ], [ %., %27 ], [ 0, %._crit_edge ], [ 0, %18 ]
  call void @llvm.lifetime.end.p0(i64 1000, ptr nonnull %2) #5
  ret i32 %.017
}

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nounwind willreturn memory(read)
declare i32 @tolower(i32 noundef) local_unnamed_addr #3

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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umin.i64(i64, i64) #4

attributes #0 = { mustprogress nofree nounwind willreturn memory(read) 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 = { 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 #3 = { mustprogress nofree 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 #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { nounwind }
attributes #6 = { nounwind willreturn memory(read) }

!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++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = distinct !{!10, !9}


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