#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 */
typedef float uint64_t;

/* Variables and functions */
int asprintf(char **, char *, int, char *);
int /*<<< orphan*/ memset(char *, char, int);
char *makeProgressBar(uint64_t currentPosition, uint64_t totalSize) {
  float percent = (float)currentPosition / totalSize * 100;
  int p = percent * 0.5;
  if (p > 50) {
    p = 50;
  }
  char line[51];
  memset(line, ' ', 50);
  memset(line, '=', p);
  line[50] = 0;
  char *progressbar;
  int res = asprintf(&progressbar, " %3d%% [%s] 100%%", (int)percent, line);
  if (res < 0) {
  }
  return progressbar;
}


x86 assembly (clang, -O0):
<makeProgressBar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movss  %xmm0,-0x4(%rbp)
movss  %xmm1,-0x8(%rbp)
movss  -0x4(%rbp),%xmm0
divss  -0x8(%rbp),%xmm0
movss  0xec4(%rip),%xmm1
mulss  %xmm1,%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xea2(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x32,-0x10(%rbp)
jle    117a <makeProgressBar+0x5a>
movl   $0x32,-0x10(%rbp)
lea    -0x50(%rbp),%rdi
mov    $0x20,%esi
mov    $0x32,%edx
call   1030 <memset@plt>
lea    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%edx
mov    $0x3d,%esi
call   1030 <memset@plt>
movb   $0x0,-0x1e(%rbp)
cvttss2si -0xc(%rbp),%edx
lea    -0x50(%rbp),%rcx
lea    -0x58(%rbp),%rdi
lea    0xe56(%rip),%rsi
call   1040 <asprintf@plt>
mov    %eax,-0x5c(%rbp)
cmpl   $0x0,-0x5c(%rbp)
jge    11cd <makeProgressBar+0xad>
jmp    11cd <makeProgressBar+0xad>
mov    -0x58(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<makeProgressBar>:
push   %r14
push   %rbx
sub    $0x48,%rsp
divss  %xmm1,%xmm0
mulss  0xecd(%rip),%xmm0
movss  %xmm0,0x4(%rsp)
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
mulsd  0xec0(%rip),%xmm1
cvttsd2si %xmm1,%ebx
cmp    $0x32,%ebx
mov    $0x32,%eax
cmovge %eax,%ebx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0x20,%esi
mov    $0x32,%edx
call   1030 <memset@plt>
mov    %r14,%rdi
mov    $0x3d,%esi
mov    %ebx,%edx
call   1030 <memset@plt>
movb   $0x0,0x42(%rsp)
cvttss2si 0x4(%rsp),%edx
lea    0xe81(%rip),%rsi
lea    0x8(%rsp),%rdi
mov    %r14,%rcx
call   1040 <asprintf@plt>
mov    0x8(%rsp),%rax
add    $0x48,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [18 x i8] c" %3d%% [%s] 100%%\00"
define i8* @makeProgressBar(float %0, float %1) {
%3 = alloca float
%4 = alloca float
%5 = alloca float
%6 = alloca i32
%7 = alloca [51 x i8]
%8 = alloca i8*
%9 = alloca i32
store float %0, float* %3
store float %1, float* %4
%10 = load float, float* %3
%11 = load float, float* %4
%12 = fdiv float %10, %11
%13 = fmul float %12, 1.000000e+02
store float %13, float* %5
%14 = load float, float* %5
%15 = fpext float %14 to double
%16 = fmul double %15, 5.000000e-01
%17 = fptosi double %16 to i32
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = icmp sgt i32 %18, 50
br i1 %19, label %20, label %21
20: ; preds = %2
store i32 50, i32* %6
br label %21
21: ; preds = %20, %2
%22 = getelementptr inbounds [51 x i8], [51 x i8]* %7, i64 0, i64 0
%23 = call i32 @memset(i8* %22, i8 signext 32, i32 50)
%24 = getelementptr inbounds [51 x i8], [51 x i8]* %7, i64 0, i64 0
%25 = load i32, i32* %6
%26 = call i32 @memset(i8* %24, i8 signext 61, i32 %25)
%27 = getelementptr inbounds [51 x i8], [51 x i8]* %7, i64 0, i64 50
store i8 0, i8* %27
%28 = load float, float* %5
%29 = fptosi float %28 to i32
%30 = getelementptr inbounds [51 x i8], [51 x i8]* %7, i64 0, i64 0
%31 = call i32 @asprintf(i8** %8, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %29, i8* %30)
store i32 %31, i32* %9
%32 = load i32, i32* %9
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %21
br label %35
35: ; preds = %34, %21
%36 = load i8*, i8** %8
ret i8* %36
}

LLVM IR (-O2):
@.str = [18 x i8] c" %3d%% [%s] 100%%\00"
define i8* @makeProgressBar(float %0, float %1) {
%3 = alloca [51 x i8]
%4 = alloca i8*
%5 = fdiv float %0, %1
%6 = fmul float %5, 1.000000e+02
%7 = fpext float %6 to double
%8 = fmul double %7, 5.000000e-01
%9 = fptosi double %8 to i32
%10 = icmp slt i32 %9, 50
%11 = select i1 %10, i32 %9, i32 50
%12 = getelementptr inbounds [51 x i8], [51 x i8]* %3, i64 0, i64 0
%13 = call i32 @memset(i8* %12, i8 signext 32, i32 50)
%14 = call i32 @memset(i8* %12, i8 signext 61, i32 %11)
%15 = getelementptr inbounds [51 x i8], [51 x i8]* %3, i64 0, i64 50
store i8 0, i8* %15
%16 = bitcast i8** %4 to i8*
%17 = fptosi float %6 to i32
%18 = call i32 @asprintf(i8** %4, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %17, i8* %12)
%19 = load i8*, i8** %4
ret i8* %19
}