#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ scanf(char *, int *);
int main() {
  int allnumbers[2000];
  int arraylength = 0;
  int smallestindex = 0;
  int temp = 0;
  int comparisons = 0;
  int swaps = 0;
  int loopstart = 1;
  int i = 0, j = 0;
  printf("Enter numbers: ");
  while (scanf("%d", &allnumbers[i]) && allnumbers[i] != 0) {
    i++;
  }
  arraylength = i;
  printf("\n");
  for (i = 0; i < arraylength + 1; i++) {
    for (j = loopstart; j < arraylength; j++) {
      if (allnumbers[smallestindex] > allnumbers[j]) {
        smallestindex = j;
      }
      comparisons++;
    }
    if (i < arraylength - 1) {
      swaps = i + 1;
      printf("Step %d: ", swaps);
    } else if (i < arraylength) {
      printf("Result: ");
    }
    for (j = 0; j < arraylength; j++) {
      if (i < arraylength - 1) {
        if (j == smallestindex) {
          printf("[");
        }
        if (j == i) {
          printf("(");
        }
        printf("%d", allnumbers[j]);
        if (j == i) {
          printf(")");
        }
        if (j == smallestindex) {
          printf("]");
        }
      } else if (i < arraylength) {
        printf("%d", allnumbers[j]);
      }
      if (i < arraylength) {
        printf(" ");
      }
    }
    temp = allnumbers[smallestindex];
    allnumbers[smallestindex] = allnumbers[i];
    allnumbers[i] = temp;
    smallestindex = i + 1;
    loopstart++;
    if (i < arraylength) {
      printf("\n");
    }
  }
  printf("\n");
  printf("Number of comparisons: %d\n", comparisons);
  printf("Number of swaps: %d\n", swaps);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1f80,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x1f54(%rbp)
movl   $0x0,-0x1f58(%rbp)
movl   $0x0,-0x1f5c(%rbp)
movl   $0x0,-0x1f60(%rbp)
movl   $0x0,-0x1f64(%rbp)
movl   $0x1,-0x1f68(%rbp)
movl   $0x0,-0x1f6c(%rbp)
movl   $0x0,-0x1f70(%rbp)
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movslq -0x1f6c(%rbp),%rax
lea    -0x1f50(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe64(%rip),%rdi
call   1040 <scanf@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x1f71(%rbp)
je     11de <main+0xbe>
movslq -0x1f6c(%rbp),%rax
cmpl   $0x0,-0x1f50(%rbp,%rax,4)
setne  %al
mov    %al,-0x1f71(%rbp)
mov    -0x1f71(%rbp),%al
test   $0x1,%al
jne    11f1 <main+0xd1>
jmp    1205 <main+0xe5>
mov    -0x1f6c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1f6c(%rbp)
jmp    1190 <main+0x70>
mov    -0x1f6c(%rbp),%eax
mov    %eax,-0x1f54(%rbp)
lea    0xe2f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1f6c(%rbp)
mov    -0x1f6c(%rbp),%eax
mov    -0x1f54(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    14ee <main+0x3ce>
mov    -0x1f68(%rbp),%eax
mov    %eax,-0x1f70(%rbp)
mov    -0x1f70(%rbp),%eax
cmp    -0x1f54(%rbp),%eax
jge    12af <main+0x18f>
movslq -0x1f58(%rbp),%rax
mov    -0x1f50(%rbp,%rax,4),%eax
movslq -0x1f70(%rbp),%rcx
cmp    -0x1f50(%rbp,%rcx,4),%eax
jle    128c <main+0x16c>
mov    -0x1f70(%rbp),%eax
mov    %eax,-0x1f58(%rbp)
mov    -0x1f60(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1f60(%rbp)
mov    -0x1f70(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1f70(%rbp)
jmp    124c <main+0x12c>
mov    -0x1f6c(%rbp),%eax
mov    -0x1f54(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    12ee <main+0x1ce>
mov    -0x1f6c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1f64(%rbp)
mov    -0x1f64(%rbp),%esi
lea    0xd31(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1313 <main+0x1f3>
mov    -0x1f6c(%rbp),%eax
cmp    -0x1f54(%rbp),%eax
jge    130e <main+0x1ee>
lea    0xd16(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1313 <main+0x1f3>
movl   $0x0,-0x1f70(%rbp)
mov    -0x1f70(%rbp),%eax
cmp    -0x1f54(%rbp),%eax
jge    1453 <main+0x333>
mov    -0x1f6c(%rbp),%eax
mov    -0x1f54(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    13e7 <main+0x2c7>
mov    -0x1f70(%rbp),%eax
cmp    -0x1f58(%rbp),%eax
jne    1366 <main+0x246>
lea    0xcc7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1f70(%rbp),%eax
cmp    -0x1f6c(%rbp),%eax
jne    1386 <main+0x266>
lea    0xca9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movslq -0x1f70(%rbp),%rax
mov    -0x1f50(%rbp,%rax,4),%esi
lea    0xc75(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1f70(%rbp),%eax
cmp    -0x1f6c(%rbp),%eax
jne    13c2 <main+0x2a2>
lea    0xc6f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1f70(%rbp),%eax
cmp    -0x1f58(%rbp),%eax
jne    13e2 <main+0x2c2>
lea    0xc51(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    141a <main+0x2fa>
mov    -0x1f6c(%rbp),%eax
cmp    -0x1f54(%rbp),%eax
jge    1415 <main+0x2f5>
movslq -0x1f70(%rbp),%rax
mov    -0x1f50(%rbp,%rax,4),%esi
lea    0xc02(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    141a <main+0x2fa>
mov    -0x1f6c(%rbp),%eax
cmp    -0x1f54(%rbp),%eax
jge    143a <main+0x31a>
lea    0xbe8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    143f <main+0x31f>
mov    -0x1f70(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1f70(%rbp)
jmp    131d <main+0x1fd>
movslq -0x1f58(%rbp),%rax
mov    -0x1f50(%rbp,%rax,4),%eax
mov    %eax,-0x1f5c(%rbp)
movslq -0x1f6c(%rbp),%rax
mov    -0x1f50(%rbp,%rax,4),%ecx
movslq -0x1f58(%rbp),%rax
mov    %ecx,-0x1f50(%rbp,%rax,4)
mov    -0x1f5c(%rbp),%ecx
movslq -0x1f6c(%rbp),%rax
mov    %ecx,-0x1f50(%rbp,%rax,4)
mov    -0x1f6c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1f58(%rbp)
mov    -0x1f68(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1f68(%rbp)
mov    -0x1f6c(%rbp),%eax
cmp    -0x1f54(%rbp),%eax
jge    14d5 <main+0x3b5>
lea    0xb79(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    14da <main+0x3ba>
mov    -0x1f6c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1f6c(%rbp)
jmp    1229 <main+0x109>
lea    0xb52(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1f60(%rbp),%esi
lea    0xb25(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1f64(%rbp),%esi
lea    0xb2c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x1f80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1f68,%rsp
lea    0xeb8(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeba(%rip),%rdi
lea    0x20(%rsp),%rsi
call   1050 <scanf@plt>
mov    $0x0,%ebx
test   %rax,%rax
je     11a4 <main+0x74>
mov    $0x4,%ebp
xor    %ebx,%ebx
lea    0xe98(%rip),%r14
nopl   0x0(%rax,%rax,1)
cmpl   $0x0,0x20(%rsp,%rbx,4)
je     11a4 <main+0x74>
add    $0x1,%rbx
lea    (%rsp,%rbp,1),%rsi
add    $0x20,%rsi
mov    %r14,%rdi
call   1050 <scanf@plt>
add    $0x4,%rbp
test   %rax,%rax
jne    1180 <main+0x50>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    -0x1(%rbx),%eax
cltq
mov    %rax,0x8(%rsp)
mov    %ebx,%r14d
add    $0x1,%ebx
mov    %rbx,0x10(%rsp)
mov    $0x1,%esi
xor    %r13d,%r13d
movl   $0x0,0x4(%rsp)
xor    %ebp,%ebp
jmp    11f7 <main+0xc7>
nopw   0x0(%rax,%rax,1)
mov    0x18(%rsp),%rsi
add    $0x1,%rsi
mov    %rbx,%r13
cmp    0x10(%rsp),%rbx
je     1381 <main+0x251>
cmp    %esi,%r14d
jbe    1240 <main+0x110>
mov    %rsi,%rax
mov    %r13d,%ecx
jmp    121f <main+0xef>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%ebp
add    $0x1,%rax
mov    %r15d,%ecx
cmp    %rax,%r14
je     1243 <main+0x113>
movslq %ecx,%rdx
mov    0x20(%rsp,%rdx,4),%edx
mov    %eax,%r15d
cmp    0x20(%rsp,%rax,4),%edx
jg     1210 <main+0xe0>
mov    %ecx,%r15d
jmp    1210 <main+0xe0>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r13d,%r15d
cmp    0x8(%rsp),%r13
mov    %rsi,0x18(%rsp)
jge    1270 <main+0x140>
lea    0x1(%r13),%esi
lea    0xdb9(%rip),%rdi
mov    %esi,0x4(%rsp)
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1283 <main+0x153>
nopw   0x0(%rax,%rax,1)
cmp    %r14,%r13
jae    1283 <main+0x153>
lea    0xda1(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
test   %r14,%r14
je     1350 <main+0x220>
mov    %r15d,%ebx
xor    %r12d,%r12d
jmp    12b7 <main+0x187>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    $0x20,%edi
call   1030 <putchar@plt>
add    $0x1,%r12
cmp    %r12,%r14
je     1350 <main+0x220>
cmp    0x8(%rsp),%r13
jge    1300 <main+0x1d0>
cmp    %r12,%rbx
jne    12cd <main+0x19d>
mov    $0x5b,%edi
call   1030 <putchar@plt>
cmp    %r12,%r13
jne    1320 <main+0x1f0>
mov    $0x28,%edi
call   1030 <putchar@plt>
mov    0x20(%rsp,%r13,4),%esi
lea    0xd28(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x29,%edi
call   1030 <putchar@plt>
cmp    %r12,%rbx
je     1338 <main+0x208>
jmp    1342 <main+0x212>
cmp    %r14,%r13
jae    12aa <main+0x17a>
mov    0x20(%rsp,%r12,4),%esi
lea    0xcff(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    12a0 <main+0x170>
nopw   0x0(%rax,%rax,1)
mov    0x20(%rsp,%r12,4),%esi
lea    0xce4(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    %r12,%rbx
jne    1342 <main+0x212>
mov    $0x5d,%edi
call   1030 <putchar@plt>
cmp    %r14,%r13
jb     12a0 <main+0x170>
jmp    12aa <main+0x17a>
movslq %r15d,%rax
mov    0x20(%rsp,%rax,4),%ecx
mov    0x20(%rsp,%r13,4),%edx
mov    %edx,0x20(%rsp,%rax,4)
mov    %ecx,0x20(%rsp,%r13,4)
lea    0x1(%r13),%rbx
cmp    %r14,%r13
jae    11e0 <main+0xb0>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    11e0 <main+0xb0>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xc94(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xc9f(%rip),%rdi
mov    0x4(%rsp),%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x1f68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"Enter numbers: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [10 x i8] c"Step %d: \00"
@.str.4 = [9 x i8] c"Result: \00"
@.str.5 = [2 x i8] c"[\00"
@.str.6 = [2 x i8] c"(\00"
@.str.7 = [2 x i8] c")\00"
@.str.8 = [2 x i8] c"]\00"
@.str.9 = [2 x i8] c" \00"
@.str.10 = [27 x i8] c"Number of comparisons: %d\0A\00"
@.str.11 = [21 x i8] c"Number of swaps: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2000 x i32]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 1, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %26, %0
%13 = load i32, i32* %9
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [2000 x i32], [2000 x i32]* %2, i64 0, i64 %14
%16 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %24
18: ; preds = %12
%19 = load i32, i32* %9
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [2000 x i32], [2000 x i32]* %2, i64 0, i64 %20
%22 = load i32, i32* %21
%23 = icmp ne i32 %22, 0
br label %24
24: ; preds = %18, %12
%25 = phi i1 [ false, %12 ], [ %23, %18 ]
br i1 %25, label %26, label %29
26: ; preds = %24
%27 = load i32, i32* %9
%28 = add nsw i32 %27, 1
store i32 %28, i32* %9
br label %12
29: ; preds = %24
%30 = load i32, i32* %9
store i32 %30, i32* %3
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %9
br label %32
32: ; preds = %165, %29
%33 = load i32, i32* %9
%34 = load i32, i32* %3
%35 = add nsw i32 %34, 1
%36 = icmp slt i32 %33, %35
br i1 %36, label %37, label %168
37: ; preds = %32
%38 = load i32, i32* %8
store i32 %38, i32* %10
br label %39
39: ; preds = %58, %37
%40 = load i32, i32* %10
%41 = load i32, i32* %3
%42 = icmp slt i32 %40, %41
br i1 %42, label %43, label %61
43: ; preds = %39
%44 = load i32, i32* %4
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [2000 x i32], [2000 x i32]* %2, i64 0, i64 %45
%47 = load i32, i32* %46
%48 = load i32, i32* %10
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [2000 x i32], [2000 x i32]* %2, i64 0, i64 %49
%51 = load i32, i32* %50
%52 = icmp sgt i32 %47, %51
br i1 %52, label %53, label %55
53: ; preds = %43
%54 = load i32, i32* %10
store i32 %54, i32* %4
br label %55
55: ; preds = %53, %43
%56 = load i32, i32* %6
%57 = add nsw i32 %56, 1
store i32 %57, i32* %6
br label %58
58: ; preds = %55
%59 = load i32, i32* %10
%60 = add nsw i32 %59, 1
store i32 %60, i32* %10
br label %39
61: ; preds = %39
%62 = load i32, i32* %9
%63 = load i32, i32* %3
%64 = sub nsw i32 %63, 1
%65 = icmp slt i32 %62, %64
br i1 %65, label %66, label %71
66: ; preds = %61
%67 = load i32, i32* %9
%68 = add nsw i32 %67, 1
store i32 %68, i32* %7
%69 = load i32, i32* %7
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %69)
br label %78
71: ; preds = %61
%72 = load i32, i32* %9
%73 = load i32, i32* %3
%74 = icmp slt i32 %72, %73
br i1 %74, label %75, label %77
75: ; preds = %71
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
br label %77
77: ; preds = %75, %71
br label %78
78: ; preds = %77, %66
store i32 0, i32* %10
br label %79
79: ; preds = %136, %78
%80 = load i32, i32* %10
%81 = load i32, i32* %3
%82 = icmp slt i32 %80, %81
br i1 %82, label %83, label %139
83: ; preds = %79
%84 = load i32, i32* %9
%85 = load i32, i32* %3
%86 = sub nsw i32 %85, 1
%87 = icmp slt i32 %84, %86
br i1 %87, label %88, label %118
88: ; preds = %83
%89 = load i32, i32* %10
%90 = load i32, i32* %4
%91 = icmp eq i32 %89, %90
br i1 %91, label %92, label %94
92: ; preds = %88
%93 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %94
94: ; preds = %92, %88
%95 = load i32, i32* %10
%96 = load i32, i32* %9
%97 = icmp eq i32 %95, %96
br i1 %97, label %98, label %100
98: ; preds = %94
%99 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %100
100: ; preds = %98, %94
%101 = load i32, i32* %10
%102 = sext i32 %101 to i64
%103 = getelementptr inbounds [2000 x i32], [2000 x i32]* %2, i64 0, i64 %102
%104 = load i32, i32* %103
%105 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %104)
%106 = load i32, i32* %10
%107 = load i32, i32* %9
%108 = icmp eq i32 %106, %107
br i1 %108, label %109, label %111
109: ; preds = %100
%110 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
br label %111
111: ; preds = %109, %100
%112 = load i32, i32* %10
%113 = load i32, i32* %4
%114 = icmp eq i32 %112, %113
br i1 %114, label %115, label %117
115: ; preds = %111
%116 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
br label %117
117: ; preds = %115, %111
br label %129
118: ; preds = %83
%119 = load i32, i32* %9
%120 = load i32, i32* %3
%121 = icmp slt i32 %119, %120
br i1 %121, label %122, label %128
122: ; preds = %118
%123 = load i32, i32* %10
%124 = sext i32 %123 to i64
%125 = getelementptr inbounds [2000 x i32], [2000 x i32]* %2, i64 0, i64 %124
%126 = load i32, i32* %125
%127 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %126)
br label %128
128: ; preds = %122, %118
br label %129
129: ; preds = %128, %117
%130 = load i32, i32* %9
%131 = load i32, i32* %3
%132 = icmp slt i32 %130, %131
br i1 %132, label %133, label %135
133: ; preds = %129
%134 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
br label %135
135: ; preds = %133, %129
br label %136
136: ; preds = %135
%137 = load i32, i32* %10
%138 = add nsw i32 %137, 1
store i32 %138, i32* %10
br label %79
139: ; preds = %79
%140 = load i32, i32* %4
%141 = sext i32 %140 to i64
%142 = getelementptr inbounds [2000 x i32], [2000 x i32]* %2, i64 0, i64 %141
%143 = load i32, i32* %142
store i32 %143, i32* %5
%144 = load i32, i32* %9
%145 = sext i32 %144 to i64
%146 = getelementptr inbounds [2000 x i32], [2000 x i32]* %2, i64 0, i64 %145
%147 = load i32, i32* %146
%148 = load i32, i32* %4
%149 = sext i32 %148 to i64
%150 = getelementptr inbounds [2000 x i32], [2000 x i32]* %2, i64 0, i64 %149
store i32 %147, i32* %150
%151 = load i32, i32* %5
%152 = load i32, i32* %9
%153 = sext i32 %152 to i64
%154 = getelementptr inbounds [2000 x i32], [2000 x i32]* %2, i64 0, i64 %153
store i32 %151, i32* %154
%155 = load i32, i32* %9
%156 = add nsw i32 %155, 1
store i32 %156, i32* %4
%157 = load i32, i32* %8
%158 = add nsw i32 %157, 1
store i32 %158, i32* %8
%159 = load i32, i32* %9
%160 = load i32, i32* %3
%161 = icmp slt i32 %159, %160
br i1 %161, label %162, label %164
162: ; preds = %139
%163 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %164
164: ; preds = %162, %139
br label %165
165: ; preds = %164
%166 = load i32, i32* %9
%167 = add nsw i32 %166, 1
store i32 %167, i32* %9
br label %32
168: ; preds = %32
%169 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%170 = load i32, i32* %6
%171 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0), i32 %170)
%172 = load i32, i32* %7
%173 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.11, i64 0, i64 0), i32 %172)
ret i32 0
}

LLVM IR (-O2):
@.str = [16 x i8] c"Enter numbers: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.3 = [10 x i8] c"Step %d: \00"
@.str.4 = [9 x i8] c"Result: \00"
@.str.10 = [27 x i8] c"Number of comparisons: %d\0A\00"
@.str.11 = [21 x i8] c"Number of swaps: %d\0A\00"
define i32 @main() {
%1 = alloca [2000 x i32]
%2 = bitcast [2000 x i32]* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%4 = getelementptr inbounds [2000 x i32], [2000 x i32]* %1, i64 0, i64 0
%5 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%6 = icmp eq i64 %5, 0
br i1 %6, label %20, label %7
7: ; preds = %0, %12
%8 = phi i64 [ %13, %12 ], [ 0, %0 ]
%9 = phi i32* [ %14, %12 ], [ %4, %0 ]
%10 = load i32, i32* %9
%11 = icmp eq i32 %10, 0
br i1 %11, label %17, label %12
12: ; preds = %7
%13 = add nuw i64 %8, 1
%14 = getelementptr inbounds [2000 x i32], [2000 x i32]* %1, i64 0, i64 %13
%15 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %7
17: ; preds = %12, %7
%18 = phi i64 [ %8, %7 ], [ %13, %12 ]
%19 = trunc i64 %18 to i32
br label %20
20: ; preds = %17, %0
%21 = phi i32 [ 0, %0 ], [ %19, %17 ]
%22 = call i32 @putchar(i32 10)
%23 = add nsw i32 %21, -1
%24 = icmp eq i32 %21, 0
%25 = sext i32 %23 to i64
%26 = zext i32 %21 to i64
%27 = add i32 %21, 1
%28 = zext i32 %27 to i64
br label %29
29: ; preds = %20, %112
%30 = phi i64 [ 0, %20 ], [ %107, %112 ]
%31 = phi i64 [ 1, %20 ], [ %108, %112 ]
%32 = phi i32 [ 0, %20 ], [ %65, %112 ]
%33 = phi i32 [ 0, %20 ], [ %54, %112 ]
%34 = trunc i64 %31 to i32
%35 = icmp ugt i32 %21, %34
%36 = trunc i64 %30 to i32
br i1 %35, label %37, label %52
37: ; preds = %29, %37
%38 = phi i64 [ %50, %37 ], [ %31, %29 ]
%39 = phi i32 [ %49, %37 ], [ %33, %29 ]
%40 = phi i32 [ %48, %37 ], [ %36, %29 ]
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [2000 x i32], [2000 x i32]* %1, i64 0, i64 %41
%43 = load i32, i32* %42
%44 = getelementptr inbounds [2000 x i32], [2000 x i32]* %1, i64 0, i64 %38
%45 = load i32, i32* %44
%46 = icmp sgt i32 %43, %45
%47 = trunc i64 %38 to i32
%48 = select i1 %46, i32 %47, i32 %40
%49 = add nsw i32 %39, 1
%50 = add nuw nsw i64 %38, 1
%51 = icmp eq i64 %50, %26
br i1 %51, label %52, label %37
52: ; preds = %37, %29
%53 = phi i32 [ %36, %29 ], [ %48, %37 ]
%54 = phi i32 [ %33, %29 ], [ %49, %37 ]
%55 = icmp slt i64 %30, %25
br i1 %55, label %56, label %60
56: ; preds = %52
%57 = trunc i64 %30 to i32
%58 = add i32 %57, 1
%59 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %58)
br label %64
60: ; preds = %52
%61 = icmp ult i64 %30, %26
br i1 %61, label %62, label %64
62: ; preds = %60
%63 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
br label %64
64: ; preds = %60, %62, %56
%65 = phi i32 [ %58, %56 ], [ %32, %62 ], [ %32, %60 ]
br i1 %24, label %101, label %66
66: ; preds = %64
%67 = icmp ult i64 %30, %26
%68 = zext i32 %53 to i64
%69 = getelementptr inbounds [2000 x i32], [2000 x i32]* %1, i64 0, i64 %30
br label %70
70: ; preds = %66, %98
%71 = phi i64 [ 0, %66 ], [ %99, %98 ]
br i1 %55, label %72, label %90
72: ; preds = %70
%73 = icmp eq i64 %71, %68
br i1 %73, label %74, label %76
74: ; preds = %72
%75 = call i32 @putchar(i32 91)
br label %76
76: ; preds = %74, %72
%77 = icmp eq i64 %71, %30
br i1 %77, label %78, label %83
78: ; preds = %76
%79 = call i32 @putchar(i32 40)
%80 = load i32, i32* %69
%81 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %80)
%82 = call i32 @putchar(i32 41)
br label %87
83: ; preds = %76
%84 = getelementptr inbounds [2000 x i32], [2000 x i32]* %1, i64 0, i64 %71
%85 = load i32, i32* %84
%86 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %85)
br label %87
87: ; preds = %83, %78
br i1 %73, label %88, label %95
88: ; preds = %87
%89 = call i32 @putchar(i32 93)
br label %95
90: ; preds = %70
br i1 %67, label %91, label %98
91: ; preds = %90
%92 = getelementptr inbounds [2000 x i32], [2000 x i32]* %1, i64 0, i64 %71
%93 = load i32, i32* %92
%94 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %93)
br label %96
95: ; preds = %87, %88
br i1 %67, label %96, label %98
96: ; preds = %91, %95
%97 = call i32 @putchar(i32 32)
br label %98
98: ; preds = %90, %95, %96
%99 = add nuw nsw i64 %71, 1
%100 = icmp eq i64 %99, %26
br i1 %100, label %101, label %70
101: ; preds = %98, %64
%102 = sext i32 %53 to i64
%103 = getelementptr inbounds [2000 x i32], [2000 x i32]* %1, i64 0, i64 %102
%104 = load i32, i32* %103
%105 = getelementptr inbounds [2000 x i32], [2000 x i32]* %1, i64 0, i64 %30
%106 = load i32, i32* %105
store i32 %106, i32* %103
store i32 %104, i32* %105
%107 = add nuw nsw i64 %30, 1
%108 = add nuw nsw i64 %31, 1
%109 = icmp ult i64 %30, %26
br i1 %109, label %110, label %112
110: ; preds = %101
%111 = call i32 @putchar(i32 10)
br label %112
112: ; preds = %101, %110
%113 = icmp eq i64 %107, %28
br i1 %113, label %114, label %29
114: ; preds = %112
%115 = call i32 @putchar(i32 10)
%116 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0), i32 %54)
%117 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.11, i64 0, i64 0), i32 %65)
ret i32 0
}