#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*/ FILE;

/* Variables and functions */
int EOF;
int errno;
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
char *strerror(int);
void show_timestamp(FILE *f, int c) {
  unsigned counter = 0;
  char *label = "";
  bool delayed = false;
  printf("TIMESTAMP - ");
  if (!(c & 0x80)) {
    switch (c) {
    case 0:
    case 0x70:
      printf("ERROR - %#02x\n", c);
      break;
    default:
      counter = c >> 4;
      goto done;
    }
    return;
  }
  switch (c) {
  default:
    label = ", reserved control\n";
    break;
  case 0xc:
    break;
  case 0xd:
    label = ", timestamp delayed";
    delayed = true;
    break;
  case 0xe:
    label = ", packet delayed";
    delayed = true;
    break;
  case 0xf:
    label = ", packet and timetamp delayed";
    delayed = true;
    break;
  }
  c = fgetc(f);
  if (c == EOF)
    goto err;
  counter = c & 0x7f;
  if (!(c & 0x80))
    goto done;
  c = fgetc(f);
  if (c == EOF)
    goto err;
  counter |= (c & 0x7f) << 7;
  if (!(c & 0x80))
    goto done;
  c = fgetc(f);
  if (c == EOF)
    goto err;
  counter |= (c & 0x7f) << 14;
  if (!(c & 0x80))
    goto done;
  c = fgetc(f);
  if (c == EOF)
    goto err;
  counter |= (c & 0x7f) << 21;
done:
  printf("+%u%s\n", counter, label);
  return;
err:
  printf("(ERROR %d - %s) ", errno, strerror(errno));
  goto done;
}


