#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*/ printf(char *, double, ...);
int rand();
double remainingTime(int, int, double, double);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(void) {
  int currentTime, startTime, bytes, totalBytes;
  srand(time(NULL));
  startTime = rand();
  totalBytes = 0 + rand() % (1000000 - 0);
  printf("startTime == %d, totalBytes == %d\n(Press Ctrl-C to exit)\n",
         startTime, totalBytes);
  currentTime = startTime;
  bytes = 0;
  do {
    sleep(1);
    bytes += 50000 + rand() % (100000 - 50000);
    if (bytes > totalBytes) {
      bytes = totalBytes;
    }
    currentTime++;
    printf("remainingTime: %.2f seconds\n",
           remainingTime(currentTime, startTime, (double)bytes,
                         (double)totalBytes));
  } while (bytes < totalBytes);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
mov    $0x0,%al
call   1080 <rand@plt>
mov    %eax,-0xc(%rbp)
mov    $0x0,%al
call   1080 <rand@plt>
mov    $0xf4240,%ecx
cltd
idiv   %ecx
add    $0x0,%edx
mov    %edx,-0x14(%rbp)
cvtsi2sdl -0xc(%rbp),%xmm0
mov    -0x14(%rbp),%esi
lea    0xe53(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
mov    $0x1,%edi
call   1070 <sleep@plt>
mov    $0x0,%al
call   1080 <rand@plt>
mov    $0xc350,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
add    $0xc350,%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jle    11f9 <main+0x99>
mov    -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
cvtsi2sdl -0x10(%rbp),%xmm0
cvtsi2sdl -0x14(%rbp),%xmm1
call   1060 <remainingTime@plt>
lea    0xe1c(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jl     11c1 <main+0x61>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
xor    %eax,%eax
call   1080 <rand@plt>
mov    %eax,%r14d
xor    %eax,%eax
call   1080 <rand@plt>
movslq %eax,%r12
imul   $0x431bde83,%r12,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x32,%rax
add    %ecx,%eax
imul   $0xf4240,%eax,%eax
sub    %eax,%r12d
cvtsi2sd %r14d,%xmm0
lea    0xe4a(%rip),%rdi
mov    %r12d,%esi
mov    $0x1,%al
call   1030 <printf@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %r12d,%xmm0
movsd  %xmm0,(%rsp)
mov    %r14d,%ebp
add    $0x1,%ebp
lea    0xe60(%rip),%r15
xor    %r13d,%r13d
jmp    1209 <main+0xa9>
nop
xorps  %xmm0,%xmm0
cvtsi2sd %r13d,%xmm0
mov    %ebp,%edi
mov    %r14d,%esi
movsd  (%rsp),%xmm1
call   1060 <remainingTime@plt>
mov    %r15,%rdi
mov    $0x1,%al
call   1030 <printf@plt>
add    $0x1,%ebp
cmp    %ebx,%r12d
jle    124f <main+0xef>
mov    $0x1,%edi
call   1070 <sleep@plt>
xor    %eax,%eax
call   1080 <rand@plt>
cltq
imul   $0x14f8b589,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x2c,%rcx
add    %edx,%ecx
imul   $0xc350,%ecx,%ecx
sub    %ecx,%eax
lea    (%rax,%r13,1),%ebx
add    $0xc350,%ebx
mov    %r12d,%r13d
cmp    %r12d,%ebx
jg     11e0 <main+0x80>
mov    %ebx,%r13d
jmp    11e0 <main+0x80>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [58 x i8] c"startTime == %d, totalBytes == %d\0A(Press Ctrl-C to exit)\0A\00"
@.str.1 = [29 x i8] c"remainingTime: %.2f seconds\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 @time(i32* null)
%7 = call i32 @srand(i32 %6)
%8 = call i32 (...) @rand()
store i32 %8, i32* %3
%9 = call i32 (...) @rand()
%10 = srem i32 %9, 1000000
%11 = add nsw i32 0, %10
store i32 %11, i32* %5
%12 = load i32, i32* %3
%13 = sitofp i32 %12 to double
%14 = load i32, i32* %5
%15 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0), double %13, i32 %14)
%16 = load i32, i32* %3
store i32 %16, i32* %2
store i32 0, i32* %4
br label %17
17: ; preds = %40, %0
%18 = call i32 @sleep(i32 1)
%19 = call i32 (...) @rand()
%20 = srem i32 %19, 50000
%21 = add nsw i32 50000, %20
%22 = load i32, i32* %4
%23 = add nsw i32 %22, %21
store i32 %23, i32* %4
%24 = load i32, i32* %4
%25 = load i32, i32* %5
%26 = icmp sgt i32 %24, %25
br i1 %26, label %27, label %29
27: ; preds = %17
%28 = load i32, i32* %5
store i32 %28, i32* %4
br label %29
29: ; preds = %27, %17
%30 = load i32, i32* %2
%31 = add nsw i32 %30, 1
store i32 %31, i32* %2
%32 = load i32, i32* %2
%33 = load i32, i32* %3
%34 = load i32, i32* %4
%35 = sitofp i32 %34 to double
%36 = load i32, i32* %5
%37 = sitofp i32 %36 to double
%38 = call double @remainingTime(i32 %32, i32 %33, double %35, double %37)
%39 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), double %38)
br label %40
40: ; preds = %29
%41 = load i32, i32* %4
%42 = load i32, i32* %5
%43 = icmp slt i32 %41, %42
br i1 %43, label %17, label %44
44: ; preds = %40
ret i32 0
}

LLVM IR (-O2):
@.str = [58 x i8] c"startTime == %d, totalBytes == %d\0A(Press Ctrl-C to exit)\0A\00"
@.str.1 = [29 x i8] c"remainingTime: %.2f seconds\0A\00"
define i32 @main() {
%1 = tail call i32 @time(i32* null)
%2 = tail call i32 @srand(i32 %1)
%3 = tail call i32 (...) @rand()
%4 = tail call i32 (...) @rand()
%5 = srem i32 %4, 1000000
%6 = sitofp i32 %3 to double
%7 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0), double %6, i32 %5)
%8 = sitofp i32 %5 to double
br label %9
9: ; preds = %9, %0
%10 = phi i32 [ 0, %0 ], [ %18, %9 ]
%11 = phi i32 [ %3, %0 ], [ %19, %9 ]
%12 = tail call i32 @sleep(i32 1)
%13 = tail call i32 (...) @rand()
%14 = srem i32 %13, 50000
%15 = add nsw i32 %10, 50000
%16 = add i32 %15, %14
%17 = icmp sgt i32 %16, %5
%18 = select i1 %17, i32 %5, i32 %16
%19 = add nsw i32 %11, 1
%20 = sitofp i32 %18 to double
%21 = tail call double @remainingTime(i32 %19, i32 %3, double %20, double %8)
%22 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), double %21)
%23 = icmp sgt i32 %5, %16
br i1 %23, label %9, label %24
24: ; preds = %9
ret i32 0
}