#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 /*<<< orphan*/ stamp_buf;
typedef int /*<<< orphan*/ spaces;
typedef float int64_t;

/* Variables and functions */
int /*<<< orphan*/ _append_buf(char const *, int);
float _get_time_us();
size_t snprintf(char *, int, char *, float, float);
char *strchr(char const *, char);
const char *_append_with_stamp(const char *buf, int stamp) {
  static const char spaces[] = "                 ";
  static int64_t t_last;
  static int64_t t_start = 0;
  int64_t t_now;
  char stamp_buf[32];
  const char *be;
  const char *bb = buf;
  size_t len;
  while ((be = strchr(bb, '\n'))) {
    if (stamp++ == 0) {
      t_now = _get_time_us();
      if (!t_start)
        t_start = t_last = t_now;
      len =
          snprintf(stamp_buf, sizeof(stamp_buf), "%8.3f%8.4f ",
                   (t_now - t_start) / 1000000.f, (t_now - t_last) / 1000000.f);
      _append_buf(stamp_buf,
                  (len < (sizeof(spaces) - 1)) ? len : (sizeof(spaces) - 1));
      t_last = t_now;
    }
    _append_buf(bb, be + 1 - bb);
    bb = be + 1;
    if (stamp > 0 && bb[0])
      _append_buf(spaces, sizeof(spaces) - 1);
  }
  return bb;
}


