; LLVM IR from 0intro/wmii :: cmd/x11 (setfocus)

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

@argv0 = external global ptr, align 8
@display = external global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local i32 @main(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  store i32 0, ptr %3, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #6
  store i32 0, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #6
  store ptr null, ptr %9, align 8, !tbaa !9
  %10 = load ptr, ptr @argv0, align 8, !tbaa !9
  %11 = icmp ne ptr %10, null
  br i1 %11, label %15, label %12

12:                                               ; preds = %2
  %13 = load ptr, ptr %5, align 8, !tbaa !9
  %14 = load ptr, ptr %13, align 8, !tbaa !9
  store ptr %14, ptr @argv0, align 8, !tbaa !9
  br label %15

15:                                               ; preds = %12, %2
  %16 = load ptr, ptr %5, align 8, !tbaa !9
  %17 = getelementptr inbounds ptr, ptr %16, i32 1
  store ptr %17, ptr %5, align 8, !tbaa !9
  %18 = load i32, ptr %4, align 4, !tbaa !5
  %19 = add nsw i32 %18, -1
  store i32 %19, ptr %4, align 4, !tbaa !5
  store i32 1, ptr %8, align 4, !tbaa !5
  %20 = load i32, ptr %8, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  call void (i64, ...) @_used(i64 noundef %21)
  br label %22

22:                                               ; preds = %67, %15
  %23 = load i32, ptr %4, align 4, !tbaa !5
  %24 = icmp ne i32 %23, 0
  br i1 %24, label %25, label %33

25:                                               ; preds = %22
  %26 = load ptr, ptr %5, align 8, !tbaa !9
  %27 = getelementptr inbounds ptr, ptr %26, i64 0
  %28 = load ptr, ptr %27, align 8, !tbaa !9
  %29 = getelementptr inbounds i8, ptr %28, i64 0
  %30 = load i8, ptr %29, align 1, !tbaa !11
  %31 = sext i8 %30 to i32
  %32 = icmp eq i32 %31, 45
  br label %33

33:                                               ; preds = %25, %22
  %34 = phi i1 [ false, %22 ], [ %32, %25 ]
  br i1 %34, label %35, label %68

35:                                               ; preds = %33
  %36 = load ptr, ptr %5, align 8, !tbaa !9
  %37 = getelementptr inbounds ptr, ptr %36, i64 0
  %38 = load ptr, ptr %37, align 8, !tbaa !9
  %39 = getelementptr inbounds i8, ptr %38, i64 1
  store ptr %39, ptr %9, align 8, !tbaa !9
  %40 = load ptr, ptr %5, align 8, !tbaa !9
  %41 = getelementptr inbounds ptr, ptr %40, i32 1
  store ptr %41, ptr %5, align 8, !tbaa !9
  %42 = load i32, ptr %4, align 4, !tbaa !5
  %43 = add nsw i32 %42, -1
  store i32 %43, ptr %4, align 4, !tbaa !5
  %44 = load ptr, ptr %9, align 8, !tbaa !9
  %45 = getelementptr inbounds i8, ptr %44, i64 0
  %46 = load i8, ptr %45, align 1, !tbaa !11
  %47 = sext i8 %46 to i32
  %48 = icmp eq i32 %47, 45
  br i1 %48, label %49, label %56

49:                                               ; preds = %35
  %50 = load ptr, ptr %9, align 8, !tbaa !9
  %51 = getelementptr inbounds i8, ptr %50, i64 1
  %52 = load i8, ptr %51, align 1, !tbaa !11
  %53 = sext i8 %52 to i32
  %54 = icmp eq i32 %53, 0
  br i1 %54, label %55, label %56

55:                                               ; preds = %49
  br label %68

56:                                               ; preds = %49, %35
  br label %57

57:                                               ; preds = %66, %56
  %58 = load ptr, ptr %9, align 8, !tbaa !9
  %59 = load i8, ptr %58, align 1, !tbaa !11
  %60 = icmp ne i8 %59, 0
  br i1 %60, label %61, label %67

61:                                               ; preds = %57
  %62 = load ptr, ptr %9, align 8, !tbaa !9
  %63 = getelementptr inbounds i8, ptr %62, i32 1
  store ptr %63, ptr %9, align 8, !tbaa !9
  %64 = load i8, ptr %62, align 1, !tbaa !11
  %65 = sext i8 %64 to i32
  switch i32 %65, label %66 [
  ]

66:                                               ; preds = %61
  br label %57, !llvm.loop !12

67:                                               ; preds = %57
  br label %22, !llvm.loop !14

68:                                               ; preds = %55, %33
  store i32 0, ptr %8, align 4, !tbaa !5
  %69 = load i32, ptr %7, align 4, !tbaa !5
  %70 = sext i32 %69 to i64
  %71 = load ptr, ptr %9, align 8, !tbaa !9
  %72 = load i32, ptr %8, align 4, !tbaa !5
  call void (i64, ...) @_used(i64 noundef %70, ptr noundef %71, i32 noundef %72)
  call void @initdisplay()
  %73 = load i32, ptr %8, align 4, !tbaa !5
  %74 = icmp ne i32 %73, 0
  br i1 %74, label %75, label %93

75:                                               ; preds = %68
  %76 = load ptr, ptr %9, align 8, !tbaa !9
  %77 = load i8, ptr %76, align 1, !tbaa !11
  %78 = sext i8 %77 to i32
  %79 = icmp ne i32 %78, 0
  br i1 %79, label %80, label %93

80:                                               ; preds = %75
  %81 = load ptr, ptr %9, align 8, !tbaa !9
  %82 = call i64 @strlen(ptr noundef %81) #7
  %83 = trunc i64 %82 to i32
  store i32 %83, ptr %7, align 4, !tbaa !5
  %84 = load i32, ptr %7, align 4, !tbaa !5
  %85 = load ptr, ptr %9, align 8, !tbaa !9
  %86 = sext i32 %84 to i64
  %87 = getelementptr inbounds i8, ptr %85, i64 %86
  store ptr %87, ptr %9, align 8, !tbaa !9
  %88 = load ptr, ptr %9, align 8, !tbaa !9
  %89 = load i32, ptr %7, align 4, !tbaa !5
  %90 = sext i32 %89 to i64
  %91 = sub i64 0, %90
  %92 = getelementptr inbounds i8, ptr %88, i64 %91
  br label %110

93:                                               ; preds = %75, %68
  %94 = load i32, ptr %4, align 4, !tbaa !5
  %95 = icmp sgt i32 %94, 0
  br i1 %95, label %96, label %106

96:                                               ; preds = %93
  %97 = load i32, ptr %4, align 4, !tbaa !5
  %98 = add nsw i32 %97, -1
  store i32 %98, ptr %4, align 4, !tbaa !5
  %99 = load ptr, ptr %5, align 8, !tbaa !9
  %100 = getelementptr inbounds ptr, ptr %99, i32 1
  store ptr %100, ptr %5, align 8, !tbaa !9
  %101 = load i32, ptr %4, align 4, !tbaa !5
  %102 = sext i32 %101 to i64
  call void (i64, ...) @_used(i64 noundef %102)
  %103 = load ptr, ptr %5, align 8, !tbaa !9
  %104 = getelementptr inbounds ptr, ptr %103, i64 -1
  %105 = load ptr, ptr %104, align 8, !tbaa !9
  br label %108

106:                                              ; preds = %93
  call void @exit(i32 noundef 1) #8
  unreachable

107:                                              ; No predecessors!
  br label %108

108:                                              ; preds = %107, %96
  %109 = phi ptr [ %105, %96 ], [ null, %107 ]
  br label %110

110:                                              ; preds = %108, %80
  %111 = phi ptr [ %92, %80 ], [ %109, %108 ]
  %112 = call zeroext i1 @getulong(ptr noundef %111, ptr noundef %6)
  br i1 %112, label %114, label %113

113:                                              ; preds = %110
  call void @exit(i32 noundef 1) #8
  unreachable

114:                                              ; preds = %110
  %115 = load ptr, ptr @display, align 8, !tbaa !9
  %116 = load i64, ptr %6, align 8, !tbaa !15
  %117 = call i32 @XSetInputFocus(ptr noundef %115, i64 noundef %116, i32 noundef 2, i64 noundef 0)
  %118 = load ptr, ptr @display, align 8, !tbaa !9
  %119 = call i32 @XCloseDisplay(ptr noundef %118)
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  %120 = load i32, ptr %3, align 4
  ret i32 %120
}

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @_used(i64 noundef, ...) #2

