#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 *, ...);
void progressbar(int nsteps, int i) {
  int j;
  int percent = (i * 100) / nsteps;
  printf("\r%3d%% [", percent);
  for (j = 0; j < nsteps; j++) {
    if (j < i)
      printf("=");
    else if (j == i)
      printf(">");
    else
      printf(" ");
  }
  printf("]");
}


x86 assembly (clang, -O0):
<progressbar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
imul   $0x64,-0x8(%rbp),%eax
cltd
idivl  -0x4(%rbp)
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%esi
lea    0xecd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11b1 <progressbar+0xa1>
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    116c <progressbar+0x5c>
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    119e <progressbar+0x8e>
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jne    118b <progressbar+0x7b>
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1199 <progressbar+0x89>
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    119e <progressbar+0x8e>
jmp    11a3 <progressbar+0x93>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1141 <progressbar+0x31>
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<progressbar>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r14d
mov    %edi,%ebp
imul   $0x64,%esi,%eax
cltd
idiv   %edi
lea    0xec6(%rip),%rdi
xor    %ebx,%ebx
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
test   %ebp,%ebp
jle    117c <progressbar+0x5c>
mov    $0x3e,%r15d
mov    $0x3d,%r12d
cs nopw 0x0(%rax,%rax,1)
nop
cmp    %ebx,%r14d
mov    $0x20,%edi
cmove  %r15d,%edi
cmovg  %r12d,%edi
call   1030 <putchar@plt>
add    $0x1,%ebx
cmp    %ebx,%ebp
jne    1160 <progressbar+0x40>
mov    $0x5d,%edi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"\0D%3d%% [\00"
@.str.1 = [2 x i8] c"=\00"
@.str.2 = [2 x i8] c">\00"
@.str.3 = [2 x i8] c" \00"
@.str.4 = [2 x i8] c"]\00"
define void @progressbar(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* %4
%8 = mul nsw i32 %7, 100
%9 = load i32, i32* %3
%10 = sdiv i32 %8, %9
store i32 %10, i32* %6
%11 = load i32, i32* %6
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %11)
store i32 0, i32* %5
br label %13
13: ; preds = %33, %2
%14 = load i32, i32* %5
%15 = load i32, i32* %3
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %36
17: ; preds = %13
%18 = load i32, i32* %5
%19 = load i32, i32* %4
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %32
23: ; preds = %17
%24 = load i32, i32* %5
%25 = load i32, i32* %4
%26 = icmp eq i32 %24, %25
br i1 %26, label %27, label %29
27: ; preds = %23
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %31
29: ; preds = %23
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %31
31: ; preds = %29, %27
br label %32
32: ; preds = %31, %21
br label %33
33: ; preds = %32
%34 = load i32, i32* %5
%35 = add nsw i32 %34, 1
store i32 %35, i32* %5
br label %13
36: ; preds = %13
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"\0D%3d%% [\00"
define void @progressbar(i32 %0, i32 %1) {
%3 = mul nsw i32 %1, 100
%4 = sdiv i32 %3, %0
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = icmp sgt i32 %0, 0
br i1 %6, label %7, label %16
7: ; preds = %2, %7
%8 = phi i32 [ %14, %7 ], [ 0, %2 ]
%9 = icmp slt i32 %8, %1
%10 = icmp eq i32 %8, %1
%11 = select i1 %10, i32 62, i32 32
%12 = select i1 %9, i32 61, i32 %11
%13 = tail call i32 @putchar(i32 %12)
%14 = add nuw nsw i32 %8, 1
%15 = icmp eq i32 %14, %0
br i1 %15, label %16, label %7
16: ; preds = %7, %2
%17 = tail call i32 @putchar(i32 93)
ret void
}