#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*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(unsigned char *);
scalar_t__ malloc(unsigned int);
int /*<<< orphan*/ memset(unsigned char *, char, unsigned int);
int /*<<< orphan*/ stderr;
void progress_print(unsigned int *prog_num, unsigned long long progress,
                    unsigned long long max) {
  unsigned int MAX_WIDTH = 40;
  unsigned long long rate = 0;
  unsigned int new_prog_num = 0;
  unsigned char *prog_bar = NULL;
  if (NULL == prog_num) {
    return;
  }
  rate = max / (unsigned long long)MAX_WIDTH;
  new_prog_num = (unsigned int)(progress / rate);
  ;
  prog_bar = (unsigned char *)malloc(MAX_WIDTH + 1);
  memset(prog_bar, 0x00, MAX_WIDTH + 1);
  memset(prog_bar, '*', new_prog_num);
  memset(prog_bar + new_prog_num, '-', MAX_WIDTH - new_prog_num);
  fprintf(stderr, "%s", prog_bar);
  fprintf(stderr, "(%lld/%lld)", progress, max);
  fprintf(stderr, "\r");
  fflush(stderr);
  if (MAX_WIDTH == new_prog_num) {
    fprintf(stderr, "\n");
  }
  *prog_num = new_prog_num;
  if (NULL == prog_bar) {
    free(prog_bar);
  }
  return;
}


