#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 */
struct iovec {
  int iov_len;
  struct iovec *iov_base;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EBADF;
int EINVAL;
void *SIZE_MAX;
int errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fileno(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, int, ...);
int /*<<< orphan*/ puts(char *);
int read(int, struct iovec *, int);
int readv(int, struct iovec *, int);
char *strerror(int);
int writev(int, struct iovec *, int);
int doErrorTest(void) {
  FILE *fp;
  int fd;
  struct iovec vec[4];
  int rc;
  fp = fopen("testfile1.tst", "wt");
  if (fp == NULL) {
    printf("fopen for error 1: %d=%s\n", errno, strerror(errno));
    return 0;
  }
  fd = fileno(fp);
  fclose(fp);
  puts("writev bad file descriptor -- EBADF");
  rc = writev(fd, vec, 4);
  if ((rc != -1) || (errno != EBADF)) {
    printf("writev error 1: %d=%s\n", errno, strerror(errno));
    return 0;
  }
  puts("readv bad file descriptor -- EBADF");
  rc = read(fd, vec, 4);
  if ((rc != -1) || (errno != EBADF)) {
    printf("readv error 1: %d=%s\n", errno, strerror(errno));
    return 0;
  }
  fp = fopen("testfile1.tst", "w+");
  if (fp == NULL) {
    printf("fopen for error 2: %d=%s\n", errno, strerror(errno));
    return 0;
  }
  fd = fileno(fp);
  puts("writev bad iovcnt negative -- EINVAL");
  rc = writev(fd, vec, -2);
  if ((rc != -1) || (errno != EINVAL)) {
    printf("writev error 4: %d=%s\n", errno, strerror(errno));
    fclose(fp);
    return 0;
  }
  puts("readv bad iovcnt negative -- EINVAL");
  rc = readv(fd, vec, -100);
  if ((rc != -1) || (errno != EINVAL)) {
    printf("readv error 4: %d=%s\n", errno, strerror(errno));
    fclose(fp);
    return 0;
  }
  vec[0].iov_base = vec;
  vec[0].iov_len = 100;
  vec[1].iov_base = vec;
  vec[1].iov_len = -10;
  puts("writev bad iov[i].iov_len < 0 -- EINVAL");
  rc = writev(fd, vec, 2);
  if ((rc != -1) || (errno != EINVAL)) {
    printf("writev error 6: %d=%s\n", errno, strerror(errno));
    fclose(fp);
    return 0;
  }
  vec[0].iov_base = vec;
  vec[0].iov_len = 100;
  vec[1].iov_base = vec;
  vec[1].iov_len = -1024;
  puts("readv bad iov[i].iov_len < 0 -- EINVAL");
  rc = readv(fd, vec, 2);
  if ((rc != -1) || (errno != EINVAL)) {
    printf("readv error 6: %d=%s\n", errno, strerror(errno));
    fclose(fp);
    return 0;
  }
  vec[0].iov_base = vec;
  vec[0].iov_len = SIZE_MAX;
  vec[1].iov_base = vec;
  vec[1].iov_len = SIZE_MAX;
  vec[2].iov_base = vec;
  vec[2].iov_len = SIZE_MAX;
  puts("writev iov_len total overflows -- EINVAL");
  rc = writev(fd, vec, 3);
  if ((rc != -1) || (errno != EINVAL)) {
    printf("writev error 7: rc=%d %d=%s\n", rc, errno, strerror(errno));
    fclose(fp);
    return 0;
  }
  vec[0].iov_base = vec;
  vec[0].iov_len = SIZE_MAX;
  vec[1].iov_base = vec;
  vec[1].iov_len = SIZE_MAX;
  vec[2].iov_base = vec;
  vec[2].iov_len = SIZE_MAX;
  puts("readv iov_len total overflows -- EINVAL");
  rc = readv(fd, vec, 3);
  if ((rc != -1) || (errno != EINVAL)) {
    printf("read error 7: rc=%d %d=%s\n", rc, errno, strerror(errno));
    fclose(fp);
    return 0;
  }
  vec[0].iov_base = vec;
  vec[0].iov_len = 0;
  vec[1].iov_base = NULL;
  vec[1].iov_len = 0;
  puts("writev iov_len works with no effect -- OK");
  rc = writev(fd, vec, 2);
  if ((rc != 0)) {
    printf("writev error 8: %d=%s\n", errno, strerror(errno));
    fclose(fp);
    return 0;
  }
  vec[0].iov_base = vec;
  vec[0].iov_len = 0;
  vec[1].iov_base = NULL;
  vec[1].iov_len = 0;
  puts("readv iov_len works with no effect -- OK");
  rc = readv(fd, vec, 2);
  if ((rc != 0)) {
    printf("readv error 8: %d=%s\n", errno, strerror(errno));
    fclose(fp);
    return 0;
  }
  fclose(fp);
  return 1;
}


x86 assembly (clang, -O0):
<doErrorTest>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
lea    0xe5e(%rip),%rdi
lea    0xe65(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11f7 <doErrorTest+0x67>
mov    0x2e1c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x68(%rbp)
mov    0x2e10(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x68(%rbp),%esi
mov    %rax,%rdx
lea    0xe2d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    18a6 <doErrorTest+0x716>
mov    -0x10(%rbp),%rdi
call   1080 <fileno@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
lea    0xe18(%rip),%rdi
call   1040 <puts@plt>
mov    -0x14(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    $0x4,%edx
call   1030 <writev@plt>
mov    %eax,-0x64(%rbp)
cmpl   $0xffffffff,-0x64(%rbp)
jne    124e <doErrorTest+0xbe>
mov    0x2da3(%rip),%rax
mov    (%rax),%eax
mov    0x2d8a(%rip),%rcx
cmp    (%rcx),%eax
je     1288 <doErrorTest+0xf8>
mov    0x2d8b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x6c(%rbp)
mov    0x2d7f(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x6c(%rbp),%esi
mov    %rax,%rdx
lea    0xdda(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    18a6 <doErrorTest+0x716>
lea    0xdd7(%rip),%rdi
call   1040 <puts@plt>
mov    -0x14(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    $0x4,%edx
call   1070 <read@plt>
mov    %eax,-0x64(%rbp)
cmpl   $0xffffffff,-0x64(%rbp)
jne    12ca <doErrorTest+0x13a>
mov    0x2d27(%rip),%rax
mov    (%rax),%eax
mov    0x2d0e(%rip),%rcx
cmp    (%rcx),%eax
je     1304 <doErrorTest+0x174>
mov    0x2d0f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x70(%rbp)
mov    0x2d03(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x70(%rbp),%esi
mov    %rax,%rdx
lea    0xd98(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    18a6 <doErrorTest+0x716>
lea    0xcf5(%rip),%rdi
lea    0xd8d(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1360 <doErrorTest+0x1d0>
mov    0x2cb3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x74(%rbp)
mov    0x2ca7(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x74(%rbp),%esi
mov    %rax,%rdx
lea    0xd55(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    18a6 <doErrorTest+0x716>
mov    -0x10(%rbp),%rdi
call   1080 <fileno@plt>
mov    %eax,-0x14(%rbp)
lea    0xd49(%rip),%rdi
call   1040 <puts@plt>
mov    -0x14(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    $0xfffffffe,%edx
call   1030 <writev@plt>
mov    %eax,-0x64(%rbp)
cmpl   $0xffffffff,-0x64(%rbp)
jne    13ae <doErrorTest+0x21e>
mov    0x2c43(%rip),%rax
mov    (%rax),%eax
mov    0x2c32(%rip),%rcx
cmp    (%rcx),%eax
je     13f1 <doErrorTest+0x261>
mov    0x2c2b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x78(%rbp)
mov    0x2c1f(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x78(%rbp),%esi
mov    %rax,%rdx
lea    0xd0c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    18a6 <doErrorTest+0x716>
lea    0xd00(%rip),%rdi
call   1040 <puts@plt>
mov    -0x14(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    $0xffffff9c,%edx
call   1090 <readv@plt>
mov    %eax,-0x64(%rbp)
cmpl   $0xffffffff,-0x64(%rbp)
jne    1433 <doErrorTest+0x2a3>
mov    0x2bbe(%rip),%rax
mov    (%rax),%eax
mov    0x2bad(%rip),%rcx
cmp    (%rcx),%eax
je     1476 <doErrorTest+0x2e6>
mov    0x2ba6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x7c(%rbp)
mov    0x2b9a(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x7c(%rbp),%esi
mov    %rax,%rdx
lea    0xcc2(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    18a6 <doErrorTest+0x716>
lea    -0x60(%rbp),%rax
mov    %rax,-0x58(%rbp)
movl   $0x64,-0x60(%rbp)
lea    -0x60(%rbp),%rax
mov    %rax,-0x48(%rbp)
movl   $0xfffffff6,-0x50(%rbp)
lea    0xc97(%rip),%rdi
call   1040 <puts@plt>
mov    -0x14(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    $0x2,%edx
call   1030 <writev@plt>
mov    %eax,-0x64(%rbp)
cmpl   $0xffffffff,-0x64(%rbp)
jne    14d6 <doErrorTest+0x346>
mov    0x2b1b(%rip),%rax
mov    (%rax),%eax
mov    0x2b0a(%rip),%rcx
cmp    (%rcx),%eax
je     1519 <doErrorTest+0x389>
mov    0x2b03(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x80(%rbp)
mov    0x2af7(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x80(%rbp),%esi
mov    %rax,%rdx
lea    0xc5d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    18a6 <doErrorTest+0x716>
lea    -0x60(%rbp),%rax
mov    %rax,-0x58(%rbp)
movl   $0x64,-0x60(%rbp)
lea    -0x60(%rbp),%rax
mov    %rax,-0x48(%rbp)
movl   $0xfffffc00,-0x50(%rbp)
lea    0xc33(%rip),%rdi
call   1040 <puts@plt>
mov    -0x14(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    $0x2,%edx
call   1090 <readv@plt>
mov    %eax,-0x64(%rbp)
cmpl   $0xffffffff,-0x64(%rbp)
jne    1579 <doErrorTest+0x3e9>
mov    0x2a78(%rip),%rax
mov    (%rax),%eax
mov    0x2a67(%rip),%rcx
cmp    (%rcx),%eax
je     15c2 <doErrorTest+0x432>
mov    0x2a60(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x84(%rbp)
mov    0x2a51(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x84(%rbp),%esi
mov    %rax,%rdx
lea    0xbf2(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    18a6 <doErrorTest+0x716>
lea    -0x60(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    0x29ef(%rip),%rax
mov    (%rax),%rax
mov    %eax,-0x60(%rbp)
lea    -0x60(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    0x29da(%rip),%rax
mov    (%rax),%rax
mov    %eax,-0x50(%rbp)
lea    -0x60(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    0x29c5(%rip),%rax
mov    (%rax),%rax
mov    %eax,-0x40(%rbp)
lea    0xba6(%rip),%rdi
call   1040 <puts@plt>
mov    -0x14(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    $0x3,%edx
call   1030 <writev@plt>
mov    %eax,-0x64(%rbp)
cmpl   $0xffffffff,-0x64(%rbp)
jne    1643 <doErrorTest+0x4b3>
mov    0x29ae(%rip),%rax
mov    (%rax),%eax
mov    0x299d(%rip),%rcx
cmp    (%rcx),%eax
je     169b <doErrorTest+0x50b>
mov    -0x64(%rbp),%eax
mov    %eax,-0x8c(%rbp)
mov    0x298d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x88(%rbp)
mov    0x297e(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x8c(%rbp),%esi
mov    -0x88(%rbp),%edx
mov    %rax,%rcx
lea    0xb58(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    18a6 <doErrorTest+0x716>
lea    -0x60(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    0x2916(%rip),%rax
mov    (%rax),%rax
mov    %eax,-0x60(%rbp)
lea    -0x60(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    0x2901(%rip),%rax
mov    (%rax),%rax
mov    %eax,-0x50(%rbp)
lea    -0x60(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    0x28ec(%rip),%rax
mov    (%rax),%rax
mov    %eax,-0x40(%rbp)
lea    0xb13(%rip),%rdi
call   1040 <puts@plt>
mov    -0x14(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    $0x3,%edx
call   1090 <readv@plt>
mov    %eax,-0x64(%rbp)
cmpl   $0xffffffff,-0x64(%rbp)
jne    171c <doErrorTest+0x58c>
mov    0x28d5(%rip),%rax
mov    (%rax),%eax
mov    0x28c4(%rip),%rcx
cmp    (%rcx),%eax
je     1774 <doErrorTest+0x5e4>
mov    -0x64(%rbp),%eax
mov    %eax,-0x94(%rbp)
mov    0x28b4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x90(%rbp)
mov    0x28a5(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x94(%rbp),%esi
mov    -0x90(%rbp),%edx
mov    %rax,%rcx
lea    0xac4(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    18a6 <doErrorTest+0x716>
lea    -0x60(%rbp),%rax
mov    %rax,-0x58(%rbp)
movl   $0x0,-0x60(%rbp)
movq   $0x0,-0x48(%rbp)
movl   $0x0,-0x50(%rbp)
lea    0xa9e(%rip),%rdi
call   1040 <puts@plt>
mov    -0x14(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    $0x2,%edx
call   1030 <writev@plt>
mov    %eax,-0x64(%rbp)
cmpl   $0x0,-0x64(%rbp)
je     1805 <doErrorTest+0x675>
mov    0x281d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x98(%rbp)
mov    0x280e(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x98(%rbp),%esi
mov    %rax,%rdx
lea    0xa78(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    18a6 <doErrorTest+0x716>
lea    -0x60(%rbp),%rax
mov    %rax,-0x58(%rbp)
movl   $0x0,-0x60(%rbp)
movq   $0x0,-0x48(%rbp)
movl   $0x0,-0x50(%rbp)
lea    0xa4e(%rip),%rdi
call   1040 <puts@plt>
mov    -0x14(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    $0x2,%edx
call   1090 <readv@plt>
mov    %eax,-0x64(%rbp)
cmpl   $0x0,-0x64(%rbp)
je     1896 <doErrorTest+0x706>
mov    0x278c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x9c(%rbp)
mov    0x277d(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x9c(%rbp),%esi
mov    %rax,%rdx
lea    0xa27(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    18a6 <doErrorTest+0x716>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<doErrorTest>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
lea    0xe5b(%rip),%rdi
lea    0xe62(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1464 <doErrorTest+0x2d4>
mov    %rax,%rbp
mov    %rax,%rdi
call   1080 <fileno@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
call   1050 <fclose@plt>
lea    0xe55(%rip),%rdi
call   1040 <puts@plt>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1030 <writev@plt>
mov    0x2def(%rip),%r15
mov    (%r15),%ebp
cmp    $0xffffffff,%eax
jne    147d <doErrorTest+0x2ed>
mov    0x2dcc(%rip),%r14
cmp    (%r14),%ebp
jne    147d <doErrorTest+0x2ed>
lea    0xe52(%rip),%rdi
call   1040 <puts@plt>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1070 <read@plt>
mov    (%r15),%ebp
cmp    $0xffffffff,%eax
jne    148d <doErrorTest+0x2fd>
cmp    (%r14),%ebp
jne    148d <doErrorTest+0x2fd>
lea    0xdbc(%rip),%rdi
lea    0xe54(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     149d <doErrorTest+0x30d>
mov    %rax,%r13
mov    %rax,%rdi
call   1080 <fileno@plt>
mov    %eax,%ebx
lea    0xe4f(%rip),%rdi
call   1040 <puts@plt>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0xfffffffe,%edx
call   1030 <writev@plt>
mov    (%r15),%ebp
cmp    $0xffffffff,%eax
jne    14cd <doErrorTest+0x33d>
mov    0x2d44(%rip),%r12
cmp    (%r12),%ebp
jne    14cd <doErrorTest+0x33d>
lea    0xe53(%rip),%rdi
call   1040 <puts@plt>
mov    %rsp,%r14
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xffffff9c,%edx
call   1090 <readv@plt>
mov    (%r15),%ebp
cmp    $0xffffffff,%eax
jne    14dd <doErrorTest+0x34d>
cmp    (%r12),%ebp
jne    14dd <doErrorTest+0x34d>
mov    %r14,0x8(%rsp)
movl   $0x64,(%rsp)
mov    %r14,0x18(%rsp)
movl   $0xfffffff6,0x10(%rsp)
ff
lea    0xe40(%rip),%rdi
call   1040 <puts@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x2,%edx
call   1030 <writev@plt>
mov    (%r15),%ebp
cmp    $0xffffffff,%eax
jne    14ed <doErrorTest+0x35d>
cmp    (%r12),%ebp
jne    14ed <doErrorTest+0x35d>
mov    %r14,0x8(%rsp)
movl   $0x64,(%rsp)
mov    %r14,0x18(%rsp)
movl   $0xfffffc00,0x10(%rsp)
ff
lea    0xe35(%rip),%rdi
call   1040 <puts@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x2,%edx
call   1090 <readv@plt>
mov    (%r15),%ebp
cmp    $0xffffffff,%eax
jne    14fd <doErrorTest+0x36d>
cmp    (%r12),%ebp
jne    14fd <doErrorTest+0x36d>
mov    %r14,0x8(%rsp)
mov    0x2c4e(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rsp)
mov    %r14,0x18(%rsp)
mov    %eax,0x10(%rsp)
mov    %r14,0x28(%rsp)
mov    %eax,0x20(%rsp)
lea    0xe1e(%rip),%rdi
call   1040 <puts@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x3,%edx
call   1030 <writev@plt>
mov    (%r15),%ebp
cmp    $0xffffffff,%eax
jne    1523 <doErrorTest+0x393>
cmp    (%r12),%ebp
jne    1523 <doErrorTest+0x393>
mov    %r14,0x8(%rsp)
mov    0x2bfa(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rsp)
mov    %r14,0x18(%rsp)
mov    %eax,0x10(%rsp)
mov    %r14,0x28(%rsp)
mov    %eax,0x20(%rsp)
lea    0xe10(%rip),%rdi
call   1040 <puts@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x3,%edx
call   1090 <readv@plt>
mov    (%r15),%ebp
cmp    $0xffffffff,%eax
jne    1536 <doErrorTest+0x3a6>
cmp    (%r12),%ebp
jne    1536 <doErrorTest+0x3a6>
mov    %r14,0x8(%rsp)
movl   $0x0,(%rsp)
movq   $0x0,0x18(%rsp)
movl   $0x0,0x10(%rsp)
lea    0xe05(%rip),%rdi
call   1040 <puts@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x2,%edx
call   1030 <writev@plt>
test   %eax,%eax
je     155a <doErrorTest+0x3ca>
mov    (%r15),%ebp
mov    %ebp,%edi
call   10b0 <strerror@plt>
lea    0xe02(%rip),%rdi
jmp    150b <doErrorTest+0x37b>
mov    0x2b75(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   10b0 <strerror@plt>
lea    0xb96(%rip),%rdi
jmp    14ae <doErrorTest+0x31e>
mov    %ebp,%edi
call   10b0 <strerror@plt>
lea    0xbc4(%rip),%rdi
jmp    14ae <doErrorTest+0x31e>
mov    %ebp,%edi
call   10b0 <strerror@plt>
lea    0xbee(%rip),%rdi
jmp    14ae <doErrorTest+0x31e>
mov    (%r15),%ebp
mov    %ebp,%edi
call   10b0 <strerror@plt>
lea    0xbf4(%rip),%rdi
xor    %ebx,%ebx
mov    %ebp,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebx,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %ebp,%edi
call   10b0 <strerror@plt>
lea    0xc06(%rip),%rdi
jmp    150b <doErrorTest+0x37b>
mov    %ebp,%edi
call   10b0 <strerror@plt>
lea    0xc31(%rip),%rdi
jmp    150b <doErrorTest+0x37b>
mov    %ebp,%edi
call   10b0 <strerror@plt>
lea    0xc5f(%rip),%rdi
jmp    150b <doErrorTest+0x37b>
mov    %ebp,%edi
call   10b0 <strerror@plt>
lea    0xc8d(%rip),%rdi
xor    %ebx,%ebx
mov    %ebp,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r13,%rdi
call   1050 <fclose@plt>
jmp    14bc <doErrorTest+0x32c>
mov    %ebp,%edi
mov    %eax,%r14d
call   10b0 <strerror@plt>
lea    0xca3(%rip),%rdi
jmp    1547 <doErrorTest+0x3b7>
mov    %ebp,%edi
mov    %eax,%r14d
call   10b0 <strerror@plt>
lea    0xcd5(%rip),%rdi
xor    %ebx,%ebx
mov    %r14d,%esi
mov    %ebp,%edx
mov    %rax,%rcx
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1519 <doErrorTest+0x389>
mov    %r14,0x8(%rsp)
movl   $0x0,(%rsp)
movq   $0x0,0x18(%rsp)
movl   $0x0,0x10(%rsp)
lea    0xcfa(%rip),%rdi
call   1040 <puts@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x2,%edx
call   1090 <readv@plt>
test   %eax,%eax
je     15ac <doErrorTest+0x41c>
mov    (%r15),%ebp
mov    %ebp,%edi
call   10b0 <strerror@plt>
lea    0xcfa(%rip),%rdi
jmp    150b <doErrorTest+0x37b>
mov    %r13,%rdi
call   1050 <fclose@plt>
mov    $0x1,%ebx
jmp    14bc <doErrorTest+0x32c>

LLVM IR (-O0):
%struct.iovec = type { i32, %struct.iovec* }
@.str = [14 x i8] c"testfile1.tst\00"
@.str.1 = [3 x i8] c"wt\00"
@.str.2 = [26 x i8] c"fopen for error 1: %d=%s\0A\00"
@errno = global i32 0
@.str.3 = [36 x i8] c"writev bad file descriptor -- EBADF\00"
@EBADF = global i32 0
@.str.4 = [23 x i8] c"writev error 1: %d=%s\0A\00"
@.str.5 = [35 x i8] c"readv bad file descriptor -- EBADF\00"
@.str.6 = [22 x i8] c"readv error 1: %d=%s\0A\00"
@.str.7 = [3 x i8] c"w+\00"
@.str.8 = [26 x i8] c"fopen for error 2: %d=%s\0A\00"
@.str.9 = [37 x i8] c"writev bad iovcnt negative -- EINVAL\00"
@EINVAL = global i32 0
@.str.10 = [23 x i8] c"writev error 4: %d=%s\0A\00"
@.str.11 = [36 x i8] c"readv bad iovcnt negative -- EINVAL\00"
@.str.12 = [22 x i8] c"readv error 4: %d=%s\0A\00"
@.str.13 = [40 x i8] c"writev bad iov[i].iov_len < 0 -- EINVAL\00"
@.str.14 = [23 x i8] c"writev error 6: %d=%s\0A\00"
@.str.15 = [39 x i8] c"readv bad iov[i].iov_len < 0 -- EINVAL\00"
@.str.16 = [22 x i8] c"readv error 6: %d=%s\0A\00"
@SIZE_MAX = global i8* null
@.str.17 = [41 x i8] c"writev iov_len total overflows -- EINVAL\00"
@.str.18 = [29 x i8] c"writev error 7: rc=%d %d=%s\0A\00"
@.str.19 = [40 x i8] c"readv iov_len total overflows -- EINVAL\00"
@.str.20 = [27 x i8] c"read error 7: rc=%d %d=%s\0A\00"
@.str.21 = [42 x i8] c"writev iov_len works with no effect -- OK\00"
@.str.22 = [23 x i8] c"writev error 8: %d=%s\0A\00"
@.str.23 = [41 x i8] c"readv iov_len works with no effect -- OK\00"
@.str.24 = [22 x i8] c"readv error 8: %d=%s\0A\00"
define i32 @doErrorTest() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca [4 x %struct.iovec]
%5 = alloca i32
%6 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %2
%7 = load i32*, i32** %2
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %14
9: ; preds = %0
%10 = load i32, i32* @errno
%11 = load i32, i32* @errno
%12 = call i8* @strerror(i32 %11)
%13 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %10, i8* %12)
store i32 0, i32* %1
br label %282
14: ; preds = %0
%15 = load i32*, i32** %2
%16 = call i32 @fileno(i32* %15)
store i32 %16, i32* %3
%17 = load i32*, i32** %2
%18 = call i32 @fclose(i32* %17)
%19 = call i32 @puts(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
%20 = load i32, i32* %3
%21 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %4, i64 0, i64 0
%22 = call i32 @writev(i32 %20, %struct.iovec* %21, i32 4)
store i32 %22, i32* %5
%23 = load i32, i32* %5
%24 = icmp ne i32 %23, -1
br i1 %24, label %29, label %25
25: ; preds = %14
%26 = load i32, i32* @errno
%27 = load i32, i32* @EBADF
%28 = icmp ne i32 %26, %27
br i1 %28, label %29, label %34
29: ; preds = %25, %14
%30 = load i32, i32* @errno
%31 = load i32, i32* @errno
%32 = call i8* @strerror(i32 %31)
%33 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %30, i8* %32)
store i32 0, i32* %1
br label %282
34: ; preds = %25
%35 = call i32 @puts(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0))
%36 = load i32, i32* %3
%37 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %4, i64 0, i64 0
%38 = call i32 @read(i32 %36, %struct.iovec* %37, i32 4)
store i32 %38, i32* %5
%39 = load i32, i32* %5
%40 = icmp ne i32 %39, -1
br i1 %40, label %45, label %41
41: ; preds = %34
%42 = load i32, i32* @errno
%43 = load i32, i32* @EBADF
%44 = icmp ne i32 %42, %43
br i1 %44, label %45, label %50
45: ; preds = %41, %34
%46 = load i32, i32* @errno
%47 = load i32, i32* @errno
%48 = call i8* @strerror(i32 %47)
%49 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i32 %46, i8* %48)
store i32 0, i32* %1
br label %282
50: ; preds = %41
%51 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
store i32* %51, i32** %2
%52 = load i32*, i32** %2
%53 = icmp eq i32* %52, null
br i1 %53, label %54, label %59
54: ; preds = %50
%55 = load i32, i32* @errno
%56 = load i32, i32* @errno
%57 = call i8* @strerror(i32 %56)
%58 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0), i32 %55, i8* %57)
store i32 0, i32* %1
br label %282
59: ; preds = %50
%60 = load i32*, i32** %2
%61 = call i32 @fileno(i32* %60)
store i32 %61, i32* %3
%62 = call i32 @puts(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.9, i64 0, i64 0))
%63 = load i32, i32* %3
%64 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %4, i64 0, i64 0
%65 = call i32 @writev(i32 %63, %struct.iovec* %64, i32 -2)
store i32 %65, i32* %5
%66 = load i32, i32* %5
%67 = icmp ne i32 %66, -1
br i1 %67, label %72, label %68
68: ; preds = %59
%69 = load i32, i32* @errno
%70 = load i32, i32* @EINVAL
%71 = icmp ne i32 %69, %70
br i1 %71, label %72, label %79
72: ; preds = %68, %59
%73 = load i32, i32* @errno
%74 = load i32, i32* @errno
%75 = call i8* @strerror(i32 %74)
%76 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.10, i64 0, i64 0), i32 %73, i8* %75)
%77 = load i32*, i32** %2
%78 = call i32 @fclose(i32* %77)
store i32 0, i32* %1
br label %282
79: ; preds = %68
%80 = call i32 @puts(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.11, i64 0, i64 0))
%81 = load i32, i32* %3
%82 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %4, i64 0, i64 0
%83 = call i32 @readv(i32 %81, %struct.iovec* %82, i32 -100)
store i32 %83, i32* %5
%84 = load i32, i32* %5
%85 = icmp ne i32 %84, -1
br i1 %85, label %90, label %86
86: ; preds = %79
%87 = load i32, i32* @errno
%88 = load i32, i32* @EINVAL
%89 = icmp ne i32 %87, %88
br i1 %89, label %90, label %97
90: ; preds = %86, %79
%91 = load i32, i32* @errno
%92 = load i32, i32* @errno
%93 = call i8* @strerror(i32 %92)
%94 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.12, i64 0, i64 0), i32 %91, i8* %93)
%95 = load i32*, i32** %2
%96 = call i32 @fclose(i32* %95)
store i32 0, i32* %1
br label %282
97: ; preds = %86
%98 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %4, i64 0, i64 0
%99 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %4, i64 0, i64 0
%100 = getelementptr inbounds %struct.iovec, %struct.iovec* %99, i32 0, i32 1
store %struct.iovec* %98, %struct.iovec** %100
%101 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %4, i64 0, i64 0
%102 = getelementptr inbounds %struct.iovec, %struct.iovec* %101, i32 0, i32 0
store i32 100, i32* %102
%103 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %4, i64 0, i64 0
%104 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %4, i64 0, i64 1
%105 = getelementptr inbounds %struct.iovec, %struct.iovec* %104, i32 0, i32 1
store %struct.iovec* %103, %struct.iovec** %105
%106 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %4, i64 0, i64 1
%107 = getelementptr inbounds %struct.iovec, %struct.iovec* %106, i32 0, i32 0
store i32 -10, i32* %107
%108 = call i32 @puts(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.13, i64 0, i64 0))
%109 = load i32, i32* %3
%110 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %4, i64 0, i64 0
%111 = call i32 @writev(i32 %109, %struct.iovec* %110, i32 2)
store i32 %111, i32* %5
%112 = load i32, i32* %5
%113 = icmp ne i32 %112, -1
br i1 %113, label %118, label %114
114: ; preds = %97
%115 = load i32, i32* @errno
%116 = load i32, i32* @EINVAL
%117 = icmp ne i32 %115, %116
br i1 %117, label %118, label %125
118: ; preds = %114, %97
%119 = load i32, i32* @errno
%120 = load i32, i32* @errno
%121 = call i8* @strerror(i32 %120)
%122 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.14, i64 0, i64 0), i32 %119, i8* %121)
%123 = load i32*, i32** %2
%124 = call i32 @fclose(i32* %123)
store i32 0, i32* %1
br label %282
125: ; preds = %114
%126 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %4, i64 0, i64 0
%127 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %4, i64 0, i64 0
%128 = getelementptr inbounds %struct.iovec, %struct.iovec* %127, i32 0, i32 1
store %struct.iovec* %126, %struct.iovec** %128
%129 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %4, i64 0, i64 0
%130 = getelementptr inbounds %struct.iovec, %struct.iovec* %129, i32 0, i32 0
store i32 100, i32* %130
%131 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %4, i64 0, i64 0
%132 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %4, i64 0, i64 1
%133 = getelementptr inbounds %struct.iovec, %struct.iovec* %132, i32 0, i32 1
store %struct.iovec* %131, %struct.iovec** %133
%134 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %4, i64 0, i64 1
%135 = getelementptr inbounds %struct.iovec, %struct.iovec* %134, i32 0, i32 0
store i32 -1024, i32* %135
%136 = call i32 @puts(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.15, i64 0, i64 0))
%137 = load i32, i32* %3
%138 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %4, i64 0, i64 0
%139 = call i32 @readv(i32 %137, %struct.iovec* %138, i32 2)
store i32 %139, i32* %5
%140 = load i32, i32* %5
%141 = icmp ne i32 %140, -1
br i1 %141, label %146, label %142
142: ; preds = %125
%143 = load i32, i32* @errno
%144 = load i32, i32* @EINVAL
%145 = icmp ne i32 %143, %144
br i1 %145, label %146, label %153
146: ; preds = %142, %125
%147 = load i32, i32* @errno
%148 = load i32, i32* @errno
%149 = call i8* @strerror(i32 %148)
%150 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.16, i64 0, i64 0), i32 %147, i8* %149)
%151 = load i32*, i32** %2
%152 = call i32 @fclose(i32* %151)
store i32 0, i32* %1
br label %282
153: ; preds = %142
%154 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %4, i64 0, i64 0
%155 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %4, i64 0, i64 0
%156 = getelementptr inbounds %struct.iovec, %struct.iovec* %155, i32 0, i32 1
store %struct.iovec* %154, %struct.iovec** %156
%157 = load i8*, i8** @SIZE_MAX
%158 = ptrtoint i8* %157 to i32
%159 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %4, i64 0, i64 0
%160 = getelementptr inbounds %struct.iovec, %struct.iovec* %159, i32 0, i32 0
store i32 %158, i32* %160
%161 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %4, i64 0, i64 0
%162 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %4, i64 0, i64 1
%163 = getelementptr inbounds %struct.iovec, %struct.iovec* %162, i32 0, i32 1
store %struct.iovec* %161, %struct.iovec** %163
%164 = load i8*, i8** @SIZE_MAX
%165 = ptrtoint i8* %164 to i32
%166 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %4, i64 0, i64 1
%167 = getelementptr inbounds %struct.iovec, %struct.iovec* %166, i32 0, i32 0
store i32 %165, i32* %167
%168 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %4, i64 0, i64 0
%169 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %4, i64 0, i64 2
%170 = getelementptr inbounds %struct.iovec, %struct.iovec* %169, i32 0, i32 1
store %struct.iovec* %168, %struct.iovec** %170
%171 = load i8*, i8** @SIZE_MAX
%172 = ptrtoint i8* %171 to i32
%173 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %4, i64 0, i64 2
%174 = getelementptr inbounds %struct.iovec, %struct.iovec* %173, i32 0, i32 0
store i32 %172, i32* %174
%175 = call i32 @puts(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.17, i64 0, i64 0))
%176 = load i32, i32* %3
%177 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %4, i64 0, i64 0
%178 = call i32 @writev(i32 %176, %struct.iovec* %177, i32 3)
store i32 %178, i32* %5
%179 = load i32, i32* %5
%180 = icmp ne i32 %179, -1
br i1 %180, label %185, label %181
181: ; preds = %153
%182 = load i32, i32* @errno
%183 = load i32, i32* @EINVAL
%184 = icmp ne i32 %182, %183
br i1 %184, label %185, label %193
185: ; preds = %181, %153
%186 = load i32, i32* %5
%187 = load i32, i32* @errno
%188 = load i32, i32* @errno
%189 = call i8* @strerror(i32 %188)
%190 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.18, i64 0, i64 0), i32 %186, i32 %187, i8* %189)
%191 = load i32*, i32** %2
%192 = call i32 @fclose(i32* %191)
store i32 0, i32* %1
br label %282
193: ; preds = %181
%194 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %4, i64 0, i64 0
%195 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %4, i64 0, i64 0
%196 = getelementptr inbounds %struct.iovec, %struct.iovec* %195, i32 0, i32 1
store %struct.iovec* %194, %struct.iovec** %196
%197 = load i8*, i8** @SIZE_MAX
%198 = ptrtoint i8* %197 to i32
%199 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %4, i64 0, i64 0
%200 = getelementptr inbounds %struct.iovec, %struct.iovec* %199, i32 0, i32 0
store i32 %198, i32* %200
%201 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %4, i64 0, i64 0
%202 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %4, i64 0, i64 1
%203 = getelementptr inbounds %struct.iovec, %struct.iovec* %202, i32 0, i32 1
store %struct.iovec* %201, %struct.iovec** %203
%204 = load i8*, i8** @SIZE_MAX
%205 = ptrtoint i8* %204 to i32
%206 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %4, i64 0, i64 1
%207 = getelementptr inbounds %struct.iovec, %struct.iovec* %206, i32 0, i32 0
store i32 %205, i32* %207
%208 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %4, i64 0, i64 0
%209 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %4, i64 0, i64 2
%210 = getelementptr inbounds %struct.iovec, %struct.iovec* %209, i32 0, i32 1
store %struct.iovec* %208, %struct.iovec** %210
%211 = load i8*, i8** @SIZE_MAX
%212 = ptrtoint i8* %211 to i32
%213 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %4, i64 0, i64 2
%214 = getelementptr inbounds %struct.iovec, %struct.iovec* %213, i32 0, i32 0
store i32 %212, i32* %214
%215 = call i32 @puts(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.19, i64 0, i64 0))
%216 = load i32, i32* %3
%217 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %4, i64 0, i64 0
%218 = call i32 @readv(i32 %216, %struct.iovec* %217, i32 3)
store i32 %218, i32* %5
%219 = load i32, i32* %5
%220 = icmp ne i32 %219, -1
br i1 %220, label %225, label %221
221: ; preds = %193
%222 = load i32, i32* @errno
%223 = load i32, i32* @EINVAL
%224 = icmp ne i32 %222, %223
br i1 %224, label %225, label %233
225: ; preds = %221, %193
%226 = load i32, i32* %5
%227 = load i32, i32* @errno
%228 = load i32, i32* @errno
%229 = call i8* @strerror(i32 %228)
%230 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.20, i64 0, i64 0), i32 %226, i32 %227, i8* %229)
%231 = load i32*, i32** %2
%232 = call i32 @fclose(i32* %231)
store i32 0, i32* %1
br label %282
233: ; preds = %221
%234 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %4, i64 0, i64 0
%235 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %4, i64 0, i64 0
%236 = getelementptr inbounds %struct.iovec, %struct.iovec* %235, i32 0, i32 1
store %struct.iovec* %234, %struct.iovec** %236
%237 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %4, i64 0, i64 0
%238 = getelementptr inbounds %struct.iovec, %struct.iovec* %237, i32 0, i32 0
store i32 0, i32* %238
%239 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %4, i64 0, i64 1
%240 = getelementptr inbounds %struct.iovec, %struct.iovec* %239, i32 0, i32 1
store %struct.iovec* null, %struct.iovec** %240
%241 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %4, i64 0, i64 1
%242 = getelementptr inbounds %struct.iovec, %struct.iovec* %241, i32 0, i32 0
store i32 0, i32* %242
%243 = call i32 @puts(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.21, i64 0, i64 0))
%244 = load i32, i32* %3
%245 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %4, i64 0, i64 0
%246 = call i32 @writev(i32 %244, %struct.iovec* %245, i32 2)
store i32 %246, i32* %5
%247 = load i32, i32* %5
%248 = icmp ne i32 %247, 0
br i1 %248, label %249, label %256
249: ; preds = %233
%250 = load i32, i32* @errno
%251 = load i32, i32* @errno
%252 = call i8* @strerror(i32 %251)
%253 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.22, i64 0, i64 0), i32 %250, i8* %252)
%254 = load i32*, i32** %2
%255 = call i32 @fclose(i32* %254)
store i32 0, i32* %1
br label %282
256: ; preds = %233
%257 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %4, i64 0, i64 0
%258 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %4, i64 0, i64 0
%259 = getelementptr inbounds %struct.iovec, %struct.iovec* %258, i32 0, i32 1
store %struct.iovec* %257, %struct.iovec** %259
%260 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %4, i64 0, i64 0
%261 = getelementptr inbounds %struct.iovec, %struct.iovec* %260, i32 0, i32 0
store i32 0, i32* %261
%262 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %4, i64 0, i64 1
%263 = getelementptr inbounds %struct.iovec, %struct.iovec* %262, i32 0, i32 1
store %struct.iovec* null, %struct.iovec** %263
%264 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %4, i64 0, i64 1
%265 = getelementptr inbounds %struct.iovec, %struct.iovec* %264, i32 0, i32 0
store i32 0, i32* %265
%266 = call i32 @puts(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.23, i64 0, i64 0))
%267 = load i32, i32* %3
%268 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %4, i64 0, i64 0
%269 = call i32 @readv(i32 %267, %struct.iovec* %268, i32 2)
store i32 %269, i32* %5
%270 = load i32, i32* %5
%271 = icmp ne i32 %270, 0
br i1 %271, label %272, label %279
272: ; preds = %256
%273 = load i32, i32* @errno
%274 = load i32, i32* @errno
%275 = call i8* @strerror(i32 %274)
%276 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.24, i64 0, i64 0), i32 %273, i8* %275)
%277 = load i32*, i32** %2
%278 = call i32 @fclose(i32* %277)
store i32 0, i32* %1
br label %282
279: ; preds = %256
%280 = load i32*, i32** %2
%281 = call i32 @fclose(i32* %280)
store i32 1, i32* %1
br label %282
282: ; preds = %279, %272, %249, %225, %185, %146, %118, %90, %72, %54, %45, %29, %9
%283 = load i32, i32* %1
ret i32 %283
}

LLVM IR (-O2):
%struct.iovec = type { i32, %struct.iovec* }
@.str = [14 x i8] c"testfile1.tst\00"
@.str.1 = [3 x i8] c"wt\00"
@.str.2 = [26 x i8] c"fopen for error 1: %d=%s\0A\00"
@errno = global i32 0
@.str.3 = [36 x i8] c"writev bad file descriptor -- EBADF\00"
@EBADF = global i32 0
@.str.4 = [23 x i8] c"writev error 1: %d=%s\0A\00"
@.str.5 = [35 x i8] c"readv bad file descriptor -- EBADF\00"
@.str.6 = [22 x i8] c"readv error 1: %d=%s\0A\00"
@.str.7 = [3 x i8] c"w+\00"
@.str.8 = [26 x i8] c"fopen for error 2: %d=%s\0A\00"
@.str.9 = [37 x i8] c"writev bad iovcnt negative -- EINVAL\00"
@EINVAL = global i32 0
@.str.10 = [23 x i8] c"writev error 4: %d=%s\0A\00"
@.str.11 = [36 x i8] c"readv bad iovcnt negative -- EINVAL\00"
@.str.12 = [22 x i8] c"readv error 4: %d=%s\0A\00"
@.str.13 = [40 x i8] c"writev bad iov[i].iov_len < 0 -- EINVAL\00"
@.str.14 = [23 x i8] c"writev error 6: %d=%s\0A\00"
@.str.15 = [39 x i8] c"readv bad iov[i].iov_len < 0 -- EINVAL\00"
@.str.16 = [22 x i8] c"readv error 6: %d=%s\0A\00"
@SIZE_MAX = global i8* null
@.str.17 = [41 x i8] c"writev iov_len total overflows -- EINVAL\00"
@.str.18 = [29 x i8] c"writev error 7: rc=%d %d=%s\0A\00"
@.str.19 = [40 x i8] c"readv iov_len total overflows -- EINVAL\00"
@.str.20 = [27 x i8] c"read error 7: rc=%d %d=%s\0A\00"
@.str.21 = [42 x i8] c"writev iov_len works with no effect -- OK\00"
@.str.22 = [23 x i8] c"writev error 8: %d=%s\0A\00"
@.str.23 = [41 x i8] c"readv iov_len works with no effect -- OK\00"
@.str.24 = [22 x i8] c"readv error 8: %d=%s\0A\00"
define i32 @doErrorTest() {
%1 = alloca [4 x %struct.iovec]
%2 = bitcast [4 x %struct.iovec]* %1 to i8*
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %9
5: ; preds = %0
%6 = load i32, i32* @errno
%7 = tail call i8* @strerror(i32 %6)
%8 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %6, i8* %7)
br label %146
9: ; preds = %0
%10 = tail call i32 @fileno(i32* %3)
%11 = tail call i32 @fclose(i32* %3)
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
%13 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %1, i64 0, i64 0
%14 = call i32 @writev(i32 %10, %struct.iovec* %13, i32 4)
%15 = icmp eq i32 %14, -1
%16 = load i32, i32* @errno
%17 = load i32, i32* @EBADF
%18 = icmp eq i32 %16, %17
%19 = select i1 %15, i1 %18, i1 false
br i1 %19, label %23, label %20
20: ; preds = %9
%21 = call i8* @strerror(i32 %16)
%22 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %16, i8* %21)
br label %146
23: ; preds = %9
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0))
%25 = call i32 @read(i32 %10, %struct.iovec* %13, i32 4)
%26 = icmp eq i32 %25, -1
%27 = load i32, i32* @errno
%28 = load i32, i32* @EBADF
%29 = icmp eq i32 %27, %28
%30 = select i1 %26, i1 %29, i1 false
br i1 %30, label %34, label %31
31: ; preds = %23
%32 = call i8* @strerror(i32 %27)
%33 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i32 %27, i8* %32)
br label %146
34: ; preds = %23
%35 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%36 = icmp eq i32* %35, null
br i1 %36, label %37, label %41
37: ; preds = %34
%38 = load i32, i32* @errno
%39 = call i8* @strerror(i32 %38)
%40 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0), i32 %38, i8* %39)
br label %146
41: ; preds = %34
%42 = call i32 @fileno(i32* %35)
%43 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.9, i64 0, i64 0))
%44 = call i32 @writev(i32 %42, %struct.iovec* %13, i32 -2)
%45 = icmp eq i32 %44, -1
%46 = load i32, i32* @errno
%47 = load i32, i32* @EINVAL
%48 = icmp eq i32 %46, %47
%49 = select i1 %45, i1 %48, i1 false
br i1 %49, label %54, label %50
50: ; preds = %41
%51 = call i8* @strerror(i32 %46)
%52 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.10, i64 0, i64 0), i32 %46, i8* %51)
%53 = call i32 @fclose(i32* %35)
br label %146
54: ; preds = %41
%55 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.11, i64 0, i64 0))
%56 = call i32 @readv(i32 %42, %struct.iovec* %13, i32 -100)
%57 = icmp eq i32 %56, -1
%58 = load i32, i32* @errno
%59 = load i32, i32* @EINVAL
%60 = icmp eq i32 %58, %59
%61 = select i1 %57, i1 %60, i1 false
br i1 %61, label %66, label %62
62: ; preds = %54
%63 = call i8* @strerror(i32 %58)
%64 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.12, i64 0, i64 0), i32 %58, i8* %63)
%65 = call i32 @fclose(i32* %35)
br label %146
66: ; preds = %54
%67 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %1, i64 0, i64 0, i32 1
store %struct.iovec* %13, %struct.iovec** %67
%68 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %1, i64 0, i64 0, i32 0
store i32 100, i32* %68
%69 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %1, i64 0, i64 1, i32 1
store %struct.iovec* %13, %struct.iovec** %69
%70 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %1, i64 0, i64 1, i32 0
store i32 -10, i32* %70
%71 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.13, i64 0, i64 0))
%72 = call i32 @writev(i32 %42, %struct.iovec* %13, i32 2)
%73 = icmp eq i32 %72, -1
%74 = load i32, i32* @errno
%75 = load i32, i32* @EINVAL
%76 = icmp eq i32 %74, %75
%77 = select i1 %73, i1 %76, i1 false
br i1 %77, label %82, label %78
78: ; preds = %66
%79 = call i8* @strerror(i32 %74)
%80 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.14, i64 0, i64 0), i32 %74, i8* %79)
%81 = call i32 @fclose(i32* %35)
br label %146
82: ; preds = %66
store %struct.iovec* %13, %struct.iovec** %67
store i32 100, i32* %68
store %struct.iovec* %13, %struct.iovec** %69
store i32 -1024, i32* %70
%83 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.15, i64 0, i64 0))
%84 = call i32 @readv(i32 %42, %struct.iovec* %13, i32 2)
%85 = icmp eq i32 %84, -1
%86 = load i32, i32* @errno
%87 = load i32, i32* @EINVAL
%88 = icmp eq i32 %86, %87
%89 = select i1 %85, i1 %88, i1 false
br i1 %89, label %94, label %90
90: ; preds = %82
%91 = call i8* @strerror(i32 %86)
%92 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.16, i64 0, i64 0), i32 %86, i8* %91)
%93 = call i32 @fclose(i32* %35)
br label %146
94: ; preds = %82
store %struct.iovec* %13, %struct.iovec** %67
%95 = load i8*, i8** @SIZE_MAX
%96 = ptrtoint i8* %95 to i64
%97 = trunc i64 %96 to i32
store i32 %97, i32* %68
store %struct.iovec* %13, %struct.iovec** %69
store i32 %97, i32* %70
%98 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %1, i64 0, i64 2, i32 1
store %struct.iovec* %13, %struct.iovec** %98
%99 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %1, i64 0, i64 2, i32 0
store i32 %97, i32* %99
%100 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.17, i64 0, i64 0))
%101 = call i32 @writev(i32 %42, %struct.iovec* %13, i32 3)
%102 = icmp eq i32 %101, -1
%103 = load i32, i32* @errno
%104 = load i32, i32* @EINVAL
%105 = icmp eq i32 %103, %104
%106 = select i1 %102, i1 %105, i1 false
br i1 %106, label %111, label %107
107: ; preds = %94
%108 = call i8* @strerror(i32 %103)
%109 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.18, i64 0, i64 0), i32 %101, i32 %103, i8* %108)
%110 = call i32 @fclose(i32* %35)
br label %146
111: ; preds = %94
store %struct.iovec* %13, %struct.iovec** %67
%112 = load i8*, i8** @SIZE_MAX
%113 = ptrtoint i8* %112 to i64
%114 = trunc i64 %113 to i32
store i32 %114, i32* %68
store %struct.iovec* %13, %struct.iovec** %69
store i32 %114, i32* %70
store %struct.iovec* %13, %struct.iovec** %98
store i32 %114, i32* %99
%115 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.19, i64 0, i64 0))
%116 = call i32 @readv(i32 %42, %struct.iovec* %13, i32 3)
%117 = icmp eq i32 %116, -1
%118 = load i32, i32* @errno
%119 = load i32, i32* @EINVAL
%120 = icmp eq i32 %118, %119
%121 = select i1 %117, i1 %120, i1 false
br i1 %121, label %126, label %122
122: ; preds = %111
%123 = call i8* @strerror(i32 %118)
%124 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.20, i64 0, i64 0), i32 %116, i32 %118, i8* %123)
%125 = call i32 @fclose(i32* %35)
br label %146
126: ; preds = %111
store %struct.iovec* %13, %struct.iovec** %67
store i32 0, i32* %68
store %struct.iovec* null, %struct.iovec** %69
store i32 0, i32* %70
%127 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.21, i64 0, i64 0))
%128 = call i32 @writev(i32 %42, %struct.iovec* %13, i32 2)
%129 = icmp eq i32 %128, 0
br i1 %129, label %135, label %130
130: ; preds = %126
%131 = load i32, i32* @errno
%132 = call i8* @strerror(i32 %131)
%133 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.22, i64 0, i64 0), i32 %131, i8* %132)
%134 = call i32 @fclose(i32* %35)
br label %146
135: ; preds = %126
store %struct.iovec* %13, %struct.iovec** %67
store i32 0, i32* %68
store %struct.iovec* null, %struct.iovec** %69
store i32 0, i32* %70
%136 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.23, i64 0, i64 0))
%137 = call i32 @readv(i32 %42, %struct.iovec* %13, i32 2)
%138 = icmp eq i32 %137, 0
br i1 %138, label %144, label %139
139: ; preds = %135
%140 = load i32, i32* @errno
%141 = call i8* @strerror(i32 %140)
%142 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.24, i64 0, i64 0), i32 %140, i8* %141)
%143 = call i32 @fclose(i32* %35)
br label %146
144: ; preds = %135
%145 = call i32 @fclose(i32* %35)
br label %146
146: ; preds = %144, %139, %130, %122, %107, %90, %78, %62, %50, %37, %31, %20, %5
%147 = phi i32 [ 0, %5 ], [ 0, %20 ], [ 0, %31 ], [ 0, %37 ], [ 0, %50 ], [ 0, %62 ], [ 0, %78 ], [ 0, %90 ], [ 0, %107 ], [ 0, %122 ], [ 0, %130 ], [ 0, %139 ], [ 1, %144 ]
ret i32 %147
}