#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 *, ...);
int strlen(char *);
void print_progress(int step, int total, int *last_i, int new_i, int p) {
  int pwidth;
  int width;
  int pos;
  int percent;
  int i;
  if (*last_i == new_i || p == 0)
    return;
  pwidth = 72;
  width = pwidth - strlen("calc : ");
  pos = (step * width) / total;
  percent = (step * 100) / total;
  printf("calc : [");
  i = 0;
  while (i < pos) {
    printf("%c", '=');
    i++;
  }
  printf("% *c", width - pos + 1, ']');
  printf(" %3d%%\r", percent);
  fflush(0);
}


x86 assembly (clang, -O0):
<print_progress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
cmp    -0x14(%rbp),%eax
je     1162 <print_progress+0x32>
cmpl   $0x0,-0x18(%rbp)
jne    1167 <print_progress+0x37>
jmp    1219 <print_progress+0xe9>
movl   $0x48,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x30(%rbp)
lea    0xe85(%rip),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x20(%rbp)
mov    -0x4(%rbp),%eax
imul   -0x20(%rbp),%eax
cltd
idivl  -0x8(%rbp)
mov    %eax,-0x24(%rbp)
imul   $0x64,-0x4(%rbp),%eax
cltd
idivl  -0x8(%rbp)
mov    %eax,-0x28(%rbp)
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    11e5 <print_progress+0xb5>
lea    0xe46(%rip),%rdi
mov    $0x3d,%esi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11b8 <print_progress+0x88>
mov    -0x20(%rbp),%esi
sub    -0x24(%rbp),%esi
add    $0x1,%esi
lea    0xe1f(%rip),%rdi
mov    $0x5d,%edx
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%esi
lea    0xe0e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1050 <fflush@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_progress>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %r8d,%r8d
je     11ec <print_progress+0xac>
cmp    %ecx,(%rdx)
je     11ec <print_progress+0xac>
mov    %esi,%r14d
mov    %edi,%ebp
lea    0xe9c(%rip),%rdi
call   1040 <strlen@plt>
mov    $0x48,%ebx
sub    %eax,%ebx
mov    %ebx,%eax
imul   %ebp,%eax
cltd
idiv   %r14d
mov    %eax,%r15d
imul   $0x64,%ebp,%eax
cltd
idiv   %r14d
mov    %eax,%r14d
lea    0xe7b(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
test   %r15d,%r15d
jle    11af <print_progress+0x6f>
mov    %r15d,%ebp
nopl   0x0(%rax)
mov    $0x3d,%edi
call   1030 <putchar@plt>
add    $0xffffffff,%ebp
jne    11a0 <print_progress+0x60>
sub    %r15d,%ebx
add    $0x1,%ebx
lea    0xe55(%rip),%rdi
mov    %ebx,%esi
mov    $0x5d,%edx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe45(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <fflush@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [8 x i8] c"calc : \00"
@.str.1 = [9 x i8] c"calc : [\00"
@.str.3 = [5 x i8] c"% *c\00"
@.str.4 = [8 x i8] c" %3d%%\0D\00"
define void @print_progress(i32 %0, i32 %1, i32* nocapture %2, i32 %3, i32 %4) {
%6 = load i32, i32* %2
%7 = icmp eq i32 %6, %3
%8 = icmp eq i32 %4, 0
%9 = or i1 %8, %7
br i1 %9, label %30, label %10
10: ; preds = %5
%11 = tail call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%12 = sub nsw i32 72, %11
%13 = mul nsw i32 %12, %0
%14 = sdiv i32 %13, %1
%15 = mul nsw i32 %0, 100
%16 = sdiv i32 %15, %1
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp sgt i32 %14, 0
br i1 %18, label %19, label %24
19: ; preds = %10, %19
%20 = phi i32 [ %22, %19 ], [ 0, %10 ]
%21 = tail call i32 @putchar(i32 61)
%22 = add nuw nsw i32 %20, 1
%23 = icmp eq i32 %22, %14
br i1 %23, label %24, label %19
24: ; preds = %19, %10
%25 = sub i32 1, %14
%26 = add i32 %25, %12
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %26, i32 93)
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 %16)
%29 = tail call i32 @fflush(i32 0)
br label %30
30: ; preds = %5, %24
ret void
}