#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*/ time_t;
struct tm {
  int dummy;
};

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int O_CREAT;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ SHM_RDONLY;
int close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
scalar_t__ getpid();
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ lock(int, int);
int /*<<< orphan*/ memcpy(int *, void *, int);
int open(char const *, int, int);
int /*<<< orphan*/ printf(char *, ...);
void *shmat(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
int shmdt(void *);
int /*<<< orphan*/ stdout;
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ strftime(char *, int, char *, struct tm *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int /*<<< orphan*/ unlock(int, int);
scalar_t__ write(int, void *, int);
int reader_from_shared_memory(int shm_id, int sem_id, const char *filename) {
  int ret_code = EXIT_SUCCESS;
  void *shared_memory = shmat(shm_id, NULL, SHM_RDONLY);
  if (shared_memory == (void *)(-1)) {
    {
      char __tb[101];
      time_t t = time(NULL);
      struct tm *tmp = localtime(&t);
      strftime(__tb, 100, "%d/%m/%Y %H:%M:%S ", tmp);
      printf("%s [pid=%d]", __tb, (int)getpid());
      printf("\x1b[31m");
      printf(" ERROR! ");
      printf("\x1b[0m");
      printf("Shared memory wan not attached");
      printf(" (%s)\n", strerror(errno));
      fflush(stdout);
    };
    ret_code = EXIT_FAILURE;
    goto reader_free_section;
  } else {
    char __tb[101];
    time_t t = time(NULL);
    struct tm *tmp = localtime(&t);
    strftime(__tb, 100, "%d/%m/%Y %H:%M:%S ", tmp);
    printf("%s [pid=%d] ", __tb, (int)getpid());
    printf("shared memory was attached to writer process");
    printf("\n");
    fflush(stdout);
  };
  int output_descriptor = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666);
  if (output_descriptor == -1) {
    {
      char __tb[101];
      time_t t = time(NULL);
      struct tm *tmp = localtime(&t);
      strftime(__tb, 100, "%d/%m/%Y %H:%M:%S ", tmp);
      printf("%s [pid=%d]", __tb, (int)getpid());
      printf("\x1b[31m");
      printf(" ERROR! ");
      printf("\x1b[0m");
      printf("\"%s\" was not opened for writing and truncated", filename);
      printf(" (%s)\n", strerror(errno));
      fflush(stdout);
    };
    ret_code = EXIT_FAILURE;
    goto reader_free_section;
  } else {
    char __tb[101];
    time_t t = time(NULL);
    struct tm *tmp = localtime(&t);
    strftime(__tb, 100, "%d/%m/%Y %H:%M:%S ", tmp);
    printf("%s [pid=%d] ", __tb, (int)getpid());
    printf("\"%s\" was opened for writing and truncated", filename);
    printf("\n");
    fflush(stdout);
  };
  int work_path = 0;
  int sum = 0;
  int data_transfer_size;
  void *buffer = shared_memory;
  {
    char __tb[101];
    time_t t = time(NULL);
    struct tm *tmp = localtime(&t);
    strftime(__tb, 100, "%d/%m/%Y %H:%M:%S ", tmp);
    printf("%s [pid=%d] ", __tb, (int)getpid());
    printf("reading process started");
    printf("\n");
    fflush(stdout);
  };
  while (1) {
    lock(sem_id, (2 * work_path));
    memcpy(&data_transfer_size, buffer, sizeof(int));
    sum = 0;
    while (sum < data_transfer_size) {
      sum += write(output_descriptor, buffer + sum + sizeof(int),
                   data_transfer_size - sum);
    }
    {
      char __tb[101];
      time_t t = time(NULL);
      struct tm *tmp = localtime(&t);
      strftime(__tb, 100, "%d/%m/%Y %H:%M:%S ", tmp);
      printf("%s [pid=%d] ", __tb, (int)getpid());
      printf("%d bytes was copied from buffer[%d] to \"%s\"",
             data_transfer_size + (int)sizeof(int), work_path, filename);
      printf("\n");
      fflush(stdout);
    };
    unlock(sem_id, (2 * work_path + 1));
    if (data_transfer_size <= 0)
      break;
    work_path = (work_path + 1) % 16;
    buffer = shared_memory + (work_path * 65536);
  }
reader_free_section : {
  char __tb[101];
  time_t t = time(NULL);
  struct tm *tmp = localtime(&t);
  strftime(__tb, 100, "%d/%m/%Y %H:%M:%S ", tmp);
  printf("%s [pid=%d] ", __tb, (int)getpid());
  printf("reading process finished");
  printf("\n");
  fflush(stdout);
};
  if (close(output_descriptor) == -1) {
    {
      char __tb[101];
      time_t t = time(NULL);
      struct tm *tmp = localtime(&t);
      strftime(__tb, 100, "%d/%m/%Y %H:%M:%S ", tmp);
      printf("%s [pid=%d]", __tb, (int)getpid());
      printf("\x1b[31m");
      printf(" ERROR! ");
      printf("\x1b[0m");
      printf("\"%s\" was not closed", filename);
      printf(" (%s)\n", strerror(errno));
      fflush(stdout);
    };
  } else {
    char __tb[101];
    time_t t = time(NULL);
    struct tm *tmp = localtime(&t);
    strftime(__tb, 100, "%d/%m/%Y %H:%M:%S ", tmp);
    printf("%s [pid=%d] ", __tb, (int)getpid());
    printf("\"%s\" was closed from write only mode", filename);
    printf("\n");
    fflush(stdout);
  };
  if (shmdt(shared_memory) == -1) {
    {
      char __tb[101];
      time_t t = time(NULL);
      struct tm *tmp = localtime(&t);
      strftime(__tb, 100, "%d/%m/%Y %H:%M:%S ", tmp);
      printf("%s [pid=%d]", __tb, (int)getpid());
      printf("\x1b[31m");
      printf(" ERROR! ");
      printf("\x1b[0m");
      printf("Shared memory was not detached");
      printf(" (%s)\n", strerror(errno));
      fflush(stdout);
    };
  } else {
    char __tb[101];
    time_t t = time(NULL);
    struct tm *tmp = localtime(&t);
    strftime(__tb, 100, "%d/%m/%Y %H:%M:%S ", tmp);
    printf("%s [pid=%d] ", __tb, (int)getpid());
    printf("shared memory was detached from reader");
    printf("\n");
    fflush(stdout);
  };
  return ret_code;
}


x86 assembly (clang, -O0):
<reader_from_shared_memory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x610,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    0x2da4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2db5(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1100 <shmat@plt>
mov    %rax,-0x20(%rbp)
mov    $0xffffffffffffffff,%rax
cmp    %rax,-0x20(%rbp)
jne    131e <reader_from_shared_memory+0x12e>
xor    %eax,%eax
mov    %eax,%edi
call   10c0 <time@plt>
mov    %eax,-0x94(%rbp)
lea    -0x94(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0xa0(%rbp)
lea    -0x90(%rbp),%rdi
mov    -0xa0(%rbp),%rcx
mov    $0x64,%esi
lea    0xd89(%rip),%rdx
call   10e0 <strftime@plt>
lea    -0x90(%rbp),%rax
mov    %rax,-0x5b8(%rbp)
mov    $0x0,%al
call   1080 <getpid@plt>
mov    -0x5b8(%rbp),%rsi
mov    %eax,%edx
lea    0xd72(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
lea    0xd70(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
lea    0xd68(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
lea    0xd63(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
lea    0xd5a(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    0x2ce1(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    %rax,%rsi
lea    0xd5a(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    0x2cb2(%rip),%rax
mov    (%rax),%edi
call   10d0 <fflush@plt>
mov    0x2cac(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
jmp    17bd <reader_from_shared_memory+0x5cd>
xor    %eax,%eax
mov    %eax,%edi
call   10c0 <time@plt>
mov    %eax,-0x114(%rbp)
lea    -0x114(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x120(%rbp)
lea    -0x110(%rbp),%rdi
mov    -0x120(%rbp),%rcx
mov    $0x64,%esi
lea    0xca6(%rip),%rdx
call   10e0 <strftime@plt>
lea    -0x110(%rbp),%rax
mov    %rax,-0x5c0(%rbp)
mov    $0x0,%al
call   1080 <getpid@plt>
mov    -0x5c0(%rbp),%rsi
mov    %eax,%edx
lea    0xcd5(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
lea    0xcd4(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
lea    0xcb7(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    0x2c0a(%rip),%rax
mov    (%rax),%edi
call   10d0 <fflush@plt>
mov    -0x10(%rbp),%rdi
mov    0x2be0(%rip),%rax
mov    (%rax),%esi
mov    0x2c2f(%rip),%rax
or     (%rax),%esi
mov    0x2c1e(%rip),%rax
or     (%rax),%esi
mov    $0x1b6,%edx
call   10f0 <open@plt>
mov    %eax,-0x124(%rbp)
cmpl   $0xffffffff,-0x124(%rbp)
jne    14d8 <reader_from_shared_memory+0x2e8>
xor    %eax,%eax
mov    %eax,%edi
call   10c0 <time@plt>
mov    %eax,-0x194(%rbp)
lea    -0x194(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x1a0(%rbp)
lea    -0x190(%rbp),%rdi
mov    -0x1a0(%rbp),%rcx
mov    $0x64,%esi
lea    0xbd3(%rip),%rdx
call   10e0 <strftime@plt>
lea    -0x190(%rbp),%rax
mov    %rax,-0x5c8(%rbp)
mov    $0x0,%al
call   1080 <getpid@plt>
mov    -0x5c8(%rbp),%rsi
mov    %eax,%edx
lea    0xbbc(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
lea    0xbba(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
lea    0xbb2(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
lea    0xbad(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    -0x10(%rbp),%rsi
lea    0xc00(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    0x2b27(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    %rax,%rsi
lea    0xba0(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    0x2af8(%rip),%rax
mov    (%rax),%edi
call   10d0 <fflush@plt>
mov    0x2af2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
jmp    17bd <reader_from_shared_memory+0x5cd>
xor    %eax,%eax
mov    %eax,%edi
call   10c0 <time@plt>
mov    %eax,-0x214(%rbp)
lea    -0x214(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x220(%rbp)
lea    -0x210(%rbp),%rdi
mov    -0x220(%rbp),%rcx
mov    $0x64,%esi
lea    0xaec(%rip),%rdx
call   10e0 <strftime@plt>
lea    -0x210(%rbp),%rax
mov    %rax,-0x5d0(%rbp)
mov    $0x0,%al
call   1080 <getpid@plt>
mov    -0x5d0(%rbp),%rsi
mov    %eax,%edx
lea    0xb1b(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    -0x10(%rbp),%rsi
lea    0xb71(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
lea    0xaf9(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    0x2a4c(%rip),%rax
mov    (%rax),%edi
call   10d0 <fflush@plt>
movl   $0x0,-0x224(%rbp)
movl   $0x0,-0x228(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x238(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   10c0 <time@plt>
mov    %eax,-0x2a4(%rbp)
lea    -0x2a4(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x2b0(%rbp)
lea    -0x2a0(%rbp),%rdi
mov    -0x2b0(%rbp),%rcx
mov    $0x64,%esi
lea    0xa32(%rip),%rdx
call   10e0 <strftime@plt>
lea    -0x2a0(%rbp),%rax
mov    %rax,-0x5d8(%rbp)
mov    $0x0,%al
call   1080 <getpid@plt>
mov    -0x5d8(%rbp),%rsi
mov    %eax,%edx
lea    0xa61(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
lea    0xae5(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
lea    0xa43(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    0x2996(%rip),%rax
mov    (%rax),%edi
call   10d0 <fflush@plt>
mov    -0x8(%rbp),%edi
mov    -0x224(%rbp),%esi
shl    $0x1,%esi
call   1050 <lock@plt>
mov    -0x238(%rbp),%rsi
lea    -0x22c(%rbp),%rdi
mov    $0x4,%edx
call   10b0 <memcpy@plt>
movl   $0x0,-0x228(%rbp)
mov    -0x228(%rbp),%eax
cmp    -0x22c(%rbp),%eax
jge    16b2 <reader_from_shared_memory+0x4c2>
mov    -0x124(%rbp),%edi
mov    -0x238(%rbp),%rsi
movslq -0x228(%rbp),%rax
add    %rax,%rsi
add    $0x4,%rsi
mov    -0x22c(%rbp),%edx
sub    -0x228(%rbp),%edx
call   1070 <write@plt>
mov    %rax,%rcx
movslq -0x228(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x228(%rbp)
jmp    165c <reader_from_shared_memory+0x46c>
xor    %eax,%eax
mov    %eax,%edi
call   10c0 <time@plt>
mov    %eax,-0x324(%rbp)
lea    -0x324(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x330(%rbp)
lea    -0x320(%rbp),%rdi
mov    -0x330(%rbp),%rcx
mov    $0x64,%esi
lea    0x912(%rip),%rdx
call   10e0 <strftime@plt>
lea    -0x320(%rbp),%rax
mov    %rax,-0x5e0(%rbp)
mov    $0x0,%al
call   1080 <getpid@plt>
mov    -0x5e0(%rbp),%rsi
mov    %eax,%edx
lea    0x941(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    -0x22c(%rbp),%esi
add    $0x4,%esi
mov    -0x224(%rbp),%edx
mov    -0x10(%rbp),%rcx
lea    0x9ca(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
lea    0x910(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    0x2863(%rip),%rax
mov    (%rax),%edi
call   10d0 <fflush@plt>
mov    -0x8(%rbp),%edi
mov    -0x224(%rbp),%esi
shl    $0x1,%esi
add    $0x1,%esi
call   1040 <unlock@plt>
cmpl   $0x0,-0x22c(%rbp)
jg     1782 <reader_from_shared_memory+0x592>
jmp    17b8 <reader_from_shared_memory+0x5c8>
mov    -0x224(%rbp),%eax
add    $0x1,%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %edx,-0x224(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x224(%rbp),%ecx
shl    $0x10,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x238(%rbp)
jmp    1629 <reader_from_shared_memory+0x439>
jmp    17bd <reader_from_shared_memory+0x5cd>
xor    %eax,%eax
mov    %eax,%edi
call   10c0 <time@plt>
mov    %eax,-0x3a4(%rbp)
lea    -0x3a4(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x3b0(%rbp)
lea    -0x3a0(%rbp),%rdi
mov    -0x3b0(%rbp),%rcx
mov    $0x64,%esi
lea    0x807(%rip),%rdx
call   10e0 <strftime@plt>
lea    -0x3a0(%rbp),%rax
mov    %rax,-0x5e8(%rbp)
mov    $0x0,%al
call   1080 <getpid@plt>
mov    -0x5e8(%rbp),%rsi
mov    %eax,%edx
lea    0x836(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
lea    0x8fe(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
lea    0x818(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    0x276b(%rip),%rax
mov    (%rax),%edi
call   10d0 <fflush@plt>
mov    -0x124(%rbp),%edi
call   10a0 <close@plt>
cmp    $0xffffffff,%eax
jne    1943 <reader_from_shared_memory+0x753>
xor    %eax,%eax
mov    %eax,%edi
call   10c0 <time@plt>
mov    %eax,-0x424(%rbp)
lea    -0x424(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x430(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x430(%rbp),%rcx
mov    $0x64,%esi
lea    0x75c(%rip),%rdx
call   10e0 <strftime@plt>
lea    -0x420(%rbp),%rax
mov    %rax,-0x5f0(%rbp)
mov    $0x0,%al
call   1080 <getpid@plt>
mov    -0x5f0(%rbp),%rsi
mov    %eax,%edx
lea    0x745(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
lea    0x743(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
lea    0x73b(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
lea    0x736(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    -0x10(%rbp),%rsi
lea    0x83e(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    0x26b0(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    %rax,%rsi
lea    0x729(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    0x2681(%rip),%rax
mov    (%rax),%edi
call   10d0 <fflush@plt>
jmp    19de <reader_from_shared_memory+0x7ee>
xor    %eax,%eax
mov    %eax,%edi
call   10c0 <time@plt>
mov    %eax,-0x4a4(%rbp)
lea    -0x4a4(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x4b0(%rbp)
lea    -0x4a0(%rbp),%rdi
mov    -0x4b0(%rbp),%rcx
mov    $0x64,%esi
lea    0x681(%rip),%rdx
call   10e0 <strftime@plt>
lea    -0x4a0(%rbp),%rax
mov    %rax,-0x5f8(%rbp)
mov    $0x0,%al
call   1080 <getpid@plt>
mov    -0x5f8(%rbp),%rsi
mov    %eax,%edx
lea    0x6b0(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    -0x10(%rbp),%rsi
lea    0x7a1(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
lea    0x68e(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    0x25e1(%rip),%rax
mov    (%rax),%edi
call   10d0 <fflush@plt>
mov    -0x20(%rbp),%rdi
call   1060 <shmdt@plt>
cmp    $0xffffffff,%eax
jne    1ac7 <reader_from_shared_memory+0x8d7>
xor    %eax,%eax
mov    %eax,%edi
call   10c0 <time@plt>
mov    %eax,-0x524(%rbp)
lea    -0x524(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x530(%rbp)
lea    -0x520(%rbp),%rdi
mov    -0x530(%rbp),%rcx
mov    $0x64,%esi
lea    0x5d4(%rip),%rdx
call   10e0 <strftime@plt>
lea    -0x520(%rbp),%rax
mov    %rax,-0x600(%rbp)
mov    $0x0,%al
call   1080 <getpid@plt>
mov    -0x600(%rbp),%rsi
mov    %eax,%edx
lea    0x5bd(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
lea    0x5bb(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
lea    0x5b3(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
lea    0x5ae(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
lea    0x6f3(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    0x252c(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    %rax,%rsi
lea    0x5a5(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    0x24fd(%rip),%rax
mov    (%rax),%edi
call   10d0 <fflush@plt>
jmp    1b5e <reader_from_shared_memory+0x96e>
xor    %eax,%eax
mov    %eax,%edi
call   10c0 <time@plt>
mov    %eax,-0x5a4(%rbp)
lea    -0x5a4(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x5b0(%rbp)
lea    -0x5a0(%rbp),%rdi
mov    -0x5b0(%rbp),%rcx
mov    $0x64,%esi
lea    0x4fd(%rip),%rdx
call   10e0 <strftime@plt>
lea    -0x5a0(%rbp),%rax
mov    %rax,-0x608(%rbp)
mov    $0x0,%al
call   1080 <getpid@plt>
mov    -0x608(%rbp),%rsi
mov    %eax,%edx
lea    0x52c(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
lea    0x665(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
lea    0x50e(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    0x2461(%rip),%rax
mov    (%rax),%edi
call   10d0 <fflush@plt>
mov    -0x14(%rbp),%eax
add    $0x610,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reader_from_shared_memory>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x98,%rsp
mov    %rdx,%r12
mov    %esi,%ebx
mov    0x2d93(%rip),%rax
mov    (%rax),%r14d
mov    0x2da9(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1110 <shmat@plt>
mov    %rax,0x18(%rsp)
xor    %edi,%edi
cmp    $0xffffffffffffffff,%rax
je     1502 <reader_from_shared_memory+0x302>
call   10d0 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1040 <localtime@plt>
lea    0xda5(%rip),%rdx
lea    0x30(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x64,%esi
mov    %rax,%rcx
call   10f0 <strftime@plt>
xor    %eax,%eax
call   1090 <getpid@plt>
lea    0xddb(%rip),%rdi
mov    %rbp,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   10a0 <printf@plt>
lea    0xdd5(%rip),%rdi
xor    %eax,%eax
call   10a0 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x2d0f(%rip),%r15
mov    (%r15),%edi
call   10e0 <fflush@plt>
mov    0x2ce8(%rip),%rax
mov    0x2d39(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2d26(%rip),%rax
or     (%rax),%esi
mov    %r12,%rdi
mov    $0x1b6,%edx
call   1100 <open@plt>
cmp    $0xffffffff,%eax
je     15bf <reader_from_shared_memory+0x3bf>
mov    %eax,%ebp
mov    %r14d,0x24(%rsp)
xor    %edi,%edi
call   10d0 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1040 <localtime@plt>
lea    0xcfb(%rip),%r13
mov    %ebx,0x14(%rsp)
lea    0x30(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x64,%esi
mov    %r13,%rdx
mov    %rax,%rcx
call   10f0 <strftime@plt>
xor    %eax,%eax
call   1090 <getpid@plt>
mov    %r15,%r14
lea    0xd27(%rip),%r15
mov    %r15,%rdi
mov    %rbx,%rsi
mov    0x14(%rsp),%ebx
mov    %eax,%edx
xor    %eax,%eax
call   10a0 <printf@plt>
lea    0xd75(%rip),%rdi
mov    %r12,0x28(%rsp)
mov    %r12,%rsi
xor    %eax,%eax
call   10a0 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    (%r14),%edi
mov    %r14,%r12
call   10e0 <fflush@plt>
xor    %edi,%edi
call   10d0 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1040 <localtime@plt>
lea    0x30(%rsp),%r14
mov    %r14,%rdi
mov    $0x64,%esi
mov    %r13,%rdx
mov    %rax,%rcx
call   10f0 <strftime@plt>
xor    %eax,%eax
call   1090 <getpid@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   10a0 <printf@plt>
lea    0xd31(%rip),%rdi
xor    %eax,%eax
call   10a0 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    (%r12),%edi
call   10e0 <fflush@plt>
mov    0x18(%rsp),%r14
xor    %r12d,%r12d
nopl   0x0(%rax)
lea    (%r12,%r12,1),%r13d
mov    %ebx,%edi
mov    %r13d,%esi
call   1060 <lock@plt>
lea    0x10(%rsp),%rdi
mov    %r14,%rsi
mov    $0x4,%edx
call   10c0 <memcpy@plt>
mov    0x10(%rsp),%edx
test   %edx,%edx
jle    142c <reader_from_shared_memory+0x22c>
add    $0x4,%r14
xor    %eax,%eax
xchg   %ax,%ax
movslq %eax,%r15
lea    (%r14,%r15,1),%rsi
sub    %r15d,%edx
mov    %ebp,%edi
call   1080 <write@plt>
add    %r15d,%eax
mov    0x10(%rsp),%edx
cmp    %eax,%edx
jg     1410 <reader_from_shared_memory+0x210>
xor    %edi,%edi
call   10d0 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1040 <localtime@plt>
lea    0x30(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x64,%esi
lea    0xbab(%rip),%rdx
mov    %rax,%rcx
call   10f0 <strftime@plt>
xor    %eax,%eax
call   1090 <getpid@plt>
lea    0xbee(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   10a0 <printf@plt>
mov    0x10(%rsp),%esi
add    $0x4,%esi
lea    0xc7e(%rip),%rdi
mov    %r12d,%edx
mov    0x28(%rsp),%rcx
xor    %eax,%eax
call   10a0 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x2b13(%rip),%rax
mov    (%rax),%edi
call   10e0 <fflush@plt>
or     $0x1,%r13d
mov    0x14(%rsp),%ebx
mov    %ebx,%edi
mov    %r13d,%esi
call   1050 <unlock@plt>
cmpl   $0x0,0x10(%rsp)
jle    14f3 <reader_from_shared_memory+0x2f3>
lea    0x1(%r12),%eax
lea    0x10(%r12),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0xfffffff0,%ecx
neg    %ecx
add    %ecx,%r12d
add    $0x1,%r12d
mov    %r12d,%eax
shl    $0x10,%eax
movslq %eax,%r14
add    0x18(%rsp),%r14
jmp    13e0 <reader_from_shared_memory+0x1e0>
mov    0x24(%rsp),%r15d
mov    0x28(%rsp),%r12
jmp    167b <reader_from_shared_memory+0x47b>
call   10d0 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1040 <localtime@plt>
lea    0xae4(%rip),%rdx
lea    0x30(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x64,%esi
mov    %rax,%rcx
call   10f0 <strftime@plt>
xor    %eax,%eax
call   1090 <getpid@plt>
lea    0xad4(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   10a0 <printf@plt>
lea    0xacd(%rip),%rdi
xor    %eax,%eax
call   10a0 <printf@plt>
lea    0xac5(%rip),%rdi
xor    %eax,%eax
call   10a0 <printf@plt>
lea    0xac0(%rip),%rdi
xor    %eax,%eax
call   10a0 <printf@plt>
lea    0xab7(%rip),%rdi
xor    %eax,%eax
call   10a0 <printf@plt>
mov    0x2a3e(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
lea    0xaba(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   10a0 <printf@plt>
mov    0x2a0f(%rip),%rax
mov    (%rax),%edi
call   10e0 <fflush@plt>
mov    0x2a09(%rip),%rax
mov    (%rax),%r15d
jmp    167b <reader_from_shared_memory+0x47b>
xor    %edi,%edi
call   10d0 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1040 <localtime@plt>
lea    0xa25(%rip),%rdx
lea    0x30(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x64,%esi
mov    %rax,%rcx
call   10f0 <strftime@plt>
xor    %eax,%eax
call   1090 <getpid@plt>
lea    0xa15(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   10a0 <printf@plt>
lea    0xa0e(%rip),%rdi
xor    %eax,%eax
call   10a0 <printf@plt>
lea    0xa06(%rip),%rdi
xor    %eax,%eax
call   10a0 <printf@plt>
lea    0xa01(%rip),%rdi
xor    %eax,%eax
call   10a0 <printf@plt>
lea    0xa58(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   10a0 <printf@plt>
mov    0x297c(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
lea    0x9f8(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   10a0 <printf@plt>
mov    (%r15),%edi
call   10e0 <fflush@plt>
mov    0x294d(%rip),%rax
mov    (%rax),%r15d
mov    $0xffffffff,%ebp
xor    %edi,%edi
call   10d0 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1040 <localtime@plt>
lea    0x969(%rip),%rdx
lea    0x30(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x64,%esi
mov    %rax,%rcx
call   10f0 <strftime@plt>
xor    %eax,%eax
call   1090 <getpid@plt>
lea    0x99f(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   10a0 <printf@plt>
lea    0xa62(%rip),%rdi
xor    %eax,%eax
call   10a0 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x28d3(%rip),%r14
mov    (%r14),%edi
call   10e0 <fflush@plt>
mov    %ebp,%edi
call   10b0 <close@plt>
xor    %edi,%edi
cmp    $0xffffffff,%eax
je     1764 <reader_from_shared_memory+0x564>
call   10d0 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1040 <localtime@plt>
lea    0x8eb(%rip),%rdx
lea    0x30(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x64,%esi
mov    %rax,%rcx
call   10f0 <strftime@plt>
xor    %eax,%eax
call   1090 <getpid@plt>
lea    0x921(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   10a0 <printf@plt>
lea    0xa11(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   10a0 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1807 <reader_from_shared_memory+0x607>
call   10d0 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1040 <localtime@plt>
lea    0x882(%rip),%rdx
lea    0x30(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x64,%esi
mov    %rax,%rcx
call   10f0 <strftime@plt>
xor    %eax,%eax
call   1090 <getpid@plt>
lea    0x872(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   10a0 <printf@plt>
lea    0x86b(%rip),%rdi
xor    %eax,%eax
call   10a0 <printf@plt>
lea    0x863(%rip),%rdi
xor    %eax,%eax
call   10a0 <printf@plt>
lea    0x85e(%rip),%rdi
xor    %eax,%eax
call   10a0 <printf@plt>
lea    0x96a(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   10a0 <printf@plt>
mov    0x27d9(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
lea    0x855(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   10a0 <printf@plt>
mov    (%r14),%edi
call   10e0 <fflush@plt>
mov    0x18(%rsp),%rdi
call   1070 <shmdt@plt>
xor    %edi,%edi
cmp    $0xffffffff,%eax
je     1886 <reader_from_shared_memory+0x686>
call   10d0 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1040 <localtime@plt>
lea    0x7c6(%rip),%rdx
lea    0x30(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x64,%esi
mov    %rax,%rcx
call   10f0 <strftime@plt>
xor    %eax,%eax
call   1090 <getpid@plt>
lea    0x7fc(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   10a0 <printf@plt>
lea    0x930(%rip),%rdi
xor    %eax,%eax
call   10a0 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1926 <reader_from_shared_memory+0x726>
call   10d0 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1040 <localtime@plt>
lea    0x760(%rip),%rdx
lea    0x30(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x64,%esi
mov    %rax,%rcx
call   10f0 <strftime@plt>
xor    %eax,%eax
call   1090 <getpid@plt>
lea    0x750(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   10a0 <printf@plt>
lea    0x749(%rip),%rdi
xor    %eax,%eax
call   10a0 <printf@plt>
lea    0x741(%rip),%rdi
xor    %eax,%eax
call   10a0 <printf@plt>
lea    0x73c(%rip),%rdi
xor    %eax,%eax
call   10a0 <printf@plt>
lea    0x881(%rip),%rdi
xor    %eax,%eax
call   10a0 <printf@plt>
mov    0x26ba(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
lea    0x736(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   10a0 <printf@plt>
mov    (%r14),%edi
call   10e0 <fflush@plt>
mov    %r15d,%eax
add    $0x98,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@EXIT_SUCCESS = global i32 0
@SHM_RDONLY = global i32 0
@.str = [19 x i8] c"%d/%m/%Y %H:%M:%S \00"
@.str.1 = [12 x i8] c"%s [pid=%d]\00"
@.str.2 = [6 x i8] c"\1B[31m\00"
@.str.3 = [9 x i8] c" ERROR! \00"
@.str.4 = [5 x i8] c"\1B[0m\00"
@.str.5 = [31 x i8] c"Shared memory wan not attached\00"
@.str.6 = [7 x i8] c" (%s)\0A\00"
@errno = global i32 0
@stdout = global i32 0
@EXIT_FAILURE = global i32 0
@.str.7 = [13 x i8] c"%s [pid=%d] \00"
@.str.8 = [45 x i8] c"shared memory was attached to writer process\00"
@.str.9 = [2 x i8] c"\0A\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.10 = [46 x i8] c"\22%s\22 was not opened for writing and truncated\00"
@.str.11 = [42 x i8] c"\22%s\22 was opened for writing and truncated\00"
@.str.12 = [24 x i8] c"reading process started\00"
@.str.13 = [44 x i8] c"%d bytes was copied from buffer[%d] to \22%s\22\00"
@.str.14 = [25 x i8] c"reading process finished\00"
@.str.15 = [20 x i8] c"\22%s\22 was not closed\00"
@.str.16 = [37 x i8] c"\22%s\22 was closed from write only mode\00"
@.str.17 = [31 x i8] c"Shared memory was not detached\00"
@.str.18 = [39 x i8] c"shared memory was detached from reader\00"
define i32 @reader_from_shared_memory(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca [101 x i8]
%10 = alloca i32
%11 = alloca %struct.tm*
%12 = alloca [101 x i8]
%13 = alloca i32
%14 = alloca %struct.tm*
%15 = alloca i32
%16 = alloca [101 x i8]
%17 = alloca i32
%18 = alloca %struct.tm*
%19 = alloca [101 x i8]
%20 = alloca i32
%21 = alloca %struct.tm*
%22 = alloca i32
%23 = alloca i32
%24 = alloca i32
%25 = alloca i8*
%26 = alloca [101 x i8]
%27 = alloca i32
%28 = alloca %struct.tm*
%29 = alloca [101 x i8]
%30 = alloca i32
%31 = alloca %struct.tm*
%32 = alloca [101 x i8]
%33 = alloca i32
%34 = alloca %struct.tm*
%35 = alloca [101 x i8]
%36 = alloca i32
%37 = alloca %struct.tm*
%38 = alloca [101 x i8]
%39 = alloca i32
%40 = alloca %struct.tm*
%41 = alloca [101 x i8]
%42 = alloca i32
%43 = alloca %struct.tm*
%44 = alloca [101 x i8]
%45 = alloca i32
%46 = alloca %struct.tm*
store i32 %0, i32* %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%47 = load i32, i32* @EXIT_SUCCESS
store i32 %47, i32* %7
%48 = load i32, i32* %4
%49 = load i32, i32* @SHM_RDONLY
%50 = call i8* @shmat(i32 %48, i32* null, i32 %49)
store i8* %50, i8** %8
%51 = load i8*, i8** %8
%52 = icmp eq i8* %51, inttoptr (i64 -1 to i8*)
br i1 %52, label %53, label %73
53: ; preds = %3
%54 = call i32 @time(i32* null)
store i32 %54, i32* %10
%55 = call %struct.tm* @localtime(i32* %10)
store %struct.tm* %55, %struct.tm** %11
%56 = getelementptr inbounds [101 x i8], [101 x i8]* %9, i64 0, i64 0
%57 = load %struct.tm*, %struct.tm** %11
%58 = call i32 @strftime(i8* %56, i32 100, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), %struct.tm* %57)
%59 = getelementptr inbounds [101 x i8], [101 x i8]* %9, i64 0, i64 0
%60 = call i64 (...) @getpid()
%61 = trunc i64 %60 to i32
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %59, i32 %61)
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0))
%67 = load i32, i32* @errno
%68 = call i8* @strerror(i32 %67)
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i8* %68)
%70 = load i32, i32* @stdout
%71 = call i32 @fflush(i32 %70)
%72 = load i32, i32* @EXIT_FAILURE
store i32 %72, i32* %7
br label %210
73: ; preds = %3
%74 = call i32 @time(i32* null)
store i32 %74, i32* %13
%75 = call %struct.tm* @localtime(i32* %13)
store %struct.tm* %75, %struct.tm** %14
%76 = getelementptr inbounds [101 x i8], [101 x i8]* %12, i64 0, i64 0
%77 = load %struct.tm*, %struct.tm** %14
%78 = call i32 @strftime(i8* %76, i32 100, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), %struct.tm* %77)
%79 = getelementptr inbounds [101 x i8], [101 x i8]* %12, i64 0, i64 0
%80 = call i64 (...) @getpid()
%81 = trunc i64 %80 to i32
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i8* %79, i32 %81)
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.8, i64 0, i64 0))
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
%85 = load i32, i32* @stdout
%86 = call i32 @fflush(i32 %85)
br label %87
87: ; preds = %73
%88 = load i8*, i8** %6
%89 = load i32, i32* @O_WRONLY
%90 = load i32, i32* @O_CREAT
%91 = or i32 %89, %90
%92 = load i32, i32* @O_TRUNC
%93 = or i32 %91, %92
%94 = call i32 @open(i8* %88, i32 %93, i32 438)
store i32 %94, i32* %15
%95 = load i32, i32* %15
%96 = icmp eq i32 %95, -1
br i1 %96, label %97, label %118
97: ; preds = %87
%98 = call i32 @time(i32* null)
store i32 %98, i32* %17
%99 = call %struct.tm* @localtime(i32* %17)
store %struct.tm* %99, %struct.tm** %18
%100 = getelementptr inbounds [101 x i8], [101 x i8]* %16, i64 0, i64 0
%101 = load %struct.tm*, %struct.tm** %18
%102 = call i32 @strftime(i8* %100, i32 100, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), %struct.tm* %101)
%103 = getelementptr inbounds [101 x i8], [101 x i8]* %16, i64 0, i64 0
%104 = call i64 (...) @getpid()
%105 = trunc i64 %104 to i32
%106 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %103, i32 %105)
%107 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%108 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%109 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%110 = load i8*, i8** %6
%111 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.10, i64 0, i64 0), i8* %110)
%112 = load i32, i32* @errno
%113 = call i8* @strerror(i32 %112)
%114 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i8* %113)
%115 = load i32, i32* @stdout
%116 = call i32 @fflush(i32 %115)
%117 = load i32, i32* @EXIT_FAILURE
store i32 %117, i32* %7
br label %210
118: ; preds = %87
%119 = call i32 @time(i32* null)
store i32 %119, i32* %20
%120 = call %struct.tm* @localtime(i32* %20)
store %struct.tm* %120, %struct.tm** %21
%121 = getelementptr inbounds [101 x i8], [101 x i8]* %19, i64 0, i64 0
%122 = load %struct.tm*, %struct.tm** %21
%123 = call i32 @strftime(i8* %121, i32 100, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), %struct.tm* %122)
%124 = getelementptr inbounds [101 x i8], [101 x i8]* %19, i64 0, i64 0
%125 = call i64 (...) @getpid()
%126 = trunc i64 %125 to i32
%127 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i8* %124, i32 %126)
%128 = load i8*, i8** %6
%129 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.11, i64 0, i64 0), i8* %128)
%130 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
%131 = load i32, i32* @stdout
%132 = call i32 @fflush(i32 %131)
br label %133
133: ; preds = %118
store i32 0, i32* %22
store i32 0, i32* %23
%134 = load i8*, i8** %8
store i8* %134, i8** %25
%135 = call i32 @time(i32* null)
store i32 %135, i32* %27
%136 = call %struct.tm* @localtime(i32* %27)
store %struct.tm* %136, %struct.tm** %28
%137 = getelementptr inbounds [101 x i8], [101 x i8]* %26, i64 0, i64 0
%138 = load %struct.tm*, %struct.tm** %28
%139 = call i32 @strftime(i8* %137, i32 100, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), %struct.tm* %138)
%140 = getelementptr inbounds [101 x i8], [101 x i8]* %26, i64 0, i64 0
%141 = call i64 (...) @getpid()
%142 = trunc i64 %141 to i32
%143 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i8* %140, i32 %142)
%144 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.12, i64 0, i64 0))
%145 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
%146 = load i32, i32* @stdout
%147 = call i32 @fflush(i32 %146)
br label %148
148: ; preds = %133, %200
%149 = load i32, i32* %5
%150 = load i32, i32* %22
%151 = mul nsw i32 2, %150
%152 = call i32 @lock(i32 %149, i32 %151)
%153 = load i8*, i8** %25
%154 = call i32 @memcpy(i32* %24, i8* %153, i32 4)
store i32 0, i32* %23
br label %155
155: ; preds = %159, %148
%156 = load i32, i32* %23
%157 = load i32, i32* %24
%158 = icmp slt i32 %156, %157
br i1 %158, label %159, label %174
159: ; preds = %155
%160 = load i32, i32* %15
%161 = load i8*, i8** %25
%162 = load i32, i32* %23
%163 = sext i32 %162 to i64
%164 = getelementptr i8, i8* %161, i64 %163
%165 = getelementptr i8, i8* %164, i64 4
%166 = load i32, i32* %24
%167 = load i32, i32* %23
%168 = sub nsw i32 %166, %167
%169 = call i64 @write(i32 %160, i8* %165, i32 %168)
%170 = load i32, i32* %23
%171 = sext i32 %170 to i64
%172 = add nsw i64 %171, %169
%173 = trunc i64 %172 to i32
store i32 %173, i32* %23
br label %155
174: ; preds = %155
%175 = call i32 @time(i32* null)
store i32 %175, i32* %30
%176 = call %struct.tm* @localtime(i32* %30)
store %struct.tm* %176, %struct.tm** %31
%177 = getelementptr inbounds [101 x i8], [101 x i8]* %29, i64 0, i64 0
%178 = load %struct.tm*, %struct.tm** %31
%179 = call i32 @strftime(i8* %177, i32 100, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), %struct.tm* %178)
%180 = getelementptr inbounds [101 x i8], [101 x i8]* %29, i64 0, i64 0
%181 = call i64 (...) @getpid()
%182 = trunc i64 %181 to i32
%183 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i8* %180, i32 %182)
%184 = load i32, i32* %24
%185 = add nsw i32 %184, 4
%186 = load i32, i32* %22
%187 = load i8*, i8** %6
%188 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.13, i64 0, i64 0), i32 %185, i32 %186, i8* %187)
%189 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
%190 = load i32, i32* @stdout
%191 = call i32 @fflush(i32 %190)
%192 = load i32, i32* %5
%193 = load i32, i32* %22
%194 = mul nsw i32 2, %193
%195 = add nsw i32 %194, 1
%196 = call i32 @unlock(i32 %192, i32 %195)
%197 = load i32, i32* %24
%198 = icmp sle i32 %197, 0
br i1 %198, label %199, label %200
199: ; preds = %174
br label %209
200: ; preds = %174
%201 = load i32, i32* %22
%202 = add nsw i32 %201, 1
%203 = srem i32 %202, 16
store i32 %203, i32* %22
%204 = load i8*, i8** %8
%205 = load i32, i32* %22
%206 = mul nsw i32 %205, 65536
%207 = sext i32 %206 to i64
%208 = getelementptr i8, i8* %204, i64 %207
store i8* %208, i8** %25
br label %148
209: ; preds = %199
br label %210
210: ; preds = %209, %97, %53
%211 = call i32 @time(i32* null)
store i32 %211, i32* %33
%212 = call %struct.tm* @localtime(i32* %33)
store %struct.tm* %212, %struct.tm** %34
%213 = getelementptr inbounds [101 x i8], [101 x i8]* %32, i64 0, i64 0
%214 = load %struct.tm*, %struct.tm** %34
%215 = call i32 @strftime(i8* %213, i32 100, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), %struct.tm* %214)
%216 = getelementptr inbounds [101 x i8], [101 x i8]* %32, i64 0, i64 0
%217 = call i64 (...) @getpid()
%218 = trunc i64 %217 to i32
%219 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i8* %216, i32 %218)
%220 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.14, i64 0, i64 0))
%221 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
%222 = load i32, i32* @stdout
%223 = call i32 @fflush(i32 %222)
%224 = load i32, i32* %15
%225 = call i32 @close(i32 %224)
%226 = icmp eq i32 %225, -1
br i1 %226, label %227, label %247
227: ; preds = %210
%228 = call i32 @time(i32* null)
store i32 %228, i32* %36
%229 = call %struct.tm* @localtime(i32* %36)
store %struct.tm* %229, %struct.tm** %37
%230 = getelementptr inbounds [101 x i8], [101 x i8]* %35, i64 0, i64 0
%231 = load %struct.tm*, %struct.tm** %37
%232 = call i32 @strftime(i8* %230, i32 100, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), %struct.tm* %231)
%233 = getelementptr inbounds [101 x i8], [101 x i8]* %35, i64 0, i64 0
%234 = call i64 (...) @getpid()
%235 = trunc i64 %234 to i32
%236 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %233, i32 %235)
%237 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%238 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%239 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%240 = load i8*, i8** %6
%241 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.15, i64 0, i64 0), i8* %240)
%242 = load i32, i32* @errno
%243 = call i8* @strerror(i32 %242)
%244 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i8* %243)
%245 = load i32, i32* @stdout
%246 = call i32 @fflush(i32 %245)
br label %262
247: ; preds = %210
%248 = call i32 @time(i32* null)
store i32 %248, i32* %39
%249 = call %struct.tm* @localtime(i32* %39)
store %struct.tm* %249, %struct.tm** %40
%250 = getelementptr inbounds [101 x i8], [101 x i8]* %38, i64 0, i64 0
%251 = load %struct.tm*, %struct.tm** %40
%252 = call i32 @strftime(i8* %250, i32 100, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), %struct.tm* %251)
%253 = getelementptr inbounds [101 x i8], [101 x i8]* %38, i64 0, i64 0
%254 = call i64 (...) @getpid()
%255 = trunc i64 %254 to i32
%256 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i8* %253, i32 %255)
%257 = load i8*, i8** %6
%258 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.16, i64 0, i64 0), i8* %257)
%259 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
%260 = load i32, i32* @stdout
%261 = call i32 @fflush(i32 %260)
br label %262
262: ; preds = %247, %227
%263 = load i8*, i8** %8
%264 = call i32 @shmdt(i8* %263)
%265 = icmp eq i32 %264, -1
br i1 %265, label %266, label %285
266: ; preds = %262
%267 = call i32 @time(i32* null)
store i32 %267, i32* %42
%268 = call %struct.tm* @localtime(i32* %42)
store %struct.tm* %268, %struct.tm** %43
%269 = getelementptr inbounds [101 x i8], [101 x i8]* %41, i64 0, i64 0
%270 = load %struct.tm*, %struct.tm** %43
%271 = call i32 @strftime(i8* %269, i32 100, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), %struct.tm* %270)
%272 = getelementptr inbounds [101 x i8], [101 x i8]* %41, i64 0, i64 0
%273 = call i64 (...) @getpid()
%274 = trunc i64 %273 to i32
%275 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %272, i32 %274)
%276 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%277 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%278 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%279 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.17, i64 0, i64 0))
%280 = load i32, i32* @errno
%281 = call i8* @strerror(i32 %280)
%282 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i8* %281)
%283 = load i32, i32* @stdout
%284 = call i32 @fflush(i32 %283)
br label %299
285: ; preds = %262
%286 = call i32 @time(i32* null)
store i32 %286, i32* %45
%287 = call %struct.tm* @localtime(i32* %45)
store %struct.tm* %287, %struct.tm** %46
%288 = getelementptr inbounds [101 x i8], [101 x i8]* %44, i64 0, i64 0
%289 = load %struct.tm*, %struct.tm** %46
%290 = call i32 @strftime(i8* %288, i32 100, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), %struct.tm* %289)
%291 = getelementptr inbounds [101 x i8], [101 x i8]* %44, i64 0, i64 0
%292 = call i64 (...) @getpid()
%293 = trunc i64 %292 to i32
%294 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i8* %291, i32 %293)
%295 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.18, i64 0, i64 0))
%296 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
%297 = load i32, i32* @stdout
%298 = call i32 @fflush(i32 %297)
br label %299
299: ; preds = %285, %266
%300 = load i32, i32* %7
ret i32 %300
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@EXIT_SUCCESS = global i32 0
@SHM_RDONLY = global i32 0
@.str = [19 x i8] c"%d/%m/%Y %H:%M:%S \00"
@.str.1 = [12 x i8] c"%s [pid=%d]\00"
@.str.2 = [6 x i8] c"\1B[31m\00"
@.str.3 = [9 x i8] c" ERROR! \00"
@.str.4 = [5 x i8] c"\1B[0m\00"
@.str.5 = [31 x i8] c"Shared memory wan not attached\00"
@.str.6 = [7 x i8] c" (%s)\0A\00"
@errno = global i32 0
@stdout = global i32 0
@EXIT_FAILURE = global i32 0
@.str.7 = [13 x i8] c"%s [pid=%d] \00"
@.str.8 = [45 x i8] c"shared memory was attached to writer process\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.10 = [46 x i8] c"\22%s\22 was not opened for writing and truncated\00"
@.str.11 = [42 x i8] c"\22%s\22 was opened for writing and truncated\00"
@.str.12 = [24 x i8] c"reading process started\00"
@.str.13 = [44 x i8] c"%d bytes was copied from buffer[%d] to \22%s\22\00"
@.str.14 = [25 x i8] c"reading process finished\00"
@.str.15 = [20 x i8] c"\22%s\22 was not closed\00"
@.str.16 = [37 x i8] c"\22%s\22 was closed from write only mode\00"
@.str.17 = [31 x i8] c"Shared memory was not detached\00"
@.str.18 = [39 x i8] c"shared memory was detached from reader\00"
define i32 @reader_from_shared_memory(i32 %0, i32 %1, i8* %2) {
%4 = alloca [101 x i8]
%5 = alloca i32
%6 = alloca [101 x i8]
%7 = alloca i32
%8 = alloca [101 x i8]
%9 = alloca i32
%10 = alloca [101 x i8]
%11 = alloca i32
%12 = alloca i32
%13 = alloca [101 x i8]
%14 = alloca i32
%15 = alloca [101 x i8]
%16 = alloca i32
%17 = alloca [101 x i8]
%18 = alloca i32
%19 = alloca [101 x i8]
%20 = alloca i32
%21 = alloca [101 x i8]
%22 = alloca i32
%23 = alloca [101 x i8]
%24 = alloca i32
%25 = alloca [101 x i8]
%26 = alloca i32
%27 = load i32, i32* @EXIT_SUCCESS
%28 = load i32, i32* @SHM_RDONLY
%29 = tail call i8* @shmat(i32 %0, i32* null, i32 %28)
%30 = icmp eq i8* %29, inttoptr (i64 -1 to i8*)
br i1 %30, label %31, label %50
31: ; preds = %3
%32 = getelementptr inbounds [101 x i8], [101 x i8]* %4, i64 0, i64 0
%33 = bitcast i32* %5 to i8*
%34 = tail call i32 @time(i32* null)
store i32 %34, i32* %5
%35 = call %struct.tm* @localtime(i32* %5)
%36 = call i32 @strftime(i8* %32, i32 100, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), %struct.tm* %35)
%37 = call i64 (...) @getpid()
%38 = trunc i64 %37 to i32
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %32, i32 %38)
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0))
%44 = load i32, i32* @errno
%45 = call i8* @strerror(i32 %44)
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i8* %45)
%47 = load i32, i32* @stdout
%48 = call i32 @fflush(i32 %47)
%49 = load i32, i32* @EXIT_FAILURE
br label %160
50: ; preds = %3
%51 = getelementptr inbounds [101 x i8], [101 x i8]* %6, i64 0, i64 0
%52 = bitcast i32* %7 to i8*
%53 = tail call i32 @time(i32* null)
store i32 %53, i32* %7
%54 = call %struct.tm* @localtime(i32* %7)
%55 = call i32 @strftime(i8* %51, i32 100, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), %struct.tm* %54)
%56 = call i64 (...) @getpid()
%57 = trunc i64 %56 to i32
%58 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i8* %51, i32 %57)
%59 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.8, i64 0, i64 0))
%60 = call i32 @putchar(i32 10)
%61 = load i32, i32* @stdout
%62 = call i32 @fflush(i32 %61)
%63 = load i32, i32* @O_WRONLY
%64 = load i32, i32* @O_CREAT
%65 = or i32 %64, %63
%66 = load i32, i32* @O_TRUNC
%67 = or i32 %65, %66
%68 = call i32 @open(i8* %2, i32 %67, i32 438)
%69 = icmp eq i32 %68, -1
br i1 %69, label %70, label %89
70: ; preds = %50
%71 = getelementptr inbounds [101 x i8], [101 x i8]* %8, i64 0, i64 0
%72 = bitcast i32* %9 to i8*
%73 = call i32 @time(i32* null)
store i32 %73, i32* %9
%74 = call %struct.tm* @localtime(i32* %9)
%75 = call i32 @strftime(i8* %71, i32 100, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), %struct.tm* %74)
%76 = call i64 (...) @getpid()
%77 = trunc i64 %76 to i32
%78 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %71, i32 %77)
%79 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%80 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%81 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%82 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.10, i64 0, i64 0), i8* %2)
%83 = load i32, i32* @errno
%84 = call i8* @strerror(i32 %83)
%85 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i8* %84)
%86 = load i32, i32* @stdout
%87 = call i32 @fflush(i32 %86)
%88 = load i32, i32* @EXIT_FAILURE
br label %160
89: ; preds = %50
%90 = getelementptr inbounds [101 x i8], [101 x i8]* %10, i64 0, i64 0
%91 = bitcast i32* %11 to i8*
%92 = call i32 @time(i32* null)
store i32 %92, i32* %11
%93 = call %struct.tm* @localtime(i32* %11)
%94 = call i32 @strftime(i8* %90, i32 100, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), %struct.tm* %93)
%95 = call i64 (...) @getpid()
%96 = trunc i64 %95 to i32
%97 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i8* %90, i32 %96)
%98 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.11, i64 0, i64 0), i8* %2)
%99 = call i32 @putchar(i32 10)
%100 = load i32, i32* @stdout
%101 = call i32 @fflush(i32 %100)
%102 = getelementptr inbounds [101 x i8], [101 x i8]* %13, i64 0, i64 0
%103 = bitcast i32* %14 to i8*
%104 = call i32 @time(i32* null)
store i32 %104, i32* %14
%105 = call %struct.tm* @localtime(i32* %14)
%106 = call i32 @strftime(i8* %102, i32 100, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), %struct.tm* %105)
%107 = call i64 (...) @getpid()
%108 = trunc i64 %107 to i32
%109 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i8* %102, i32 %108)
%110 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.12, i64 0, i64 0))
%111 = call i32 @putchar(i32 10)
%112 = load i32, i32* @stdout
%113 = call i32 @fflush(i32 %112)
%114 = getelementptr inbounds [101 x i8], [101 x i8]* %15, i64 0, i64 0
%115 = bitcast i32* %16 to i8*
br label %116
116: ; preds = %154, %89
%117 = phi i8* [ %29, %89 ], [ %159, %154 ]
%118 = phi i32 [ 0, %89 ], [ %156, %154 ]
%119 = shl nsw i32 %118, 1
%120 = call i32 @lock(i32 %1, i32 %119)
%121 = call i32 @memcpy(i32* %12, i8* %117, i32 4)
%122 = load i32, i32* %12
%123 = icmp sgt i32 %122, 0
br i1 %123, label %124, label %137
124: ; preds = %116
%125 = getelementptr i8, i8* %117, i64 4
br label %126
126: ; preds = %124, %126
%127 = phi i32 [ %135, %126 ], [ %122, %124 ]
%128 = phi i32 [ %134, %126 ], [ 0, %124 ]
%129 = sext i32 %128 to i64
%130 = getelementptr i8, i8* %125, i64 %129
%131 = sub nsw i32 %127, %128
%132 = call i64 @write(i32 %68, i8* %130, i32 %131)
%133 = trunc i64 %132 to i32
%134 = add i32 %128, %133
%135 = load i32, i32* %12
%136 = icmp sgt i32 %135, %134
br i1 %136, label %126, label %137
137: ; preds = %126, %116
%138 = call i32 @time(i32* null)
store i32 %138, i32* %16
%139 = call %struct.tm* @localtime(i32* %16)
%140 = call i32 @strftime(i8* %114, i32 100, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), %struct.tm* %139)
%141 = call i64 (...) @getpid()
%142 = trunc i64 %141 to i32
%143 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i8* %114, i32 %142)
%144 = load i32, i32* %12
%145 = add nsw i32 %144, 4
%146 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.13, i64 0, i64 0), i32 %145, i32 %118, i8* %2)
%147 = call i32 @putchar(i32 10)
%148 = load i32, i32* @stdout
%149 = call i32 @fflush(i32 %148)
%150 = or i32 %119, 1
%151 = call i32 @unlock(i32 %1, i32 %150)
%152 = load i32, i32* %12
%153 = icmp slt i32 %152, 1
br i1 %153, label %160, label %154
154: ; preds = %137
%155 = add nsw i32 %118, 1
%156 = srem i32 %155, 16
%157 = shl nsw i32 %156, 16
%158 = sext i32 %157 to i64
%159 = getelementptr i8, i8* %29, i64 %158
br label %116
160: ; preds = %137, %70, %31
%161 = phi i32 [ undef, %31 ], [ -1, %70 ], [ %68, %137 ]
%162 = phi i32 [ %49, %31 ], [ %88, %70 ], [ %27, %137 ]
%163 = getelementptr inbounds [101 x i8], [101 x i8]* %17, i64 0, i64 0
%164 = bitcast i32* %18 to i8*
%165 = call i32 @time(i32* null)
store i32 %165, i32* %18
%166 = call %struct.tm* @localtime(i32* %18)
%167 = call i32 @strftime(i8* %163, i32 100, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), %struct.tm* %166)
%168 = call i64 (...) @getpid()
%169 = trunc i64 %168 to i32
%170 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i8* %163, i32 %169)
%171 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.14, i64 0, i64 0))
%172 = call i32 @putchar(i32 10)
%173 = load i32, i32* @stdout
%174 = call i32 @fflush(i32 %173)
%175 = call i32 @close(i32 %161)
%176 = icmp eq i32 %175, -1
br i1 %176, label %177, label %195
177: ; preds = %160
%178 = getelementptr inbounds [101 x i8], [101 x i8]* %19, i64 0, i64 0
%179 = bitcast i32* %20 to i8*
%180 = call i32 @time(i32* null)
store i32 %180, i32* %20
%181 = call %struct.tm* @localtime(i32* %20)
%182 = call i32 @strftime(i8* %178, i32 100, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), %struct.tm* %181)
%183 = call i64 (...) @getpid()
%184 = trunc i64 %183 to i32
%185 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %178, i32 %184)
%186 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%187 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%188 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%189 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.15, i64 0, i64 0), i8* %2)
%190 = load i32, i32* @errno
%191 = call i8* @strerror(i32 %190)
%192 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i8* %191)
%193 = load i32, i32* @stdout
%194 = call i32 @fflush(i32 %193)
br label %208
195: ; preds = %160
%196 = getelementptr inbounds [101 x i8], [101 x i8]* %21, i64 0, i64 0
%197 = bitcast i32* %22 to i8*
%198 = call i32 @time(i32* null)
store i32 %198, i32* %22
%199 = call %struct.tm* @localtime(i32* %22)
%200 = call i32 @strftime(i8* %196, i32 100, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), %struct.tm* %199)
%201 = call i64 (...) @getpid()
%202 = trunc i64 %201 to i32
%203 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i8* %196, i32 %202)
%204 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.16, i64 0, i64 0), i8* %2)
%205 = call i32 @putchar(i32 10)
%206 = load i32, i32* @stdout
%207 = call i32 @fflush(i32 %206)
br label %208
208: ; preds = %195, %177
%209 = call i32 @shmdt(i8* %29)
%210 = icmp eq i32 %209, -1
br i1 %210, label %211, label %229
211: ; preds = %208
%212 = getelementptr inbounds [101 x i8], [101 x i8]* %23, i64 0, i64 0
%213 = bitcast i32* %24 to i8*
%214 = call i32 @time(i32* null)
store i32 %214, i32* %24
%215 = call %struct.tm* @localtime(i32* %24)
%216 = call i32 @strftime(i8* %212, i32 100, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), %struct.tm* %215)
%217 = call i64 (...) @getpid()
%218 = trunc i64 %217 to i32
%219 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %212, i32 %218)
%220 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%221 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%222 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%223 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.17, i64 0, i64 0))
%224 = load i32, i32* @errno
%225 = call i8* @strerror(i32 %224)
%226 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i8* %225)
%227 = load i32, i32* @stdout
%228 = call i32 @fflush(i32 %227)
br label %242
229: ; preds = %208
%230 = getelementptr inbounds [101 x i8], [101 x i8]* %25, i64 0, i64 0
%231 = bitcast i32* %26 to i8*
%232 = call i32 @time(i32* null)
store i32 %232, i32* %26
%233 = call %struct.tm* @localtime(i32* %26)
%234 = call i32 @strftime(i8* %230, i32 100, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), %struct.tm* %233)
%235 = call i64 (...) @getpid()
%236 = trunc i64 %235 to i32
%237 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i8* %230, i32 %236)
%238 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.18, i64 0, i64 0))
%239 = call i32 @putchar(i32 10)
%240 = load i32, i32* @stdout
%241 = call i32 @fflush(i32 %240)
br label %242
242: ; preds = %229, %211
ret i32 %162
}