#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*/ memset(char *, char, unsigned int);
int /*<<< orphan*/ printf(char *, char *, char *, unsigned int, unsigned int);
int /*<<< orphan*/ stdout;
void progressbar(char *label, unsigned cur, unsigned total) {
  unsigned pos;
  char bar[40 + 1], spinner[] = "-\\|/";
  pos = (40 * cur) / total;
  memset(bar, '.', 40);
  memset(bar, '#', pos);
  bar[40] = '\0';
  if ((pos < 40) && (total >= 40 * 2))
    bar[pos] = spinner[cur % 4];
  printf("\r%18s [%s] %u/%u", label, bar, cur, total);
  fflush(stdout);
}


x86 assembly (clang, -O0):
<progressbar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    0xeb8(%rip),%eax
mov    %eax,-0x45(%rbp)
mov    0xeb3(%rip),%al
mov    %al,-0x41(%rbp)
imul   $0x28,-0xc(%rbp),%eax
xor    %edx,%edx
divl   -0x10(%rbp)
mov    %eax,-0x14(%rbp)
lea    -0x40(%rbp),%rdi
mov    $0x2e,%esi
mov    $0x28,%edx
call   1040 <memset@plt>
lea    -0x40(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    $0x23,%esi
call   1040 <memset@plt>
movb   $0x0,-0x18(%rbp)
cmpl   $0x28,-0x14(%rbp)
jae    11af <progressbar+0x7f>
cmpl   $0x50,-0x10(%rbp)
jb     11af <progressbar+0x7f>
mov    -0xc(%rbp),%eax
and    $0x3,%eax
mov    %eax,%eax
mov    -0x45(%rbp,%rax,1),%cl
mov    -0x14(%rbp),%eax
mov    %cl,-0x40(%rbp,%rax,1)
mov    -0x8(%rbp),%rsi
lea    -0x40(%rbp),%rdx
mov    -0xc(%rbp),%ecx
mov    -0x10(%rbp),%r8d
lea    0xe40(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<progressbar>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x30,%rsp
mov    %edx,%ebx
mov    %esi,%r14d
mov    %rdi,%r15
lea    0x0(,%r14,8),%eax
lea    (%rax,%rax,4),%eax
xor    %edx,%edx
div    %ebx
mov    %eax,%ebp
mov    %rsp,%r12
mov    %r12,%rdi
mov    $0x2e,%esi
mov    $0x28,%edx
call   1040 <memset@plt>
mov    %r12,%rdi
mov    $0x23,%esi
mov    %ebp,%edx
call   1040 <memset@plt>
movb   $0x0,0x28(%rsp)
cmp    $0x50,%ebx
jb     119d <progressbar+0x6d>
cmp    $0x27,%ebp
ja     119d <progressbar+0x6d>
mov    %r14d,%eax
and    $0x3,%eax
lea    0xe6b(%rip),%rcx
mov    (%rax,%rcx,1),%al
mov    %ebp,%ecx
mov    %al,(%rsp,%rcx,1)
lea    0xe61(%rip),%rdi
mov    %rsp,%rdx
mov    %r15,%rsi
mov    %r14d,%ecx
mov    %ebx,%r8d
call   1030 <printf@plt>
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.progressbar.spinner = [5 x i8] c"-\\|/\00"
@.str = [17 x i8] c"\0D%18s [%s] %u/%u\00"
@stdout = global i32 0
define void @progressbar(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca [41 x i8]
%9 = alloca [5 x i8]
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%10 = bitcast [5 x i8]* %9 to i8*
%11 = load i32, i32* %5
%12 = mul i32 40, %11
%13 = load i32, i32* %6
%14 = udiv i32 %12, %13
store i32 %14, i32* %7
%15 = getelementptr inbounds [41 x i8], [41 x i8]* %8, i64 0, i64 0
%16 = call i32 @memset(i8* %15, i8 signext 46, i32 40)
%17 = getelementptr inbounds [41 x i8], [41 x i8]* %8, i64 0, i64 0
%18 = load i32, i32* %7
%19 = call i32 @memset(i8* %17, i8 signext 35, i32 %18)
%20 = getelementptr inbounds [41 x i8], [41 x i8]* %8, i64 0, i64 40
store i8 0, i8* %20
%21 = load i32, i32* %7
%22 = icmp ult i32 %21, 40
br i1 %22, label %23, label %35
23: ; preds = %3
%24 = load i32, i32* %6
%25 = icmp uge i32 %24, 80
br i1 %25, label %26, label %35
26: ; preds = %23
%27 = load i32, i32* %5
%28 = urem i32 %27, 4
%29 = zext i32 %28 to i64
%30 = getelementptr inbounds [5 x i8], [5 x i8]* %9, i64 0, i64 %29
%31 = load i8, i8* %30
%32 = load i32, i32* %7
%33 = zext i32 %32 to i64
%34 = getelementptr inbounds [41 x i8], [41 x i8]* %8, i64 0, i64 %33
store i8 %31, i8* %34
br label %35
35: ; preds = %26, %23, %3
%36 = load i8*, i8** %4
%37 = getelementptr inbounds [41 x i8], [41 x i8]* %8, i64 0, i64 0
%38 = load i32, i32* %5
%39 = load i32, i32* %6
%40 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %36, i8* %37, i32 %38, i32 %39)
%41 = load i32, i32* @stdout
%42 = call i32 @fflush(i32 %41)
ret void
}

LLVM IR (-O2):
@__const.progressbar.spinner = [5 x i8] c"-\\|/\00"
@.str = [17 x i8] c"\0D%18s [%s] %u/%u\00"
@stdout = global i32 0
define void @progressbar(i8* %0, i32 %1, i32 %2) {
%4 = alloca [41 x i8]
%5 = getelementptr inbounds [41 x i8], [41 x i8]* %4, i64 0, i64 0
%6 = mul i32 %1, 40
%7 = udiv i32 %6, %2
%8 = call i32 @memset(i8* %5, i8 signext 46, i32 40)
%9 = call i32 @memset(i8* %5, i8 signext 35, i32 %7)
%10 = getelementptr inbounds [41 x i8], [41 x i8]* %4, i64 0, i64 40
store i8 0, i8* %10
%11 = icmp ult i32 %7, 40
%12 = icmp ugt i32 %2, 79
%13 = and i1 %12, %11
br i1 %13, label %14, label %21
14: ; preds = %3
%15 = and i32 %1, 3
%16 = zext i32 %15 to i64
%17 = getelementptr inbounds [5 x i8], [5 x i8]* @__const.progressbar.spinner, i64 0, i64 %16
%18 = load i8, i8* %17
%19 = zext i32 %7 to i64
%20 = getelementptr inbounds [41 x i8], [41 x i8]* %4, i64 0, i64 %19
store i8 %18, i8* %20
br label %21
21: ; preds = %14, %3
%22 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %5, i32 %1, i32 %2)
%23 = load i32, i32* @stdout
%24 = call i32 @fflush(i32 %23)
ret void
}