; LLVM IR from AllAlgorithms/c :: algorithms/ciphers (caesar_cipher)

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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @caesarCipher(i32 noundef %0, ptr noundef %1, i8 noundef signext %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i8, align 1
  %7 = alloca [26 x i8], align 16
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca i8, align 1
  %13 = alloca i8, align 1
  %14 = alloca i8, align 1
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  store i8 %2, ptr %6, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 26, ptr %7) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  store i32 65, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #6
  %17 = load ptr, ptr %5, align 8, !tbaa !9
  %18 = call i64 @strlen(ptr noundef %17) #7
  %19 = trunc i64 %18 to i32
  store i32 %19, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #6
  store i32 0, ptr %10, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #6
  %20 = load i32, ptr %9, align 4, !tbaa !5
  %21 = add nsw i32 %20, 1
  %22 = sext i32 %21 to i64
  %23 = call noalias ptr @malloc(i64 noundef %22) #8
  store ptr %23, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %12) #6
  call void @llvm.lifetime.start.p0(i64 1, ptr %13) #6
  call void @llvm.lifetime.start.p0(i64 1, ptr %14) #6
  %24 = load ptr, ptr %11, align 8, !tbaa !9
  %25 = icmp ne ptr %24, null
  br i1 %25, label %27, label %26

26:                                               ; preds = %3
  call void @exit(i32 noundef 1) #9
  unreachable

27:                                               ; preds = %3
  %28 = load i8, ptr %6, align 1, !tbaa !11
  %29 = sext i8 %28 to i32
  %30 = icmp eq i32 %29, 100
  br i1 %30, label %31, label %34

31:                                               ; preds = %27
  %32 = load i32, ptr %4, align 4, !tbaa !5
  %33 = sub nsw i32 0, %32
  store i32 %33, ptr %4, align 4, !tbaa !5
  br label %34

34:                                               ; preds = %31, %27
  store i32 0, ptr %10, align 4, !tbaa !5
  br label %35

35:                                               ; preds = %46, %34
  %36 = load i32, ptr %10, align 4, !tbaa !5
  %37 = icmp slt i32 %36, 26
  br i1 %37, label %38, label %49

38:                                               ; preds = %35
  %39 = load i32, ptr %8, align 4, !tbaa !5
  %40 = load i32, ptr %10, align 4, !tbaa !5
  %41 = add nsw i32 %39, %40
  %42 = trunc i32 %41 to i8
  %43 = load i32, ptr %10, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [26 x i8], ptr %7, i64 0, i64 %44
  store i8 %42, ptr %45, align 1, !tbaa !11
  br label %46

46:                                               ; preds = %38
  %47 = load i32, ptr %10, align 4, !tbaa !5
  %48 = add nsw i32 %47, 1
  store i32 %48, ptr %10, align 4, !tbaa !5
  br label %35, !llvm.loop !12

49:                                               ; preds = %35
  store i32 0, ptr %10, align 4, !tbaa !5
  br label %50

50:                                               ; preds = %123, %49
  %51 = load i32, ptr %10, align 4, !tbaa !5
  %52 = load i32, ptr %9, align 4, !tbaa !5
  %53 = icmp slt i32 %51, %52
  br i1 %53, label %54, label %126

54:                                               ; preds = %50
  %55 = call ptr @__ctype_b_loc() #10
  %56 = load ptr, ptr %55, align 8, !tbaa !9
  %57 = load ptr, ptr %5, align 8, !tbaa !9
  %58 = load i32, ptr %10, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds i8, ptr %57, i64 %59
  %61 = load i8, ptr %60, align 1, !tbaa !11
  %62 = sext i8 %61 to i32
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds i16, ptr %56, i64 %63
  %65 = load i16, ptr %64, align 2, !tbaa !14
  %66 = zext i16 %65 to i32
  %67 = and i32 %66, 1024
  %68 = icmp ne i32 %67, 0
  br i1 %68, label %69, label %112

