#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 uint64_t;
typedef size_t ssize_t;
typedef int int64_t;
typedef int /*<<< orphan*/ buf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int fread(char *, int, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ memmove(char *, char const *, size_t);
int /*<<< orphan*/ printf(char *, int, int, char, int, char const *);
void parse_inputstream(FILE *input_file) {
  char buf[64 * 1024];
  ssize_t buf_size = sizeof(buf);
  ssize_t buf_offset = 0;
  int read;
  while ((read = fread(buf + buf_offset, 1, buf_size - buf_offset,
                       input_file)) > 0) {
    size_t buf_alive = buf_offset + read;
    const char *bufp = buf;
    while (buf_alive >= 3 * sizeof(uint64_t)) {
      int64_t timestamp_secs = ((int64_t *)bufp)[0];
      uint64_t size = ((uint64_t *)bufp)[1];
      char event_type = (char)((uint64_t *)bufp)[2];
      uint64_t len_of_path = ((uint64_t *)bufp)[3];
      if (3 * sizeof(uint64_t) + len_of_path > buf_alive) {
        buf_offset = buf_alive;
        memmove(buf, bufp, buf_alive);
        break;
      }
      const char *path = bufp + 4 * sizeof(uint64_t);
      bufp += len_of_path + 1 + 4 * sizeof(uint64_t);
      buf_alive -= len_of_path + 1 + 4 * sizeof(uint64_t);
      printf("%i %i %c %u %s\n", timestamp_secs, size, event_type, len_of_path,
             path);
    }
    if (4 * sizeof(uint64_t) >= buf_alive) {
      buf_offset = buf_alive;
      memmove(buf, bufp, buf_alive);
    }
  }
}


x86 assembly (clang, -O0):
<parse_inputstream>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10050,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x10000,-0x10018(%rbp)
movq   $0x0,-0x10020(%rbp)
lea    -0x10010(%rbp),%rdi
add    -0x10020(%rbp),%rdi
mov    -0x10018(%rbp),%rdx
sub    -0x10020(%rbp),%rdx
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %eax,-0x10024(%rbp)
cmp    $0x0,%eax
jle    1309 <parse_inputstream+0x1d9>
mov    -0x10020(%rbp),%rax
movslq -0x10024(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x10030(%rbp)
lea    -0x10010(%rbp),%rax
mov    %rax,-0x10038(%rbp)
cmpq   $0xc,-0x10030(%rbp)
0c
jb     12ca <parse_inputstream+0x19a>
mov    -0x10038(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x1003c(%rbp)
mov    -0x10038(%rbp),%rax
mov    0x4(%rax),%eax
mov    %eax,-0x10040(%rbp)
mov    -0x10038(%rbp),%rax
mov    0x8(%rax),%eax
mov    %al,-0x10041(%rbp)
mov    -0x10038(%rbp),%rax
mov    0xc(%rax),%eax
mov    %eax,-0x10048(%rbp)
movslq -0x10048(%rbp),%rax
add    $0xc,%rax
cmp    -0x10030(%rbp),%rax
jbe    1246 <parse_inputstream+0x116>
mov    -0x10030(%rbp),%rax
mov    %rax,-0x10020(%rbp)
lea    -0x10010(%rbp),%rdi
mov    -0x10038(%rbp),%rsi
mov    -0x10030(%rbp),%rdx
call   1050 <memmove@plt>
jmp    12ca <parse_inputstream+0x19a>
mov    -0x10038(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x10050(%rbp)
mov    -0x10048(%rbp),%eax
add    $0x1,%eax
cltq
add    $0x10,%rax
add    -0x10038(%rbp),%rax
mov    %rax,-0x10038(%rbp)
mov    -0x10048(%rbp),%eax
add    $0x1,%eax
movslq %eax,%rcx
add    $0x10,%rcx
mov    -0x10030(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x10030(%rbp)
mov    -0x1003c(%rbp),%esi
mov    -0x10040(%rbp),%edx
mov    -0x10041(%rbp),%al
mov    -0x10048(%rbp),%r8d
mov    -0x10050(%rbp),%r9
lea    0xd43(%rip),%rdi
movsbl %al,%ecx
call   1040 <printf@plt>
jmp    11b4 <parse_inputstream+0x84>
mov    $0x10,%eax
cmp    -0x10030(%rbp),%rax
jb     1304 <parse_inputstream+0x1d4>
mov    -0x10030(%rbp),%rax
mov    %rax,-0x10020(%rbp)
lea    -0x10010(%rbp),%rdi
mov    -0x10038(%rbp),%rsi
mov    -0x10030(%rbp),%rdx
call   1050 <memmove@plt>
jmp    1155 <parse_inputstream+0x25>
add    $0x10050,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_inputstream>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10008,%rsp
mov    %rdi,%r14
mov    %rsp,%r15
mov    $0x10000,%edx
mov    %r15,%rdi
mov    $0x1,%esi
mov    %r14,%rcx
call   1030 <fread@plt>
test   %eax,%eax
jle    1220 <parse_inputstream+0xf0>
xor    %ecx,%ecx
lea    0xe93(%rip),%r12
jmp    11a1 <parse_inputstream+0x71>
nop
mov    %r15,%rbp
mov    %r15,%rdi
mov    %rbp,%rsi
mov    %r13,%rdx
call   1050 <memmove@plt>
lea    (%rsp,%r13,1),%rdi
mov    $0x10000,%edx
sub    %r13,%rdx
mov    $0x1,%esi
mov    %r14,%rcx
call   1030 <fread@plt>
mov    %r13,%rcx
test   %eax,%eax
jle    1220 <parse_inputstream+0xf0>
mov    %eax,%r13d
add    %rcx,%r13
cmp    $0xc,%r13
jb     1170 <parse_inputstream+0x40>
mov    %r15,%rbx
movslq 0xc(%rbx),%r8
lea    0xc(%r8),%rax
cmp    %r13,%rax
ja     1200 <parse_inputstream+0xd0>
movsbl 0x8(%rbx),%ecx
mov    (%rbx),%esi
mov    0x4(%rbx),%edx
lea    (%rbx,%r8,1),%rbp
add    $0x11,%rbp
mov    %r8,%rax
add    $0x11,%rax
add    $0x10,%rbx
sub    %rax,%r13
mov    %r12,%rdi
mov    %rbx,%r9
call   1040 <printf@plt>
mov    %rbp,%rbx
cmp    $0xb,%r13
ja     11b0 <parse_inputstream+0x80>
jmp    1173 <parse_inputstream+0x43>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r13,%rdx
call   1050 <memmove@plt>
mov    %rbx,%rbp
cmp    $0x10,%r13
jbe    1173 <parse_inputstream+0x43>
jmp    1181 <parse_inputstream+0x51>
add    $0x10008,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"%i %i %c %u %s\0A\00"
define void @parse_inputstream(i32* %0) {
%2 = alloca i32*
%3 = alloca [65536 x i8]
%4 = alloca i64
%5 = alloca i64
%6 = alloca i32
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8
%12 = alloca i32
%13 = alloca i8*
store i32* %0, i32** %2
store i64 65536, i64* %4
store i64 0, i64* %5
br label %14
14: ; preds = %92, %1
%15 = getelementptr inbounds [65536 x i8], [65536 x i8]* %3, i64 0, i64 0
%16 = load i64, i64* %5
%17 = getelementptr inbounds i8, i8* %15, i64 %16
%18 = load i64, i64* %4
%19 = load i64, i64* %5
%20 = sub i64 %18, %19
%21 = load i32*, i32** %2
%22 = call i32 @fread(i8* %17, i32 1, i64 %20, i32* %21)
store i32 %22, i32* %6
%23 = icmp sgt i32 %22, 0
br i1 %23, label %24, label %93
24: ; preds = %14
%25 = load i64, i64* %5
%26 = load i32, i32* %6
%27 = sext i32 %26 to i64
%28 = add i64 %25, %27
store i64 %28, i64* %7
%29 = getelementptr inbounds [65536 x i8], [65536 x i8]* %3, i64 0, i64 0
store i8* %29, i8** %8
br label %30
30: ; preds = %62, %24
%31 = load i64, i64* %7
%32 = icmp uge i64 %31, 12
br i1 %32, label %33, label %83
33: ; preds = %30
%34 = load i8*, i8** %8
%35 = bitcast i8* %34 to i32*
%36 = getelementptr inbounds i32, i32* %35, i64 0
%37 = load i32, i32* %36
store i32 %37, i32* %9
%38 = load i8*, i8** %8
%39 = bitcast i8* %38 to i32*
%40 = getelementptr inbounds i32, i32* %39, i64 1
%41 = load i32, i32* %40
store i32 %41, i32* %10
%42 = load i8*, i8** %8
%43 = bitcast i8* %42 to i32*
%44 = getelementptr inbounds i32, i32* %43, i64 2
%45 = load i32, i32* %44
%46 = trunc i32 %45 to i8
store i8 %46, i8* %11
%47 = load i8*, i8** %8
%48 = bitcast i8* %47 to i32*
%49 = getelementptr inbounds i32, i32* %48, i64 3
%50 = load i32, i32* %49
store i32 %50, i32* %12
%51 = load i32, i32* %12
%52 = sext i32 %51 to i64
%53 = add i64 12, %52
%54 = load i64, i64* %7
%55 = icmp ugt i64 %53, %54
br i1 %55, label %56, label %62
56: ; preds = %33
%57 = load i64, i64* %7
store i64 %57, i64* %5
%58 = getelementptr inbounds [65536 x i8], [65536 x i8]* %3, i64 0, i64 0
%59 = load i8*, i8** %8
%60 = load i64, i64* %7
%61 = call i32 @memmove(i8* %58, i8* %59, i64 %60)
br label %83
62: ; preds = %33
%63 = load i8*, i8** %8
%64 = getelementptr inbounds i8, i8* %63, i64 16
store i8* %64, i8** %13
%65 = load i32, i32* %12
%66 = add nsw i32 %65, 1
%67 = sext i32 %66 to i64
%68 = add i64 %67, 16
%69 = load i8*, i8** %8
%70 = getelementptr inbounds i8, i8* %69, i64 %68
store i8* %70, i8** %8
%71 = load i32, i32* %12
%72 = add nsw i32 %71, 1
%73 = sext i32 %72 to i64
%74 = add i64 %73, 16
%75 = load i64, i64* %7
%76 = sub i64 %75, %74
store i64 %76, i64* %7
%77 = load i32, i32* %9
%78 = load i32, i32* %10
%79 = load i8, i8* %11
%80 = load i32, i32* %12
%81 = load i8*, i8** %13
%82 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %77, i32 %78, i8 signext %79, i32 %80, i8* %81)
br label %30
83: ; preds = %56, %30
%84 = load i64, i64* %7
%85 = icmp uge i64 16, %84
br i1 %85, label %86, label %92
86: ; preds = %83
%87 = load i64, i64* %7
store i64 %87, i64* %5
%88 = getelementptr inbounds [65536 x i8], [65536 x i8]* %3, i64 0, i64 0
%89 = load i8*, i8** %8
%90 = load i64, i64* %7
%91 = call i32 @memmove(i8* %88, i8* %89, i64 %90)
br label %92
92: ; preds = %86, %83
br label %14
93: ; preds = %14
ret void
}

LLVM IR (-O2):
@.str = [16 x i8] c"%i %i %c %u %s\0A\00"
define void @parse_inputstream(i32* nocapture %0) {
%2 = alloca [65536 x i8]
%3 = getelementptr inbounds [65536 x i8], [65536 x i8]* %2, i64 0, i64 0
%4 = call i32 @fread(i8* %3, i32 1, i64 65536, i32* %0)
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %50
6: ; preds = %1, %44
%7 = phi i32 [ %48, %44 ], [ %4, %1 ]
%8 = phi i64 [ %45, %44 ], [ 0, %1 ]
%9 = zext i32 %7 to i64
%10 = add i64 %8, %9
%11 = icmp ugt i64 %10, 11
br i1 %11, label %12, label %40
12: ; preds = %6, %21
%13 = phi i64 [ %34, %21 ], [ %10, %6 ]
%14 = phi i8* [ %33, %21 ], [ %3, %6 ]
%15 = getelementptr inbounds i8, i8* %14, i64 12
%16 = bitcast i8* %15 to i32*
%17 = load i32, i32* %16
%18 = sext i32 %17 to i64
%19 = add nsw i64 %18, 12
%20 = icmp ugt i64 %19, %13
br i1 %20, label %37, label %21
21: ; preds = %12
%22 = bitcast i8* %14 to i32*
%23 = getelementptr inbounds i8, i8* %14, i64 8
%24 = bitcast i8* %23 to i32*
%25 = load i32, i32* %24
%26 = trunc i32 %25 to i8
%27 = getelementptr inbounds i8, i8* %14, i64 4
%28 = bitcast i8* %27 to i32*
%29 = load i32, i32* %28
%30 = load i32, i32* %22
%31 = getelementptr inbounds i8, i8* %14, i64 16
%32 = add nsw i64 %18, 17
%33 = getelementptr inbounds i8, i8* %14, i64 %32
%34 = sub i64 %13, %32
%35 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %30, i32 %29, i8 signext %26, i32 %17, i8* %31)
%36 = icmp ugt i64 %34, 11
br i1 %36, label %12, label %40
37: ; preds = %12
%38 = call i32 @memmove(i8* %3, i8* %14, i64 %13)
%39 = icmp ult i64 %13, 17
br i1 %39, label %40, label %44
40: ; preds = %21, %6, %37
%41 = phi i8* [ %14, %37 ], [ %3, %6 ], [ %33, %21 ]
%42 = phi i64 [ %13, %37 ], [ %10, %6 ], [ %34, %21 ]
%43 = call i32 @memmove(i8* %3, i8* %41, i64 %42)
br label %44
44: ; preds = %40, %37
%45 = phi i64 [ %42, %40 ], [ %13, %37 ]
%46 = getelementptr inbounds [65536 x i8], [65536 x i8]* %2, i64 0, i64 %45
%47 = sub i64 65536, %45
%48 = call i32 @fread(i8* %46, i32 1, i64 %47, i32* %0)
%49 = icmp sgt i32 %48, 0
br i1 %49, label %6, label %50
50: ; preds = %44, %1
ret void
}