#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*/ getchar();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ puts(char *);
int rand();
int /*<<< orphan*/ srand(unsigned int);
scalar_t__ time(int /*<<< orphan*/ *);
int main() {
  int r[1000];
  int c, a, b, temp;
  srand((unsigned)time(NULL));
  puts("Here is the array unsorted:");
  for (c = 0; c < 1000; c++) {
    r[c] = rand() % 100 + 1;
    printf("%3d\t", r[c]);
  }
  putchar('\n');
  for (a = 0; a < 1000 - 1; a++)
    for (b = a + 1; b < 1000; b++)
      if (r[a] > r[b]) {
        temp = r[b];
        printf(" temp, r[b], %d / %d\n", temp, r[b]);
        r[b] = r[a];
        printf("r[b] , r[a] , %d / %d\n", r[b], r[a]);
        r[a] = temp;
        printf("r[a] , temp , %d / %d\n", r[a], temp);
      }
  printf("Press Enter to see the sorted array:");
  getchar();
  for (c = 0; c < 1000; c++)
    printf("%3d\t", r[c]);
  putchar('\n');
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xfc0,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
lea    0xe67(%rip),%rdi
call   1040 <puts@plt>
movl   $0x0,-0xfb4(%rbp)
cmpl   $0x3e8,-0xfb4(%rbp)
jge    1208 <main+0x98>
mov    $0x0,%al
call   1090 <rand@plt>
mov    $0x64,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
movslq -0xfb4(%rbp),%rax
mov    %edx,-0xfb0(%rbp,%rax,4)
movslq -0xfb4(%rbp),%rax
mov    -0xfb0(%rbp,%rax,4),%esi
lea    0xe2f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xfb4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xfb4(%rbp)
jmp    11a8 <main+0x38>
mov    $0xa,%edi
call   1030 <putchar@plt>
movl   $0x0,-0xfb8(%rbp)
cmpl   $0x3e7,-0xfb8(%rbp)
jge    1351 <main+0x1e1>
mov    -0xfb8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xfbc(%rbp)
cmpl   $0x3e8,-0xfbc(%rbp)
jge    1338 <main+0x1c8>
movslq -0xfb8(%rbp),%rax
mov    -0xfb0(%rbp,%rax,4),%eax
movslq -0xfbc(%rbp),%rcx
cmp    -0xfb0(%rbp,%rcx,4),%eax
jle    131f <main+0x1af>
movslq -0xfbc(%rbp),%rax
mov    -0xfb0(%rbp,%rax,4),%eax
mov    %eax,-0xfc0(%rbp)
mov    -0xfc0(%rbp),%esi
movslq -0xfbc(%rbp),%rax
mov    -0xfb0(%rbp,%rax,4),%edx
lea    0xd85(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movslq -0xfb8(%rbp),%rax
mov    -0xfb0(%rbp,%rax,4),%ecx
movslq -0xfbc(%rbp),%rax
mov    %ecx,-0xfb0(%rbp,%rax,4)
movslq -0xfbc(%rbp),%rax
mov    -0xfb0(%rbp,%rax,4),%esi
movslq -0xfb8(%rbp),%rax
mov    -0xfb0(%rbp,%rax,4),%edx
lea    0xd55(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xfc0(%rbp),%ecx
movslq -0xfb8(%rbp),%rax
mov    %ecx,-0xfb0(%rbp,%rax,4)
movslq -0xfb8(%rbp),%rax
mov    -0xfb0(%rbp,%rax,4),%esi
mov    -0xfc0(%rbp),%edx
lea    0xd36(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1324 <main+0x1b4>
mov    -0xfbc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xfbc(%rbp)
jmp    123b <main+0xcb>
jmp    133d <main+0x1cd>
mov    -0xfb8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xfb8(%rbp)
jmp    121c <main+0xac>
lea    0xd0d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1070 <getchar@plt>
movl   $0x0,-0xfb4(%rbp)
cmpl   $0x3e8,-0xfb4(%rbp)
jge    13b0 <main+0x240>
movslq -0xfb4(%rbp),%rax
mov    -0xfb0(%rbp,%rax,4),%esi
lea    0xc87(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xfb4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xfb4(%rbp)
jmp    1370 <main+0x200>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0xfc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xfb8,%rsp
xor    %edi,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
lea    0xe6a(%rip),%rdi
call   1040 <puts@plt>
lea    0xe7a(%rip),%rbx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
call   1090 <rand@plt>
cltq
imul   $0x51eb851f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x25,%rcx
add    %edx,%ecx
imul   $0x64,%ecx,%ecx
neg    %ecx
lea    (%rax,%rcx,1),%esi
add    $0x1,%esi
mov    %esi,0x10(%rsp,%rbp,4)
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbp
cmp    $0x3e8,%rbp
jne    11b0 <main+0x40>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0x1,%r14d
lea    0xe2d(%rip),%r15
lea    0xe3d(%rip),%r12
xor    %r13d,%r13d
jmp    1236 <main+0xc6>
cs nopw 0x0(%rax,%rax,1)
mov    0x8(%rsp),%r14
add    $0x1,%r14
mov    (%rsp),%r13
cmp    $0x3e7,%r13
je     12a5 <main+0x135>
lea    0x1(%r13),%rax
mov    %rax,(%rsp)
mov    0x10(%rsp,%r13,4),%ebx
mov    %r14,0x8(%rsp)
jmp    125d <main+0xed>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r14
cmp    $0x3e8,%r14
je     1220 <main+0xb0>
mov    0x10(%rsp,%r14,4),%ebp
cmp    %ebp,%ebx
jle    1250 <main+0xe0>
lea    0xdb4(%rip),%rdi
mov    %ebp,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,0x10(%rsp,%r14,4)
mov    0x10(%rsp,%r13,4),%edx
mov    %r15,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,0x10(%rsp,%r13,4)
mov    %r12,%rdi
mov    %ebp,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,%ebx
jmp    1250 <main+0xe0>
lea    0xdb9(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
lea    0xd5b(%rip),%rbx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x10(%rsp,%rbp,4),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbp
cmp    $0x3e8,%rbp
jne    12d0 <main+0x160>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0xfb8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [28 x i8] c"Here is the array unsorted:\00"
@.str.1 = [5 x i8] c"%3d\09\00"
@.str.2 = [22 x i8] c" temp, r[b], %d / %d\0A\00"
@.str.3 = [23 x i8] c"r[b] , r[a] , %d / %d\0A\00"
@.str.4 = [23 x i8] c"r[a] , temp , %d / %d\0A\00"
@.str.5 = [37 x i8] c"Press Enter to see the sorted array:\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [1000 x i32]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = call i64 @time(i32* null)
%8 = trunc i64 %7 to i32
%9 = call i32 @srand(i32 %8)
%10 = call i32 @puts(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %11
11: ; preds = %26, %0
%12 = load i32, i32* %3
%13 = icmp slt i32 %12, 1000
br i1 %13, label %14, label %29
14: ; preds = %11
%15 = call i32 (...) @rand()
%16 = srem i32 %15, 100
%17 = add nsw i32 %16, 1
%18 = load i32, i32* %3
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [1000 x i32], [1000 x i32]* %2, i64 0, i64 %19
store i32 %17, i32* %20
%21 = load i32, i32* %3
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [1000 x i32], [1000 x i32]* %2, i64 0, i64 %22
%24 = load i32, i32* %23
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %24)
br label %26
26: ; preds = %14
%27 = load i32, i32* %3
%28 = add nsw i32 %27, 1
store i32 %28, i32* %3
br label %11
29: ; preds = %11
%30 = call i32 @putchar(i8 signext 10)
store i32 0, i32* %4
br label %31
31: ; preds = %92, %29
%32 = load i32, i32* %4
%33 = icmp slt i32 %32, 999
br i1 %33, label %34, label %95
34: ; preds = %31
%35 = load i32, i32* %4
%36 = add nsw i32 %35, 1
store i32 %36, i32* %5
br label %37
37: ; preds = %88, %34
%38 = load i32, i32* %5
%39 = icmp slt i32 %38, 1000
br i1 %39, label %40, label %91
40: ; preds = %37
%41 = load i32, i32* %4
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [1000 x i32], [1000 x i32]* %2, i64 0, i64 %42
%44 = load i32, i32* %43
%45 = load i32, i32* %5
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [1000 x i32], [1000 x i32]* %2, i64 0, i64 %46
%48 = load i32, i32* %47
%49 = icmp sgt i32 %44, %48
br i1 %49, label %50, label %87
50: ; preds = %40
%51 = load i32, i32* %5
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [1000 x i32], [1000 x i32]* %2, i64 0, i64 %52
%54 = load i32, i32* %53
store i32 %54, i32* %6
%55 = load i32, i32* %6
%56 = load i32, i32* %5
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds [1000 x i32], [1000 x i32]* %2, i64 0, i64 %57
%59 = load i32, i32* %58
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %55, i32 %59)
%61 = load i32, i32* %4
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds [1000 x i32], [1000 x i32]* %2, i64 0, i64 %62
%64 = load i32, i32* %63
%65 = load i32, i32* %5
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds [1000 x i32], [1000 x i32]* %2, i64 0, i64 %66
store i32 %64, i32* %67
%68 = load i32, i32* %5
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds [1000 x i32], [1000 x i32]* %2, i64 0, i64 %69
%71 = load i32, i32* %70
%72 = load i32, i32* %4
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds [1000 x i32], [1000 x i32]* %2, i64 0, i64 %73
%75 = load i32, i32* %74
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %71, i32 %75)
%77 = load i32, i32* %6
%78 = load i32, i32* %4
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds [1000 x i32], [1000 x i32]* %2, i64 0, i64 %79
store i32 %77, i32* %80
%81 = load i32, i32* %4
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds [1000 x i32], [1000 x i32]* %2, i64 0, i64 %82
%84 = load i32, i32* %83
%85 = load i32, i32* %6
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %84, i32 %85)
br label %87
87: ; preds = %50, %40
br label %88
88: ; preds = %87
%89 = load i32, i32* %5
%90 = add nsw i32 %89, 1
store i32 %90, i32* %5
br label %37
91: ; preds = %37
br label %92
92: ; preds = %91
%93 = load i32, i32* %4
%94 = add nsw i32 %93, 1
store i32 %94, i32* %4
br label %31
95: ; preds = %31
%96 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0))
%97 = call i32 (...) @getchar()
store i32 0, i32* %3
br label %98
98: ; preds = %107, %95
%99 = load i32, i32* %3
%100 = icmp slt i32 %99, 1000
br i1 %100, label %101, label %110
101: ; preds = %98
%102 = load i32, i32* %3
%103 = sext i32 %102 to i64
%104 = getelementptr inbounds [1000 x i32], [1000 x i32]* %2, i64 0, i64 %103
%105 = load i32, i32* %104
%106 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %105)
br label %107
107: ; preds = %101
%108 = load i32, i32* %3
%109 = add nsw i32 %108, 1
store i32 %109, i32* %3
br label %98
110: ; preds = %98
%111 = call i32 @putchar(i8 signext 10)
ret i32 0
}