69:                                               ; preds = %54
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #6
  %70 = call ptr @__ctype_toupper_loc() #10
  %71 = load ptr, ptr %70, align 8, !tbaa !9
  %72 = load ptr, ptr %5, align 8, !tbaa !9
  %73 = load i32, ptr %10, align 4, !tbaa !5
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds i8, ptr %72, i64 %74
  %76 = load i8, ptr %75, align 1, !tbaa !11
  %77 = sext i8 %76 to i32
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds i32, ptr %71, i64 %78
  %80 = load i32, ptr %79, align 4, !tbaa !5
  store i32 %80, ptr %15, align 4, !tbaa !5
  %81 = load i32, ptr %15, align 4, !tbaa !5
  store i32 %81, ptr %16, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #6
  %82 = load i32, ptr %16, align 4, !tbaa !5
  %83 = trunc i32 %82 to i8
  store i8 %83, ptr %14, align 1, !tbaa !11
  %84 = load i8, ptr %14, align 1, !tbaa !11
  %85 = sext i8 %84 to i32
  %86 = load i32, ptr %8, align 4, !tbaa !5
  %87 = sub nsw i32 %85, %86
  %88 = trunc i32 %87 to i8
  store i8 %88, ptr %12, align 1, !tbaa !11
  %89 = load i8, ptr %12, align 1, !tbaa !11
  %90 = sext i8 %89 to i32
  %91 = load i32, ptr %4, align 4, !tbaa !5
  %92 = add nsw i32 %90, %91
  %93 = srem i32 %92, 26
  %94 = trunc i32 %93 to i8
  store i8 %94, ptr %13, align 1, !tbaa !11
  %95 = load i8, ptr %13, align 1, !tbaa !11
  %96 = sext i8 %95 to i32
  %97 = icmp slt i32 %96, 0
  br i1 %97, label %98, label %103

98:                                               ; preds = %69
  %99 = load i8, ptr %13, align 1, !tbaa !11
  %100 = sext i8 %99 to i32
  %101 = add nsw i32 %100, 26
  %102 = trunc i32 %101 to i8
  store i8 %102, ptr %13, align 1, !tbaa !11
  br label %103

103:                                              ; preds = %98, %69
  %104 = load i8, ptr %13, align 1, !tbaa !11
  %105 = sext i8 %104 to i64
  %106 = getelementptr inbounds [26 x i8], ptr %7, i64 0, i64 %105
  %107 = load i8, ptr %106, align 1, !tbaa !11
  %108 = load ptr, ptr %11, align 8, !tbaa !9
  %109 = load i32, ptr %10, align 4, !tbaa !5
  %110 = sext i32 %109 to i64
  %111 = getelementptr inbounds i8, ptr %108, i64 %110
  store i8 %107, ptr %111, align 1, !tbaa !11
  br label %122

112:                                              ; preds = %54
  %113 = load ptr, ptr %5, align 8, !tbaa !9
  %114 = load i32, ptr %10, align 4, !tbaa !5
  %115 = sext i32 %114 to i64
  %116 = getelementptr inbounds i8, ptr %113, i64 %115
  %117 = load i8, ptr %116, align 1, !tbaa !11
  %118 = load ptr, ptr %11, align 8, !tbaa !9
  %119 = load i32, ptr %10, align 4, !tbaa !5
  %120 = sext i32 %119 to i64
  %121 = getelementptr inbounds i8, ptr %118, i64 %120
  store i8 %117, ptr %121, align 1, !tbaa !11
  br label %122

122:                                              ; preds = %112, %103
  br label %123

123:                                              ; preds = %122
  %124 = load i32, ptr %10, align 4, !tbaa !5
  %125 = add nsw i32 %124, 1
  store i32 %125, ptr %10, align 4, !tbaa !5
  br label %50, !llvm.loop !16

126:                                              ; preds = %50
  %127 = load ptr, ptr %11, align 8, !tbaa !9
  %128 = load i32, ptr %9, align 4, !tbaa !5
  %129 = sext i32 %128 to i64
  %130 = getelementptr inbounds i8, ptr %127, i64 %129
  store i8 0, ptr %130, align 1, !tbaa !11
  %131 = load ptr, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 1, ptr %14) #6
  call void @llvm.lifetime.end.p0(i64 1, ptr %13) #6
  call void @llvm.lifetime.end.p0(i64 1, ptr %12) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 26, ptr %7) #6
  ret ptr %131
}

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

