; LLVM IR from devicehive/esp8266-firmware :: firmware-src/sources (rand)

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

@__const.rand_generate_deviceid.prefix = external hidden unnamed_addr constant [12 x i8], align 1
@.str = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @rand() #0

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @rand_generate_deviceid(ptr noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca [12 x i8], align 1
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 12, ptr %4) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %4, ptr align 1 @__const.rand_generate_deviceid.prefix, i64 12, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 16, ptr %5, align 4, !tbaa !9
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = icmp eq ptr %9, null
  br i1 %10, label %11, label %12

11:                                               ; preds = %1
  store i32 27, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %34

12:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds [12 x i8], ptr %4, i64 0, i64 0
  %15 = call i32 (ptr, i32, ptr, ...) @snprintf(ptr noundef %13, i32 noundef 12, ptr noundef %14)
  store i32 %15, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %16

16:                                               ; preds = %29, %12
  %17 = load i32, ptr %8, align 4, !tbaa !9
  %18 = icmp ult i32 %17, 16
  br i1 %18, label %19, label %32

19:                                               ; preds = %16
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = load i32, ptr %7, align 4, !tbaa !9
  %22 = zext i32 %21 to i64
  %23 = getelementptr inbounds i8, ptr %20, i64 %22
  %24 = call i32 @rand()
  %25 = srem i32 %24, 16
  %26 = call i32 (ptr, i32, ptr, ...) @snprintf(ptr noundef %23, i32 noundef 2, ptr noundef @.str, i32 noundef %25)
  %27 = load i32, ptr %7, align 4, !tbaa !9
  %28 = add i32 %27, %26
  store i32 %28, ptr %7, align 4, !tbaa !9
  br label %29

29:                                               ; preds = %19
  %30 = load i32, ptr %8, align 4, !tbaa !9
  %31 = add nsw i32 %30, 1
  store i32 %31, ptr %8, align 4, !tbaa !9
  br label %16, !llvm.loop !11

32:                                               ; preds = %16
  %33 = load i32, ptr %7, align 4, !tbaa !9
  store i32 %33, ptr %2, align 4
  store i32 1, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %34

34:                                               ; preds = %32, %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 12, ptr %4) #4
  %35 = load i32, ptr %2, align 4
  ret i32 %35
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

declare i32 @snprintf(ptr noundef, i32 noundef, ptr noundef, ...) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 }

!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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"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"

@__const.rand_generate_deviceid.prefix = external hidden unnamed_addr constant [12 x i8], align 1
@.str = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @rand() local_unnamed_addr #0

; 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @rand_generate_deviceid(ptr noundef %0) local_unnamed_addr #0 {
  %2 = alloca [12 x i8], align 1
  call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %2) #4
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(12) %2, ptr noundef nonnull align 1 dereferenceable(12) @__const.rand_generate_deviceid.prefix, i64 12, i1 false)
  %3 = icmp eq ptr %0, null
  br i1 %3, label %.loopexit, label %.loopexit.loopexit