LLVM IR (-O2):
@.str = [28 x i8] c"Here is the array unsorted:\00"
@.str.1 = [5 x i8] c"%3d\09\00"
@.str.2 = [22 x i8] c" temp, r[b], %d / %d\0A\00"
@.str.3 = [23 x i8] c"r[b] , r[a] , %d / %d\0A\00"
@.str.4 = [23 x i8] c"r[a] , temp , %d / %d\0A\00"
@.str.5 = [37 x i8] c"Press Enter to see the sorted array:\00"
define i32 @main() {
%1 = alloca [1000 x i32]
%2 = bitcast [1000 x i32]* %1 to i8*
%3 = tail call i64 @time(i32* null)
%4 = trunc i64 %3 to i32
%5 = tail call i32 @srand(i32 %4)
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %0, %7
%8 = phi i64 [ 0, %0 ], [ %14, %7 ]
%9 = tail call i32 (...) @rand()
%10 = srem i32 %9, 100
%11 = add nsw i32 %10, 1
%12 = getelementptr inbounds [1000 x i32], [1000 x i32]* %1, i64 0, i64 %8
store i32 %11, i32* %12
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%14 = add nuw nsw i64 %8, 1
%15 = icmp eq i64 %14, 1000
br i1 %15, label %16, label %7
16: ; preds = %7
%17 = tail call i32 @putchar(i8 signext 10)
br label %21
18: ; preds = %38
%19 = add nuw nsw i64 %23, 1
%20 = icmp eq i64 %24, 999
br i1 %20, label %42, label %21
21: ; preds = %18, %16
%22 = phi i64 [ 0, %16 ], [ %24, %18 ]
%23 = phi i64 [ 1, %16 ], [ %19, %18 ]
%24 = add nuw nsw i64 %22, 1
%25 = getelementptr inbounds [1000 x i32], [1000 x i32]* %1, i64 0, i64 %22
%26 = load i32, i32* %25
br label %27
27: ; preds = %21, %38
%28 = phi i32 [ %26, %21 ], [ %39, %38 ]
%29 = phi i64 [ %23, %21 ], [ %40, %38 ]
%30 = getelementptr inbounds [1000 x i32], [1000 x i32]* %1, i64 0, i64 %29
%31 = load i32, i32* %30
%32 = icmp sgt i32 %28, %31
br i1 %32, label %33, label %38
33: ; preds = %27
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %31, i32 %31)
store i32 %28, i32* %30
%35 = load i32, i32* %25
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %28, i32 %35)
store i32 %31, i32* %25
%37 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %31, i32 %31)
br label %38
38: ; preds = %27, %33
%39 = phi i32 [ %28, %27 ], [ %31, %33 ]
%40 = add nuw nsw i64 %29, 1
%41 = icmp eq i64 %40, 1000
br i1 %41, label %18, label %27
42: ; preds = %18
%43 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0))
%44 = tail call i32 (...) @getchar()
br label %45
45: ; preds = %42, %45
%46 = phi i64 [ 0, %42 ], [ %50, %45 ]
%47 = getelementptr inbounds [1000 x i32], [1000 x i32]* %1, i64 0, i64 %46
%48 = load i32, i32* %47
%49 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %48)
%50 = add nuw nsw i64 %46, 1
%51 = icmp eq i64 %50, 1000
br i1 %51, label %52, label %45
52: ; preds = %45
%53 = tail call i32 @putchar(i8 signext 10)
ret i32 0
}