#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*/ err_msg(char *, char const *, ...);
void show_progress(long cur, long sum) {
  const char PROC_MSG[] = "Processing...";
  const char DONE_MSG[] = "Processing complete";
  static int pct;
  int tmp;
  tmp = (int)((double)cur / (double)sum * 100.0);
  if (tmp > pct) {
    pct = tmp;
    if (pct == 0)
      err_msg("%s\r", PROC_MSG);
    else if (pct == 100)
      err_msg("%s\n", DONE_MSG);
    else
      err_msg("%s (%d%%)\r", PROC_MSG, pct);
  }
}


x86 assembly (clang, -O0):
<show_progress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xee1(%rip),%rax
mov    %rax,-0x1e(%rbp)
mov    0xedf(%rip),%eax
mov    %eax,-0x16(%rbp)
mov    0xed9(%rip),%ax
mov    %ax,-0x12(%rbp)
mov    0xeea(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xee7(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0xee5(%rip),%eax
mov    %eax,-0x30(%rbp)
cvtsi2sdq -0x8(%rbp),%xmm0
cvtsi2sdq -0x10(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  0xe8a(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    0x2ea2(%rip),%eax
jle    1203 <show_progress+0xf3>
mov    -0x44(%rbp),%eax
mov    %eax,0x2e93(%rip)
cmpl   $0x0,0x2e8c(%rip)
jne    11bd <show_progress+0xad>
lea    -0x1e(%rbp),%rsi
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1030 <err_msg@plt>
jmp    11fe <show_progress+0xee>
cmpl   $0x64,0x2e68(%rip)
jne    11e1 <show_progress+0xd1>
lea    -0x40(%rbp),%rsi
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1030 <err_msg@plt>
jmp    11f9 <show_progress+0xe9>
lea    -0x1e(%rbp),%rsi
mov    0x2e41(%rip),%edx
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1030 <err_msg@plt>
jmp    11fe <show_progress+0xee>
jmp    1203 <show_progress+0xf3>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<show_progress>:
sub    $0x28,%rsp
movabs $0x2e2e2e676e6973,%rax
mov    %rax,0x6(%rsp)
movabs $0x69737365636f7250,%rax
73 73 69
mov    %rax,(%rsp)
movaps 0xef8(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %rdi,%xmm0
cvtsi2sd %rsi,%xmm1
movl   $0x657465,0x20(%rsp)
divsd  %xmm1,%xmm0
mulsd  0xea2(%rip),%xmm0
cvttsd2si %xmm0,%edx
cmp    %edx,0x2ec4(%rip)
jge    119e <show_progress+0x8e>
mov    %edx,0x2ebc(%rip)
cmp    $0x64,%edx
jne    118d <show_progress+0x7d>
lea    0xe9a(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1030 <err_msg@plt>
add    $0x28,%rsp
ret
lea    0xe86(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1030 <err_msg@plt>
add    $0x28,%rsp
ret

LLVM IR (-O0):
@__const.show_progress.PROC_MSG = [14 x i8] c"Processing...\00"
@__const.show_progress.DONE_MSG = [20 x i8] c"Processing complete\00"
@show_progress.pct = internal global i32 0
@.str = [4 x i8] c"%s\0D\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [11 x i8] c"%s (%d%%)\0D\00"
define void @show_progress(i64 %0, i64 %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca [14 x i8]
%6 = alloca [20 x i8]
%7 = alloca i32
store i64 %0, i64* %3
store i64 %1, i64* %4
%8 = bitcast [14 x i8]* %5 to i8*
%9 = bitcast [20 x i8]* %6 to i8*
%10 = load i64, i64* %3
%11 = sitofp i64 %10 to double
%12 = load i64, i64* %4
%13 = sitofp i64 %12 to double
%14 = fdiv double %11, %13
%15 = fmul double %14, 1.000000e+02
%16 = fptosi double %15 to i32
store i32 %16, i32* %7
%17 = load i32, i32* %7
%18 = load i32, i32* @show_progress.pct
%19 = icmp sgt i32 %17, %18
br i1 %19, label %20, label %39
20: ; preds = %2
%21 = load i32, i32* %7
store i32 %21, i32* @show_progress.pct
%22 = load i32, i32* @show_progress.pct
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %20
%25 = getelementptr inbounds [14 x i8], [14 x i8]* %5, i64 0, i64 0
%26 = call i32 (i8*, i8*, ...) @err_msg(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %25)
br label %38
27: ; preds = %20
%28 = load i32, i32* @show_progress.pct
%29 = icmp eq i32 %28, 100
br i1 %29, label %30, label %33
30: ; preds = %27
%31 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%32 = call i32 (i8*, i8*, ...) @err_msg(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %31)
br label %37
33: ; preds = %27
%34 = getelementptr inbounds [14 x i8], [14 x i8]* %5, i64 0, i64 0
%35 = load i32, i32* @show_progress.pct
%36 = call i32 (i8*, i8*, ...) @err_msg(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %34, i32 %35)
br label %37
37: ; preds = %33, %30
br label %38
38: ; preds = %37, %24
br label %39
39: ; preds = %38, %2
ret void
}

LLVM IR (-O2):
@__const.show_progress.PROC_MSG = [14 x i8] c"Processing...\00"
@__const.show_progress.DONE_MSG = [20 x i8] c"Processing complete\00"
@show_progress.pct = internal unnamed_addr global i32 0
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [11 x i8] c"%s (%d%%)\0D\00"
define void @show_progress(i64 %0, i64 %1) {
%3 = alloca [14 x i8]
%4 = alloca [20 x i8]
%5 = getelementptr inbounds [14 x i8], [14 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%7 = sitofp i64 %0 to double
%8 = sitofp i64 %1 to double
%9 = fdiv double %7, %8
%10 = fmul double %9, 1.000000e+02
%11 = fptosi double %10 to i32
%12 = load i32, i32* @show_progress.pct
%13 = icmp slt i32 %12, %11
br i1 %13, label %14, label %20
14: ; preds = %2
store i32 %11, i32* @show_progress.pct
%15 = icmp eq i32 %11, 100
br i1 %15, label %16, label %18
16: ; preds = %14
%17 = call i32 (i8*, i8*, ...) @err_msg(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %6)
br label %20
18: ; preds = %14
%19 = call i32 (i8*, i8*, ...) @err_msg(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %5, i32 %11)
br label %20
20: ; preds = %18, %16, %2
ret void
}