#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*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
void percentage(int idx, int total) {
  static int percent = 0;
  int p, i;
  p = idx * 10 / total;
  if (p != percent) {
    percent = p;
  } else {
    return;
  }
  fprintf(stderr, "|");
  for (i = 0; i < p; i++)
    fprintf(stderr, "=");
  for (i = 0; i < (10 - p); i++)
    fprintf(stderr, "-");
  fprintf(stderr, "| %d%%\r", p * 10);
}


x86 assembly (clang, -O0):
<percentage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
imul   $0xa,-0x4(%rbp),%eax
cltd
idivl  -0x8(%rbp)
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    0x2efa(%rip),%eax
je     1146 <percentage+0x36>
mov    -0xc(%rbp),%eax
mov    %eax,0x2eeb(%rip)
jmp    114b <percentage+0x3b>
jmp    11f4 <percentage+0xe4>
mov    0x2e8e(%rip),%rax
mov    (%rax),%edi
lea    0xea5(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    119a <percentage+0x8a>
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
lea    0xe7d(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1169 <percentage+0x59>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    $0xa,%ecx
sub    -0xc(%rbp),%ecx
cmp    %ecx,%eax
jge    11d9 <percentage+0xc9>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
lea    0xe40(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11a1 <percentage+0x91>
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
imul   $0xa,-0xc(%rbp),%edx
lea    0xe19(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<percentage>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
add    %edi,%edi
lea    (%rdi,%rdi,4),%eax
cltd
idiv   %esi
cmp    0x2f07(%rip),%eax
jne    1132 <percentage+0x22>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%r14d
mov    %eax,0x2ef1(%rip)
mov    0x2e9e(%rip),%r15
mov    (%r15),%edi
lea    0xeb4(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
test   %r14d,%r14d
jle    1188 <percentage+0x78>
lea    0xea3(%rip),%rbx
mov    %r14d,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%r15),%edi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
add    $0xffffffff,%ebp
jne    1170 <percentage+0x60>
cmp    $0x9,%r14d
jg     11c2 <percentage+0xb2>
mov    $0xa,%eax
sub    %r14d,%eax
cmp    $0x2,%eax
mov    $0x1,%ebp
cmovge %eax,%ebp
lea    0xe62(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%r15),%edi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
add    $0xffffffff,%ebp
jne    11b0 <percentage+0xa0>
mov    (%r15),%edi
add    %r14d,%r14d
lea    (%r14,%r14,4),%edx
lea    0xe33(%rip),%rsi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fprintf@plt>

LLVM IR (-O0):
@percentage.percent = internal global i32 0
@stderr = global i32 0
@.str = [2 x i8] c"|\00"
@.str.1 = [2 x i8] c"=\00"
@.str.2 = [2 x i8] c"-\00"
@.str.3 = [8 x i8] c"| %d%%\0D\00"
define void @percentage(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%7 = load i32, i32* %3
%8 = mul nsw i32 %7, 10
%9 = load i32, i32* %4
%10 = sdiv i32 %8, %9
store i32 %10, i32* %5
%11 = load i32, i32* %5
%12 = load i32, i32* @percentage.percent
%13 = icmp ne i32 %11, %12
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = load i32, i32* %5
store i32 %15, i32* @percentage.percent
br label %17
16: ; preds = %2
br label %47
17: ; preds = %14
%18 = load i32, i32* @stderr
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %6
br label %20
20: ; preds = %27, %17
%21 = load i32, i32* %6
%22 = load i32, i32* %5
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %30
24: ; preds = %20
%25 = load i32, i32* @stderr
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %27
27: ; preds = %24
%28 = load i32, i32* %6
%29 = add nsw i32 %28, 1
store i32 %29, i32* %6
br label %20
30: ; preds = %20
store i32 0, i32* %6
br label %31
31: ; preds = %39, %30
%32 = load i32, i32* %6
%33 = load i32, i32* %5
%34 = sub nsw i32 10, %33
%35 = icmp slt i32 %32, %34
br i1 %35, label %36, label %42
36: ; preds = %31
%37 = load i32, i32* @stderr
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %39
39: ; preds = %36
%40 = load i32, i32* %6
%41 = add nsw i32 %40, 1
store i32 %41, i32* %6
br label %31
42: ; preds = %31
%43 = load i32, i32* @stderr
%44 = load i32, i32* %5
%45 = mul nsw i32 %44, 10
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %45)
br label %47
47: ; preds = %42, %16
ret void
}

LLVM IR (-O2):
@percentage.percent = internal unnamed_addr global i32 0
@stderr = global i32 0
@.str = [2 x i8] c"|\00"
@.str.1 = [2 x i8] c"=\00"
@.str.2 = [2 x i8] c"-\00"
@.str.3 = [8 x i8] c"| %d%%\0D\00"
define void @percentage(i32 %0, i32 %1) {
%3 = mul nsw i32 %0, 10
%4 = sdiv i32 %3, %1
%5 = load i32, i32* @percentage.percent
%6 = icmp eq i32 %4, %5
br i1 %6, label %32, label %7
7: ; preds = %2
store i32 %4, i32* @percentage.percent
%8 = load i32, i32* @stderr
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = icmp sgt i32 %4, 0
br i1 %10, label %16, label %13
11: ; preds = %16
%12 = icmp slt i32 %4, 10
br i1 %12, label %13, label %28
13: ; preds = %7, %11
%14 = sub i32 10, %4
%15 = call i32 @llvm.smax.i32(i32 %14, i32 1)
br label %22
16: ; preds = %7, %16
%17 = phi i32 [ %20, %16 ], [ 0, %7 ]
%18 = load i32, i32* @stderr
%19 = tail call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%20 = add nuw nsw i32 %17, 1
%21 = icmp eq i32 %20, %4
br i1 %21, label %11, label %16
22: ; preds = %13, %22
%23 = phi i32 [ %26, %22 ], [ 0, %13 ]
%24 = load i32, i32* @stderr
%25 = tail call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%26 = add nuw nsw i32 %23, 1
%27 = icmp eq i32 %26, %15
br i1 %27, label %28, label %22
28: ; preds = %22, %11
%29 = load i32, i32* @stderr
%30 = mul nsw i32 %4, 10
%31 = tail call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %30)
br label %32
32: ; preds = %2, %28
ret void
}