x86 assembly (clang, -O0):
<_append_with_stamp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
je     12ad <_append_with_stamp+0x16d>
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0xc(%rbp)
cmp    $0x0,%eax
jne    1257 <_append_with_stamp+0x117>
mov    $0x0,%al
call   1030 <_get_time_us@plt>
movss  %xmm0,-0x10(%rbp)
movss  0x2ead(%rip),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    11c2 <_append_with_stamp+0x82>
jp     11c2 <_append_with_stamp+0x82>
movss  -0x10(%rbp),%xmm0
movss  %xmm0,0x2e8a(%rip)
movss  %xmm0,0x2e86(%rip)
lea    -0x30(%rbp),%rdi
movss  -0x10(%rbp),%xmm0
subss  0x2e75(%rip),%xmm0
movss  0xe25(%rip),%xmm1
divss  %xmm1,%xmm0
movss  -0x10(%rbp),%xmm1
subss  0x2e58(%rip),%xmm1
movss  0xe0c(%rip),%xmm2
divss  %xmm2,%xmm1
mov    $0x20,%esi
lea    0xe1e(%rip),%rdx
call   1050 <snprintf@plt>
mov    %rax,-0x48(%rbp)
lea    -0x30(%rbp),%rax
mov    %rax,-0x50(%rbp)
cmpq   $0x11,-0x48(%rbp)
jae    122d <_append_with_stamp+0xed>
mov    -0x48(%rbp),%rax
mov    %rax,-0x58(%rbp)
jmp    123b <_append_with_stamp+0xfb>
mov    $0x11,%eax
mov    %rax,-0x58(%rbp)
jmp    123b <_append_with_stamp+0xfb>
mov    -0x50(%rbp),%rdi
mov    -0x58(%rbp),%rax
mov    %eax,%esi
call   1060 <_append_buf@plt>
movss  -0x10(%rbp),%xmm0
movss  %xmm0,0x2ded(%rip)
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    -0x40(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%esi
call   1060 <_append_buf@plt>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
cmpl   $0x0,-0xc(%rbp)
jle    12a8 <_append_with_stamp+0x168>
mov    -0x40(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     12a8 <_append_with_stamp+0x168>
lea    0xd72(%rip),%rdi
mov    $0x11,%esi
call   1060 <_append_buf@plt>
jmp    1157 <_append_with_stamp+0x17>
mov    -0x40(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_append_with_stamp>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %esi,%ebx
mov    %rdi,%r14
mov    $0xa,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1292 <_append_with_stamp+0x152>
mov    %rax,%rbp
lea    0x10(%rsp),%r12
mov    $0x11,%r15d
lea    0xe95(%rip),%r13
jmp    119c <_append_with_stamp+0x5c>
nopl   (%rax)
mov    %r14,%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
mov    %rax,%rbp
add    $0x1,%ebx
test   %rax,%rax
je     1292 <_append_with_stamp+0x152>
test   %ebx,%ebx
je     11d0 <_append_with_stamp+0x90>
add    $0x1,%rbp
mov    %ebp,%esi
sub    %r14d,%esi
mov    %r14,%rdi
call   1060 <_append_buf@plt>
mov    %rbp,%r14
test   %ebx,%ebx
js     1180 <_append_with_stamp+0x40>
cmpb   $0x0,(%r14)
jne    1280 <_append_with_stamp+0x140>
jmp    1180 <_append_with_stamp+0x40>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
call   1030 <_get_time_us@plt>
movss  0x2e69(%rip),%xmm1
ucomiss 0xe1e(%rip),%xmm1
jne    11ea <_append_with_stamp+0xaa>
jnp    11f4 <_append_with_stamp+0xb4>
movss  0x2e52(%rip),%xmm2
jmp    120a <_append_with_stamp+0xca>
movss  %xmm0,0x2e48(%rip)
movss  %xmm0,0x2e44(%rip)
movaps %xmm0,%xmm2
movaps %xmm0,%xmm1
movaps %xmm0,%xmm4
movss  %xmm0,0xc(%rsp)
subss  %xmm1,%xmm0
movss  0xde1(%rip),%xmm3
divss  %xmm3,%xmm0
movaps %xmm4,%xmm1
subss  %xmm2,%xmm1
divss  %xmm3,%xmm1
mov    %r12,%rdi
mov    $0x20,%esi
lea    0xde5(%rip),%rdx
call   1050 <snprintf@plt>
cmp    $0x11,%rax
cmovae %r15d,%eax
mov    %r12,%rdi
mov    %eax,%esi
call   1060 <_append_buf@plt>
movss  0xc(%rsp),%xmm0
movss  %xmm0,0x2de2(%rip)
add    $0x1,%rbp
mov    %ebp,%esi
sub    %r14d,%esi
mov    %r14,%rdi
call   1060 <_append_buf@plt>
mov    %rbp,%r14
cmpb   $0x0,(%r14)
je     1180 <_append_with_stamp+0x40>
mov    %r13,%rdi
mov    $0x11,%esi
call   1060 <_append_buf@plt>
jmp    1180 <_append_with_stamp+0x40>
mov    %r14,%rax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@_append_with_stamp.spaces = internal constant [18 x i8] c" \00"
@_append_with_stamp.t_last = internal global float 0.000000e+00
@_append_with_stamp.t_start = internal global float 0.000000e+00
@.str = [12 x i8] c"%8.3f%8.4f \00"
define i8* @_append_with_stamp(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca float
%6 = alloca [32 x i8]
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
store i8* %0, i8** %3
store i32 %1, i32* %4
%10 = load i8*, i8** %3
store i8* %10, i8** %8
br label %11
11: ; preds = %69, %2
%12 = load i8*, i8** %8
%13 = call i8* @strchr(i8* %12, i8 signext 10)
store i8* %13, i8** %7
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %70
15: ; preds = %11
%16 = load i32, i32* %4
%17 = add nsw i32 %16, 1
store i32 %17, i32* %4
%18 = icmp eq i32 %16, 0
br i1 %18, label %19, label %47
19: ; preds = %15
%20 = call float (...) @_get_time_us()
store float %20, float* %5
%21 = load float, float* @_append_with_stamp.t_start
%22 = fcmp une float %21, 0.000000e+00
br i1 %22, label %25, label %23
23: ; preds = %19
%24 = load float, float* %5
store float %24, float* @_append_with_stamp.t_last
store float %24, float* @_append_with_stamp.t_start
br label %25
25: ; preds = %23, %19
%26 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%27 = load float, float* %5
%28 = load float, float* @_append_with_stamp.t_start
%29 = fsub float %27, %28
%30 = fdiv float %29, 1.000000e+06
%31 = load float, float* %5
%32 = load float, float* @_append_with_stamp.t_last
%33 = fsub float %31, %32
%34 = fdiv float %33, 1.000000e+06
%35 = call i64 @snprintf(i8* %26, i32 32, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), float %30, float %34)
store i64 %35, i64* %9
%36 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%37 = load i64, i64* %9
%38 = icmp ult i64 %37, 17
br i1 %38, label %39, label %41
39: ; preds = %25
%40 = load i64, i64* %9
br label %42
41: ; preds = %25
br label %42
42: ; preds = %41, %39
%43 = phi i64 [ %40, %39 ], [ 17, %41 ]
%44 = trunc i64 %43 to i32
%45 = call i32 @_append_buf(i8* %36, i32 %44)
%46 = load float, float* %5
store float %46, float* @_append_with_stamp.t_last
br label %47
47: ; preds = %42, %15
%48 = load i8*, i8** %8
%49 = load i8*, i8** %7
%50 = getelementptr inbounds i8, i8* %49, i64 1
%51 = load i8*, i8** %8
%52 = ptrtoint i8* %50 to i64
%53 = ptrtoint i8* %51 to i64
%54 = sub i64 %52, %53
%55 = trunc i64 %54 to i32
%56 = call i32 @_append_buf(i8* %48, i32 %55)
%57 = load i8*, i8** %7
%58 = getelementptr inbounds i8, i8* %57, i64 1
store i8* %58, i8** %8
%59 = load i32, i32* %4
%60 = icmp sgt i32 %59, 0
br i1 %60, label %61, label %69
61: ; preds = %47
%62 = load i8*, i8** %8
%63 = getelementptr inbounds i8, i8* %62, i64 0
%64 = load i8, i8* %63
%65 = sext i8 %64 to i32
%66 = icmp ne i32 %65, 0
br i1 %66, label %67, label %69
67: ; preds = %61
%68 = call i32 @_append_buf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @_append_with_stamp.spaces, i64 0, i64 0), i32 17)
br label %69
69: ; preds = %67, %61, %47
br label %11
70: ; preds = %11
%71 = load i8*, i8** %8
ret i8* %71
}

