#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*/ sprintf(char *, char *, ...);
char *airDoneStr(double start, double here, double end, char *str) {
  int perc = 0;
  if (str) {
    if (end != start)
      perc = (int)(1000 * (here - start) / (end - start) + 0.5);
    else
      perc = 1000;
    if (perc < 0) {
      sprintf(str, "\b\b\b\b\b\b ---- ");
    } else if (perc < 1000) {
      sprintf(str, "\b\b\b\b\b\b% 3d.%d%%", perc / 10, perc % 10);
    } else if (perc == 1000) {
      sprintf(str, "\b\b\b\b\b\b100.0%%");
    } else {
      sprintf(str, "\b\b\b\b\b\b done.");
    }
  }
  return str;
}


x86 assembly (clang, -O0):
<airDoneStr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
mov    %rdi,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1243 <airDoneStr+0x133>
movsd  -0x18(%rbp),%xmm0
ucomisd -0x8(%rbp),%xmm0
jne    1158 <airDoneStr+0x48>
jp     1158 <airDoneStr+0x48>
jmp    1194 <airDoneStr+0x84>
movsd  -0x10(%rbp),%xmm1
subsd  -0x8(%rbp),%xmm1
movsd  0xe9e(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  -0x18(%rbp),%xmm1
subsd  -0x8(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  0xe7c(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x24(%rbp)
jmp    119b <airDoneStr+0x8b>
movl   $0x3e8,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    11bc <airDoneStr+0xac>
mov    -0x20(%rbp),%rdi
lea    0xe60(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    123e <airDoneStr+0x12e>
cmpl   $0x3e8,-0x24(%rbp)
jge    11fe <airDoneStr+0xee>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,%ecx
mov    -0x28(%rbp),%edx
lea    0xe2b(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    1239 <airDoneStr+0x129>
cmpl   $0x3e8,-0x24(%rbp)
jne    1222 <airDoneStr+0x112>
mov    -0x20(%rbp),%rdi
lea    0xe17(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    1234 <airDoneStr+0x124>
mov    -0x20(%rbp),%rdi
lea    0xe0e(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    1239 <airDoneStr+0x129>
jmp    123e <airDoneStr+0x12e>
jmp    1243 <airDoneStr+0x133>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<airDoneStr>:
push   %rbx
mov    %rdi,%rbx
test   %rdi,%rdi
je     11c9 <airDoneStr+0xb9>
ucomisd %xmm0,%xmm2
jne    1125 <airDoneStr+0x15>
jnp    119b <airDoneStr+0x8b>
subsd  %xmm0,%xmm1
mulsd  0xecf(%rip),%xmm1
subsd  %xmm0,%xmm2
divsd  %xmm2,%xmm1
addsd  0xec7(%rip),%xmm1
cvttsd2si %xmm1,%eax
test   %eax,%eax
js     117a <airDoneStr+0x6a>
cmp    $0x3e7,%eax
ja     1194 <airDoneStr+0x84>
movzwl %ax,%ecx
imul   $0xcccd,%ecx,%edx
shr    $0x13,%edx
lea    (%rdx,%rdx,1),%ecx
lea    (%rcx,%rcx,4),%ecx
sub    %ecx,%eax
movzwl %ax,%ecx
lea    0xeaf(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <sprintf@plt>
jmp    11c9 <airDoneStr+0xb9>
movabs $0x202d2d2d2d2008,%rax
mov    %rax,0x5(%rbx)
movabs $0x2d20080808080808,%rax
08 20 2d
jmp    11c6 <airDoneStr+0xb6>
cmp    $0x3e8,%eax
jne    11ae <airDoneStr+0x9e>
lea    0xe8b(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <sprintf@plt>
jmp    11c9 <airDoneStr+0xb9>
movabs $0x2e656e6f642008,%rax
mov    %rax,0x5(%rbx)
movabs $0x6420080808080808,%rax
08 20 64
mov    %rax,(%rbx)
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [13 x i8] c"\08\08\08\08\08\08 ---- \00"
@.str.1 = [16 x i8] c"\08\08\08\08\08\08% 3d.%d%%\00"
@.str.2 = [14 x i8] c"\08\08\08\08\08\08100.0%%\00"
@.str.3 = [13 x i8] c"\08\08\08\08\08\08 done.\00"
define i8* @airDoneStr(double %0, double %1, double %2, i8* %3) {
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca i8*
%9 = alloca i32
store double %0, double* %5
store double %1, double* %6
store double %2, double* %7
store i8* %3, i8** %8
store i32 0, i32* %9
%10 = load i8*, i8** %8
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %56
12: ; preds = %4
%13 = load double, double* %7
%14 = load double, double* %5
%15 = fcmp une double %13, %14
br i1 %15, label %16, label %27
16: ; preds = %12
%17 = load double, double* %6
%18 = load double, double* %5
%19 = fsub double %17, %18
%20 = fmul double 1.000000e+03, %19
%21 = load double, double* %7
%22 = load double, double* %5
%23 = fsub double %21, %22
%24 = fdiv double %20, %23
%25 = fadd double %24, 5.000000e-01
%26 = fptosi double %25 to i32
store i32 %26, i32* %9
br label %28
27: ; preds = %12
store i32 1000, i32* %9
br label %28
28: ; preds = %27, %16
%29 = load i32, i32* %9
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = load i8*, i8** %8
%33 = call i32 (i8*, i8*, ...) @sprintf(i8* %32, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %55
34: ; preds = %28
%35 = load i32, i32* %9
%36 = icmp slt i32 %35, 1000
br i1 %36, label %37, label %44
37: ; preds = %34
%38 = load i8*, i8** %8
%39 = load i32, i32* %9
%40 = sdiv i32 %39, 10
%41 = load i32, i32* %9
%42 = srem i32 %41, 10
%43 = call i32 (i8*, i8*, ...) @sprintf(i8* %38, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %40, i32 %42)
br label %54
44: ; preds = %34
%45 = load i32, i32* %9
%46 = icmp eq i32 %45, 1000
br i1 %46, label %47, label %50
47: ; preds = %44
%48 = load i8*, i8** %8
%49 = call i32 (i8*, i8*, ...) @sprintf(i8* %48, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %53
50: ; preds = %44
%51 = load i8*, i8** %8
%52 = call i32 (i8*, i8*, ...) @sprintf(i8* %51, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br label %53
53: ; preds = %50, %47
br label %54
54: ; preds = %53, %37
br label %55
55: ; preds = %54, %31
br label %56
56: ; preds = %55, %4
%57 = load i8*, i8** %8
ret i8* %57
}

LLVM IR (-O2):
@.str = [13 x i8] c"\08\08\08\08\08\08 ---- \00"
@.str.1 = [16 x i8] c"\08\08\08\08\08\08% 3d.%d%%\00"
@.str.2 = [14 x i8] c"\08\08\08\08\08\08100.0%%\00"
@.str.3 = [13 x i8] c"\08\08\08\08\08\08 done.\00"
define i8* @airDoneStr(double %0, double %1, double %2, i8* returned writeonly %3) {
%5 = icmp eq i8* %3, null
br i1 %5, label %31, label %6
6: ; preds = %4
%7 = fcmp une double %2, %0
br i1 %7, label %8, label %28
8: ; preds = %6
%9 = fsub double %1, %0
%10 = fmul double %9, 1.000000e+03
%11 = fsub double %2, %0
%12 = fdiv double %10, %11
%13 = fadd double %12, 5.000000e-01
%14 = fptosi double %13 to i32
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %8
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(13) %3, i8* align 1 dereferenceable(13) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i64 13, i1 false)
br label %31
17: ; preds = %8
%18 = icmp ult i32 %14, 1000
br i1 %18, label %19, label %26
19: ; preds = %17
%20 = trunc i32 %14 to i16
%21 = udiv i16 %20, 10
%22 = zext i16 %21 to i32
%23 = urem i16 %20, 10
%24 = zext i16 %23 to i32
%25 = tail call i32 (i8*, i8*, ...) @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %22, i32 %24)
br label %31
26: ; preds = %17
%27 = icmp eq i32 %14, 1000
br i1 %27, label %28, label %30
28: ; preds = %6, %26
%29 = tail call i32 (i8*, i8*, ...) @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %31
30: ; preds = %26
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(13) %3, i8* align 1 dereferenceable(13) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i64 13, i1 false)
br label %31
31: ; preds = %16, %28, %30, %19, %4
ret i8* %3
}