#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 u_long;
struct stat {
  int st_size;
};

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, int *, int);
int stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int fd, rc;
  struct stat st;
  int bytes_read = 0;
  u_long total_clock = 0;
  int new_errno;
  if (argc < 2) {
    printf("Format: parseulog <log file>\n");
    exit(0);
  }
  rc = stat(argv[1], &st);
  if (rc < 0) {
    fprintf(stderr, "stat of %s failed with %d\n", argv[1], rc);
    perror("stat failed\n");
    return rc;
  }
  fd = open(argv[1], O_RDONLY);
  if (fd < 0) {
    perror("open log file\n");
    return fd;
  }
  while (bytes_read < st.st_size) {
    if (bytes_read > st.st_size) {
      perror("bytes_read > st.st_size ???\n");
    }
    int count = 0;
    int num_bytes;
    rc = read(fd, &num_bytes, sizeof(int));
    if (rc != sizeof(int)) {
      perror("Could not read the count\n");
      return -1;
    }
    printf("** reading %d bytes ***\n", num_bytes);
    bytes_read += rc;
    while (count < num_bytes) {
      u_long entry;
      long i;
      int skip, retval, fake_calls;
      rc = read(fd, &entry, sizeof(u_long));
      if (rc != sizeof(u_long)) {
        perror("read log record\n");
        return rc;
      }
      count += rc;
      bytes_read += rc;
      printf("   entry %lx usual recs %ld non-zero retval? %d errno change? %d "
             "fake calls? %d skip? %d\n",
             entry, (entry & 0x0fffffff), !!(entry & 0x80000000),
             !!(entry & 0x10000000), !!(entry & 0x40000000),
             !!(entry & 0x20000000));
      for (i = 0; i < (entry & 0x0fffffff); i++) {
        total_clock++;
        printf("clock %lu fake calls 0 retval 0\n", total_clock - 1);
      }
      if (entry & 0x20000000) {
        rc = read(fd, &skip, sizeof(int));
        if (rc != sizeof(int)) {
          perror("read skip value\n");
          return rc;
        }
        printf("     skip %d records\n", skip);
        count += rc;
        bytes_read += rc;
        total_clock += skip + 1;
      } else {
        total_clock++;
      }
      if (entry & 0x80000000) {
        rc = read(fd, &retval, sizeof(int));
        if (rc != sizeof(int)) {
          perror("read retval value\n");
          return rc;
        }
        count += rc;
        bytes_read += rc;
      } else {
        retval = 0;
      }
      if (entry & 0x10000000) {
        rc = read(fd, &new_errno, sizeof(int));
        if (rc != sizeof(int)) {
          perror("read retval value\n");
          return rc;
        }
        count += rc;
        bytes_read += rc;
      } else {
        retval = 0;
      }
      if (entry & 0x40000000) {
        rc = read(fd, &fake_calls, sizeof(int));
        if (rc != sizeof(int)) {
          perror("read fake calls value\n");
          return rc;
        }
        count += rc;
        bytes_read += rc;
      } else {
        fake_calls = 0;
      }
      if (entry & (0x20000000 | 0x80000000 | 0x40000000 | 0x10000000)) {
        printf("clock %lu fake calls %d retval %d \n", total_clock - 1,
               fake_calls, retval);
      }
    }
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11c3 <main+0x43>
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x20(%rbp),%rsi
call   1070 <stat@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1218 <main+0x98>
mov    0x2df0(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
mov    -0x18(%rbp),%ecx
lea    0xe22(%rip),%rsi
call   1060 <fprintf@plt>
lea    0xe31(%rip),%rdi
call   1090 <perror@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    15fa <main+0x47a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2dc1(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1252 <main+0xd2>
lea    0xe04(%rip),%rdi
call   1090 <perror@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    15fa <main+0x47a>
jmp    1257 <main+0xd7>
mov    -0x24(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    15eb <main+0x46b>
mov    -0x24(%rbp),%eax
cmp    -0x20(%rbp),%eax
jle    127b <main+0xfb>
lea    0xddf(%rip),%rdi
call   1090 <perror@plt>
movl   $0x0,-0x30(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x34(%rbp),%rsi
mov    $0x4,%edx
call   1050 <read@plt>
mov    %eax,-0x18(%rbp)
movslq -0x18(%rbp),%rax
cmp    $0x4,%rax
je     12bc <main+0x13c>
lea    0xdc7(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15fa <main+0x47a>
mov    -0x34(%rbp),%esi
lea    0xdc6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x34(%rbp),%eax
jge    15e6 <main+0x466>
mov    -0x14(%rbp),%edi
lea    -0x38(%rbp),%rsi
mov    $0x4,%edx
call   1050 <read@plt>
mov    %eax,-0x18(%rbp)
movslq -0x18(%rbp),%rax
cmp    $0x4,%rax
je     131b <main+0x19b>
lea    0xd9a(%rip),%rdi
call   1090 <perror@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    15fa <main+0x47a>
mov    -0x18(%rbp),%eax
add    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x18(%rbp),%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x38(%rbp),%esi
mov    -0x38(%rbp),%edx
and    $0xfffffff,%edx
mov    -0x38(%rbp),%eax
and    $0x80000000,%eax
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%ecx
mov    -0x38(%rbp),%eax
and    $0x10000000,%eax
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%r8d
mov    -0x38(%rbp),%eax
and    $0x40000000,%eax
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%r9d
mov    -0x38(%rbp),%eax
and    $0x20000000,%eax
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
lea    0xd18(%rip),%rdi
mov    %eax,(%rsp)
mov    $0x0,%al
call   1030 <printf@plt>
movq   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    -0x38(%rbp),%ecx
and    $0xfffffff,%ecx
movslq %ecx,%rcx
cmp    %rcx,%rax
jge    13f7 <main+0x277>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%esi
sub    $0x1,%esi
lea    0xd31(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    13b0 <main+0x230>
mov    -0x38(%rbp),%eax
and    $0x20000000,%eax
cmp    $0x0,%eax
je     1475 <main+0x2f5>
mov    -0x14(%rbp),%edi
lea    -0x44(%rbp),%rsi
mov    $0x4,%edx
call   1050 <read@plt>
mov    %eax,-0x18(%rbp)
movslq -0x18(%rbp),%rax
cmp    $0x4,%rax
je     1441 <main+0x2c1>
lea    0xd00(%rip),%rdi
call   1090 <perror@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    15fa <main+0x47a>
mov    -0x44(%rbp),%esi
lea    0xcf7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x18(%rbp),%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
add    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
jmp    147e <main+0x2fe>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x38(%rbp),%eax
and    $0x80000000,%eax
cmp    $0x0,%eax
je     14df <main+0x35f>
mov    -0x14(%rbp),%edi
lea    -0x48(%rbp),%rsi
mov    $0x4,%edx
call   1050 <read@plt>
mov    %eax,-0x18(%rbp)
movslq -0x18(%rbp),%rax
cmp    $0x4,%rax
je     14c8 <main+0x348>
lea    0xca0(%rip),%rdi
call   1090 <perror@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    15fa <main+0x47a>
mov    -0x18(%rbp),%eax
add    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x18(%rbp),%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    14e6 <main+0x366>
movl   $0x0,-0x48(%rbp)
mov    -0x38(%rbp),%eax
and    $0x10000000,%eax
cmp    $0x0,%eax
je     1547 <main+0x3c7>
mov    -0x14(%rbp),%edi
lea    -0x2c(%rbp),%rsi
mov    $0x4,%edx
call   1050 <read@plt>
mov    %eax,-0x18(%rbp)
movslq -0x18(%rbp),%rax
cmp    $0x4,%rax
je     1530 <main+0x3b0>
lea    0xc38(%rip),%rdi
call   1090 <perror@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    15fa <main+0x47a>
mov    -0x18(%rbp),%eax
add    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x18(%rbp),%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    154e <main+0x3ce>
movl   $0x0,-0x48(%rbp)
mov    -0x38(%rbp),%eax
and    $0x40000000,%eax
cmp    $0x0,%eax
je     15af <main+0x42f>
mov    -0x14(%rbp),%edi
lea    -0x4c(%rbp),%rsi
mov    $0x4,%edx
call   1050 <read@plt>
mov    %eax,-0x18(%rbp)
movslq -0x18(%rbp),%rax
cmp    $0x4,%rax
je     1598 <main+0x418>
lea    0xbe3(%rip),%rdi
call   1090 <perror@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    15fa <main+0x47a>
mov    -0x18(%rbp),%eax
add    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x18(%rbp),%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    15b6 <main+0x436>
movl   $0x0,-0x4c(%rbp)
mov    -0x38(%rbp),%eax
and    $0xf0000000,%eax
cmp    $0x0,%eax
je     15e1 <main+0x461>
mov    -0x28(%rbp),%esi
sub    $0x1,%esi
mov    -0x4c(%rbp),%edx
mov    -0x48(%rbp),%ecx
lea    0xba8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12d6 <main+0x156>
jmp    1257 <main+0xd7>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
cmp    $0x1,%edi
jle    14ae <main+0x31e>
mov    %rsi,%rbp
mov    0x8(%rsi),%rdi
lea    0x18(%rsp),%rsi
call   1080 <stat@plt>
test   %eax,%eax
js     1469 <main+0x2d9>
mov    0x8(%rbp),%rdi
mov    0x2e1d(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,%r13d
test   %eax,%eax
js     1491 <main+0x301>
mov    0x18(%rsp),%eax
mov    %eax,0x1c(%rsp)
test   %eax,%eax
jle    141d <main+0x28d>
lea    0xee1(%rip),%r15
xor    %r14d,%r14d
xor    %ebx,%ebx
mov    %r13d,0x14(%rsp)
jmp    120e <main+0x7e>
mov    0xc(%rsp),%ebx
cmp    0x1c(%rsp),%ebx
jge    141d <main+0x28d>
mov    %r13d,%edi
lea    0x30(%rsp),%rsi
mov    $0x4,%edx
call   1060 <read@plt>
cmp    $0x4,%eax
jne    149a <main+0x30a>
mov    0x30(%rsp),%ebp
lea    0xe1d(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x4,%ebx
mov    %ebx,0xc(%rsp)
mov    %ebp,0x20(%rsp)
test   %ebp,%ebp
jle    1200 <main+0x70>
xor    %ebx,%ebx
jmp    1297 <main+0x107>
mov    %r13d,%edi
lea    0x24(%rsp),%rsi
mov    $0x4,%edx
call   1060 <read@plt>
cmp    $0x4,%eax
jne    1448 <main+0x2b8>
add    $0x4,%ebx
addl   $0x4,0xc(%rsp)
mov    0x24(%rsp),%edx
lea    -0x1(%r14),%esi
mov    0x10(%rsp),%ecx
lea    0xec1(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    0x20(%rsp),%ebx
jge    1200 <main+0x70>
mov    %r13d,%edi
lea    0x2c(%rsp),%rsi
mov    $0x4,%edx
call   1060 <read@plt>
cmp    $0x4,%eax
jne    142a <main+0x29a>
mov    0x2c(%rsp),%ebp
mov    %ebp,%r13d
and    $0xfffffff,%r13d
mov    %ebp,%ecx
shr    $0x1f,%ecx
mov    %ebp,%r8d
shr    $0x1c,%r8d
and    $0x1,%r8d
mov    %ebp,%r9d
shr    $0x1e,%r9d
and    $0x1,%r9d
mov    %ebp,%eax
shr    $0x1d,%eax
and    $0x1,%eax
mov    %eax,(%rsp)
lea    0xd8e(%rip),%rdi
mov    %ebp,%esi
mov    %r13d,%edx
xor    %eax,%eax
call   1040 <printf@plt>
test   %r13,%r13
je     1360 <main+0x1d0>
xchg   %ax,%ax
lea    0x1(%r14),%r12d
mov    %r15,%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r12d,%r14d
add    $0xffffffffffffffff,%r13
jne    1300 <main+0x170>
test   $0x20000000,%ebp
jne    136b <main+0x1db>
add    $0x4,%ebx
addl   $0x4,0xc(%rsp)
mov    $0x1,%r14d
mov    0x14(%rsp),%r13d
test   %ebp,%ebp
js     13b1 <main+0x221>
movl   $0x0,0x10(%rsp)
test   $0x10000000,%ebp
jne    13dc <main+0x24c>
movl   $0x0,0x10(%rsp)
jmp    13fb <main+0x26b>
nopw   0x0(%rax,%rax,1)
mov    %r14d,%r12d
test   $0x20000000,%ebp
je     1322 <main+0x192>
mov    0x14(%rsp),%r13d
mov    %r13d,%edi
lea    0x28(%rsp),%rsi
mov    $0x4,%edx
call   1060 <read@plt>
cmp    $0x4,%eax
jne    143f <main+0x2af>
mov    0x28(%rsp),%r14d
lea    0xd70(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x8,%ebx
addl   $0x8,0xc(%rsp)
add    $0x1,%r14d
test   %ebp,%ebp
jns    1339 <main+0x1a9>
mov    %r13d,%edi
lea    0x10(%rsp),%rsi
mov    $0x4,%edx
call   1060 <read@plt>
cmp    $0x4,%eax
jne    1436 <main+0x2a6>
add    $0x4,%ebx
addl   $0x4,0xc(%rsp)
test   $0x10000000,%ebp
je     134d <main+0x1bd>
mov    %r13d,%edi
lea    0x34(%rsp),%rsi
mov    $0x4,%edx
call   1060 <read@plt>
cmp    $0x4,%eax
jne    1436 <main+0x2a6>
add    $0x4,%ebx
addl   $0x4,0xc(%rsp)
add    %r12d,%r14d
test   $0x40000000,%ebp
jne    1250 <main+0xc0>
xor    %edx,%edx
cmp    $0x10000000,%ebp
jae    1277 <main+0xe7>
jmp    128d <main+0xfd>
mov    %r13d,%edi
call   1050 <close@plt>
xor    %r13d,%r13d
jmp    1457 <main+0x2c7>
mov    %eax,%r13d
lea    0xc36(%rip),%rdi
jmp    1452 <main+0x2c2>
lea    0xce0(%rip),%rdi
jmp    144f <main+0x2bf>
lea    0xcb0(%rip),%rdi
jmp    144f <main+0x2bf>
lea    0xce1(%rip),%rdi
mov    %eax,%r13d
call   10a0 <perror@plt>
mov    %r13d,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%r13d
mov    0x2b65(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbp),%rdx
lea    0xb80(%rip),%rsi
mov    %r13d,%ecx
call   1070 <fprintf@plt>
lea    0xb8c(%rip),%rdi
jmp    1452 <main+0x2c2>
lea    0xb90(%rip),%rdi
jmp    1452 <main+0x2c2>
lea    0xb96(%rip),%rdi
call   10a0 <perror@plt>
mov    $0xffffffff,%r13d
jmp    1457 <main+0x2c7>
lea    0xcb6(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [30 x i8] c"Format: parseulog <log file>\0A\00"
@stderr = global i32 0
@.str.1 = [27 x i8] c"stat of %s failed with %d\0A\00"
@.str.2 = [13 x i8] c"stat failed\0A\00"
@O_RDONLY = global i32 0
@.str.3 = [15 x i8] c"open log file\0A\00"
@.str.4 = [29 x i8] c"bytes_read > st.st_size ???\0A\00"
@.str.5 = [26 x i8] c"Could not read the count\0A\00"
@.str.6 = [25 x i8] c"** reading %d bytes ***\0A\00"
@.str.7 = [17 x i8] c"read log record\0A\00"
@.str.8 = [90 x i8] c" entry %lx usual recs %ld non-zero retval? %d errno change? %d fake calls? %d skip? %d\0A\00"
@.str.9 = [33 x i8] c"clock %lu fake calls 0 retval 0\0A\00"
@.str.10 = [17 x i8] c"read skip value\0A\00"
@.str.11 = [22 x i8] c" skip %d records\0A\00"
@.str.12 = [19 x i8] c"read retval value\0A\00"
@.str.13 = [23 x i8] c"read fake calls value\0A\00"
@.str.14 = [36 x i8] c"clock %lu fake calls %d retval %d \0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.stat
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i64
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %9
store i32 0, i32* %10
%19 = load i32, i32* %4
%20 = icmp slt i32 %19, 2
br i1 %20, label %21, label %24
21: ; preds = %2
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%23 = call i32 @exit(i32 0)
unreachable
24: ; preds = %2
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32 @stat(i8* %27, %struct.stat* %8)
store i32 %28, i32* %7
%29 = load i32, i32* %7
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %40
31: ; preds = %24
%32 = load i32, i32* @stderr
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = load i32, i32* %7
%37 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %35, i32 %36)
%38 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%39 = load i32, i32* %7
store i32 %39, i32* %3
br label %248
40: ; preds = %24
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 1
%43 = load i8*, i8** %42
%44 = load i32, i32* @O_RDONLY
%45 = call i32 @open(i8* %43, i32 %44)
store i32 %45, i32* %6
%46 = load i32, i32* %6
%47 = icmp slt i32 %46, 0
br i1 %47, label %48, label %51
48: ; preds = %40
%49 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%50 = load i32, i32* %6
store i32 %50, i32* %3
br label %248
51: ; preds = %40
br label %52
52: ; preds = %244, %51
%53 = load i32, i32* %9
%54 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%55 = load i32, i32* %54
%56 = icmp slt i32 %53, %55
br i1 %56, label %57, label %245
57: ; preds = %52
%58 = load i32, i32* %9
%59 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%60 = load i32, i32* %59
%61 = icmp sgt i32 %58, %60
br i1 %61, label %62, label %64
62: ; preds = %57
%63 = call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
br label %64
64: ; preds = %62, %57
store i32 0, i32* %12
%65 = load i32, i32* %6
%66 = call i32 @read(i32 %65, i32* %13, i32 4)
store i32 %66, i32* %7
%67 = load i32, i32* %7
%68 = sext i32 %67 to i64
%69 = icmp ne i64 %68, 4
br i1 %69, label %70, label %72
70: ; preds = %64
%71 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %3
br label %248
72: ; preds = %64
%73 = load i32, i32* %13
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i32 %73)
%75 = load i32, i32* %7
%76 = load i32, i32* %9
%77 = add nsw i32 %76, %75
store i32 %77, i32* %9
br label %78
78: ; preds = %243, %72
%79 = load i32, i32* %12
%80 = load i32, i32* %13
%81 = icmp slt i32 %79, %80
br i1 %81, label %82, label %244
82: ; preds = %78
%83 = load i32, i32* %6
%84 = call i32 @read(i32 %83, i32* %14, i32 4)
store i32 %84, i32* %7
%85 = load i32, i32* %7
%86 = sext i32 %85 to i64
%87 = icmp ne i64 %86, 4
br i1 %87, label %88, label %91
88: ; preds = %82
%89 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0))
%90 = load i32, i32* %7
store i32 %90, i32* %3
br label %248
91: ; preds = %82
%92 = load i32, i32* %7
%93 = load i32, i32* %12
%94 = add nsw i32 %93, %92
store i32 %94, i32* %12
%95 = load i32, i32* %7
%96 = load i32, i32* %9
%97 = add nsw i32 %96, %95
store i32 %97, i32* %9
%98 = load i32, i32* %14
%99 = load i32, i32* %14
%100 = and i32 %99, 268435455
%101 = load i32, i32* %14
%102 = and i32 %101, -2147483648
%103 = icmp ne i32 %102, 0
%104 = xor i1 %103, true
%105 = xor i1 %104, true
%106 = zext i1 %105 to i32
%107 = load i32, i32* %14
%108 = and i32 %107, 268435456
%109 = icmp ne i32 %108, 0
%110 = xor i1 %109, true
%111 = xor i1 %110, true
%112 = zext i1 %111 to i32
%113 = load i32, i32* %14
%114 = and i32 %113, 1073741824
%115 = icmp ne i32 %114, 0
%116 = xor i1 %115, true
%117 = xor i1 %116, true
%118 = zext i1 %117 to i32
%119 = load i32, i32* %14
%120 = and i32 %119, 536870912
%121 = icmp ne i32 %120, 0
%122 = xor i1 %121, true
%123 = xor i1 %122, true
%124 = zext i1 %123 to i32
%125 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([90 x i8], [90 x i8]* @.str.8, i64 0, i64 0), i32 %98, i32 %100, i32 %106, i32 %112, i32 %118, i32 %124)
store i64 0, i64* %15
br label %126
126: ; preds = %138, %91
%127 = load i64, i64* %15
%128 = load i32, i32* %14
%129 = and i32 %128, 268435455
%130 = sext i32 %129 to i64
%131 = icmp slt i64 %127, %130
br i1 %131, label %132, label %141
132: ; preds = %126
%133 = load i32, i32* %10
%134 = add nsw i32 %133, 1
store i32 %134, i32* %10
%135 = load i32, i32* %10
%136 = sub nsw i32 %135, 1
%137 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.9, i64 0, i64 0), i32 %136)
br label %138
138: ; preds = %132
%139 = load i64, i64* %15
%140 = add nsw i64 %139, 1
store i64 %140, i64* %15
br label %126
141: ; preds = %126
%142 = load i32, i32* %14
%143 = and i32 %142, 536870912
%144 = icmp ne i32 %143, 0
br i1 %144, label %145, label %167
145: ; preds = %141
%146 = load i32, i32* %6
%147 = call i32 @read(i32 %146, i32* %16, i32 4)
store i32 %147, i32* %7
%148 = load i32, i32* %7
%149 = sext i32 %148 to i64
%150 = icmp ne i64 %149, 4
br i1 %150, label %151, label %154
151: ; preds = %145
%152 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.10, i64 0, i64 0))
%153 = load i32, i32* %7
store i32 %153, i32* %3
br label %248
154: ; preds = %145
%155 = load i32, i32* %16
%156 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.11, i64 0, i64 0), i32 %155)
%157 = load i32, i32* %7
%158 = load i32, i32* %12
%159 = add nsw i32 %158, %157
store i32 %159, i32* %12
%160 = load i32, i32* %7
%161 = load i32, i32* %9
%162 = add nsw i32 %161, %160
store i32 %162, i32* %9
%163 = load i32, i32* %16
%164 = add nsw i32 %163, 1
%165 = load i32, i32* %10
%166 = add nsw i32 %165, %164
store i32 %166, i32* %10
br label %170
167: ; preds = %141
%168 = load i32, i32* %10
%169 = add nsw i32 %168, 1
store i32 %169, i32* %10
br label %170
170: ; preds = %167, %154
%171 = load i32, i32* %14
%172 = and i32 %171, -2147483648
%173 = icmp ne i32 %172, 0
br i1 %173, label %174, label %190
174: ; preds = %170
%175 = load i32, i32* %6
%176 = call i32 @read(i32 %175, i32* %17, i32 4)
store i32 %176, i32* %7
%177 = load i32, i32* %7
%178 = sext i32 %177 to i64
%179 = icmp ne i64 %178, 4
br i1 %179, label %180, label %183
180: ; preds = %174
%181 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.12, i64 0, i64 0))
%182 = load i32, i32* %7
store i32 %182, i32* %3
br label %248
183: ; preds = %174
%184 = load i32, i32* %7
%185 = load i32, i32* %12
%186 = add nsw i32 %185, %184
store i32 %186, i32* %12
%187 = load i32, i32* %7
%188 = load i32, i32* %9
%189 = add nsw i32 %188, %187
store i32 %189, i32* %9
br label %191
190: ; preds = %170
store i32 0, i32* %17
br label %191
191: ; preds = %190, %183
%192 = load i32, i32* %14
%193 = and i32 %192, 268435456
%194 = icmp ne i32 %193, 0
br i1 %194, label %195, label %211
195: ; preds = %191
%196 = load i32, i32* %6
%197 = call i32 @read(i32 %196, i32* %11, i32 4)
store i32 %197, i32* %7
%198 = load i32, i32* %7
%199 = sext i32 %198 to i64
%200 = icmp ne i64 %199, 4
br i1 %200, label %201, label %204
201: ; preds = %195
%202 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.12, i64 0, i64 0))
%203 = load i32, i32* %7
store i32 %203, i32* %3
br label %248
204: ; preds = %195
%205 = load i32, i32* %7
%206 = load i32, i32* %12
%207 = add nsw i32 %206, %205
store i32 %207, i32* %12
%208 = load i32, i32* %7
%209 = load i32, i32* %9
%210 = add nsw i32 %209, %208
store i32 %210, i32* %9
br label %212
211: ; preds = %191
store i32 0, i32* %17
br label %212
212: ; preds = %211, %204
%213 = load i32, i32* %14
%214 = and i32 %213, 1073741824
%215 = icmp ne i32 %214, 0
br i1 %215, label %216, label %232
216: ; preds = %212
%217 = load i32, i32* %6
%218 = call i32 @read(i32 %217, i32* %18, i32 4)
store i32 %218, i32* %7
%219 = load i32, i32* %7
%220 = sext i32 %219 to i64
%221 = icmp ne i64 %220, 4
br i1 %221, label %222, label %225
222: ; preds = %216
%223 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.13, i64 0, i64 0))
%224 = load i32, i32* %7
store i32 %224, i32* %3
br label %248
225: ; preds = %216
%226 = load i32, i32* %7
%227 = load i32, i32* %12
%228 = add nsw i32 %227, %226
store i32 %228, i32* %12
%229 = load i32, i32* %7
%230 = load i32, i32* %9
%231 = add nsw i32 %230, %229
store i32 %231, i32* %9
br label %233
232: ; preds = %212
store i32 0, i32* %18
br label %233
233: ; preds = %232, %225
%234 = load i32, i32* %14
%235 = and i32 %234, -268435456
%236 = icmp ne i32 %235, 0
br i1 %236, label %237, label %243
237: ; preds = %233
%238 = load i32, i32* %10
%239 = sub nsw i32 %238, 1
%240 = load i32, i32* %18
%241 = load i32, i32* %17
%242 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.14, i64 0, i64 0), i32 %239, i32 %240, i32 %241)
br label %243
243: ; preds = %237, %233
br label %78
244: ; preds = %78
br label %52
245: ; preds = %52
%246 = load i32, i32* %6
%247 = call i32 @close(i32 %246)
store i32 0, i32* %3
br label %248
248: ; preds = %245, %222, %201, %180, %151, %88, %70, %48, %31
%249 = load i32, i32* %3
ret i32 %249
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str.1 = [27 x i8] c"stat of %s failed with %d\0A\00"
@.str.2 = [13 x i8] c"stat failed\0A\00"
@O_RDONLY = global i32 0
@.str.3 = [15 x i8] c"open log file\0A\00"
@.str.5 = [26 x i8] c"Could not read the count\0A\00"
@.str.6 = [25 x i8] c"** reading %d bytes ***\0A\00"
@.str.7 = [17 x i8] c"read log record\0A\00"
@.str.8 = [90 x i8] c" entry %lx usual recs %ld non-zero retval? %d errno change? %d fake calls? %d skip? %d\0A\00"
@.str.9 = [33 x i8] c"clock %lu fake calls 0 retval 0\0A\00"
@.str.10 = [17 x i8] c"read skip value\0A\00"
@.str.11 = [22 x i8] c" skip %d records\0A\00"
@.str.12 = [19 x i8] c"read retval value\0A\00"
@.str.13 = [23 x i8] c"read fake calls value\0A\00"
@.str.14 = [36 x i8] c"clock %lu fake calls %d retval %d \0A\00"
@str = [29 x i8] c"Format: parseulog <log file>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = bitcast %struct.stat* %3 to i8*
%11 = bitcast i32* %4 to i8*
%12 = icmp slt i32 %0, 2
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
%15 = tail call i32 @exit(i32 0)
unreachable
16: ; preds = %2
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = call i32 @stat(i8* %18, %struct.stat* %3)
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %16
%22 = load i32, i32* @stderr
%23 = load i8*, i8** %17
%24 = tail call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %23, i32 %19)
%25 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %158
26: ; preds = %16
%27 = load i8*, i8** %17
%28 = load i32, i32* @O_RDONLY
%29 = tail call i32 @open(i8* %27, i32 %28)
%30 = icmp slt i32 %29, 0
br i1 %30, label %41, label %31
31: ; preds = %26
%32 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%33 = load i32, i32* %32
%34 = icmp sgt i32 %33, 0
br i1 %34, label %35, label %156
35: ; preds = %31
%36 = bitcast i32* %5 to i8*
%37 = bitcast i32* %6 to i8*
%38 = bitcast i32* %7 to i8*
%39 = bitcast i32* %8 to i8*
%40 = bitcast i32* %9 to i8*
br label %43
41: ; preds = %26
%42 = tail call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
br label %158
43: ; preds = %35, %152
%44 = phi i32 [ 0, %35 ], [ %154, %152 ]
%45 = phi i32 [ 0, %35 ], [ %153, %152 ]
%46 = call i32 @read(i32 %29, i32* %5, i32 4)
%47 = icmp eq i32 %46, 4
br i1 %47, label %50, label %48
48: ; preds = %43
%49 = tail call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0))
br label %150
50: ; preds = %43
%51 = load i32, i32* %5
%52 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i32 %51)
%53 = add nsw i32 %45, 4
%54 = icmp sgt i32 %51, 0
br i1 %54, label %55, label %152
55: ; preds = %50, %146
%56 = phi i32 [ %148, %146 ], [ 0, %50 ]
%57 = phi i32 [ %100, %146 ], [ %44, %50 ]
%58 = phi i32 [ %147, %146 ], [ %53, %50 ]
%59 = call i32 @read(i32 %29, i32* %6, i32 4)
%60 = icmp eq i32 %59, 4
br i1 %60, label %61, label %142
61: ; preds = %55
%62 = add nsw i32 %56, 4
%63 = add nsw i32 %58, 4
%64 = load i32, i32* %6
%65 = and i32 %64, 268435455
%66 = lshr i32 %64, 31
%67 = lshr i32 %64, 28
%68 = and i32 %67, 1
%69 = lshr i32 %64, 30
%70 = and i32 %69, 1
%71 = lshr i32 %64, 29
%72 = and i32 %71, 1
%73 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([90 x i8], [90 x i8]* @.str.8, i64 0, i64 0), i32 %64, i32 %65, i32 %66, i32 %68, i32 %70, i32 %72)
%74 = zext i32 %65 to i64
%75 = icmp eq i32 %65, 0
br i1 %75, label %83, label %76
76: ; preds = %61, %76
%77 = phi i64 [ %81, %76 ], [ 0, %61 ]
%78 = phi i32 [ %79, %76 ], [ %57, %61 ]
%79 = add nsw i32 %78, 1
%80 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.9, i64 0, i64 0), i32 %78)
%81 = add nuw nsw i64 %77, 1
%82 = icmp eq i64 %81, %74
br i1 %82, label %83, label %76
83: ; preds = %76, %61
%84 = phi i32 [ %57, %61 ], [ %79, %76 ]
%85 = and i32 %64, 536870912
%86 = icmp eq i32 %85, 0
br i1 %86, label %96, label %87
87: ; preds = %83
%88 = call i32 @read(i32 %29, i32* %7, i32 4)
%89 = icmp eq i32 %88, 4
br i1 %89, label %90, label %142
90: ; preds = %87
%91 = load i32, i32* %7
%92 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.11, i64 0, i64 0), i32 %91)
%93 = add nsw i32 %56, 8
%94 = add nsw i32 %58, 8
%95 = add nsw i32 %91, 1
br label %96
96: ; preds = %83, %90
%97 = phi i32 [ %94, %90 ], [ %63, %83 ]
%98 = phi i32 [ %95, %90 ], [ 1, %83 ]
%99 = phi i32 [ %93, %90 ], [ %62, %83 ]
%100 = add nsw i32 %98, %84
%101 = icmp sgt i32 %64, -1
br i1 %101, label %108, label %102
102: ; preds = %96
%103 = call i32 @read(i32 %29, i32* %8, i32 4)
%104 = icmp eq i32 %103, 4
br i1 %104, label %105, label %142
105: ; preds = %102
%106 = add nsw i32 %99, 4
%107 = add nsw i32 %97, 4
br label %109
108: ; preds = %96
store i32 0, i32* %8
br label %109
109: ; preds = %108, %105
%110 = phi i32 [ %107, %105 ], [ %97, %108 ]
%111 = phi i32 [ %106, %105 ], [ %99, %108 ]
%112 = and i32 %64, 268435456
%113 = icmp eq i32 %112, 0
br i1 %113, label %120, label %114
114: ; preds = %109
%115 = call i32 @read(i32 %29, i32* %4, i32 4)
%116 = icmp eq i32 %115, 4
br i1 %116, label %117, label %142
117: ; preds = %114
%118 = add nsw i32 %111, 4
%119 = add nsw i32 %110, 4
br label %121
120: ; preds = %109
store i32 0, i32* %8
br label %121
121: ; preds = %120, %117
%122 = phi i32 [ %119, %117 ], [ %110, %120 ]
%123 = phi i32 [ %118, %117 ], [ %111, %120 ]
%124 = and i32 %64, 1073741824
%125 = icmp eq i32 %124, 0
br i1 %125, label %133, label %126
126: ; preds = %121
%127 = call i32 @read(i32 %29, i32* %9, i32 4)
%128 = icmp eq i32 %127, 4
br i1 %128, label %129, label %142
129: ; preds = %126
%130 = add nsw i32 %123, 4
%131 = add nsw i32 %122, 4
%132 = load i32, i32* %9
br label %135
133: ; preds = %121
%134 = icmp ult i32 %64, 268435456
br i1 %134, label %146, label %135
135: ; preds = %129, %133
%136 = phi i32 [ %132, %129 ], [ 0, %133 ]
%137 = phi i32 [ %130, %129 ], [ %123, %133 ]
%138 = phi i32 [ %131, %129 ], [ %122, %133 ]
%139 = add nsw i32 %100, -1
%140 = load i32, i32* %8
%141 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.14, i64 0, i64 0), i32 %139, i32 %136, i32 %140)
br label %146
142: ; preds = %126, %114, %102, %87, %55
%143 = phi i8* [ getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0), %55 ], [ getelementptr inbounds ([17 x i8], [17 x i8]* @.str.10, i64 0, i64 0), %87 ], [ getelementptr inbounds ([19 x i8], [19 x i8]* @.str.12, i64 0, i64 0), %102 ], [ getelementptr inbounds ([19 x i8], [19 x i8]* @.str.12, i64 0, i64 0), %114 ], [ getelementptr inbounds ([23 x i8], [23 x i8]* @.str.13, i64 0, i64 0), %126 ]
%144 = phi i32 [ %59, %55 ], [ %88, %87 ], [ %103, %102 ], [ %115, %114 ], [ %127, %126 ]
%145 = tail call i32 @perror(i8* %143)
br label %150
146: ; preds = %133, %135
%147 = phi i32 [ %138, %135 ], [ %122, %133 ]
%148 = phi i32 [ %137, %135 ], [ %123, %133 ]
%149 = icmp slt i32 %148, %51
br i1 %149, label %55, label %152
150: ; preds = %48, %142
%151 = phi i32 [ %144, %142 ], [ -1, %48 ]
br label %158
152: ; preds = %146, %50
%153 = phi i32 [ %53, %50 ], [ %147, %146 ]
%154 = phi i32 [ %44, %50 ], [ %100, %146 ]
%155 = icmp slt i32 %153, %33
br i1 %155, label %43, label %156
156: ; preds = %152, %31
%157 = tail call i32 @close(i32 %29)
br label %158
158: ; preds = %150, %156, %41, %21
%159 = phi i32 [ %19, %21 ], [ %29, %41 ], [ 0, %156 ], [ %151, %150 ]
ret i32 %159
}