declare void @initdisplay() #3

declare zeroext i1 @getulong(ptr noundef, ptr noundef) #3

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

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

declare i32 @XSetInputFocus(ptr noundef, i64 noundef, i32 noundef, i64 noundef) #3

declare i32 @XCloseDisplay(ptr noundef) #3

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

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 = { inlinehint 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 #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 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 = { 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 #6 = { nounwind }
attributes #7 = { nounwind willreturn memory(read) }
attributes #8 = { noreturn 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 = !{!"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 = distinct !{!14, !13}
!15 = !{!16, !16, i64 0}
!16 = !{!"long", !7, i64 0}


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

@argv0 = external local_unnamed_addr global ptr, align 8
@display = external local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main(i32 noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #5
  %4 = load ptr, ptr @argv0, align 8, !tbaa !5
  %.not = icmp eq ptr %4, null
  br i1 %.not, label %5, label %7

5:                                                ; preds = %2
  %6 = load ptr, ptr %1, align 8, !tbaa !5
  store ptr %6, ptr @argv0, align 8, !tbaa !5
  br label %7

7:                                                ; preds = %5, %2
  %8 = getelementptr inbounds i8, ptr %1, i64 8
  %9 = add nsw i32 %0, -1
  tail call void (i64, ...) @_used(i64 noundef 1)
  %.not3234 = icmp eq i32 %9, 0
  br i1 %.not3234, label %.critedge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %7
  %10 = load ptr, ptr %8, align 8, !tbaa !5
  %11 = load i8, ptr %10, align 1, !tbaa !9
  %12 = icmp eq i8 %11, 45
  br i1 %12, label %.lr.ph50, label %.critedge

.loopexit:                                        ; preds = %26
  %.not32 = icmp eq i32 %19, 0
  br i1 %.not32, label %.critedge, label %.lr.ph, !llvm.loop !10

.lr.ph:                                           ; preds = %.loopexit
  %13 = load ptr, ptr %18, align 8, !tbaa !5
  %14 = load i8, ptr %13, align 1, !tbaa !9
  %15 = icmp eq i8 %14, 45
  br i1 %15, label %.lr.ph50, label %.critedge, !llvm.loop !10

.lr.ph50:                                         ; preds = %.lr.ph.preheader, %.lr.ph
  %16 = phi ptr [ %13, %.lr.ph ], [ %10, %.lr.ph.preheader ]
  %.0303549 = phi i32 [ %19, %.lr.ph ], [ %9, %.lr.ph.preheader ]
  %.0283648 = phi ptr [ %18, %.lr.ph ], [ %8, %.lr.ph.preheader ]
  %17 = getelementptr inbounds i8, ptr %16, i64 1
  %18 = getelementptr inbounds i8, ptr %.0283648, i64 8
  %19 = add nsw i32 %.0303549, -1
  %20 = load i8, ptr %17, align 1, !tbaa !9
  %21 = icmp eq i8 %20, 45
  br i1 %21, label %22, label %.preheader

22:                                               ; preds = %.lr.ph50
  %23 = getelementptr inbounds i8, ptr %16, i64 2
  %24 = load i8, ptr %23, align 1, !tbaa !9
  %25 = icmp eq i8 %24, 0
  br i1 %25, label %.critedge, label %.preheader

.preheader:                                       ; preds = %22, %.lr.ph50
  br label %26

26:                                               ; preds = %.preheader, %26
  %.1 = phi ptr [ %28, %26 ], [ %17, %.preheader ]
  %27 = load i8, ptr %.1, align 1, !tbaa !9
  %.not33 = icmp eq i8 %27, 0
  %28 = getelementptr inbounds i8, ptr %.1, i64 1
  br i1 %.not33, label %.loopexit, label %26, !llvm.loop !12

.critedge:                                        ; preds = %.loopexit, %22, %.lr.ph, %.lr.ph.preheader, %7
  %.131 = phi i32 [ 0, %7 ], [ %9, %.lr.ph.preheader ], [ %19, %.lr.ph ], [ %19, %22 ], [ 0, %.loopexit ]
  %.129 = phi ptr [ %8, %7 ], [ %8, %.lr.ph.preheader ], [ %18, %.lr.ph ], [ %18, %22 ], [ %18, %.loopexit ]
  %.2 = phi ptr [ null, %7 ], [ null, %.lr.ph.preheader ], [ %.1, %.lr.ph ], [ %17, %22 ], [ %.1, %.loopexit ]
  tail call void (i64, ...) @_used(i64 noundef 0, ptr noundef %.2, i32 noundef 0)
  tail call void @initdisplay() #5
  %29 = icmp sgt i32 %.131, 0
  br i1 %29, label %30, label %35

30:                                               ; preds = %.critedge
  %31 = add nsw i32 %.131, -1
  %32 = zext nneg i32 %31 to i64
  tail call void (i64, ...) @_used(i64 noundef %32)
  %33 = load ptr, ptr %.129, align 8, !tbaa !5
  %34 = call zeroext i1 @getulong(ptr noundef %33, ptr noundef nonnull %3) #5
  br i1 %34, label %37, label %36

35:                                               ; preds = %.critedge
  tail call void @exit(i32 noundef 1) #6
  unreachable

36:                                               ; preds = %30
  call void @exit(i32 noundef 1) #6
  unreachable

37:                                               ; preds = %30
  %38 = load ptr, ptr @display, align 8, !tbaa !5
  %39 = load i64, ptr %3, align 8, !tbaa !13
  %40 = call i32 @XSetInputFocus(ptr noundef %38, i64 noundef %39, i32 noundef 2, i64 noundef 0) #5
  %41 = load ptr, ptr @display, align 8, !tbaa !5
  %42 = call i32 @XCloseDisplay(ptr noundef %41) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #5
  ret i32 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: inlinehint nounwind uwtable
declare hidden void @_used(i64 noundef, ...) local_unnamed_addr #2

declare void @initdisplay() local_unnamed_addr #3

declare zeroext i1 @getulong(ptr noundef, ptr noundef) local_unnamed_addr #3

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

declare i32 @XSetInputFocus(ptr noundef, i64 noundef, i32 noundef, i64 noundef) local_unnamed_addr #3

declare i32 @XCloseDisplay(ptr noundef) local_unnamed_addr #3

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

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 = { inlinehint 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 #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 = { 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 }
attributes #6 = { noreturn 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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}
!13 = !{!14, !14, i64 0}
!14 = !{!"long", !7, i64 0}


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