.loopexit.loopexit:                               ; preds = %1
  %4 = call i32 (ptr, i32, ptr, ...) @snprintf(ptr noundef nonnull %0, i32 noundef 12, ptr noundef nonnull %2) #4
  %5 = zext i32 %4 to i64
  %6 = getelementptr inbounds i8, ptr %0, i64 %5
  %7 = call i32 @rand()
  %8 = srem i32 %7, 16
  %9 = call i32 (ptr, i32, ptr, ...) @snprintf(ptr noundef nonnull %6, i32 noundef 2, ptr noundef nonnull @.str, i32 noundef %8) #4
  %10 = add i32 %9, %4
  %11 = zext i32 %10 to i64
  %12 = getelementptr inbounds i8, ptr %0, i64 %11
  %13 = call i32 @rand()
  %14 = srem i32 %13, 16
  %15 = call i32 (ptr, i32, ptr, ...) @snprintf(ptr noundef nonnull %12, i32 noundef 2, ptr noundef nonnull @.str, i32 noundef %14) #4
  %16 = add i32 %15, %10
  %17 = zext i32 %16 to i64
  %18 = getelementptr inbounds i8, ptr %0, i64 %17
  %19 = call i32 @rand()
  %20 = srem i32 %19, 16
  %21 = call i32 (ptr, i32, ptr, ...) @snprintf(ptr noundef nonnull %18, i32 noundef 2, ptr noundef nonnull @.str, i32 noundef %20) #4
  %22 = add i32 %21, %16
  %23 = zext i32 %22 to i64
  %24 = getelementptr inbounds i8, ptr %0, i64 %23
  %25 = call i32 @rand()
  %26 = srem i32 %25, 16
  %27 = call i32 (ptr, i32, ptr, ...) @snprintf(ptr noundef nonnull %24, i32 noundef 2, ptr noundef nonnull @.str, i32 noundef %26) #4
  %28 = add i32 %27, %22
  %29 = zext i32 %28 to i64
  %30 = getelementptr inbounds i8, ptr %0, i64 %29
  %31 = call i32 @rand()
  %32 = srem i32 %31, 16
  %33 = call i32 (ptr, i32, ptr, ...) @snprintf(ptr noundef nonnull %30, i32 noundef 2, ptr noundef nonnull @.str, i32 noundef %32) #4
  %34 = add i32 %33, %28
  %35 = zext i32 %34 to i64
  %36 = getelementptr inbounds i8, ptr %0, i64 %35
  %37 = call i32 @rand()
  %38 = srem i32 %37, 16
  %39 = call i32 (ptr, i32, ptr, ...) @snprintf(ptr noundef nonnull %36, i32 noundef 2, ptr noundef nonnull @.str, i32 noundef %38) #4
  %40 = add i32 %39, %34
  %41 = zext i32 %40 to i64
  %42 = getelementptr inbounds i8, ptr %0, i64 %41
  %43 = call i32 @rand()
  %44 = srem i32 %43, 16
  %45 = call i32 (ptr, i32, ptr, ...) @snprintf(ptr noundef nonnull %42, i32 noundef 2, ptr noundef nonnull @.str, i32 noundef %44) #4
  %46 = add i32 %45, %40
  %47 = zext i32 %46 to i64
  %48 = getelementptr inbounds i8, ptr %0, i64 %47
  %49 = call i32 @rand()
  %50 = srem i32 %49, 16
  %51 = call i32 (ptr, i32, ptr, ...) @snprintf(ptr noundef nonnull %48, i32 noundef 2, ptr noundef nonnull @.str, i32 noundef %50) #4
  %52 = add i32 %51, %46
  %53 = zext i32 %52 to i64
  %54 = getelementptr inbounds i8, ptr %0, i64 %53
  %55 = call i32 @rand()
  %56 = srem i32 %55, 16
  %57 = call i32 (ptr, i32, ptr, ...) @snprintf(ptr noundef nonnull %54, i32 noundef 2, ptr noundef nonnull @.str, i32 noundef %56) #4
  %58 = add i32 %57, %52
  %59 = zext i32 %58 to i64
  %60 = getelementptr inbounds i8, ptr %0, i64 %59
  %61 = call i32 @rand()
  %62 = srem i32 %61, 16
  %63 = call i32 (ptr, i32, ptr, ...) @snprintf(ptr noundef nonnull %60, i32 noundef 2, ptr noundef nonnull @.str, i32 noundef %62) #4
  %64 = add i32 %63, %58
  %65 = zext i32 %64 to i64
  %66 = getelementptr inbounds i8, ptr %0, i64 %65
  %67 = call i32 @rand()
  %68 = srem i32 %67, 16
  %69 = call i32 (ptr, i32, ptr, ...) @snprintf(ptr noundef nonnull %66, i32 noundef 2, ptr noundef nonnull @.str, i32 noundef %68) #4
  %70 = add i32 %69, %64
  %71 = zext i32 %70 to i64
  %72 = getelementptr inbounds i8, ptr %0, i64 %71
  %73 = call i32 @rand()
  %74 = srem i32 %73, 16
  %75 = call i32 (ptr, i32, ptr, ...) @snprintf(ptr noundef nonnull %72, i32 noundef 2, ptr noundef nonnull @.str, i32 noundef %74) #4
  %76 = add i32 %75, %70
  %77 = zext i32 %76 to i64
  %78 = getelementptr inbounds i8, ptr %0, i64 %77
  %79 = call i32 @rand()
  %80 = srem i32 %79, 16
  %81 = call i32 (ptr, i32, ptr, ...) @snprintf(ptr noundef nonnull %78, i32 noundef 2, ptr noundef nonnull @.str, i32 noundef %80) #4
  %82 = add i32 %81, %76
  %83 = zext i32 %82 to i64
  %84 = getelementptr inbounds i8, ptr %0, i64 %83
  %85 = call i32 @rand()
  %86 = srem i32 %85, 16
  %87 = call i32 (ptr, i32, ptr, ...) @snprintf(ptr noundef nonnull %84, i32 noundef 2, ptr noundef nonnull @.str, i32 noundef %86) #4
  %88 = add i32 %87, %82
  %89 = zext i32 %88 to i64
  %90 = getelementptr inbounds i8, ptr %0, i64 %89
  %91 = call i32 @rand()
  %92 = srem i32 %91, 16
  %93 = call i32 (ptr, i32, ptr, ...) @snprintf(ptr noundef nonnull %90, i32 noundef 2, ptr noundef nonnull @.str, i32 noundef %92) #4
  %94 = add i32 %93, %88
  %95 = zext i32 %94 to i64
  %96 = getelementptr inbounds i8, ptr %0, i64 %95
  %97 = call i32 @rand()
  %98 = srem i32 %97, 16
  %99 = call i32 (ptr, i32, ptr, ...) @snprintf(ptr noundef nonnull %96, i32 noundef 2, ptr noundef nonnull @.str, i32 noundef %98) #4
  %100 = add i32 %99, %94
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.loopexit, %1
  %.09 = phi i32 [ 27, %1 ], [ %100, %.loopexit.loopexit ]
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %2) #4
  ret i32 %.09
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

declare i32 @snprintf(ptr noundef, i32 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 nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 }

!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)"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,ReassociatePass,SROAPass,SimplifyCFGPass