; LLVM IR from freddiev4/dailyprogrammerchallenges :: Easy Challenges/Challenge 0115 Easy - Guess-that-number game!/solutions (solution)

; 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 [4 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [109 x i8], align 1
@stdin = external global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [39 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [49 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [49 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [58 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca [10 x i8], align 1
  %4 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %5 = call i32 @system(ptr noundef @.str)
  %6 = call i64 @time(ptr noundef null) #5
  %7 = trunc i64 %6 to i32
  call void @srand(i32 noundef %7) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  %8 = call i32 @rand() #5
  %9 = srem i32 %8, 100
  %10 = add nsw i32 %9, 1
  store i32 %10, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 10, ptr %3) #5
  %11 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  %12 = getelementptr inbounds [10 x i8], ptr %3, i64 0, i64 0
  %13 = load ptr, ptr @stdin, align 8, !tbaa !9
  %14 = call ptr @fgets(ptr noundef %12, i32 noundef 10, ptr noundef %13)
  %15 = getelementptr inbounds [10 x i8], ptr %3, i64 0, i64 0
  %16 = call i64 @strlen(ptr noundef %15) #6
  %17 = sub i64 %16, 1
  %18 = getelementptr inbounds [10 x i8], ptr %3, i64 0, i64 %17
  store i8 0, ptr %18, align 1, !tbaa !11
  br label %19

19:                                               ; preds = %49, %0
  %20 = getelementptr inbounds [10 x i8], ptr %3, i64 0, i64 0
  %21 = call i64 @strtol(ptr noundef %20, ptr noundef null, i32 noundef 10) #5
  %22 = load i32, ptr %2, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = icmp ne i64 %21, %23
  br i1 %24, label %25, label %58

25:                                               ; preds = %19
  %26 = getelementptr inbounds [10 x i8], ptr %3, i64 0, i64 0
  %27 = call i32 @strcmp(ptr noundef %26, ptr noundef @.str.2) #6
  %28 = icmp eq i32 %27, 0
  br i1 %28, label %29, label %31

29:                                               ; preds = %25
  %30 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %4, align 4
  br label %60

31:                                               ; preds = %25
  %32 = getelementptr inbounds [10 x i8], ptr %3, i64 0, i64 0
  %33 = call i64 @strtol(ptr noundef %32, ptr noundef null, i32 noundef 10) #5
  %34 = icmp eq i64 %33, 0
  br i1 %34, label %35, label %37

35:                                               ; preds = %31
  %36 = call i32 (ptr, ...) @printf(ptr noundef @.str.4)
  br label %48

37:                                               ; preds = %31
  %38 = getelementptr inbounds [10 x i8], ptr %3, i64 0, i64 0
  %39 = call i64 @strtol(ptr noundef %38, ptr noundef null, i32 noundef 10) #5
  %40 = load i32, ptr %2, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = icmp sgt i64 %39, %41
  br i1 %42, label %43, label %45

43:                                               ; preds = %37
  %44 = call i32 (ptr, ...) @printf(ptr noundef @.str.5)
  br label %47

45:                                               ; preds = %37
  %46 = call i32 (ptr, ...) @printf(ptr noundef @.str.6)
  br label %47

47:                                               ; preds = %45, %43
  br label %48

48:                                               ; preds = %47, %35
  br label %49

49:                                               ; preds = %48
  %50 = call i32 (ptr, ...) @printf(ptr noundef @.str.7)
  %51 = getelementptr inbounds [10 x i8], ptr %3, i64 0, i64 0
  %52 = load ptr, ptr @stdin, align 8, !tbaa !9
  %53 = call ptr @fgets(ptr noundef %51, i32 noundef 10, ptr noundef %52)
  %54 = getelementptr inbounds [10 x i8], ptr %3, i64 0, i64 0
  %55 = call i64 @strlen(ptr noundef %54) #6
  %56 = sub i64 %55, 1
  %57 = getelementptr inbounds [10 x i8], ptr %3, i64 0, i64 %56
  store i8 0, ptr %57, align 1, !tbaa !11
  br label %19, !llvm.loop !12

58:                                               ; preds = %19
  %59 = call i32 (ptr, ...) @printf(ptr noundef @.str.8)
  store i32 0, ptr %4, align 4
  br label %60

60:                                               ; preds = %58, %29
  call void @llvm.lifetime.end.p0(i64 10, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  %61 = load i32, ptr %4, align 4
  switch i32 %61, label %64 [
    i32 0, label %62
    i32 1, label %62
  ]

62:                                               ; preds = %60, %60
  %63 = load i32, ptr %1, align 4
  ret i32 %63

64:                                               ; preds = %60
  unreachable
}

declare i32 @system(ptr noundef) #1

; Function Attrs: nounwind
declare void @srand(i32 noundef) #2

; Function Attrs: nounwind
declare i64 @time(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 @rand() #2

declare i32 @printf(ptr noundef, ...) #1

declare ptr @fgets(ptr noundef, i32 noundef, ptr noundef) #1

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

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

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

; 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(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 #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 = !{!"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"}


; 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 [4 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [109 x i8], align 1
@stdin = external local_unnamed_addr global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [39 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [49 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [49 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [58 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca [10 x i8], align 1
  %2 = tail call i32 @system(ptr noundef nonnull @.str) #7
  %3 = tail call i64 @time(ptr noundef null) #7
  %4 = trunc i64 %3 to i32
  tail call void @srand(i32 noundef %4) #7
  %5 = tail call i32 @rand() #7
  %6 = srem i32 %5, 100
  %7 = add nsw i32 %6, 1
  call void @llvm.lifetime.start.p0(i64 10, ptr nonnull %1) #7
  %8 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1)
  %9 = load ptr, ptr @stdin, align 8, !tbaa !5
  %10 = call ptr @fgets(ptr noundef nonnull %1, i32 noundef 10, ptr noundef %9)
  %11 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %1) #8
  %12 = add i64 %11, -1
  %13 = getelementptr inbounds [10 x i8], ptr %1, i64 0, i64 %12
  store i8 0, ptr %13, align 1, !tbaa !9
  %14 = sext i32 %7 to i64
  %15 = call i64 @strtol(ptr nocapture noundef nonnull %1, ptr noundef null, i32 noundef 10) #7
  %.not3 = icmp eq i64 %15, %14
  br i1 %.not3, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %0, %24
  %16 = call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %1, ptr noundef nonnull dereferenceable(1) @.str.2) #8
  %17 = icmp eq i32 %16, 0
  br i1 %17, label %._crit_edge, label %18

18:                                               ; preds = %.lr.ph
  %19 = call i64 @strtol(ptr nocapture noundef nonnull %1, ptr noundef null, i32 noundef 10) #7
  %20 = icmp eq i64 %19, 0
  br i1 %20, label %24, label %21

21:                                               ; preds = %18
  %22 = call i64 @strtol(ptr nocapture noundef nonnull %1, ptr noundef null, i32 noundef 10) #7
  %23 = icmp sgt i64 %22, %14
  %.str.5..str.6 = select i1 %23, ptr @.str.5, ptr @.str.6
  br label %24

24:                                               ; preds = %21, %18
  %.str.4.sink = phi ptr [ @.str.4, %18 ], [ %.str.5..str.6, %21 ]
  %25 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) %.str.4.sink)
  %26 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7)
  %27 = load ptr, ptr @stdin, align 8, !tbaa !5
  %28 = call ptr @fgets(ptr noundef nonnull %1, i32 noundef 10, ptr noundef %27)
  %29 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %1) #8
  %30 = add i64 %29, -1
  %31 = getelementptr inbounds [10 x i8], ptr %1, i64 0, i64 %30
  store i8 0, ptr %31, align 1, !tbaa !9
  %32 = call i64 @strtol(ptr nocapture noundef nonnull %1, ptr noundef null, i32 noundef 10) #7
  %.not = icmp eq i64 %32, %14
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !10

._crit_edge:                                      ; preds = %24, %.lr.ph, %0
  %.str.8.sink = phi ptr [ @.str.8, %0 ], [ @.str.3, %.lr.ph ], [ @.str.8, %24 ]
  %33 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) %.str.8.sink)
  call void @llvm.lifetime.end.p0(i64 10, ptr nonnull %1) #7
  ret i32 0
}

; Function Attrs: nofree
declare noundef i32 @system(ptr nocapture noundef readonly) local_unnamed_addr #1

; Function Attrs: nounwind
declare void @srand(i32 noundef) local_unnamed_addr #2

; Function Attrs: nounwind
declare i64 @time(ptr 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: nounwind
declare i32 @rand() local_unnamed_addr #2

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

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

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

; Function Attrs: mustprogress nofree nounwind willreturn
declare i64 @strtol(ptr noundef readonly, ptr nocapture noundef, i32 noundef) local_unnamed_addr #6

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

; 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 = { nofree "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 = { 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 = { 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 #6 = { mustprogress nofree nounwind willreturn "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(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/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass