#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 int off_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
void printPercentage(off_t written, off_t fileSize, off_t *last) {
  off_t percent = ((double)written / (double)fileSize) * 100.0;
  if (*last == -1)
    percent == 100 ? printf("%s100%%%s", "\x1b[1;32m", "\x1b[0m")
                   : printf("%ld%%", percent);
  else if (*last < 10)
    percent == 100 ? printf("\b\b%s100%%%s", "\x1b[1;32m", "\x1b[0m")
                   : printf("\b\b%ld%%", percent);
  else if (*last < 100)
    percent == 100 ? printf("\b\b\b%s100%%%s", "\x1b[1;32m", "\x1b[0m")
                   : printf("\b\b\b%ld%%", percent);
  *last = percent;
}


x86 assembly (clang, -O0):
<printPercentage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
cvtsi2sdl -0x4(%rbp),%xmm0
cvtsi2sdl -0x8(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  0xec8(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
cmpl   $0xffffffff,(%rax)
jne    1191 <printPercentage+0x81>
cmpl   $0x64,-0x14(%rbp)
jne    117b <printPercentage+0x6b>
lea    0xeb7(%rip),%rdi
lea    0xea0(%rip),%rsi
lea    0xea1(%rip),%rdx
mov    $0x0,%al
call   1030 <printf@plt>
jmp    118c <printPercentage+0x7c>
mov    -0x14(%rbp),%esi
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1232 <printPercentage+0x122>
mov    -0x10(%rbp),%rax
cmpl   $0xa,(%rax)
jge    11df <printPercentage+0xcf>
cmpl   $0x64,-0x14(%rbp)
jne    11c9 <printPercentage+0xb9>
lea    0xe67(%rip),%rdi
lea    0xe52(%rip),%rsi
lea    0xe53(%rip),%rdx
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11da <printPercentage+0xca>
mov    -0x14(%rbp),%esi
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    122d <printPercentage+0x11d>
mov    -0x10(%rbp),%rax
cmpl   $0x64,(%rax)
jge    1228 <printPercentage+0x118>
cmpl   $0x64,-0x14(%rbp)
jne    1217 <printPercentage+0x107>
lea    0xe18(%rip),%rdi
lea    0xe04(%rip),%rsi
lea    0xe05(%rip),%rdx
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1228 <printPercentage+0x118>
mov    -0x14(%rbp),%esi
lea    0xe01(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    122d <printPercentage+0x11d>
jmp    1232 <printPercentage+0x122>
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printPercentage>:
push   %rbp
push   %rbx
push   %rax
cvtsi2sd %edi,%xmm0
cvtsi2sd %esi,%xmm1
mov    %rdx,%rbx
divsd  %xmm1,%xmm0
mulsd  0xed6(%rip),%xmm0
cvttsd2si %xmm0,%ebp
mov    (%rdx),%eax
cmp    $0xffffffff,%eax
je     1148 <printPercentage+0x38>
cmp    $0x9,%eax
jg     1156 <printPercentage+0x46>
cmp    $0x64,%ebp
jne    1187 <printPercentage+0x77>
lea    0xed0(%rip),%rdi
jmp    1167 <printPercentage+0x57>
cmp    $0x64,%ebp
jne    117e <printPercentage+0x6e>
lea    0xec4(%rip),%rdi
jmp    1167 <printPercentage+0x57>
cmp    $0x63,%eax
ja     11a0 <printPercentage+0x90>
cmp    $0x64,%ebp
jne    1190 <printPercentage+0x80>
lea    0xeae(%rip),%rdi
lea    0xe9a(%rip),%rsi
lea    0xe9b(%rip),%rdx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    11a0 <printPercentage+0x90>
lea    0xea0(%rip),%rdi
jmp    1197 <printPercentage+0x87>
lea    0xe95(%rip),%rdi
jmp    1197 <printPercentage+0x87>
lea    0xe8b(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebp,(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"%s100%%%s\00"
@.str.1 = [8 x i8] c"\1B[1;32m\00"
@.str.2 = [5 x i8] c"\1B[0m\00"
@.str.3 = [6 x i8] c"%ld%%\00"
@.str.4 = [12 x i8] c"\08\08%s100%%%s\00"
@.str.5 = [8 x i8] c"\08\08%ld%%\00"
@.str.6 = [13 x i8] c"\08\08\08%s100%%%s\00"
@.str.7 = [9 x i8] c"\08\08\08%ld%%\00"
define void @printPercentage(i32 %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32* %2, i32** %6
%8 = load i32, i32* %4
%9 = sitofp i32 %8 to double
%10 = load i32, i32* %5
%11 = sitofp i32 %10 to double
%12 = fdiv double %9, %11
%13 = fmul double %12, 1.000000e+02
%14 = fptosi double %13 to i32
store i32 %14, i32* %7
%15 = load i32*, i32** %6
%16 = load i32, i32* %15
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %28
18: ; preds = %3
%19 = load i32, i32* %7
%20 = icmp eq i32 %19, 100
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %26
23: ; preds = %18
%24 = load i32, i32* %7
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %24)
br label %26
26: ; preds = %23, %21
%27 = phi i32 [ %22, %21 ], [ %25, %23 ]
br label %58
28: ; preds = %3
%29 = load i32*, i32** %6
%30 = load i32, i32* %29
%31 = icmp slt i32 %30, 10
br i1 %31, label %32, label %42
32: ; preds = %28
%33 = load i32, i32* %7
%34 = icmp eq i32 %33, 100
br i1 %34, label %35, label %37
35: ; preds = %32
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %40
37: ; preds = %32
%38 = load i32, i32* %7
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 %38)
br label %40
40: ; preds = %37, %35
%41 = phi i32 [ %36, %35 ], [ %39, %37 ]
br label %57
42: ; preds = %28
%43 = load i32*, i32** %6
%44 = load i32, i32* %43
%45 = icmp slt i32 %44, 100
br i1 %45, label %46, label %56
46: ; preds = %42
%47 = load i32, i32* %7
%48 = icmp eq i32 %47, 100
br i1 %48, label %49, label %51
49: ; preds = %46
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %54
51: ; preds = %46
%52 = load i32, i32* %7
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), i32 %52)
br label %54
54: ; preds = %51, %49
%55 = phi i32 [ %50, %49 ], [ %53, %51 ]
br label %56
56: ; preds = %54, %42
br label %57
57: ; preds = %56, %40
br label %58
58: ; preds = %57, %26
%59 = load i32, i32* %7
%60 = load i32*, i32** %6
store i32 %59, i32* %60
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"%s100%%%s\00"
@.str.1 = [8 x i8] c"\1B[1;32m\00"
@.str.2 = [5 x i8] c"\1B[0m\00"
@.str.3 = [6 x i8] c"%ld%%\00"
@.str.4 = [12 x i8] c"\08\08%s100%%%s\00"
@.str.5 = [8 x i8] c"\08\08%ld%%\00"
@.str.6 = [13 x i8] c"\08\08\08%s100%%%s\00"
@.str.7 = [9 x i8] c"\08\08\08%ld%%\00"
define void @printPercentage(i32 %0, i32 %1, i32* nocapture %2) {
%4 = sitofp i32 %0 to double
%5 = sitofp i32 %1 to double
%6 = fdiv double %4, %5
%7 = fmul double %6, 1.000000e+02
%8 = fptosi double %7 to i32
%9 = load i32, i32* %2
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %17
11: ; preds = %3
%12 = icmp eq i32 %8, 100
br i1 %12, label %13, label %15
13: ; preds = %11
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %33
15: ; preds = %11
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %8)
br label %33
17: ; preds = %3
%18 = icmp slt i32 %9, 10
br i1 %18, label %19, label %25
19: ; preds = %17
%20 = icmp eq i32 %8, 100
br i1 %20, label %21, label %23
21: ; preds = %19
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %33
23: ; preds = %19
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 %8)
br label %33
25: ; preds = %17
%26 = icmp ult i32 %9, 100
br i1 %26, label %27, label %33
27: ; preds = %25
%28 = icmp eq i32 %8, 100
br i1 %28, label %29, label %31
29: ; preds = %27
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %33
31: ; preds = %27
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), i32 %8)
br label %33
33: ; preds = %23, %21, %29, %31, %25, %13, %15
store i32 %8, i32* %2
ret void
}