x86 assembly (clang, -O0):
<progress_print>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x28,-0x1c(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movq   $0x0,-0x38(%rbp)
xor    %eax,%eax
cmp    -0x8(%rbp),%rax
jne    1193 <progress_print+0x43>
jmp    12a2 <progress_print+0x152>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x28(%rbp)
mov    %eax,-0x2c(%rbp)
mov    -0x1c(%rbp),%edi
add    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x1c(%rbp),%edx
add    $0x1,%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x38(%rbp),%rdi
mov    -0x2c(%rbp),%edx
mov    $0x2a,%esi
call   1040 <memset@plt>
mov    -0x38(%rbp),%rdi
mov    -0x2c(%rbp),%eax
add    %rax,%rdi
mov    -0x1c(%rbp),%edx
sub    -0x2c(%rbp),%edx
mov    $0x2d,%esi
call   1040 <memset@plt>
mov    0x2ddc(%rip),%rax
mov    (%rax),%edi
mov    -0x38(%rbp),%rdx
lea    0xdef(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2dc1(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xdd3(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2da2(%rip),%rax
mov    (%rax),%edi
lea    0xdc8(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2d8b(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
mov    -0x1c(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jne    127f <progress_print+0x12f>
mov    0x2d71(%rip),%rax
mov    (%rax),%edi
lea    0xd99(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x2c(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
xor    %eax,%eax
cmp    -0x38(%rbp),%rax
jne    129d <progress_print+0x14d>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
jmp    12a2 <progress_print+0x152>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<progress_print>:
test   %rdi,%rdi
je     1262 <progress_print+0x112>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%r14
movabs $0xcccccccccccccccd,%rcx
cc cc cc
mov    %rdx,%rax
mul    %rcx
mov    %rdx,%rcx
shr    $0x5,%rcx
mov    %rsi,%rax
or     %rcx,%rax
shr    $0x20,%rax
je     119d <progress_print+0x4d>
mov    %r12,%rax
xor    %edx,%edx
div    %rcx
mov    %rax,%r13
jmp    11a7 <progress_print+0x57>
mov    %r12d,%eax
xor    %edx,%edx
div    %ecx
mov    %eax,%r13d
mov    $0x29,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x29,%edx
call   1040 <memset@plt>
mov    %rbx,%rdi
mov    $0x2a,%esi
mov    %r13d,%edx
call   1040 <memset@plt>
mov    %r13d,%edi
add    %rbx,%rdi
lea    -0x28(%r13),%edx
neg    %edx
mov    $0x2d,%esi
call   1040 <memset@plt>
mov    0x2df0(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0xe06(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x0(%rbp),%edi
lea    0xdf5(%rip),%rsi
mov    %r12,%rdx
mov    %r15,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x0(%rbp),%edi
lea    0xdea(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x0(%rbp),%edi
call   1070 <fflush@plt>
cmp    $0x28,%r13d
jne    124b <progress_print+0xfb>
mov    0x0(%rbp),%edi
lea    0xdcd(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %r13d,(%r14)
test   %rbx,%rbx
lea    0x8(%rsp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
je     1263 <progress_print+0x113>
ret
xor    %edi,%edi
jmp    1030 <free@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [3 x i8] c"%s\00"
@.str.1 = [12 x i8] c"(%lld/%lld)\00"
@.str.2 = [2 x i8] c"\0D\00"
@.str.3 = [2 x i8] c"\0A\00"
define void @progress_print(i32* %0, i64 %1, i64 %2) {
%4 = alloca i32*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i32
%8 = alloca i64
%9 = alloca i32
%10 = alloca i8*
store i32* %0, i32** %4
store i64 %1, i64* %5
store i64 %2, i64* %6
store i32 40, i32* %7
store i64 0, i64* %8
store i32 0, i32* %9
store i8* null, i8** %10
%11 = load i32*, i32** %4
%12 = icmp eq i32* null, %11
br i1 %12, label %13, label %14
13: ; preds = %3
br label %68
14: ; preds = %3
%15 = load i64, i64* %6
%16 = load i32, i32* %7
%17 = zext i32 %16 to i64
%18 = udiv i64 %15, %17
store i64 %18, i64* %8
%19 = load i64, i64* %5
%20 = load i64, i64* %8
%21 = udiv i64 %19, %20
%22 = trunc i64 %21 to i32
store i32 %22, i32* %9
%23 = load i32, i32* %7
%24 = add i32 %23, 1
%25 = call i64 @malloc(i32 %24)
%26 = inttoptr i64 %25 to i8*
store i8* %26, i8** %10
%27 = load i8*, i8** %10
%28 = load i32, i32* %7
%29 = add i32 %28, 1
%30 = call i32 @memset(i8* %27, i8 signext 0, i32 %29)
%31 = load i8*, i8** %10
%32 = load i32, i32* %9
%33 = call i32 @memset(i8* %31, i8 signext 42, i32 %32)
%34 = load i8*, i8** %10
%35 = load i32, i32* %9
%36 = zext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
%38 = load i32, i32* %7
%39 = load i32, i32* %9
%40 = sub i32 %38, %39
%41 = call i32 @memset(i8* %37, i8 signext 45, i32 %40)
%42 = load i32, i32* @stderr
%43 = load i8*, i8** %10
%44 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %43)
%45 = load i32, i32* @stderr
%46 = load i64, i64* %5
%47 = load i64, i64* %6
%48 = call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i64 %46, i64 %47)
%49 = load i32, i32* @stderr
%50 = call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%51 = load i32, i32* @stderr
%52 = call i32 @fflush(i32 %51)
%53 = load i32, i32* %7
%54 = load i32, i32* %9
%55 = icmp eq i32 %53, %54
br i1 %55, label %56, label %59
56: ; preds = %14
%57 = load i32, i32* @stderr
%58 = call i32 (i32, i8*, ...) @fprintf(i32 %57, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %59
59: ; preds = %56, %14
%60 = load i32, i32* %9
%61 = load i32*, i32** %4
store i32 %60, i32* %61
%62 = load i8*, i8** %10
%63 = icmp eq i8* null, %62
br i1 %63, label %64, label %67
64: ; preds = %59
%65 = load i8*, i8** %10
%66 = call i32 @free(i8* %65)
br label %67
67: ; preds = %64, %59
br label %68
68: ; preds = %67, %13
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [3 x i8] c"%s\00"
@.str.1 = [12 x i8] c"(%lld/%lld)\00"
@.str.2 = [2 x i8] c"\0D\00"
@.str.3 = [2 x i8] c"\0A\00"
define void @progress_print(i32* writeonly %0, i64 %1, i64 %2) {
%4 = icmp eq i32* %0, null
br i1 %4, label %33, label %5
5: ; preds = %3
%6 = udiv i64 %2, 40
%7 = udiv i64 %1, %6
%8 = trunc i64 %7 to i32
%9 = tail call i64 @malloc(i32 41)
%10 = inttoptr i64 %9 to i8*
%11 = tail call i32 @memset(i8* %10, i8 signext 0, i32 41)
%12 = tail call i32 @memset(i8* %10, i8 signext 42, i32 %8)
%13 = and i64 %7, 4294967295
%14 = getelementptr inbounds i8, i8* %10, i64 %13
%15 = sub i32 40, %8
%16 = tail call i32 @memset(i8* %14, i8 signext 45, i32 %15)
%17 = load i32, i32* @stderr
%18 = tail call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %10)
%19 = load i32, i32* @stderr
%20 = tail call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i64 %1, i64 %2)
%21 = load i32, i32* @stderr
%22 = tail call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%23 = load i32, i32* @stderr
%24 = tail call i32 @fflush(i32 %23)
%25 = icmp eq i32 %8, 40
br i1 %25, label %26, label %29
26: ; preds = %5
%27 = load i32, i32* @stderr
%28 = tail call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %29
29: ; preds = %26, %5
store i32 %8, i32* %0
%30 = icmp eq i64 %9, 0
br i1 %30, label %31, label %33
31: ; preds = %29
%32 = tail call i32 @free(i8* null)
br label %33
33: ; preds = %29, %31, %3
ret void
}