#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 */
struct timeval {
  int tv_sec;
  int tv_usec;
};

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
scalar_t__ fgets(char *, int, int /*<<< orphan*/);
double floor(double);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ fwrite(char *, int /*<<< orphan*/, int, int /*<<< orphan*/);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ select(int /*<<< orphan*/, int /*<<< orphan*/ *,
                          int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                          struct timeval *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
char *strchr(char *, char);
int /*<<< orphan*/ strlen(char *);
double strtod(char *, int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  char line[10000];
  double delta = 0;
  if (argc != 1) {
    fprintf(stderr,
            "Usage: %s < <vespa.log>\n"
            "Replays a vespa log file with the same timing delta between each "
            "log message.\n"
            "Reprints the log messages without timestamps.\n\n",
            argv[0]);
    return EXIT_FAILURE;
  }
  while (fgets(line, sizeof line, stdin)) {
    struct timeval tv;
    char *s;
    double log_time;
    double now;
    double delay;
    gettimeofday(&tv, NULL);
    now = tv.tv_sec + 1e-6 * tv.tv_usec;
    log_time = strtod(line, NULL);
    if (!delta) {
      delta = now - log_time;
    }
    delay = log_time + delta - now;
    if (delay > 0) {
      tv.tv_sec = floor(delay);
      tv.tv_usec = 1e6 * (delay - floor(delay));
      select(0, NULL, NULL, NULL, &tv);
    }
    s = strchr(line, '\t');
    if (s) {
      s = s + 1;
    } else {
      s = line;
    }
    fwrite(s, strlen(s), 1, stdout);
    fflush(stdout);
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2760,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x2728(%rbp)
ff
cmpl   $0x1,-0x8(%rbp)
je     11fb <main+0x5b>
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe2b(%rip),%rsi
call   1080 <fprintf@plt>
mov    0x2ddf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13ea <main+0x24a>
jmp    1200 <main+0x60>
lea    -0x2720(%rbp),%rdi
mov    0x2dda(%rip),%rax
mov    (%rax),%edx
mov    $0x2710,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     13de <main+0x23e>
lea    -0x2730(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <gettimeofday@plt>
cvtsi2sdl -0x2730(%rbp),%xmm1
ff
cvtsi2sdl -0x272c(%rbp),%xmm0
ff
movsd  0xdb4(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x2748(%rbp)
ff
lea    -0x2720(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <strtod@plt>
movsd  %xmm0,-0x2740(%rbp)
ff
movsd  -0x2728(%rbp),%xmm0
ff
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    12a7 <main+0x107>
jp     12a7 <main+0x107>
movsd  -0x2748(%rbp),%xmm0
ff
subsd  -0x2740(%rbp),%xmm0
ff
movsd  %xmm0,-0x2728(%rbp)
ff
movsd  -0x2740(%rbp),%xmm0
ff
addsd  -0x2728(%rbp),%xmm0
ff
subsd  -0x2748(%rbp),%xmm0
ff
movsd  %xmm0,-0x2750(%rbp)
ff
movsd  -0x2750(%rbp),%xmm0
ff
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    134a <main+0x1aa>
movsd  -0x2750(%rbp),%xmm0
ff
call   10c0 <floor@plt>
cvttsd2si %xmm0,%eax
mov    %eax,-0x2730(%rbp)
movsd  -0x2750(%rbp),%xmm0
ff
movsd  %xmm0,-0x2758(%rbp)
ff
movsd  -0x2750(%rbp),%xmm0
ff
call   10c0 <floor@plt>
movsd  -0x2758(%rbp),%xmm1
ff
subsd  %xmm0,%xmm1
movsd  0xce4(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x272c(%rbp)
xor    %edi,%edi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x2730(%rbp),%r8
mov    %rcx,%rsi
mov    %rcx,%rdx
call   1090 <select@plt>
lea    -0x2720(%rbp),%rdi
mov    $0x9,%esi
call   1050 <strchr@plt>
mov    %rax,-0x2738(%rbp)
cmpq   $0x0,-0x2738(%rbp)
je     1387 <main+0x1e7>
mov    -0x2738(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x2738(%rbp)
jmp    1395 <main+0x1f5>
lea    -0x2720(%rbp),%rax
mov    %rax,-0x2738(%rbp)
mov    -0x2738(%rbp),%rax
mov    %rax,-0x2760(%rbp)
mov    -0x2738(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x2760(%rbp),%rdi
mov    %eax,%esi
mov    0x2c09(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%edx
call   10b0 <fwrite@plt>
mov    0x2bf6(%rip),%rax
mov    (%rax),%edi
call   10a0 <fflush@plt>
jmp    1200 <main+0x60>
mov    0x2bdb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2760,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2758,%rsp
cmp    $0x1,%edi
jne    1327 <main+0x187>
mov    0x2e27(%rip),%r12
mov    (%r12),%edx
lea    0x40(%rsp),%r15
mov    %r15,%rdi
mov    $0x2710,%esi
call   1070 <fgets@plt>
mov    0x2de2(%rip),%r13
test   %rax,%rax
je     1346 <main+0x1a6>
lea    0x8(%rsp),%r14
mov    0x2dd5(%rip),%rbp
xorps  %xmm1,%xmm1
movaps %xmm1,%xmm0
jmp    125c <main+0xbc>
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    $0x9,%esi
call   1050 <strchr@plt>
lea    0x1(%rax),%rbx
test   %rax,%rax
cmove  %r15,%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    0x0(%rbp),%ecx
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x1,%edx
call   10b0 <fwrite@plt>
mov    0x0(%rbp),%edi
call   10a0 <fflush@plt>
mov    (%r12),%edx
mov    %r15,%rdi
mov    $0x2710,%esi
call   1070 <fgets@plt>
movaps 0x20(%rsp),%xmm0
movaps %xmm0,%xmm1
test   %rax,%rax
je     1346 <main+0x1a6>
movaps %xmm0,0x20(%rsp)
movaps %xmm1,0x10(%rsp)
mov    %r14,%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
xorps  %xmm0,%xmm0
cvtsi2sdl 0x8(%rsp),%xmm0
xorps  %xmm1,%xmm1
cvtsi2sdl 0xc(%rsp),%xmm1
mulsd  0xd76(%rip),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x38(%rsp)
mov    %r15,%rdi
xor    %esi,%esi
call   1030 <strtod@plt>
movsd  0x38(%rsp),%xmm5
movapd %xmm5,%xmm3
subsd  %xmm0,%xmm3
xorpd  %xmm2,%xmm2
movapd 0x20(%rsp),%xmm4
cmpneqsd %xmm2,%xmm4
movapd %xmm4,%xmm1
andnpd %xmm3,%xmm1
andpd  0x10(%rsp),%xmm4
orpd   %xmm1,%xmm4
movapd %xmm4,0x20(%rsp)
addsd  %xmm4,%xmm0
subsd  %xmm5,%xmm0
ucomisd %xmm2,%xmm0
jbe    1200 <main+0x60>
movsd  %xmm0,0x10(%rsp)
call   10c0 <floor@plt>
cvttsd2si %xmm0,%eax
mov    %eax,0x8(%rsp)
movsd  0x10(%rsp),%xmm1
subsd  %xmm0,%xmm1
mulsd  0xcfe(%rip),%xmm1
cvttsd2si %xmm1,%eax
mov    %eax,0xc(%rsp)
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %r14,%r8
call   1090 <select@plt>
jmp    1200 <main+0x60>
mov    0x2caa(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xcd6(%rip),%rsi
call   1080 <fprintf@plt>
mov    0x2c8a(%rip),%r13
mov    0x0(%r13),%eax
add    $0x2758,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@stderr = global i32 0
@.str = [150 x i8] c"Usage: %s < <vespa.log>\0AReplays a vespa log file with the same timing delta between each log message.\0AReprints the log messages without timestamps.\0A\0A\00"
@EXIT_FAILURE = global i32 0
@stdin = global i32 0
@stdout = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [10000 x i8]
%7 = alloca double
%8 = alloca %struct.timeval
%9 = alloca i8*
%10 = alloca double
%11 = alloca double
%12 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store double 0.000000e+00, double* %7
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 1
br i1 %14, label %15, label %22
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([150 x i8], [150 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = load i32, i32* @EXIT_FAILURE
store i32 %21, i32* %3
br label %86
22: ; preds = %2
br label %23
23: ; preds = %76, %22
%24 = getelementptr inbounds [10000 x i8], [10000 x i8]* %6, i64 0, i64 0
%25 = load i32, i32* @stdin
%26 = call i64 @fgets(i8* %24, i32 10000, i32 %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %84
28: ; preds = %23
%29 = call i32 @gettimeofday(%struct.timeval* %8, i32* null)
%30 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 0
%31 = load i32, i32* %30
%32 = sitofp i32 %31 to double
%33 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 1
%34 = load i32, i32* %33
%35 = sitofp i32 %34 to double
%36 = call double @llvm.fmuladd.f64(double 0x3EB0C6F7A0B5ED8D, double %35, double %32)
store double %36, double* %11
%37 = getelementptr inbounds [10000 x i8], [10000 x i8]* %6, i64 0, i64 0
%38 = call double @strtod(i8* %37, i32* null)
store double %38, double* %10
%39 = load double, double* %7
%40 = fcmp une double %39, 0.000000e+00
br i1 %40, label %45, label %41
41: ; preds = %28
%42 = load double, double* %11
%43 = load double, double* %10
%44 = fsub double %42, %43
store double %44, double* %7
br label %45
45: ; preds = %41, %28
%46 = load double, double* %10
%47 = load double, double* %7
%48 = fadd double %46, %47
%49 = load double, double* %11
%50 = fsub double %48, %49
store double %50, double* %12
%51 = load double, double* %12
%52 = fcmp ogt double %51, 0.000000e+00
br i1 %52, label %53, label %66
53: ; preds = %45
%54 = load double, double* %12
%55 = call double @llvm.floor.f64(double %54)
%56 = fptosi double %55 to i32
%57 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 0
store i32 %56, i32* %57
%58 = load double, double* %12
%59 = load double, double* %12
%60 = call double @llvm.floor.f64(double %59)
%61 = fsub double %58, %60
%62 = fmul double 1.000000e+06, %61
%63 = fptosi double %62 to i32
%64 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 1
store i32 %63, i32* %64
%65 = call i32 @select(i32 0, i32* null, i32* null, i32* null, %struct.timeval* %8)
br label %66
66: ; preds = %53, %45
%67 = getelementptr inbounds [10000 x i8], [10000 x i8]* %6, i64 0, i64 0
%68 = call i8* @strchr(i8* %67, i8 signext 9)
store i8* %68, i8** %9
%69 = load i8*, i8** %9
%70 = icmp ne i8* %69, null
br i1 %70, label %71, label %74
71: ; preds = %66
%72 = load i8*, i8** %9
%73 = getelementptr inbounds i8, i8* %72, i64 1
store i8* %73, i8** %9
br label %76
74: ; preds = %66
%75 = getelementptr inbounds [10000 x i8], [10000 x i8]* %6, i64 0, i64 0
store i8* %75, i8** %9
br label %76
76: ; preds = %74, %71
%77 = load i8*, i8** %9
%78 = load i8*, i8** %9
%79 = call i32 @strlen(i8* %78)
%80 = load i32, i32* @stdout
%81 = call i32 @fwrite(i8* %77, i32 %79, i32 1, i32 %80)
%82 = load i32, i32* @stdout
%83 = call i32 @fflush(i32 %82)
br label %23
84: ; preds = %23
%85 = load i32, i32* @EXIT_SUCCESS
store i32 %85, i32* %3
br label %86
86: ; preds = %84, %15
%87 = load i32, i32* %3
ret i32 %87
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@stderr = global i32 0
@.str = [150 x i8] c"Usage: %s < <vespa.log>\0AReplays a vespa log file with the same timing delta between each log message.\0AReprints the log messages without timestamps.\0A\0A\00"
@EXIT_FAILURE = global i32 0
@stdin = global i32 0
@stdout = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [10000 x i8]
%4 = alloca %struct.timeval
%5 = getelementptr inbounds [10000 x i8], [10000 x i8]* %3, i64 0, i64 0
%6 = icmp eq i32 %0, 1
br i1 %6, label %7, label %15
7: ; preds = %2
%8 = load i32, i32* @stdin
%9 = call i64 @fgets(i8* %5, i32 10000, i32 %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %54, label %11
11: ; preds = %7
%12 = bitcast %struct.timeval* %4 to i8*
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
br label %19
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = load i8*, i8** %1
%18 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([150 x i8], [150 x i8]* @.str, i64 0, i64 0), i8* %17)
br label %54
19: ; preds = %11, %41
%20 = phi double [ 0.000000e+00, %11 ], [ %30, %41 ]
%21 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%22 = load i32, i32* %13
%23 = sitofp i32 %22 to double
%24 = load i32, i32* %14
%25 = sitofp i32 %24 to double
%26 = call double @llvm.fmuladd.f64(double %25, double 0x3EB0C6F7A0B5ED8D, double %23)
%27 = call double @strtod(i8* nocapture %5, i32* null)
%28 = fcmp une double %20, 0.000000e+00
%29 = fsub double %26, %27
%30 = select i1 %28, double %20, double %29
%31 = fadd double %27, %30
%32 = fsub double %31, %26
%33 = fcmp ogt double %32, 0.000000e+00
br i1 %33, label %34, label %41
34: ; preds = %19
%35 = call double @llvm.floor.f64(double %32)
%36 = fptosi double %35 to i32
store i32 %36, i32* %13
%37 = fsub double %32, %35
%38 = fmul double %37, 1.000000e+06
%39 = fptosi double %38 to i32
store i32 %39, i32* %14
%40 = call i32 @select(i32 0, i32* null, i32* null, i32* null, %struct.timeval* %4)
br label %41
41: ; preds = %34, %19
%42 = call i8* @strchr(i8* %5, i8 signext 9)
%43 = icmp eq i8* %42, null
%44 = getelementptr inbounds i8, i8* %42, i64 1
%45 = select i1 %43, i8* %5, i8* %44
%46 = call i32 @strlen(i8* %45)
%47 = load i32, i32* @stdout
%48 = call i32 @fwrite(i8* %45, i32 %46, i32 1, i32 %47)
%49 = load i32, i32* @stdout
%50 = call i32 @fflush(i32 %49)
%51 = load i32, i32* @stdin
%52 = call i64 @fgets(i8* %5, i32 10000, i32 %51)
%53 = icmp eq i64 %52, 0
br i1 %53, label %54, label %19
54: ; preds = %41, %7, %15
%55 = phi i32* [ @EXIT_FAILURE, %15 ], [ @EXIT_SUCCESS, %7 ], [ @EXIT_SUCCESS, %41 ]
%56 = load i32, i32* %55
ret i32 %56
}