LLVM IR (-O2):
@_append_with_stamp.spaces = internal constant [18 x i8] c" \00"
@_append_with_stamp.t_last = internal unnamed_addr global float 0.000000e+00
@_append_with_stamp.t_start = internal unnamed_addr global float 0.000000e+00
@.str = [12 x i8] c"%8.3f%8.4f \00"
define i8* @_append_with_stamp(i8* %0, i32 %1) {
%3 = alloca [32 x i8]
%4 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%5 = call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 10)
%6 = icmp eq i8* %5, null
br i1 %6, label %56, label %7
7: ; preds = %2, %52
%8 = phi i8* [ %54, %52 ], [ %5, %2 ]
%9 = phi i32 [ %11, %52 ], [ %1, %2 ]
%10 = phi i8* [ %53, %52 ], [ %0, %2 ]
%11 = add nsw i32 %9, 1
%12 = icmp eq i32 %9, 0
br i1 %12, label %13, label %38
13: ; preds = %7
%14 = call float (...) @_get_time_us()
%15 = load float, float* @_append_with_stamp.t_start
%16 = fcmp une float %15, 0.000000e+00
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = load float, float* @_append_with_stamp.t_last
br label %20
19: ; preds = %13
store float %14, float* @_append_with_stamp.t_last
store float %14, float* @_append_with_stamp.t_start
br label %20
20: ; preds = %17, %19
%21 = phi float [ %18, %17 ], [ %14, %19 ]
%22 = phi float [ %15, %17 ], [ %14, %19 ]
%23 = fsub float %14, %22
%24 = fdiv float %23, 1.000000e+06
%25 = fsub float %14, %21
%26 = fdiv float %25, 1.000000e+06
%27 = call i64 @snprintf(i8* %4, i32 32, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), float %24, float %26)
%28 = icmp ult i64 %27, 17
%29 = select i1 %28, i64 %27, i64 17
%30 = trunc i64 %29 to i32
%31 = call i32 @_append_buf(i8* %4, i32 %30)
store float %14, float* @_append_with_stamp.t_last
%32 = getelementptr inbounds i8, i8* %8, i64 1
%33 = ptrtoint i8* %32 to i64
%34 = ptrtoint i8* %10 to i64
%35 = sub i64 %33, %34
%36 = trunc i64 %35 to i32
%37 = call i32 @_append_buf(i8* %10, i32 %36)
br label %46
38: ; preds = %7
%39 = getelementptr inbounds i8, i8* %8, i64 1
%40 = ptrtoint i8* %39 to i64
%41 = ptrtoint i8* %10 to i64
%42 = sub i64 %40, %41
%43 = trunc i64 %42 to i32
%44 = call i32 @_append_buf(i8* %10, i32 %43)
%45 = icmp sgt i32 %9, -1
br i1 %45, label %46, label %52
46: ; preds = %20, %38
%47 = phi i8* [ %32, %20 ], [ %39, %38 ]
%48 = load i8, i8* %47
%49 = icmp eq i8 %48, 0
br i1 %49, label %52, label %50
50: ; preds = %46
%51 = call i32 @_append_buf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @_append_with_stamp.spaces, i64 0, i64 0), i32 17)
br label %52
52: ; preds = %50, %46, %38
%53 = phi i8* [ %47, %50 ], [ %47, %46 ], [ %39, %38 ]
%54 = call i8* @strchr(i8* dereferenceable(1) %53, i8 signext 10)
%55 = icmp eq i8* %54, null
br i1 %55, label %56, label %7
56: ; preds = %52, %2
%57 = phi i8* [ %0, %2 ], [ %53, %52 ]
ret i8* %57
}