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

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ SEEK_CUR;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int errno;
int lseek(int, int, int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int write(int, char *, int);
int main() {
  char readBuffer[256] = {0};
  char writeBuffer[] = "writeme";
  int fl = open("/folder", O_RDWR);
  printf("read from folder: %d\n", read(fl, readBuffer, sizeof readBuffer));
  printf("errno: %d\n", errno);
  errno = 0;
  printf("write to folder: %d\n", write(fl, writeBuffer, sizeof writeBuffer));
  printf("errno: %d\n\n", errno);
  errno = 0;
  int bd = open("/broken-device", O_RDWR);
  printf("read from broken device: %d\n",
         read(bd, readBuffer, sizeof readBuffer));
  printf("errno: %d\n", errno);
  errno = 0;
  printf("write to broken device: %d\n",
         write(bd, writeBuffer, sizeof writeBuffer));
  printf("errno: %d\n\n", errno);
  errno = 0;
  int d = open("/device", O_RDWR);
  printf("read from device: %d\n", read(d, readBuffer, sizeof readBuffer));
  printf("data: %s\n", readBuffer);
  memset(readBuffer, 0, sizeof readBuffer);
  printf("errno: %d\n", errno);
  errno = 0;
  printf("write to device: %d\n", write(d, writeBuffer, sizeof writeBuffer));
  printf("errno: %d\n\n", errno);
  errno = 0;
  int f = open("/file", O_RDWR);
  printf("read from file: %d\n", read(f, readBuffer, sizeof readBuffer));
  printf("data: %s\n", readBuffer);
  memset(readBuffer, 0, sizeof readBuffer);
  printf("errno: %d\n\n", errno);
  errno = 0;
  printf("seek: %d\n", lseek(f, 3, SEEK_SET));
  printf("errno: %d\n\n", errno);
  printf("partial read from file: %d\n", read(f, readBuffer, 3));
  printf("data: %s\n", readBuffer);
  memset(readBuffer, 0, sizeof readBuffer);
  printf("errno: %d\n\n", errno);
  errno = 0;
  printf("seek: %d\n", lseek(f, -2, SEEK_END));
  printf("errno: %d\n", errno);
  errno = 0;
  printf("partial read from end of file: %d\n", read(f, readBuffer, 3));
  printf("data: %s\n", readBuffer);
  memset(readBuffer, 0, sizeof readBuffer);
  printf("errno: %d\n\n", errno);
  errno = 0;
  printf("seek: %d\n", lseek(f, -15, SEEK_CUR));
  printf("errno: %d\n", errno);
  errno = 0;
  printf("partial read from before start of file: %d\n",
         read(f, readBuffer, 3));
  printf("data: %s\n", readBuffer);
  memset(readBuffer, 0, sizeof readBuffer);
  printf("errno: %d\n\n", errno);
  errno = 0;
  printf("seek: %d\n", lseek(f, 0, SEEK_SET));
  printf("write to start of file: %d\n", write(f, writeBuffer, 3));
  printf("errno: %d\n\n", errno);
  errno = 0;
  printf("seek: %d\n", lseek(f, 0, SEEK_END));
  printf("write to end of file: %d\n", write(f, writeBuffer, 3));
  printf("errno: %d\n\n", errno);
  errno = 0;
  printf("seek: %d\n", lseek(f, 10, SEEK_END));
  printf("write after end of file: %d\n",
         write(f, writeBuffer, sizeof writeBuffer));
  printf("errno: %d\n\n", errno);
  errno = 0;
  int bytesRead;
  printf("seek: %d\n", lseek(f, 0, SEEK_SET));
  printf("read after write: %d\n",
         bytesRead = read(f, readBuffer, sizeof readBuffer));
  printf("errno: %d\n", errno);
  errno = 0;
  printf("final: ");
  for (int i = 0; i < bytesRead; i++) {
    if (readBuffer[i] == 0) {
      printf("\\0");
    } else {
      printf("%c", readBuffer[i]);
    }
  }
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
mov    0xe74(%rip),%rax
mov    %rax,-0x118(%rbp)
mov    0x2e4e(%rip),%rax
mov    (%rax),%esi
lea    0xe65(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x11c(%rbp)
mov    -0x11c(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    $0x100,%edx
call   1070 <read@plt>
mov    %eax,%esi
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2dec(%rip),%rax
mov    (%rax),%esi
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2dd5(%rip),%rax
movl   $0x0,(%rax)
mov    -0x11c(%rbp),%edi
lea    -0x118(%rbp),%rsi
mov    $0x8,%edx
call   1030 <write@plt>
mov    %eax,%esi
lea    0xe18(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2da1(%rip),%rax
mov    (%rax),%esi
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2d8a(%rip),%rax
movl   $0x0,(%rax)
mov    0x2d9d(%rip),%rax
mov    (%rax),%esi
lea    0xdfe(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x120(%rbp)
mov    -0x120(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    $0x100,%edx
call   1070 <read@plt>
mov    %eax,%esi
lea    0xde2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2d3b(%rip),%rax
mov    (%rax),%esi
lea    0xd90(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2d24(%rip),%rax
movl   $0x0,(%rax)
mov    -0x120(%rbp),%edi
lea    -0x118(%rbp),%rsi
mov    $0x8,%edx
call   1030 <write@plt>
mov    %eax,%esi
lea    0xdb4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2cf0(%rip),%rax
mov    (%rax),%esi
lea    0xd65(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2cd9(%rip),%rax
movl   $0x0,(%rax)
mov    0x2cec(%rip),%rax
mov    (%rax),%esi
lea    0xd95(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x124(%rbp)
mov    -0x124(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    $0x100,%edx
call   1070 <read@plt>
mov    %eax,%esi
lea    0xd72(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x110(%rbp),%rsi
lea    0xd73(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
mov    0x2c62(%rip),%rax
mov    (%rax),%esi
lea    0xcb7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2c4b(%rip),%rax
movl   $0x0,(%rax)
mov    -0x124(%rbp),%edi
lea    -0x118(%rbp),%rsi
mov    $0x8,%edx
call   1030 <write@plt>
mov    %eax,%esi
lea    0xd1f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2c17(%rip),%rax
mov    (%rax),%esi
lea    0xc8c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2c00(%rip),%rax
movl   $0x0,(%rax)
mov    0x2c13(%rip),%rax
mov    (%rax),%esi
lea    0xcf9(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x128(%rbp)
mov    -0x128(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    $0x100,%edx
call   1070 <read@plt>
mov    %eax,%esi
lea    0xce6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x110(%rbp),%rsi
lea    0xc9a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
mov    0x2b89(%rip),%rax
mov    (%rax),%esi
lea    0xbfe(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2b72(%rip),%rax
movl   $0x0,(%rax)
mov    -0x128(%rbp),%edi
mov    0x2b57(%rip),%rax
mov    (%rax),%edx
mov    $0x3,%esi
call   1050 <lseek@plt>
mov    %eax,%esi
lea    0xc5f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2b3c(%rip),%rax
mov    (%rax),%esi
lea    0xbb1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x128(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    $0x3,%edx
call   1070 <read@plt>
mov    %eax,%esi
lea    0xc2b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x110(%rbp),%rsi
lea    0xbe7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
mov    0x2ad6(%rip),%rax
mov    (%rax),%esi
lea    0xb4b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2abf(%rip),%rax
movl   $0x0,(%rax)
mov    -0x128(%rbp),%edi
mov    0x2ac4(%rip),%rax
mov    (%rax),%edx
mov    $0xfffffffe,%esi
call   1050 <lseek@plt>
mov    %eax,%esi
lea    0xbac(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2a89(%rip),%rax
mov    (%rax),%esi
lea    0xade(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2a72(%rip),%rax
movl   $0x0,(%rax)
mov    -0x128(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    $0x3,%edx
call   1070 <read@plt>
mov    %eax,%esi
lea    0xb87(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x110(%rbp),%rsi
lea    0xb27(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
mov    0x2a16(%rip),%rax
mov    (%rax),%esi
lea    0xa8b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x29ff(%rip),%rax
movl   $0x0,(%rax)
mov    -0x128(%rbp),%edi
mov    0x29fc(%rip),%rax
mov    (%rax),%edx
mov    $0xfffffff1,%esi
call   1050 <lseek@plt>
mov    %eax,%esi
lea    0xaec(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x29c9(%rip),%rax
mov    (%rax),%esi
lea    0xa1e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x29b2(%rip),%rax
movl   $0x0,(%rax)
mov    -0x128(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    $0x3,%edx
call   1070 <read@plt>
mov    %eax,%esi
lea    0xaea(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x110(%rbp),%rsi
lea    0xa67(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
mov    0x2956(%rip),%rax
mov    (%rax),%esi
lea    0x9cb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x293f(%rip),%rax
movl   $0x0,(%rax)
mov    -0x128(%rbp),%edi
mov    0x2924(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <lseek@plt>
mov    %eax,%esi
lea    0xa2f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x128(%rbp),%edi
lea    -0x118(%rbp),%rsi
mov    $0x3,%edx
call   1030 <write@plt>
mov    %eax,%esi
lea    0xa7d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x28e5(%rip),%rax
mov    (%rax),%esi
lea    0x95a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x28ce(%rip),%rax
movl   $0x0,(%rax)
mov    -0x128(%rbp),%edi
mov    0x28d3(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <lseek@plt>
mov    %eax,%esi
lea    0x9be(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x128(%rbp),%edi
lea    -0x118(%rbp),%rsi
mov    $0x3,%edx
call   1030 <write@plt>
mov    %eax,%esi
lea    0xa28(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2874(%rip),%rax
mov    (%rax),%esi
lea    0x8e9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x285d(%rip),%rax
movl   $0x0,(%rax)
mov    -0x128(%rbp),%edi
mov    0x2862(%rip),%rax
mov    (%rax),%edx
mov    $0xa,%esi
call   1050 <lseek@plt>
mov    %eax,%esi
lea    0x94a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x128(%rbp),%edi
lea    -0x118(%rbp),%rsi
mov    $0x8,%edx
call   1030 <write@plt>
mov    %eax,%esi
lea    0x9ce(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2800(%rip),%rax
mov    (%rax),%esi
lea    0x875(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x27e9(%rip),%rax
movl   $0x0,(%rax)
mov    -0x128(%rbp),%edi
mov    0x27ce(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <lseek@plt>
mov    %eax,%esi
lea    0x8d9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x128(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    $0x100,%edx
call   1070 <read@plt>
mov    %eax,%esi
mov    %esi,-0x12c(%rbp)
lea    0x974(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2789(%rip),%rax
mov    (%rax),%esi
lea    0x7de(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2772(%rip),%rax
movl   $0x0,(%rax)
lea    0x958(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x130(%rbp)
mov    -0x130(%rbp),%eax
cmp    -0x12c(%rbp),%eax
jge    18e7 <main+0x787>
movslq -0x130(%rbp),%rax
movsbl -0x110(%rbp,%rax,1),%eax
ff
cmp    $0x0,%eax
jne    18b1 <main+0x751>
lea    0x91e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    18ce <main+0x76e>
movslq -0x130(%rbp),%rax
movsbl -0x110(%rbp,%rax,1),%esi
ff
lea    0x8ff(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    18d3 <main+0x773>
mov    -0x130(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x130(%rbp)
jmp    1874 <main+0x714>
lea    0x762(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x100(%rsp)
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movabs $0x656d6574697277,%rax
mov    %rax,0x8(%rsp)
mov    0x2de3(%rip),%rbx
mov    (%rbx),%esi
lea    0xdf2(%rip),%rdi
call   1090 <open@plt>
mov    %eax,%ebp
lea    0x10(%rsp),%rsi
mov    %eax,%edi
mov    $0x100,%edx
call   1080 <read@plt>
lea    0xddb(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2d8b(%rip),%r15
mov    (%r15),%esi
lea    0xdd7(%rip),%r12
mov    %r12,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movl   $0x0,(%r15)
lea    0x8(%rsp),%r13
mov    %ebp,%edi
mov    %r13,%rsi
mov    $0x8,%edx
call   1040 <write@plt>
lea    0xdb6(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%r15),%esi
lea    0xdb8(%rip),%r14
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movl   $0x0,(%r15)
mov    (%rbx),%esi
lea    0xdaa(%rip),%rdi
call   1090 <open@plt>
mov    %eax,%ebp
mov    %eax,%edi
lea    0x10(%rsp),%rsi
mov    $0x100,%edx
call   1080 <read@plt>
lea    0xd9a(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%r15),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movl   $0x0,(%r15)
mov    %ebp,%edi
mov    %r13,%rsi
mov    $0x8,%edx
call   1040 <write@plt>
lea    0xd84(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%r15),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movl   $0x0,(%r15)
mov    (%rbx),%esi
lea    0xd7a(%rip),%rdi
call   1090 <open@plt>
mov    %eax,%ebp
mov    %eax,%edi
lea    0x10(%rsp),%r14
mov    %r14,%rsi
mov    $0x100,%edx
call   1080 <read@plt>
lea    0xd60(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xd66(%rip),%r12
mov    %r12,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1070 <memset@plt>
mov    (%r15),%esi
lea    0xcae(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movl   $0x0,(%r15)
mov    %ebp,%edi
mov    %r13,%rsi
mov    $0x8,%edx
call   1040 <write@plt>
lea    0xd26(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%r15),%esi
lea    0xc97(%rip),%rdi
mov    %rdi,%rbx
xor    %eax,%eax
call   1050 <printf@plt>
movl   $0x0,(%r15)
mov    0x2c29(%rip),%rax
mov    (%rax),%esi
lea    0xd07(%rip),%rdi
call   1090 <open@plt>
mov    %eax,%ebp
mov    %eax,%edi
mov    %r14,%rsi
mov    $0x100,%edx
call   1080 <read@plt>
lea    0xd02(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12,%rdi
mov    %r12,%r13
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1070 <memset@plt>
mov    (%r15),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movl   $0x0,(%r15)
mov    0x2b98(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
mov    $0x3,%esi
call   1060 <lseek@plt>
lea    0xc98(%rip),%r12
mov    %r12,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%r15),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x3,%edx
call   1080 <read@plt>
lea    0xc73(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r13,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1070 <memset@plt>
mov    (%r15),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movl   $0x0,(%r15)
mov    0x2b34(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
mov    $0xfffffffe,%esi
call   1060 <lseek@plt>
mov    %r12,%rdi
mov    %r12,%r13
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%r15),%esi
lea    0xb4b(%rip),%rbx
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movl   $0x0,(%r15)
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x3,%edx
call   1080 <read@plt>
lea    0xc01(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xba6(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1070 <memset@plt>
mov    (%r15),%esi
lea    0xb11(%rip),%r12
mov    %r12,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movl   $0x0,(%r15)
mov    0x2a93(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
mov    $0xfffffff1,%esi
call   1060 <lseek@plt>
mov    %r13,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%r15),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movl   $0x0,(%r15)
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x3,%edx
call   1080 <read@plt>
lea    0xb95(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xb17(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1070 <memset@plt>
mov    (%r15),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movl   $0x0,(%r15)
mov    0x29f3(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
xor    %esi,%esi
call   1060 <lseek@plt>
mov    %r13,%rdi
mov    %r13,%r14
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,%edi
lea    0x8(%rsp),%rbx
mov    %rbx,%rsi
mov    $0x3,%edx
call   1040 <write@plt>
lea    0xb48(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%r15),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movl   $0x0,(%r15)
mov    0x29ba(%rip),%r13
mov    0x0(%r13),%edx
mov    %ebp,%edi
xor    %esi,%esi
call   1060 <lseek@plt>
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x3,%edx
call   1040 <write@plt>
lea    0xb11(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%r15),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movl   $0x0,(%r15)
mov    0x0(%r13),%edx
mov    %ebp,%edi
mov    $0xa,%esi
call   1060 <lseek@plt>
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x8,%edx
call   1040 <write@plt>
lea    0xadc(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%r15),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movl   $0x0,(%r15)
mov    0x28f8(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
xor    %esi,%esi
call   1060 <lseek@plt>
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,%edi
lea    0x10(%rsp),%rsi
mov    $0x100,%edx
call   1080 <read@plt>
mov    %eax,%ebx
lea    0xaa4(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%r15),%esi
lea    0x912(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movl   $0x0,(%r15)
lea    0xa92(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
test   %ebx,%ebx
jle    1763 <main+0x5f3>
mov    %ebx,%ebp
lea    0xa86(%rip),%r14
xor    %ebx,%ebx
jmp    174e <main+0x5de>
nopl   0x0(%rax)
call   1030 <putchar@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
je     1763 <main+0x5f3>
movsbl 0x10(%rsp,%rbx,1),%edi
test   %edi,%edi
jne    1740 <main+0x5d0>
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1745 <main+0x5d5>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.writeBuffer = [8 x i8] c"writeme\00"
@.str = [8 x i8] c"/folder\00"
@O_RDWR = global i32 0
@.str.1 = [22 x i8] c"read from folder: %d\0A\00"
@.str.2 = [11 x i8] c"errno: %d\0A\00"
@errno = global i32 0
@.str.3 = [21 x i8] c"write to folder: %d\0A\00"
@.str.4 = [12 x i8] c"errno: %d\0A\0A\00"
@.str.5 = [15 x i8] c"/broken-device\00"
@.str.6 = [29 x i8] c"read from broken device: %d\0A\00"
@.str.7 = [28 x i8] c"write to broken device: %d\0A\00"
@.str.8 = [8 x i8] c"/device\00"
@.str.9 = [22 x i8] c"read from device: %d\0A\00"
@.str.10 = [10 x i8] c"data: %s\0A\00"
@.str.11 = [21 x i8] c"write to device: %d\0A\00"
@.str.12 = [6 x i8] c"/file\00"
@.str.13 = [20 x i8] c"read from file: %d\0A\00"
@.str.14 = [10 x i8] c"seek: %d\0A\00"
@SEEK_SET = global i32 0
@.str.15 = [28 x i8] c"partial read from file: %d\0A\00"
@SEEK_END = global i32 0
@.str.16 = [35 x i8] c"partial read from end of file: %d\0A\00"
@SEEK_CUR = global i32 0
@.str.17 = [44 x i8] c"partial read from before start of file: %d\0A\00"
@.str.18 = [28 x i8] c"write to start of file: %d\0A\00"
@.str.19 = [26 x i8] c"write to end of file: %d\0A\00"
@.str.20 = [29 x i8] c"write after end of file: %d\0A\00"
@.str.21 = [22 x i8] c"read after write: %d\0A\00"
@.str.22 = [8 x i8] c"final: \00"
@.str.23 = [3 x i8] c"\\0\00"
@.str.24 = [3 x i8] c"%c\00"
@.str.25 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [256 x i8]
%3 = alloca [8 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %1
%10 = bitcast [256 x i8]* %2 to i8*
%11 = bitcast [8 x i8]* %3 to i8*
%12 = load i32, i32* @O_RDWR
%13 = call i32 @open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %12)
store i32 %13, i32* %4
%14 = load i32, i32* %4
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%16 = call i32 @read(i32 %14, i8* %15, i32 256)
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%18 = load i32, i32* @errno
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %18)
store i32 0, i32* @errno
%20 = load i32, i32* %4
%21 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%22 = call i32 @write(i32 %20, i8* %21, i32 8)
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %22)
%24 = load i32, i32* @errno
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %24)
store i32 0, i32* @errno
%26 = load i32, i32* @O_RDWR
%27 = call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i32 %26)
store i32 %27, i32* %5
%28 = load i32, i32* %5
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%30 = call i32 @read(i32 %28, i8* %29, i32 256)
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0), i32 %30)
%32 = load i32, i32* @errno
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %32)
store i32 0, i32* @errno
%34 = load i32, i32* %5
%35 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%36 = call i32 @write(i32 %34, i8* %35, i32 8)
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0), i32 %36)
%38 = load i32, i32* @errno
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %38)
store i32 0, i32* @errno
%40 = load i32, i32* @O_RDWR
%41 = call i32 @open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0), i32 %40)
store i32 %41, i32* %6
%42 = load i32, i32* %6
%43 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%44 = call i32 @read(i32 %42, i8* %43, i32 256)
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0), i32 %44)
%46 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i64 0, i64 0), i8* %46)
%48 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%49 = call i32 @memset(i8* %48, i32 0, i32 256)
%50 = load i32, i32* @errno
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %50)
store i32 0, i32* @errno
%52 = load i32, i32* %6
%53 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%54 = call i32 @write(i32 %52, i8* %53, i32 8)
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.11, i64 0, i64 0), i32 %54)
%56 = load i32, i32* @errno
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %56)
store i32 0, i32* @errno
%58 = load i32, i32* @O_RDWR
%59 = call i32 @open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.12, i64 0, i64 0), i32 %58)
store i32 %59, i32* %7
%60 = load i32, i32* %7
%61 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%62 = call i32 @read(i32 %60, i8* %61, i32 256)
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.13, i64 0, i64 0), i32 %62)
%64 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i64 0, i64 0), i8* %64)
%66 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%67 = call i32 @memset(i8* %66, i32 0, i32 256)
%68 = load i32, i32* @errno
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %68)
store i32 0, i32* @errno
%70 = load i32, i32* %7
%71 = load i32, i32* @SEEK_SET
%72 = call i32 @lseek(i32 %70, i32 3, i32 %71)
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.14, i64 0, i64 0), i32 %72)
%74 = load i32, i32* @errno
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %74)
%76 = load i32, i32* %7
%77 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%78 = call i32 @read(i32 %76, i8* %77, i32 3)
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.15, i64 0, i64 0), i32 %78)
%80 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i64 0, i64 0), i8* %80)
%82 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%83 = call i32 @memset(i8* %82, i32 0, i32 256)
%84 = load i32, i32* @errno
%85 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %84)
store i32 0, i32* @errno
%86 = load i32, i32* %7
%87 = load i32, i32* @SEEK_END
%88 = call i32 @lseek(i32 %86, i32 -2, i32 %87)
%89 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.14, i64 0, i64 0), i32 %88)
%90 = load i32, i32* @errno
%91 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %90)
store i32 0, i32* @errno
%92 = load i32, i32* %7
%93 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%94 = call i32 @read(i32 %92, i8* %93, i32 3)
%95 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.16, i64 0, i64 0), i32 %94)
%96 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%97 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i64 0, i64 0), i8* %96)
%98 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%99 = call i32 @memset(i8* %98, i32 0, i32 256)
%100 = load i32, i32* @errno
%101 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %100)
store i32 0, i32* @errno
%102 = load i32, i32* %7
%103 = load i32, i32* @SEEK_CUR
%104 = call i32 @lseek(i32 %102, i32 -15, i32 %103)
%105 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.14, i64 0, i64 0), i32 %104)
%106 = load i32, i32* @errno
%107 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %106)
store i32 0, i32* @errno
%108 = load i32, i32* %7
%109 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%110 = call i32 @read(i32 %108, i8* %109, i32 3)
%111 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.17, i64 0, i64 0), i32 %110)
%112 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%113 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i64 0, i64 0), i8* %112)
%114 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%115 = call i32 @memset(i8* %114, i32 0, i32 256)
%116 = load i32, i32* @errno
%117 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %116)
store i32 0, i32* @errno
%118 = load i32, i32* %7
%119 = load i32, i32* @SEEK_SET
%120 = call i32 @lseek(i32 %118, i32 0, i32 %119)
%121 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.14, i64 0, i64 0), i32 %120)
%122 = load i32, i32* %7
%123 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%124 = call i32 @write(i32 %122, i8* %123, i32 3)
%125 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.18, i64 0, i64 0), i32 %124)
%126 = load i32, i32* @errno
%127 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %126)
store i32 0, i32* @errno
%128 = load i32, i32* %7
%129 = load i32, i32* @SEEK_END
%130 = call i32 @lseek(i32 %128, i32 0, i32 %129)
%131 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.14, i64 0, i64 0), i32 %130)
%132 = load i32, i32* %7
%133 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%134 = call i32 @write(i32 %132, i8* %133, i32 3)
%135 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.19, i64 0, i64 0), i32 %134)
%136 = load i32, i32* @errno
%137 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %136)
store i32 0, i32* @errno
%138 = load i32, i32* %7
%139 = load i32, i32* @SEEK_END
%140 = call i32 @lseek(i32 %138, i32 10, i32 %139)
%141 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.14, i64 0, i64 0), i32 %140)
%142 = load i32, i32* %7
%143 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%144 = call i32 @write(i32 %142, i8* %143, i32 8)
%145 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.20, i64 0, i64 0), i32 %144)
%146 = load i32, i32* @errno
%147 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %146)
store i32 0, i32* @errno
%148 = load i32, i32* %7
%149 = load i32, i32* @SEEK_SET
%150 = call i32 @lseek(i32 %148, i32 0, i32 %149)
%151 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.14, i64 0, i64 0), i32 %150)
%152 = load i32, i32* %7
%153 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%154 = call i32 @read(i32 %152, i8* %153, i32 256)
store i32 %154, i32* %8
%155 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.21, i64 0, i64 0), i32 %154)
%156 = load i32, i32* @errno
%157 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %156)
store i32 0, i32* @errno
%158 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.22, i64 0, i64 0))
store i32 0, i32* %9
br label %159
159: ; preds = %180, %0
%160 = load i32, i32* %9
%161 = load i32, i32* %8
%162 = icmp slt i32 %160, %161
br i1 %162, label %163, label %183
163: ; preds = %159
%164 = load i32, i32* %9
%165 = sext i32 %164 to i64
%166 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 %165
%167 = load i8, i8* %166
%168 = sext i8 %167 to i32
%169 = icmp eq i32 %168, 0
br i1 %169, label %170, label %172
170: ; preds = %163
%171 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.23, i64 0, i64 0))
br label %179
172: ; preds = %163
%173 = load i32, i32* %9
%174 = sext i32 %173 to i64
%175 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 %174
%176 = load i8, i8* %175
%177 = sext i8 %176 to i32
%178 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.24, i64 0, i64 0), i32 %177)
br label %179
179: ; preds = %172, %170
br label %180
180: ; preds = %179
%181 = load i32, i32* %9
%182 = add nsw i32 %181, 1
store i32 %182, i32* %9
br label %159
183: ; preds = %159
%184 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.25, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"/folder\00"
@O_RDWR = global i32 0
@.str.1 = [22 x i8] c"read from folder: %d\0A\00"
@.str.2 = [11 x i8] c"errno: %d\0A\00"
@errno = global i32 0
@.str.3 = [21 x i8] c"write to folder: %d\0A\00"
@.str.4 = [12 x i8] c"errno: %d\0A\0A\00"
@.str.5 = [15 x i8] c"/broken-device\00"
@.str.6 = [29 x i8] c"read from broken device: %d\0A\00"
@.str.7 = [28 x i8] c"write to broken device: %d\0A\00"
@.str.8 = [8 x i8] c"/device\00"
@.str.9 = [22 x i8] c"read from device: %d\0A\00"
@.str.10 = [10 x i8] c"data: %s\0A\00"
@.str.11 = [21 x i8] c"write to device: %d\0A\00"
@.str.12 = [6 x i8] c"/file\00"
@.str.13 = [20 x i8] c"read from file: %d\0A\00"
@.str.14 = [10 x i8] c"seek: %d\0A\00"
@SEEK_SET = global i32 0
@.str.15 = [28 x i8] c"partial read from file: %d\0A\00"
@SEEK_END = global i32 0
@.str.16 = [35 x i8] c"partial read from end of file: %d\0A\00"
@SEEK_CUR = global i32 0
@.str.17 = [44 x i8] c"partial read from before start of file: %d\0A\00"
@.str.18 = [28 x i8] c"write to start of file: %d\0A\00"
@.str.19 = [26 x i8] c"write to end of file: %d\0A\00"
@.str.20 = [29 x i8] c"write after end of file: %d\0A\00"
@.str.21 = [22 x i8] c"read after write: %d\0A\00"
@.str.22 = [8 x i8] c"final: \00"
@.str.23 = [3 x i8] c"\\0\00"
define i32 @main() {
%1 = alloca [256 x i8]
%2 = alloca i64
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%4 = bitcast i64* %2 to i8*
store i64 28549255159968375, i64* %2
%5 = load i32, i32* @O_RDWR
%6 = tail call i32 @open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = call i32 @read(i32 %6, i8* %3, i32 256)
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = load i32, i32* @errno
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %9)
store i32 0, i32* @errno
%11 = call i32 @write(i32 %6, i8* %4, i32 8)
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %11)
%13 = load i32, i32* @errno
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %13)
store i32 0, i32* @errno
%15 = load i32, i32* @O_RDWR
%16 = tail call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i32 %15)
%17 = call i32 @read(i32 %16, i8* %3, i32 256)
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0), i32 %17)
%19 = load i32, i32* @errno
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %19)
store i32 0, i32* @errno
%21 = call i32 @write(i32 %16, i8* %4, i32 8)
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0), i32 %21)
%23 = load i32, i32* @errno
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %23)
store i32 0, i32* @errno
%25 = load i32, i32* @O_RDWR
%26 = tail call i32 @open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0), i32 %25)
%27 = call i32 @read(i32 %26, i8* %3, i32 256)
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0), i32 %27)
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i64 0, i64 0), i8* %3)
%30 = call i32 @memset(i8* %3, i32 0, i32 256)
%31 = load i32, i32* @errno
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %31)
store i32 0, i32* @errno
%33 = call i32 @write(i32 %26, i8* %4, i32 8)
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.11, i64 0, i64 0), i32 %33)
%35 = load i32, i32* @errno
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %35)
store i32 0, i32* @errno
%37 = load i32, i32* @O_RDWR
%38 = call i32 @open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.12, i64 0, i64 0), i32 %37)
%39 = call i32 @read(i32 %38, i8* %3, i32 256)
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.13, i64 0, i64 0), i32 %39)
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i64 0, i64 0), i8* %3)
%42 = call i32 @memset(i8* %3, i32 0, i32 256)
%43 = load i32, i32* @errno
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %43)
store i32 0, i32* @errno
%45 = load i32, i32* @SEEK_SET
%46 = call i32 @lseek(i32 %38, i32 3, i32 %45)
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.14, i64 0, i64 0), i32 %46)
%48 = load i32, i32* @errno
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %48)
%50 = call i32 @read(i32 %38, i8* %3, i32 3)
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.15, i64 0, i64 0), i32 %50)
%52 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i64 0, i64 0), i8* %3)
%53 = call i32 @memset(i8* %3, i32 0, i32 256)
%54 = load i32, i32* @errno
%55 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %54)
store i32 0, i32* @errno
%56 = load i32, i32* @SEEK_END
%57 = call i32 @lseek(i32 %38, i32 -2, i32 %56)
%58 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.14, i64 0, i64 0), i32 %57)
%59 = load i32, i32* @errno
%60 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %59)
store i32 0, i32* @errno
%61 = call i32 @read(i32 %38, i8* %3, i32 3)
%62 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.16, i64 0, i64 0), i32 %61)
%63 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i64 0, i64 0), i8* %3)
%64 = call i32 @memset(i8* %3, i32 0, i32 256)
%65 = load i32, i32* @errno
%66 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %65)
store i32 0, i32* @errno
%67 = load i32, i32* @SEEK_CUR
%68 = call i32 @lseek(i32 %38, i32 -15, i32 %67)
%69 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.14, i64 0, i64 0), i32 %68)
%70 = load i32, i32* @errno
%71 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %70)
store i32 0, i32* @errno
%72 = call i32 @read(i32 %38, i8* %3, i32 3)
%73 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.17, i64 0, i64 0), i32 %72)
%74 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i64 0, i64 0), i8* %3)
%75 = call i32 @memset(i8* %3, i32 0, i32 256)
%76 = load i32, i32* @errno
%77 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %76)
store i32 0, i32* @errno
%78 = load i32, i32* @SEEK_SET
%79 = call i32 @lseek(i32 %38, i32 0, i32 %78)
%80 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.14, i64 0, i64 0), i32 %79)
%81 = call i32 @write(i32 %38, i8* %4, i32 3)
%82 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.18, i64 0, i64 0), i32 %81)
%83 = load i32, i32* @errno
%84 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %83)
store i32 0, i32* @errno
%85 = load i32, i32* @SEEK_END
%86 = call i32 @lseek(i32 %38, i32 0, i32 %85)
%87 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.14, i64 0, i64 0), i32 %86)
%88 = call i32 @write(i32 %38, i8* %4, i32 3)
%89 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.19, i64 0, i64 0), i32 %88)
%90 = load i32, i32* @errno
%91 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %90)
store i32 0, i32* @errno
%92 = load i32, i32* @SEEK_END
%93 = call i32 @lseek(i32 %38, i32 10, i32 %92)
%94 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.14, i64 0, i64 0), i32 %93)
%95 = call i32 @write(i32 %38, i8* %4, i32 8)
%96 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.20, i64 0, i64 0), i32 %95)
%97 = load i32, i32* @errno
%98 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %97)
store i32 0, i32* @errno
%99 = load i32, i32* @SEEK_SET
%100 = call i32 @lseek(i32 %38, i32 0, i32 %99)
%101 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.14, i64 0, i64 0), i32 %100)
%102 = call i32 @read(i32 %38, i8* %3, i32 256)
%103 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.21, i64 0, i64 0), i32 %102)
%104 = load i32, i32* @errno
%105 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %104)
store i32 0, i32* @errno
%106 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.22, i64 0, i64 0))
%107 = icmp sgt i32 %102, 0
br i1 %107, label %108, label %110
108: ; preds = %0
%109 = zext i32 %102 to i64
br label %112
110: ; preds = %122, %0
%111 = call i32 @putchar(i32 10)
ret i32 0
112: ; preds = %108, %122
%113 = phi i64 [ 0, %108 ], [ %123, %122 ]
%114 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 %113
%115 = load i8, i8* %114
%116 = icmp eq i8 %115, 0
br i1 %116, label %117, label %119
117: ; preds = %112
%118 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.23, i64 0, i64 0))
br label %122
119: ; preds = %112
%120 = sext i8 %115 to i32
%121 = call i32 @putchar(i32 %120)
br label %122
122: ; preds = %117, %119
%123 = add nuw nsw i64 %113, 1
%124 = icmp eq i64 %123, %109
br i1 %124, label %110, label %112
}