#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 *, ...);
int bubble_duplicates(int *values, int count) {
  printf("%3d%%", 0);
  int percentstep = count / 100;
  int duplicates = 0;
  for (int i = 0; i < count; ++i) {
    int value = values[i];
    for (int j = i + 1; j < count; ++j) {
      if (value == values[j]) {
        ++duplicates;
        break;
      }
    }
    if (i % percentstep == 0)
      printf("\b\b\b\b%3d%%", (i * 100) / count);
  }
  printf("\b\b\b\b");
  return duplicates;
}


x86 assembly (clang, -O0):
<bubble_duplicates>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    0xede(%rip),%rdi
xor    %esi,%esi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11ea <bubble_duplicates+0xda>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11af <bubble_duplicates+0x9f>
mov    -0x1c(%rbp),%eax
mov    -0x8(%rbp),%rcx
movslq -0x20(%rbp),%rdx
cmp    (%rcx,%rdx,4),%eax
jne    119c <bubble_duplicates+0x8c>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11af <bubble_duplicates+0x9f>
jmp    11a1 <bubble_duplicates+0x91>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    116e <bubble_duplicates+0x5e>
mov    -0x18(%rbp),%eax
cltd
idivl  -0x10(%rbp)
cmp    $0x0,%edx
jne    11d7 <bubble_duplicates+0xc7>
imul   $0x64,-0x18(%rbp),%eax
cltd
idivl  -0xc(%rbp)
mov    %eax,%esi
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11dc <bubble_duplicates+0xcc>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    114b <bubble_duplicates+0x3b>
lea    0xe19(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bubble_duplicates>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %esi,%ebx
mov    %rdi,0x10(%rsp)
lea    0xed8(%rip),%rdi
xor    %r13d,%r13d
xor    %esi,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebx,0xc(%rsp)
test   %ebx,%ebx
jle    11fa <bubble_duplicates+0xea>
mov    0xc(%rsp),%ecx
movslq %ecx,%rax
imul   $0x51eb851f,%rax,%rbx
mov    %rbx,%rax
shr    $0x3f,%rax
sar    $0x25,%rbx
add    %eax,%ebx
mov    %ecx,%r15d
mov    %r15,%rbp
mov    0x10(%rsp),%r12
xor    %ecx,%ecx
xor    %r13d,%r13d
jmp    119d <bubble_duplicates+0x8d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%r13d
mov    %ecx,%eax
cltd
idiv   %ebx
test   %edx,%edx
je     11e0 <bubble_duplicates+0xd0>
add    $0x4,%r12
add    $0xffffffffffffffff,%rbp
mov    %r14,%rcx
cmp    %r15,%r14
je     11fa <bubble_duplicates+0xea>
lea    0x1(%rcx),%r14
cmp    %r15,%r14
jae    1184 <bubble_duplicates+0x74>
mov    0x10(%rsp),%rax
mov    (%rax,%rcx,4),%eax
mov    $0x1,%edx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmp    (%r12,%rdx,4),%eax
je     1180 <bubble_duplicates+0x70>
add    $0x1,%rdx
cmp    %rdx,%rbp
jne    11c0 <bubble_duplicates+0xb0>
jmp    1184 <bubble_duplicates+0x74>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
imul   $0x64,%ecx,%eax
cltd
idivl  0xc(%rsp)
lea    0xe11(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    118d <bubble_duplicates+0x7d>
lea    0xe09(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r13d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%3d%%\00"
@.str.1 = [10 x i8] c"\08\08\08\08%3d%%\00"
@.str.2 = [5 x i8] c"\08\08\08\08\00"
define i32 @bubble_duplicates(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 0)
%11 = load i32, i32* %4
%12 = sdiv i32 %11, 100
store i32 %12, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
br label %13
13: ; preds = %56, %2
%14 = load i32, i32* %7
%15 = load i32, i32* %4
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %59
17: ; preds = %13
%18 = load i32*, i32** %3
%19 = load i32, i32* %7
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i32, i32* %18, i64 %20
%22 = load i32, i32* %21
store i32 %22, i32* %8
%23 = load i32, i32* %7
%24 = add nsw i32 %23, 1
store i32 %24, i32* %9
br label %25
25: ; preds = %41, %17
%26 = load i32, i32* %9
%27 = load i32, i32* %4
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %44
29: ; preds = %25
%30 = load i32, i32* %8
%31 = load i32*, i32** %3
%32 = load i32, i32* %9
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i32, i32* %31, i64 %33
%35 = load i32, i32* %34
%36 = icmp eq i32 %30, %35
br i1 %36, label %37, label %40
37: ; preds = %29
%38 = load i32, i32* %6
%39 = add nsw i32 %38, 1
store i32 %39, i32* %6
br label %44
40: ; preds = %29
br label %41
41: ; preds = %40
%42 = load i32, i32* %9
%43 = add nsw i32 %42, 1
store i32 %43, i32* %9
br label %25
44: ; preds = %37, %25
%45 = load i32, i32* %7
%46 = load i32, i32* %5
%47 = srem i32 %45, %46
%48 = icmp eq i32 %47, 0
br i1 %48, label %49, label %55
49: ; preds = %44
%50 = load i32, i32* %7
%51 = mul nsw i32 %50, 100
%52 = load i32, i32* %4
%53 = sdiv i32 %51, %52
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %53)
br label %55
55: ; preds = %49, %44
br label %56
56: ; preds = %55
%57 = load i32, i32* %7
%58 = add nsw i32 %57, 1
store i32 %58, i32* %7
br label %13
59: ; preds = %13
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%61 = load i32, i32* %6
ret i32 %61
}

LLVM IR (-O2):
@.str = [6 x i8] c"%3d%%\00"
@.str.1 = [10 x i8] c"\08\08\08\08%3d%%\00"
@.str.2 = [5 x i8] c"\08\08\08\08\00"
define i32 @bubble_duplicates(i32* nocapture %0, i32 %1) {
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 0)
%4 = sdiv i32 %1, 100
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = zext i32 %1 to i64
%8 = zext i32 %1 to i64
br label %12
9: ; preds = %39, %2
%10 = phi i32 [ 0, %2 ], [ %31, %39 ]
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
ret i32 %10
12: ; preds = %6, %39
%13 = phi i64 [ 0, %6 ], [ %18, %39 ]
%14 = phi i64 [ 1, %6 ], [ %40, %39 ]
%15 = phi i32 [ 0, %6 ], [ %31, %39 ]
%16 = getelementptr inbounds i32, i32* %0, i64 %13
%17 = load i32, i32* %16
%18 = add nuw nsw i64 %13, 1
%19 = icmp ult i64 %18, %7
br i1 %19, label %22, label %30
20: ; preds = %22
%21 = icmp eq i64 %27, %8
br i1 %21, label %30, label %22
22: ; preds = %12, %20
%23 = phi i64 [ %27, %20 ], [ %14, %12 ]
%24 = getelementptr inbounds i32, i32* %0, i64 %23
%25 = load i32, i32* %24
%26 = icmp eq i32 %17, %25
%27 = add nuw nsw i64 %23, 1
br i1 %26, label %28, label %20
28: ; preds = %22
%29 = add nsw i32 %15, 1
br label %30
30: ; preds = %20, %12, %28
%31 = phi i32 [ %29, %28 ], [ %15, %12 ], [ %15, %20 ]
%32 = trunc i64 %13 to i32
%33 = srem i32 %32, %4
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %39
35: ; preds = %30
%36 = mul nsw i32 %32, 100
%37 = sdiv i32 %36, %1
%38 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %37)
br label %39
39: ; preds = %35, %30
%40 = add nuw nsw i64 %14, 1
%41 = icmp eq i64 %18, %8
br i1 %41, label %9, label %12
}