#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*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, unsigned int);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ stdout;
void display_progress(unsigned int cur, unsigned int total) {
  static unsigned int last = 0;
  unsigned int percent;
  unsigned int bar_len, i;
  if (total == 0)
    return;
  percent = (cur * 100) / total;
  if (percent == last)
    return;
  putchar('|');
  bar_len = (cur * 50) / total;
  for (i = 0; i < bar_len; i++) {
    putchar('*');
  }
  for (i = bar_len; i < 50; i++) {
    putchar(' ');
  }
  putchar('|');
  printf(" %d%%\r", percent);
  fflush(stdout);
  last = percent;
}


x86 assembly (clang, -O0):
<display_progress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    114d <display_progress+0x1d>
jmp    1206 <display_progress+0xd6>
imul   $0x64,-0x4(%rbp),%eax
xor    %edx,%edx
divl   -0x8(%rbp)
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    0x2eda(%rip),%eax
jne    116d <display_progress+0x3d>
jmp    1206 <display_progress+0xd6>
mov    $0x7c,%edi
call   1030 <putchar@plt>
imul   $0x32,-0x4(%rbp),%eax
xor    %edx,%edx
divl   -0x8(%rbp)
mov    %eax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jae    11ae <display_progress+0x7e>
mov    $0x2a,%edi
call   1030 <putchar@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    118a <display_progress+0x5a>
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x32,-0x14(%rbp)
jae    11d6 <display_progress+0xa6>
mov    $0x20,%edi
call   1030 <putchar@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11b4 <display_progress+0x84>
mov    $0x7c,%edi
call   1030 <putchar@plt>
mov    -0xc(%rbp),%esi
lea    0xe16(%rip),%rdi
call   1040 <printf@plt>
mov    0x2dea(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
mov    -0xc(%rbp),%eax
mov    %eax,0x2e36(%rip)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<display_progress>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %esi,%esi
je     11f0 <display_progress+0xc0>
mov    %esi,%r15d
mov    %edi,%ebp
imul   $0x64,%edi,%eax
xor    %edx,%edx
div    %esi
cmp    0x2eeb(%rip),%eax
je     11f0 <display_progress+0xc0>
mov    %eax,%r14d
mov    $0x7c,%edi
call   1030 <putchar@plt>
imul   $0x32,%ebp,%ecx
xor    %ebx,%ebx
mov    %ecx,%eax
xor    %edx,%edx
div    %r15d
mov    %eax,%ebp
cmp    %r15d,%ecx
jb     11a2 <display_progress+0x72>
cmp    $0x2,%ebp
mov    $0x1,%r15d
cmovae %ebp,%r15d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    $0x2a,%edi
call   1030 <putchar@plt>
add    $0x1,%ebx
cmp    %r15d,%ebx
jne    1190 <display_progress+0x60>
cmp    $0x31,%ebp
ja     11c2 <display_progress+0x92>
nopw   0x0(%rax,%rax,1)
mov    $0x20,%edi
call   1030 <putchar@plt>
add    $0x1,%ebp
cmp    $0x32,%ebp
jne    11b0 <display_progress+0x80>
mov    $0x7c,%edi
call   1030 <putchar@plt>
lea    0xe2d(%rip),%rdi
mov    %r14d,%esi
call   1040 <printf@plt>
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
mov    %r14d,0x2e4c(%rip)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@display_progress.last = internal global i32 0
@.str = [7 x i8] c" %d%%\0D\00"
@stdout = global i32 0
define void @display_progress(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%8 = load i32, i32* %4
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %2
br label %52
11: ; preds = %2
%12 = load i32, i32* %3
%13 = mul i32 %12, 100
%14 = load i32, i32* %4
%15 = udiv i32 %13, %14
store i32 %15, i32* %5
%16 = load i32, i32* %5
%17 = load i32, i32* @display_progress.last
%18 = icmp eq i32 %16, %17
br i1 %18, label %19, label %20
19: ; preds = %11
br label %52
20: ; preds = %11
%21 = call i32 @putchar(i8 signext 124)
%22 = load i32, i32* %3
%23 = mul i32 %22, 50
%24 = load i32, i32* %4
%25 = udiv i32 %23, %24
store i32 %25, i32* %6
store i32 0, i32* %7
br label %26
26: ; preds = %32, %20
%27 = load i32, i32* %7
%28 = load i32, i32* %6
%29 = icmp ult i32 %27, %28
br i1 %29, label %30, label %35
30: ; preds = %26
%31 = call i32 @putchar(i8 signext 42)
br label %32
32: ; preds = %30
%33 = load i32, i32* %7
%34 = add i32 %33, 1
store i32 %34, i32* %7
br label %26
35: ; preds = %26
%36 = load i32, i32* %6
store i32 %36, i32* %7
br label %37
37: ; preds = %42, %35
%38 = load i32, i32* %7
%39 = icmp ult i32 %38, 50
br i1 %39, label %40, label %45
40: ; preds = %37
%41 = call i32 @putchar(i8 signext 32)
br label %42
42: ; preds = %40
%43 = load i32, i32* %7
%44 = add i32 %43, 1
store i32 %44, i32* %7
br label %37
45: ; preds = %37
%46 = call i32 @putchar(i8 signext 124)
%47 = load i32, i32* %5
%48 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %47)
%49 = load i32, i32* @stdout
%50 = call i32 @fflush(i32 %49)
%51 = load i32, i32* %5
store i32 %51, i32* @display_progress.last
br label %52
52: ; preds = %45, %19, %10
ret void
}

LLVM IR (-O2):
@display_progress.last = internal unnamed_addr global i32 0
@.str = [7 x i8] c" %d%%\0D\00"
@stdout = global i32 0
define void @display_progress(i32 %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %33, label %4
4: ; preds = %2
%5 = mul i32 %0, 100
%6 = udiv i32 %5, %1
%7 = load i32, i32* @display_progress.last
%8 = icmp eq i32 %6, %7
br i1 %8, label %33, label %9
9: ; preds = %4
%10 = tail call i32 @putchar(i8 signext 124)
%11 = mul i32 %0, 50
%12 = udiv i32 %11, %1
%13 = icmp ult i32 %11, %1
br i1 %13, label %16, label %14
14: ; preds = %9
%15 = call i32 @llvm.umax.i32(i32 %12, i32 1)
br label %18
16: ; preds = %18, %9
%17 = icmp ult i32 %12, 50
br i1 %17, label %23, label %28
18: ; preds = %14, %18
%19 = phi i32 [ %21, %18 ], [ 0, %14 ]
%20 = tail call i32 @putchar(i8 signext 42)
%21 = add nuw i32 %19, 1
%22 = icmp eq i32 %21, %15
br i1 %22, label %16, label %18
23: ; preds = %16, %23
%24 = phi i32 [ %26, %23 ], [ %12, %16 ]
%25 = tail call i32 @putchar(i8 signext 32)
%26 = add i32 %24, 1
%27 = icmp eq i32 %26, 50
br i1 %27, label %28, label %23
28: ; preds = %23, %16
%29 = tail call i32 @putchar(i8 signext 124)
%30 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %6)
%31 = load i32, i32* @stdout
%32 = tail call i32 @fflush(i32 %31)
store i32 %6, i32* @display_progress.last
br label %33
33: ; preds = %4, %2, %28
ret void
}