x86 assembly (clang, -O0):
<show_timestamp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
lea    0xef2(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
and    $0x80,%eax
cmp    $0x0,%eax
jne    11c4 <show_timestamp+0x94>
mov    -0xc(%rbp),%eax
mov    %eax,-0x20(%rbp)
test   %eax,%eax
je     119b <show_timestamp+0x6b>
jmp    118a <show_timestamp+0x5a>
mov    -0x20(%rbp),%eax
sub    $0x70,%eax
jne    11b1 <show_timestamp+0x81>
jmp    119b <show_timestamp+0x6b>
mov    -0xc(%rbp),%esi
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11bf <show_timestamp+0x8f>
mov    -0xc(%rbp),%eax
sar    $0x4,%eax
mov    %eax,-0x10(%rbp)
jmp    1346 <show_timestamp+0x216>
jmp    1393 <show_timestamp+0x263>
mov    -0xc(%rbp),%eax
add    $0xfffffff4,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x3,%eax
ja     11ed <show_timestamp+0xbd>
mov    -0x28(%rbp),%rax
lea    0xe1c(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xe38(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    1242 <show_timestamp+0x112>
jmp    1242 <show_timestamp+0x112>
lea    0xe37(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
jmp    1242 <show_timestamp+0x112>
lea    0xe34(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
jmp    1242 <show_timestamp+0x112>
lea    0xe2e(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    0x2d90(%rip),%rcx
cmp    (%rcx),%eax
jne    1265 <show_timestamp+0x135>
jmp    1360 <show_timestamp+0x230>
mov    -0xc(%rbp),%eax
and    $0x7f,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
and    $0x80,%eax
cmp    $0x0,%eax
jne    1284 <show_timestamp+0x154>
jmp    1346 <show_timestamp+0x216>
mov    -0x8(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    0x2d4e(%rip),%rcx
cmp    (%rcx),%eax
jne    12a7 <show_timestamp+0x177>
jmp    1360 <show_timestamp+0x230>
mov    -0xc(%rbp),%eax
and    $0x7f,%eax
shl    $0x7,%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
and    $0x80,%eax
cmp    $0x0,%eax
jne    12cc <show_timestamp+0x19c>
jmp    1346 <show_timestamp+0x216>
mov    -0x8(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    0x2d06(%rip),%rcx
cmp    (%rcx),%eax
jne    12ef <show_timestamp+0x1bf>
jmp    1360 <show_timestamp+0x230>
mov    -0xc(%rbp),%eax
and    $0x7f,%eax
shl    $0xe,%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
and    $0x80,%eax
cmp    $0x0,%eax
jne    1314 <show_timestamp+0x1e4>
jmp    1346 <show_timestamp+0x216>
mov    -0x8(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    0x2cbe(%rip),%rcx
cmp    (%rcx),%eax
jne    1337 <show_timestamp+0x207>
jmp    1360 <show_timestamp+0x230>
mov    -0xc(%rbp),%eax
and    $0x7f,%eax
shl    $0x15,%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%esi
mov    -0x18(%rbp),%rdx
lea    0xd2f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1393 <show_timestamp+0x263>
mov    0x2c71(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2c65(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x2c(%rbp),%esi
mov    %rax,%rdx
lea    0xd03(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1346 <show_timestamp+0x216>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<show_timestamp>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%ebx
mov    %rdi,%r15
lea    0xebc(%rip),%rdi
xor    %ebp,%ebp
xor    %eax,%eax
call   1030 <printf@plt>
test   $0x80,%bl
jne    1177 <show_timestamp+0x47>
cmp    $0x70,%ebx
je     115f <show_timestamp+0x2f>
test   %ebx,%ebx
jne    1216 <show_timestamp+0xe6>
lea    0xea7(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <printf@plt>
mov    %r15,%rdi
call   1040 <fgetc@plt>
mov    0x2e62(%rip),%r12
cmp    (%r12),%eax
je     11e8 <show_timestamp+0xb8>
mov    %eax,%ebx
and    $0x7f,%ebx
lea    0xe84(%rip),%r14
test   $0x80,%al
je     1220 <show_timestamp+0xf0>
mov    %r15,%rdi
call   1040 <fgetc@plt>
cmp    (%r12),%eax
je     11e6 <show_timestamp+0xb6>
mov    %eax,%ecx
and    $0x7f,%ecx
shl    $0x7,%ecx
or     %ecx,%ebx
test   $0x80,%al
je     1220 <show_timestamp+0xf0>
mov    %r15,%rdi
call   1040 <fgetc@plt>
cmp    (%r12),%eax
je     11e6 <show_timestamp+0xb6>
mov    %eax,%ecx
and    $0x7f,%ecx
shl    $0xe,%ecx
or     %ecx,%ebx
test   $0x80,%al
je     1220 <show_timestamp+0xf0>
mov    %r15,%rdi
call   1040 <fgetc@plt>
cmp    (%r12),%eax
jne    123b <show_timestamp+0x10b>
mov    %ebx,%ebp
mov    0x2de9(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   1050 <strerror@plt>
lea    0xe38(%rip),%rdi
mov    %ebx,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe0a(%rip),%r14
mov    %ebp,%ebx
jmp    1220 <show_timestamp+0xf0>
sar    $0x4,%ebx
lea    0xe0f(%rip),%r14
lea    0xe09(%rip),%rdi
mov    %ebx,%esi
mov    %r14,%rdx
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <printf@plt>
and    $0x7f,%eax
shl    $0x15,%eax
or     %eax,%ebx
jmp    1220 <show_timestamp+0xf0>

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [13 x i8] c"TIMESTAMP - \00"
@.str.2 = [15 x i8] c"ERROR - %x\0A\00"
@.str.3 = [20 x i8] c", reserved control\0A\00"
@.str.4 = [20 x i8] c", timestamp delayed\00"
@.str.5 = [17 x i8] c", packet delayed\00"
@.str.6 = [30 x i8] c", packet and timetamp delayed\00"
@EOF = global i32 0
@.str.7 = [7 x i8] c"+%u%s\0A\00"
@.str.8 = [17 x i8] c"(ERROR %d - %s) \00"
@errno = global i32 0
define void @show_timestamp(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
store i32 0, i32* %5
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %6
store i32 0, i32* %7
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%9 = load i32, i32* %4
%10 = and i32 %9, 128
%11 = icmp ne i32 %10, 0
br i1 %11, label %21, label %12
12: ; preds = %2
%13 = load i32, i32* %4
switch i32 %13, label %17 [
i32 0, label %14
i32 112, label %14
]
14: ; preds = %12, %12
%15 = load i32, i32* %4
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %15)
br label %20
17: ; preds = %12
%18 = load i32, i32* %4
%19 = ashr i32 %18, 4
store i32 %19, i32* %5
br label %89
20: ; preds = %14
br label %98
21: ; preds = %2
%22 = load i32, i32* %4
switch i32 %22, label %23 [
i32 12, label %24
i32 13, label %25
i32 14, label %26
i32 15, label %27
]
23: ; preds = %21
store i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8** %6
br label %28
24: ; preds = %21
br label %28
25: ; preds = %21
store i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8** %6
store i32 1, i32* %7
br label %28
26: ; preds = %21
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i8** %6
store i32 1, i32* %7
br label %28
27: ; preds = %21
store i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0), i8** %6
store i32 1, i32* %7
br label %28
28: ; preds = %27, %26, %25, %24, %23
%29 = load i32*, i32** %3
%30 = call i32 @fgetc(i32* %29)
store i32 %30, i32* %4
%31 = load i32, i32* %4
%32 = load i32, i32* @EOF
%33 = icmp eq i32 %31, %32
br i1 %33, label %34, label %35
34: ; preds = %28
br label %93
35: ; preds = %28
%36 = load i32, i32* %4
%37 = and i32 %36, 127
store i32 %37, i32* %5
%38 = load i32, i32* %4
%39 = and i32 %38, 128
%40 = icmp ne i32 %39, 0
br i1 %40, label %42, label %41
41: ; preds = %35
br label %89
42: ; preds = %35
%43 = load i32*, i32** %3
%44 = call i32 @fgetc(i32* %43)
store i32 %44, i32* %4
%45 = load i32, i32* %4
%46 = load i32, i32* @EOF
%47 = icmp eq i32 %45, %46
br i1 %47, label %48, label %49
48: ; preds = %42
br label %93
49: ; preds = %42
%50 = load i32, i32* %4
%51 = and i32 %50, 127
%52 = shl i32 %51, 7
%53 = load i32, i32* %5
%54 = or i32 %53, %52
store i32 %54, i32* %5
%55 = load i32, i32* %4
%56 = and i32 %55, 128
%57 = icmp ne i32 %56, 0
br i1 %57, label %59, label %58
58: ; preds = %49
br label %89
59: ; preds = %49
%60 = load i32*, i32** %3
%61 = call i32 @fgetc(i32* %60)
store i32 %61, i32* %4
%62 = load i32, i32* %4
%63 = load i32, i32* @EOF
%64 = icmp eq i32 %62, %63
br i1 %64, label %65, label %66
65: ; preds = %59
br label %93
66: ; preds = %59
%67 = load i32, i32* %4
%68 = and i32 %67, 127
%69 = shl i32 %68, 14
%70 = load i32, i32* %5
%71 = or i32 %70, %69
store i32 %71, i32* %5
%72 = load i32, i32* %4
%73 = and i32 %72, 128
%74 = icmp ne i32 %73, 0
br i1 %74, label %76, label %75
75: ; preds = %66
br label %89
76: ; preds = %66
%77 = load i32*, i32** %3
%78 = call i32 @fgetc(i32* %77)
store i32 %78, i32* %4
%79 = load i32, i32* %4
%80 = load i32, i32* @EOF
%81 = icmp eq i32 %79, %80
br i1 %81, label %82, label %83
82: ; preds = %76
br label %93
83: ; preds = %76
%84 = load i32, i32* %4
%85 = and i32 %84, 127
%86 = shl i32 %85, 21
%87 = load i32, i32* %5
%88 = or i32 %87, %86
store i32 %88, i32* %5
br label %89
89: ; preds = %93, %83, %75, %58, %41, %17
%90 = load i32, i32* %5
%91 = load i8*, i8** %6
%92 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i32 %90, i8* %91)
br label %98
93: ; preds = %82, %65, %48, %34
%94 = load i32, i32* @errno
%95 = load i32, i32* @errno
%96 = call i8* @strerror(i32 %95)
%97 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0), i32 %94, i8* %96)
br label %89
98: ; preds = %89, %20
ret void
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [13 x i8] c"TIMESTAMP - \00"
@.str.2 = [15 x i8] c"ERROR - %x\0A\00"
@.str.3 = [20 x i8] c", reserved control\0A\00"
@EOF = global i32 0
@.str.7 = [7 x i8] c"+%u%s\0A\00"
@.str.8 = [17 x i8] c"(ERROR %d - %s) \00"
@errno = global i32 0
define void @show_timestamp(i32* nocapture %0, i32 %1) {
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%4 = and i32 %1, 128
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %11
6: ; preds = %2
switch i32 %1, label %9 [
i32 0, label %7
i32 112, label %7
]
7: ; preds = %6, %6
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %1)
br label %56
9: ; preds = %6
%10 = ashr i32 %1, 4
br label %47
11: ; preds = %2
%12 = tail call i32 @fgetc(i32* %0)
%13 = load i32, i32* @EOF
%14 = icmp eq i32 %12, %13
br i1 %14, label %51, label %15
15: ; preds = %11
%16 = and i32 %12, 127
%17 = and i32 %12, 128
%18 = icmp eq i32 %17, 0
br i1 %18, label %47, label %19
19: ; preds = %15
%20 = tail call i32 @fgetc(i32* %0)
%21 = load i32, i32* @EOF
%22 = icmp eq i32 %20, %21
br i1 %22, label %51, label %23
23: ; preds = %19
%24 = shl i32 %20, 7
%25 = and i32 %24, 16256
%26 = or i32 %25, %16
%27 = and i32 %20, 128
%28 = icmp eq i32 %27, 0
br i1 %28, label %47, label %29
29: ; preds = %23
%30 = tail call i32 @fgetc(i32* %0)
%31 = load i32, i32* @EOF
%32 = icmp eq i32 %30, %31
br i1 %32, label %51, label %33
33: ; preds = %29
%34 = shl i32 %30, 14
%35 = and i32 %34, 2080768
%36 = or i32 %35, %26
%37 = and i32 %30, 128
%38 = icmp eq i32 %37, 0
br i1 %38, label %47, label %39
39: ; preds = %33
%40 = tail call i32 @fgetc(i32* %0)
%41 = load i32, i32* @EOF
%42 = icmp eq i32 %40, %41
br i1 %42, label %51, label %43
43: ; preds = %39
%44 = shl i32 %40, 21
%45 = and i32 %44, 266338304
%46 = or i32 %45, %36
br label %47
47: ; preds = %33, %23, %15, %51, %43, %9
%48 = phi i32 [ %52, %51 ], [ %46, %43 ], [ %36, %33 ], [ %26, %23 ], [ %16, %15 ], [ %10, %9 ]
%49 = phi i8* [ getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), %51 ], [ getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), %43 ], [ getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), %33 ], [ getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), %23 ], [ getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), %15 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %9 ]
%50 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i32 %48, i8* %49)
br label %56
51: ; preds = %39, %29, %19, %11
%52 = phi i32 [ 0, %11 ], [ %16, %19 ], [ %26, %29 ], [ %36, %39 ]
%53 = load i32, i32* @errno
%54 = tail call i8* @strerror(i32 %53)
%55 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0), i32 %53, i8* %54)
br label %47
56: ; preds = %47, %7
ret void
}