; 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: noreturn nounwind
declare void @exit(i32 noundef) #4

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__ctype_b_loc() #5

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__ctype_toupper_loc() #5

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { noreturn 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 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 #6 = { nounwind }
attributes #7 = { nounwind willreturn memory(read) }
attributes #8 = { nounwind allocsize(0) }
attributes #9 = { noreturn nounwind }
attributes #10 = { 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 = !{!"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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!15, !15, i64 0}
!15 = !{!"short", !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"

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

; Function Attrs: nounwind uwtable
define dso_local noalias noundef ptr @caesarCipher(i32 noundef %0, ptr nocapture noundef readonly %1, i8 noundef signext %2) local_unnamed_addr #1 {
  %4 = alloca [26 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 26, ptr nonnull %4) #6
  %5 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %1) #7
  %6 = shl i64 %5, 32
  %sext = add i64 %6, 4294967296
  %7 = ashr exact i64 %sext, 32
  %8 = tail call noalias ptr @malloc(i64 noundef %7) #8
  %.not = icmp eq ptr %8, null
  br i1 %.not, label %9, label %.preheader

9:                                                ; preds = %3
  tail call void @exit(i32 noundef 1) #9
  unreachable

.preheader:                                       ; preds = %3
  %10 = trunc i64 %5 to i32
  %11 = sub nsw i32 0, %0
  store <16 x i8> <i8 65, i8 66, i8 67, i8 68, i8 69, i8 70, i8 71, i8 72, i8 73, i8 74, i8 75, i8 76, i8 77, i8 78, i8 79, i8 80>, ptr %4, align 16, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %4, i64 16
  store <8 x i8> <i8 81, i8 82, i8 83, i8 84, i8 85, i8 86, i8 87, i8 88>, ptr %12, align 16, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %4, i64 24
  store i8 89, ptr %13, align 8, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %4, i64 25
  store i8 90, ptr %14, align 1, !tbaa !5
  %15 = icmp eq i8 %2, 100
  %spec.select = select i1 %15, i32 %11, i32 %0
  %16 = icmp sgt i32 %10, 0
  br i1 %16, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader
  %17 = tail call ptr @__ctype_b_loc() #10
  %18 = load ptr, ptr %17, align 8, !tbaa !8
  %wide.trip.count = and i64 %5, 2147483647
  br label %19

19:                                               ; preds = %.lr.ph, %42
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %42 ]
  %20 = getelementptr inbounds i8, ptr %1, i64 %indvars.iv
  %21 = load i8, ptr %20, align 1, !tbaa !5
  %22 = sext i8 %21 to i64
  %23 = getelementptr inbounds i16, ptr %18, i64 %22
  %24 = load i16, ptr %23, align 2, !tbaa !10
  %25 = and i16 %24, 1024
  %.not40 = icmp eq i16 %25, 0
  br i1 %.not40, label %42, label %26

26:                                               ; preds = %19
  %27 = tail call ptr @__ctype_toupper_loc() #10
  %28 = load ptr, ptr %27, align 8, !tbaa !8
  %29 = getelementptr inbounds i32, ptr %28, i64 %22
  %30 = load i32, ptr %29, align 4, !tbaa !12
  %31 = shl i32 %30, 24
  %sext42 = add i32 %31, -1090519040
  %32 = ashr exact i32 %sext42, 24
  %33 = add nsw i32 %32, %spec.select
  %34 = srem i32 %33, 26
  %35 = zext i32 %34 to i64
  %36 = icmp slt i32 %34, 0
  %37 = shl i64 %35, 56
  %38 = add nsw i64 %37, 1873497444986126336
  %sext43 = select i1 %36, i64 %38, i64 %37
  %39 = ashr exact i64 %sext43, 56
  %40 = getelementptr inbounds [26 x i8], ptr %4, i64 0, i64 %39
  %41 = load i8, ptr %40, align 1, !tbaa !5
  br label %42

42:                                               ; preds = %19, %26
  %.sink = phi i8 [ %41, %26 ], [ %21, %19 ]
  %43 = getelementptr inbounds i8, ptr %8, i64 %indvars.iv
  store i8 %.sink, ptr %43, align 1
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %19, !llvm.loop !14

._crit_edge:                                      ; preds = %42, %.preheader
  %44 = ashr exact i64 %6, 32
  %45 = getelementptr inbounds i8, ptr %8, i64 %44
  store i8 0, ptr %45, align 1, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 26, ptr nonnull %4) #6
  ret ptr %8
}

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

; 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 allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #3

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #4

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

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

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


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